veyron/lib/stats/sysstats: add the pid to sysstats
To facillitate, the implementation of app process management, make it
possible to always determine the pid of an application from the debug
stats interface.
Change-Id: If4a078caef16c3cdfbf2c689d6eab0971a30a77f
diff --git a/lib/stats/sysstats/sysstats.go b/lib/stats/sysstats/sysstats.go
index 75c0c17..9579280 100644
--- a/lib/stats/sysstats/sysstats.go
+++ b/lib/stats/sysstats/sysstats.go
@@ -21,6 +21,7 @@
stats.NewInteger("system/num-cpu").Set(int64(runtime.NumCPU()))
stats.NewIntegerFunc("system/num-goroutine", func() int64 { return int64(runtime.NumGoroutine()) })
stats.NewString("system/version").Set(runtime.Version())
+ stats.NewInteger("system/pid").Set(int64(os.Getpid()))
if hostname, err := os.Hostname(); err == nil {
stats.NewString("system/hostname").Set(hostname)
}
diff --git a/lib/stats/sysstats/sysstats_test.go b/lib/stats/sysstats/sysstats_test.go
index ee2f835..d157b5e 100644
--- a/lib/stats/sysstats/sysstats_test.go
+++ b/lib/stats/sysstats/sysstats_test.go
@@ -31,3 +31,14 @@
t.Errorf("unexpected Alloc value. Got %v, want != 0", v)
}
}
+
+func TestPid(t *testing.T) {
+ obj, err := stats.GetStatsObject("system/pid")
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ expected := int64(os.Getpid())
+ if got := obj.Value(); got != expected {
+ t.Errorf("unexpected result. Got %q, want %q", got, expected)
+ }
+}