-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpstats.go
66 lines (56 loc) · 1.86 KB
/
pstats.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
57
58
59
60
61
62
63
64
65
66
// Package procstats attempts to provide process stats for a given PID.
package procstats
import (
"errors"
"time"
)
// ErrUnimplementedPlatform indicates that this request is not implemented for
// this specific platform.
var ErrUnimplementedPlatform = errors.New("unimplemented for this platform")
// RSS takes a pid and returns the RSS of that process (or an error)
// This may return ErrUnimplementedPlatform on non-linux and non-darwin platforms.
func RSS(pid int) (int64, error) {
return readProcessRSS(pid)
}
// CPUTime contains the user and system time consumed by a process.
type CPUTime struct {
Utime time.Duration
Stime time.Duration
}
// Sub subtracts the operand from the receiver, returning a new CPUTime object.
func (c *CPUTime) Sub(other *CPUTime) CPUTime {
return CPUTime{
Utime: c.Utime - other.Utime,
Stime: c.Stime - other.Stime,
}
}
// Add subtracts the operand from the receiver, returning a new CPUTime object.
func (c *CPUTime) Add(other *CPUTime) CPUTime {
return CPUTime{
Utime: c.Utime + other.Utime,
Stime: c.Stime + other.Stime,
}
}
// ProcessCPUTime returns either the cumulative CPUTime of the specified
// process or an error.
// This is a portable wrapper around platform-specific functions.
func ProcessCPUTime(pid int) (CPUTime, error) {
return readProcessCPUTime(pid)
}
// eq reports if the two CPUTimes are equal.
func (c *CPUTime) eq(b *CPUTime) bool {
return c.Utime == b.Utime &&
c.Stime == b.Stime
}
// MaxRSS returns the maximum RSS (High Water Mark) of the process with PID
// pid.
// This is a portable wrapper around platform-specific functions.
func MaxRSS(pid int) (int64, error) {
return readMaxRSS(pid)
}
// ResetMaxRSS returns the maximum RSS (High Water Mark) of the process with PID
// pid.
// This is a portable wrapper around platform-specific functions.
func ResetMaxRSS(pid int) error {
return resetMaxRSS(pid)
}