diff options
author | Zhaozhong Ni <nzz@google.com> | 2018-05-04 13:55:06 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-04 13:55:53 -0700 |
commit | 0ce9c81b416494e3c3da793c278dfc767341fa6d (patch) | |
tree | 90e2af4bac14167f57694b0457fb0dec3bc2f945 /pkg/sentry/state/state_metadata.go | |
parent | 7bb10dc7a0499e20a37291d6f5fd105e6ae6fdbf (diff) |
sentry: capture CPU usage metadata for save.
PiperOrigin-RevId: 195466647
Change-Id: Ib5ca815f7b64a4881441e58567adedf344b206f1
Diffstat (limited to 'pkg/sentry/state/state_metadata.go')
-rw-r--r-- | pkg/sentry/state/state_metadata.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/sentry/state/state_metadata.go b/pkg/sentry/state/state_metadata.go index ac374f428..b6d3dbcb4 100644 --- a/pkg/sentry/state/state_metadata.go +++ b/pkg/sentry/state/state_metadata.go @@ -17,13 +17,29 @@ package state import ( "fmt" "time" + + "gvisor.googlesource.com/gvisor/pkg/log" ) // The save metadata keys for timestamp. const ( + cpuUsage = "cpu_usage" metadataTimestamp = "timestamp" ) func addSaveMetadata(m map[string]string) { + t, err := cpuTime() + if err != nil { + log.Warningf("Error getting cpu time: %v", err) + } + if previousMetadata != nil { + p, err := time.ParseDuration(previousMetadata[cpuUsage]) + if err != nil { + log.Warningf("Error parsing previous runs' cpu time: %v", err) + } + t += p + } + m[cpuUsage] = t.String() + m[metadataTimestamp] = fmt.Sprintf("%v", time.Now()) } |