forked from DataDog/go-profiler-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv.go
69 lines (63 loc) · 1.5 KB
/
csv.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
67
68
69
package main
import (
"fmt"
"time"
)
type Record struct {
Blockprofilerate int
Bufsize int
Depth int
Duration time.Duration
Goroutines int
Ops int
Run int
Workload string
}
type Column struct {
Name string
MarshalValue func(*Record) (string, error)
}
var Columns = []Column{
{"workload", func(r *Record) (string, error) {
return fmt.Sprintf("%s", r.Workload), nil
}},
{"ops", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Ops), nil
}},
{"goroutines", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Goroutines), nil
}},
{"depth", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Depth), nil
}},
{"bufsize", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Bufsize), nil
}},
{"blockprofilerate", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Blockprofilerate), nil
}},
{"run", func(r *Record) (string, error) {
return fmt.Sprintf("%d", r.Run), nil
}},
{"ms", func(r *Record) (string, error) {
return fmt.Sprintf("%f", r.Duration.Seconds()*1000), nil
}},
}
func (r *Record) MarshalRecord() ([]string, error) {
record := make([]string, len(Columns))
for i, col := range Columns {
val, err := col.MarshalValue(r)
if err != nil {
return nil, err
}
record[i] = val
}
return record, nil
}
func Headers() []string {
headers := make([]string, len(Columns))
for i, col := range Columns {
headers[i] = col.Name
}
return headers
}