expose exec-id on ctr task ps

Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
This commit is contained in:
Jess Valarezo 2017-11-03 14:49:47 -07:00
parent b4a65de5c6
commit 807f4d2ec7
12 changed files with 319 additions and 102 deletions

View File

@ -6,7 +6,7 @@ import (
"text/tabwriter" "text/tabwriter"
"github.com/containerd/containerd/cmd/ctr/commands" "github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/windows/hcsshimtypes" "github.com/containerd/typeurl"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -29,7 +29,6 @@ var psCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
task, err := container.Task(ctx, nil) task, err := container.Task(ctx, nil)
if err != nil { if err != nil {
return err return err
@ -38,21 +37,19 @@ var psCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0) w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
fmt.Fprintln(w, "PID\tINFO") fmt.Fprintln(w, "PID\tINFO")
for _, ps := range processes { for _, ps := range processes {
var info interface{} = "-"
if ps.Info != nil { if ps.Info != nil {
var details hcsshimtypes.ProcessDetails info, err = typeurl.UnmarshalAny(ps.Info)
if err := details.Unmarshal(ps.Info.Value); err == nil { if err != nil {
if _, err := fmt.Fprintf(w, "%d\t%+v\n", ps.Pid, details); err != nil {
return err
}
}
} else {
if _, err := fmt.Fprintf(w, "%d\t-\n", ps.Pid); err != nil {
return err return err
} }
} }
if _, err := fmt.Fprintf(w, "%d\t%+v\n", ps.Pid, info); err != nil {
return err
}
} }
return w.Flush() return w.Flush()
}, },

View File

@ -165,6 +165,16 @@ file {
json_name: "cgroupsMode" json_name: "cgroupsMode"
} }
} }
message_type {
name: "ProcessDetails"
field {
name: "exec_id"
number: 1
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "execId"
}
}
options { options {
go_package: "github.com/containerd/containerd/linux/runcopts;runcopts" go_package: "github.com/containerd/containerd/linux/runcopts;runcopts"
} }

View File

@ -11,6 +11,7 @@
RuncOptions RuncOptions
CreateOptions CreateOptions
CheckpointOptions CheckpointOptions
ProcessDetails
*/ */
package runcopts package runcopts
@ -78,10 +79,19 @@ func (m *CheckpointOptions) Reset() { *m = CheckpointOptions{
func (*CheckpointOptions) ProtoMessage() {} func (*CheckpointOptions) ProtoMessage() {}
func (*CheckpointOptions) Descriptor() ([]byte, []int) { return fileDescriptorRunc, []int{2} } func (*CheckpointOptions) Descriptor() ([]byte, []int) { return fileDescriptorRunc, []int{2} }
type ProcessDetails struct {
ExecID string `protobuf:"bytes,1,opt,name=exec_id,json=execId,proto3" json:"exec_id,omitempty"`
}
func (m *ProcessDetails) Reset() { *m = ProcessDetails{} }
func (*ProcessDetails) ProtoMessage() {}
func (*ProcessDetails) Descriptor() ([]byte, []int) { return fileDescriptorRunc, []int{3} }
func init() { func init() {
proto.RegisterType((*RuncOptions)(nil), "containerd.linux.runc.RuncOptions") proto.RegisterType((*RuncOptions)(nil), "containerd.linux.runc.RuncOptions")
proto.RegisterType((*CreateOptions)(nil), "containerd.linux.runc.CreateOptions") proto.RegisterType((*CreateOptions)(nil), "containerd.linux.runc.CreateOptions")
proto.RegisterType((*CheckpointOptions)(nil), "containerd.linux.runc.CheckpointOptions") proto.RegisterType((*CheckpointOptions)(nil), "containerd.linux.runc.CheckpointOptions")
proto.RegisterType((*ProcessDetails)(nil), "containerd.linux.runc.ProcessDetails")
} }
func (m *RuncOptions) Marshal() (dAtA []byte, err error) { func (m *RuncOptions) Marshal() (dAtA []byte, err error) {
size := m.Size() size := m.Size()
@ -333,6 +343,30 @@ func (m *CheckpointOptions) MarshalTo(dAtA []byte) (int, error) {
return i, nil return i, nil
} }
func (m *ProcessDetails) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ProcessDetails) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if len(m.ExecID) > 0 {
dAtA[i] = 0xa
i++
i = encodeVarintRunc(dAtA, i, uint64(len(m.ExecID)))
i += copy(dAtA[i:], m.ExecID)
}
return i, nil
}
func encodeVarintRunc(dAtA []byte, offset int, v uint64) int { func encodeVarintRunc(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 { for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80) dAtA[offset] = uint8(v&0x7f | 0x80)
@ -438,6 +472,16 @@ func (m *CheckpointOptions) Size() (n int) {
return n return n
} }
func (m *ProcessDetails) Size() (n int) {
var l int
_ = l
l = len(m.ExecID)
if l > 0 {
n += 1 + l + sovRunc(uint64(l))
}
return n
}
func sovRunc(x uint64) (n int) { func sovRunc(x uint64) (n int) {
for { for {
n++ n++
@ -500,6 +544,16 @@ func (this *CheckpointOptions) String() string {
}, "") }, "")
return s return s
} }
func (this *ProcessDetails) String() string {
if this == nil {
return "nil"
}
s := strings.Join([]string{`&ProcessDetails{`,
`ExecID:` + fmt.Sprintf("%v", this.ExecID) + `,`,
`}`,
}, "")
return s
}
func valueToStringRunc(v interface{}) string { func valueToStringRunc(v interface{}) string {
rv := reflect.ValueOf(v) rv := reflect.ValueOf(v)
if rv.IsNil() { if rv.IsNil() {
@ -1168,6 +1222,85 @@ func (m *CheckpointOptions) Unmarshal(dAtA []byte) error {
} }
return nil return nil
} }
func (m *ProcessDetails) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRunc
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ProcessDetails: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ProcessDetails: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ExecID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRunc
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthRunc
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ExecID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipRunc(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthRunc
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipRunc(dAtA []byte) (n int, err error) { func skipRunc(dAtA []byte) (n int, err error) {
l := len(dAtA) l := len(dAtA)
iNdEx := 0 iNdEx := 0
@ -1278,36 +1411,39 @@ func init() {
} }
var fileDescriptorRunc = []byte{ var fileDescriptorRunc = []byte{
// 495 bytes of a gzipped FileDescriptorProto // 536 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x93, 0x31, 0x6f, 0xd3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x93, 0xc1, 0x6e, 0xd3, 0x40,
0x14, 0xc7, 0x7b, 0xb4, 0x4d, 0x9c, 0x4b, 0x53, 0xe0, 0x20, 0xd2, 0x51, 0x84, 0x09, 0x11, 0x48, 0x10, 0x86, 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0xdb, 0x03, 0x00, 0x00, 0x41, 0xdc, 0x2a, 0xad, 0xc3, 0x74, 0x2f, 0xbe, 0xb8, 0xec, 0xaf, 0x7c, 0xbf, 0xec, 0xaf, 0x9c,
0x2f, 0xfb, 0xc1, 0xc5, 0xb2, 0x1f, 0x7c, 0x5b, 0xf6, 0x83, 0x9f, 0xcb, 0x7e, 0xf0, 0xe9, 0xf9,
0x3f, 0xde, 0xf3, 0xcb, 0x46, 0x9c, 0xb6, 0xfc, 0x9d, 0x3e, 0xfd, 0x1d, 0x00, 0x00, 0xff, 0xff,
0x15, 0x0d, 0x16, 0x1d, 0x12, 0x04, 0x00, 0x00,
} }

View File

@ -36,3 +36,7 @@ message CheckpointOptions {
repeated string empty_namespaces = 6; repeated string empty_namespaces = 6;
string cgroups_mode = 7; string cgroups_mode = 7;
} }
message ProcessDetails {
string exec_id = 1;
}

View File

@ -15,12 +15,14 @@ import (
"github.com/containerd/containerd/api/types/task" "github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events" "github.com/containerd/containerd/events"
"github.com/containerd/containerd/linux/runcopts"
shimapi "github.com/containerd/containerd/linux/shim/v1" shimapi "github.com/containerd/containerd/linux/shim/v1"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/reaper" "github.com/containerd/containerd/reaper"
"github.com/containerd/containerd/runtime" "github.com/containerd/containerd/runtime"
runc "github.com/containerd/go-runc" runc "github.com/containerd/go-runc"
"github.com/containerd/typeurl"
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -357,9 +359,23 @@ func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*sh
} }
var processes []*task.ProcessInfo var processes []*task.ProcessInfo
for _, pid := range pids { for _, pid := range pids {
processes = append(processes, &task.ProcessInfo{ pInfo := task.ProcessInfo{
Pid: pid, Pid: pid,
}) }
for _, p := range s.processes {
if p.Pid() == int(pid) {
d := &runcopts.ProcessDetails{
ExecID: p.ID(),
}
a, err := typeurl.MarshalAny(d)
if err != nil {
return nil, errors.Wrapf(err, "failed to marshal process %d info", pid)
}
pInfo.Info = a
break
}
}
processes = append(processes, &pInfo)
} }
return &shimapi.ListPidsResponse{ return &shimapi.ListPidsResponse{
Processes: processes, Processes: processes,

View File

@ -182,7 +182,8 @@ func (t *Task) Pids(ctx context.Context) ([]runtime.ProcessInfo, error) {
var processList []runtime.ProcessInfo var processList []runtime.ProcessInfo
for _, p := range resp.Processes { for _, p := range resp.Processes {
processList = append(processList, runtime.ProcessInfo{ processList = append(processList, runtime.ProcessInfo{
Pid: p.Pid, Pid: p.Pid,
Info: p.Info,
}) })
} }
return processList, nil return processList, nil

View File

@ -348,7 +348,7 @@ func (s *service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.Li
} }
var processes []*task.ProcessInfo var processes []*task.ProcessInfo
for _, p := range processList { for _, p := range processList {
processInfo := task.ProcessInfo{ pInfo := task.ProcessInfo{
Pid: p.Pid, Pid: p.Pid,
} }
if p.Info != nil { if p.Info != nil {
@ -356,9 +356,9 @@ func (s *service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.Li
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to marshal process %d info", p.Pid) return nil, errors.Wrapf(err, "failed to marshal process %d info", p.Pid)
} }
processInfo.Info = a pInfo.Info = a
} }
processes = append(processes, &processInfo) processes = append(processes, &pInfo)
} }
return &api.ListPidsResponse{ return &api.ListPidsResponse{
Processes: processes, Processes: processes,

View File

@ -60,6 +60,7 @@ type ProcessDetails struct {
MemoryWorkingSetSharedBytes uint64 `protobuf:"varint,6,opt,name=memory_working_set_shared_bytes,json=memoryWorkingSetSharedBytes,proto3" json:"memory_working_set_shared_bytes,omitempty"` MemoryWorkingSetSharedBytes uint64 `protobuf:"varint,6,opt,name=memory_working_set_shared_bytes,json=memoryWorkingSetSharedBytes,proto3" json:"memory_working_set_shared_bytes,omitempty"`
ProcessID uint32 `protobuf:"varint,7,opt,name=process_id,json=processId,proto3" json:"process_id,omitempty"` ProcessID uint32 `protobuf:"varint,7,opt,name=process_id,json=processId,proto3" json:"process_id,omitempty"`
UserTime_100Ns uint64 `protobuf:"varint,8,opt,name=user_time_100_ns,json=userTime100Ns,proto3" json:"user_time_100_ns,omitempty"` UserTime_100Ns uint64 `protobuf:"varint,8,opt,name=user_time_100_ns,json=userTime100Ns,proto3" json:"user_time_100_ns,omitempty"`
ExecID string `protobuf:"bytes,9,opt,name=exec_id,json=execId,proto3" json:"exec_id,omitempty"`
} }
func (m *ProcessDetails) Reset() { *m = ProcessDetails{} } func (m *ProcessDetails) Reset() { *m = ProcessDetails{} }
@ -155,6 +156,12 @@ func (m *ProcessDetails) MarshalTo(dAtA []byte) (int, error) {
i++ i++
i = encodeVarintHcsshim(dAtA, i, uint64(m.UserTime_100Ns)) i = encodeVarintHcsshim(dAtA, i, uint64(m.UserTime_100Ns))
} }
if len(m.ExecID) > 0 {
dAtA[i] = 0x4a
i++
i = encodeVarintHcsshim(dAtA, i, uint64(len(m.ExecID)))
i += copy(dAtA[i:], m.ExecID)
}
return i, nil return i, nil
} }
@ -202,6 +209,10 @@ func (m *ProcessDetails) Size() (n int) {
if m.UserTime_100Ns != 0 { if m.UserTime_100Ns != 0 {
n += 1 + sovHcsshim(uint64(m.UserTime_100Ns)) n += 1 + sovHcsshim(uint64(m.UserTime_100Ns))
} }
l = len(m.ExecID)
if l > 0 {
n += 1 + l + sovHcsshim(uint64(l))
}
return n return n
} }
@ -241,6 +252,7 @@ func (this *ProcessDetails) String() string {
`MemoryWorkingSetSharedBytes:` + fmt.Sprintf("%v", this.MemoryWorkingSetSharedBytes) + `,`, `MemoryWorkingSetSharedBytes:` + fmt.Sprintf("%v", this.MemoryWorkingSetSharedBytes) + `,`,
`ProcessID:` + fmt.Sprintf("%v", this.ProcessID) + `,`, `ProcessID:` + fmt.Sprintf("%v", this.ProcessID) + `,`,
`UserTime_100Ns:` + fmt.Sprintf("%v", this.UserTime_100Ns) + `,`, `UserTime_100Ns:` + fmt.Sprintf("%v", this.UserTime_100Ns) + `,`,
`ExecID:` + fmt.Sprintf("%v", this.ExecID) + `,`,
`}`, `}`,
}, "") }, "")
return s return s
@ -535,6 +547,35 @@ func (m *ProcessDetails) Unmarshal(dAtA []byte) error {
break break
} }
} }
case 9:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ExecID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowHcsshim
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthHcsshim
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ExecID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipHcsshim(dAtA[iNdEx:]) skippy, err := skipHcsshim(dAtA[iNdEx:])
@ -666,35 +707,37 @@ func init() {
} }
var fileDescriptorHcsshim = []byte{ var fileDescriptorHcsshim = []byte{
// 479 bytes of a gzipped FileDescriptorProto // 503 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x41, 0x6f, 0xd3, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x41, 0x6f, 0xd3, 0x30,
0x14, 0xc7, 0x1b, 0x36, 0xc6, 0x62, 0x54, 0x60, 0x86, 0x43, 0x28, 0x90, 0x54, 0xbb, 0x50, 0x09, 0x14, 0xc7, 0x1b, 0x36, 0xba, 0xc5, 0xa8, 0xc0, 0x0c, 0x87, 0x52, 0x20, 0xa9, 0xc6, 0x81, 0x4a,
0x94, 0x74, 0x70, 0xe4, 0x44, 0x5a, 0x21, 0xed, 0x32, 0xa6, 0x0c, 0x09, 0x09, 0x21, 0x59, 0x6e, 0xa0, 0xb4, 0x83, 0x23, 0x27, 0xd2, 0x82, 0xd4, 0xcb, 0x98, 0x32, 0x24, 0x24, 0x84, 0x64, 0xb9,
0xf2, 0x48, 0xad, 0xd5, 0x71, 0x64, 0xbb, 0x54, 0xbd, 0xf1, 0x11, 0x38, 0xf2, 0x49, 0xf8, 0x0c, 0xc9, 0x23, 0xb5, 0x56, 0xc7, 0x91, 0xed, 0xd2, 0xf5, 0xc6, 0x47, 0xe0, 0xc8, 0x47, 0xea, 0x91,
0x3d, 0x72, 0xe4, 0x34, 0x58, 0x3e, 0x09, 0x8a, 0xed, 0x96, 0x51, 0x38, 0x71, 0xf3, 0xf3, 0xff, 0x23, 0x12, 0x52, 0x61, 0xf9, 0x24, 0xc8, 0x76, 0xba, 0x8d, 0xc1, 0x89, 0x9b, 0xed, 0xff, 0xef,
0xf7, 0x7e, 0xaf, 0x7e, 0x0d, 0x1a, 0x95, 0x4c, 0x4f, 0xe7, 0x93, 0x38, 0x17, 0x3c, 0xc9, 0x45, 0xfd, 0x5e, 0xfc, 0xac, 0xa0, 0x61, 0xce, 0xf4, 0x74, 0x3e, 0x89, 0x52, 0xc1, 0xfb, 0xa9, 0x28,
0xa5, 0x29, 0xab, 0x40, 0x16, 0x57, 0x8f, 0x0b, 0x56, 0x15, 0x62, 0xa1, 0x92, 0x69, 0xae, 0xd4, 0x34, 0x65, 0x05, 0xc8, 0xec, 0xf2, 0x72, 0xc1, 0x8a, 0x4c, 0x2c, 0x54, 0x7f, 0x9a, 0x2a, 0x35,
0x94, 0x71, 0xbd, 0xac, 0x61,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, 0xed, 0x6b, 0x3f, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xff,
0xc7, 0x40, 0x0e, 0x61, 0x03, 0x00, 0x00,
} }

View File

@ -23,4 +23,5 @@ message ProcessDetails {
uint64 memory_working_set_shared_bytes = 6; uint64 memory_working_set_shared_bytes = 6;
uint32 process_id = 7; uint32 process_id = 7;
uint64 user_time_100_ns = 8; uint64 user_time_100_ns = 8;
string exec_id = 9;
} }

View File

@ -144,6 +144,13 @@ file {
type: TYPE_UINT64 type: TYPE_UINT64
json_name: "userTime100Ns" json_name: "userTime100Ns"
} }
field {
name: "exec_id"
number: 9
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "execId"
}
} }
options { options {
go_package: "github.com/containerd/containerd/windows/hcsshimtypes;hcsshimtypes" go_package: "github.com/containerd/containerd/windows/hcsshimtypes;hcsshimtypes"

View File

@ -99,6 +99,10 @@ func (p *process) Pid() uint32 {
return p.pid return p.pid
} }
func (p *process) HcsPid() uint32 {
return uint32(p.hcs.Pid())
}
func (p *process) ExitCode() (uint32, time.Time, error) { func (p *process) ExitCode() (uint32, time.Time, error) {
if s := p.Status(); s != runtime.StoppedStatus && s != runtime.CreatedStatus { if s := p.Status(); s != runtime.StoppedStatus && s != runtime.CreatedStatus {
return 255, time.Time{}, errors.Wrapf(errdefs.ErrFailedPrecondition, "process is not stopped: %s", s) return 255, time.Time{}, errors.Wrapf(errdefs.ErrFailedPrecondition, "process is not stopped: %s", s)

View File

@ -218,24 +218,36 @@ func (t *task) Pids(ctx context.Context) ([]runtime.ProcessInfo, error) {
t.Lock() t.Lock()
defer t.Unlock() defer t.Unlock()
var infoList []runtime.ProcessInfo var processList []runtime.ProcessInfo
hcsProcessList, err := t.hcsContainer.ProcessList() hcsProcessList, err := t.hcsContainer.ProcessList()
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, process := range hcsProcessList { for _, hcsProcess := range hcsProcessList {
info, err := t.convertToProcessDetails(process) info := &hcsshimtypes.ProcessDetails{
if err != nil { ImageName: hcsProcess.ImageName,
return nil, err CreatedAt: hcsProcess.CreateTimestamp,
KernelTime_100Ns: hcsProcess.KernelTime100ns,
MemoryCommitBytes: hcsProcess.MemoryCommitBytes,
MemoryWorkingSetPrivateBytes: hcsProcess.MemoryWorkingSetPrivateBytes,
MemoryWorkingSetSharedBytes: hcsProcess.MemoryWorkingSetSharedBytes,
ProcessID: hcsProcess.ProcessId,
UserTime_100Ns: hcsProcess.UserTime100ns,
} }
infoList = append(infoList, runtime.ProcessInfo{ for _, p := range t.processes {
Pid: process.ProcessId, if p.HcsPid() == hcsProcess.ProcessId {
info.ExecID = p.ID()
break
}
}
processList = append(processList, runtime.ProcessInfo{
Pid: hcsProcess.ProcessId,
Info: info, Info: info,
}) })
} }
return infoList, nil return processList, nil
} }
func (t *task) Checkpoint(_ context.Context, _ string, _ *types.Any) error { func (t *task) Checkpoint(_ context.Context, _ string, _ *types.Any) error {
@ -397,17 +409,3 @@ func (t *task) cleanup() {
removeLayer(context.Background(), t.rwLayer) removeLayer(context.Background(), t.rwLayer)
t.Unlock() t.Unlock()
} }
// convertToProcessDetails converts a given hcsshim ProcessListItem to proto ProcessDetails
func (t *task) convertToProcessDetails(p hcsshim.ProcessListItem) (*hcsshimtypes.ProcessDetails, error) {
return &hcsshimtypes.ProcessDetails{
ImageName: p.ImageName,
CreatedAt: p.CreateTimestamp,
KernelTime_100Ns: p.KernelTime100ns,
MemoryCommitBytes: p.MemoryCommitBytes,
MemoryWorkingSetPrivateBytes: p.MemoryWorkingSetPrivateBytes,
MemoryWorkingSetSharedBytes: p.MemoryWorkingSetSharedBytes,
ProcessID: p.ProcessId,
UserTime_100Ns: p.UserTime100ns,
}, nil
}