-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpages_stats.go
56 lines (46 loc) · 1.01 KB
/
pages_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package statgo
// #cgo LDFLAGS: -lstatgrab
// #include <statgrab.h>
import "C"
import (
"fmt"
"time"
)
// PageStats contains pages stats
type PageStats struct {
// The number of pages swapped into memory.
PageIn int
// The number of pages swapped out of memory (to swap).
PageOut int
// The time period over which pages_pagein and pages_pageout weretransferred.
Period time.Duration
TimeTaken time.Time
}
// PageStats get pages related stats
// Go equivalent to sg_get_page_stats_diff
func (s *Stat) PageStats() *PageStats {
s.Lock()
defer s.Unlock()
var p *PageStats
do(func() {
pstats := C.sg_get_page_stats_diff(nil)
p = &PageStats{
PageIn: int(pstats.pages_pagein),
PageOut: int(pstats.pages_pageout),
Period: time.Duration(int(pstats.systime)),
TimeTaken: time.Now(),
}
})
return p
}
func (p *PageStats) String() string {
return fmt.Sprintf(
"PageIn:\t%d\n"+
"PageOut:\t%d\n"+
"Period:\t%v\n"+
"TimeTaken:\t%s\n",
p.PageIn,
p.PageOut,
p.Period,
p.TimeTaken)
}