diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-02-02 21:00:56 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-02 21:00:56 +0000 |
commit | 33d705db793eee0fe24f4a8a187fec65305957f7 (patch) | |
tree | 17bdcf658abd6497a9decc63ab48e1a5cc810e19 /pkg/sentry/control/proc.go | |
parent | 5011c8943e1048c3b34b9dc11a888ee3c8d42302 (diff) | |
parent | 5f7bf3152652d36903f9659688321ae7c42995d0 (diff) |
Merge release-20210125.0-62-g5f7bf3152 (automated)
Diffstat (limited to 'pkg/sentry/control/proc.go')
-rw-r--r-- | pkg/sentry/control/proc.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pkg/sentry/control/proc.go b/pkg/sentry/control/proc.go index 1d88db12f..de7a0f3ab 100644 --- a/pkg/sentry/control/proc.go +++ b/pkg/sentry/control/proc.go @@ -404,3 +404,16 @@ func ttyName(tty *kernel.TTY) string { } return fmt.Sprintf("pts/%d", tty.Index) } + +// ContainerUsage retrieves per-container CPU usage. +func ContainerUsage(kr *kernel.Kernel) map[string]uint64 { + cusage := make(map[string]uint64) + for _, tg := range kr.TaskSet().Root.ThreadGroups() { + // We want each tg's usage including reaped children. + cid := tg.Leader().ContainerID() + stats := tg.CPUStats() + stats.Accumulate(tg.JoinedChildCPUStats()) + cusage[cid] += uint64(stats.UserTime.Nanoseconds()) + uint64(stats.SysTime.Nanoseconds()) + } + return cusage +} |