-
Notifications
You must be signed in to change notification settings - Fork 4
/
reporter.go
34 lines (30 loc) · 920 Bytes
/
reporter.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
package gomrjob
import (
"fmt"
"log"
"os"
"syscall"
"time"
)
// reporter:counter:<group>,<counter>,<amount>
func Counter(group string, counter string, amount int64) {
fmt.Fprintf(os.Stderr, "reporter:counter:%s,%s,%d\n", group, counter, amount)
os.Stderr.Sync()
}
// reporter:status:<message>
func Status(message string) {
fmt.Fprintf(os.Stderr, "reporter:status:%s\n", message)
os.Stderr.Sync()
}
func auditCpuTime(group string, prefix string) {
var u syscall.Rusage
err := syscall.Getrusage(syscall.RUSAGE_SELF, &u)
if err != nil {
log.Printf("error getting Rusage: %s", err)
return
}
userTime := time.Duration(u.Utime.Nano()) * time.Nanosecond
systemTime := time.Duration(u.Stime.Nano()) * time.Nanosecond
Counter(group, fmt.Sprintf("%s userTime (ms)", prefix), int64(userTime/time.Millisecond))
Counter(group, fmt.Sprintf("%s systemTime (ms)", prefix), int64(systemTime/time.Millisecond))
}