8 containertypes "github.com/docker/docker/api/types/container"
9 "github.com/docker/go-units"
12 // ContainerTop handles `docker top` client requests.
13 // Future considerations:
14 // -- Windows users are far more familiar with CPU% total.
15 // Further, users on Windows rarely see user/kernel CPU stats split.
16 // The kernel returns everything in terms of 100ns. To obtain
17 // CPU%, we could do something like docker stats does which takes two
18 // samples, subtract the difference and do the maths. Unfortunately this
19 // would slow the stat call down and require two kernel calls. So instead,
20 // we do something similar to linux and display the CPU as combined HH:MM:SS.mmm.
21 // -- Perhaps we could add an argument to display "raw" stats
22 // -- "Memory" is an extremely overloaded term in Windows. Hence we do what
23 // task manager does and use the private working set as the memory counter.
24 // We could return more info for those who really understand how memory
25 // management works in Windows if we introduced a "raw" stats (above).
26 func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.ContainerTopOKBody, error) {
27 // It's not at all an equivalent to linux 'ps' on Windows
29 return nil, errors.New("Windows does not support arguments to top")
32 container, err := daemon.GetContainer(name)
37 s, err := daemon.containerd.Summary(container.ID)
41 procList := &containertypes.ContainerTopOKBody{}
42 procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"}
45 d := time.Duration((j.KernelTime100ns + j.UserTime100ns) * 100) // Combined time in nanoseconds
46 procList.Processes = append(procList.Processes, []string{
48 fmt.Sprint(j.ProcessId),
49 fmt.Sprintf("%02d:%02d:%02d.%03d", int(d.Hours()), int(d.Minutes())%60, int(d.Seconds())%60, int(d.Nanoseconds()/1000000)%1000),
50 units.HumanSize(float64(j.MemoryWorkingSetPrivateBytes))})