This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
graph.go
97 lines (87 loc) · 3.25 KB
/
graph.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"html/template"
"io"
"sync"
"time"
)
type graphPoints [2]float64
type Graph struct {
Title string
HeapUse, ScvgInuse, ScvgIdle []graphPoints
ScvgSys, ScvgReleased, ScvgConsumed []graphPoints
STWSclock []graphPoints
MASclock []graphPoints
STWMclock []graphPoints
STWScpu []graphPoints
MASAssistcpu []graphPoints
MASBGcpu []graphPoints
MASIdlecpu []graphPoints
STWMcpu []graphPoints
Tmpl *template.Template `json:"-"`
mu sync.RWMutex `json:"-"`
}
var StartTime = time.Now()
func NewGraph(title, tmpl string) Graph {
g := Graph{
Title: title,
HeapUse: []graphPoints{},
ScvgInuse: []graphPoints{},
ScvgIdle: []graphPoints{},
ScvgSys: []graphPoints{},
ScvgReleased: []graphPoints{},
ScvgConsumed: []graphPoints{},
STWSclock: []graphPoints{},
MASclock: []graphPoints{},
STWMclock: []graphPoints{},
STWScpu: []graphPoints{},
MASAssistcpu: []graphPoints{},
MASBGcpu: []graphPoints{},
MASIdlecpu: []graphPoints{},
STWMcpu: []graphPoints{},
}
g.setTmpl(tmpl)
return g
}
func (g *Graph) setTmpl(tmplStr string) {
g.Tmpl = template.Must(template.New("vis").Parse(tmplStr))
}
func (g *Graph) Write(w io.Writer) error {
g.mu.RLock()
defer g.mu.RUnlock()
return g.Tmpl.Execute(w, g)
}
func (g *Graph) AddGCTraceGraphPoint(gcTrace *gctrace) {
g.mu.RLock()
defer g.mu.RUnlock()
var elapsedTime float64
if gcTrace.ElapsedTime == 0 {
elapsedTime = time.Now().Sub(StartTime).Seconds()
} else {
elapsedTime = gcTrace.ElapsedTime
}
g.HeapUse = append(g.HeapUse, graphPoints{elapsedTime, float64(gcTrace.Heap1)})
g.STWSclock = append(g.STWSclock, graphPoints{elapsedTime, float64(gcTrace.STWSclock)})
g.MASclock = append(g.MASclock, graphPoints{elapsedTime, float64(gcTrace.MASclock)})
g.STWMclock = append(g.STWMclock, graphPoints{elapsedTime, float64(gcTrace.STWMclock)})
g.STWScpu = append(g.STWScpu, graphPoints{elapsedTime, float64(gcTrace.STWScpu)})
g.MASAssistcpu = append(g.MASAssistcpu, graphPoints{elapsedTime, float64(gcTrace.MASAssistcpu)})
g.MASBGcpu = append(g.MASBGcpu, graphPoints{elapsedTime, float64(gcTrace.MASBGcpu)})
g.MASIdlecpu = append(g.MASIdlecpu, graphPoints{elapsedTime, float64(gcTrace.MASIdlecpu)})
g.STWMcpu = append(g.STWMcpu, graphPoints{elapsedTime, float64(gcTrace.STWMcpu)})
}
func (g *Graph) AddScavengerGraphPoint(scvg *scvgtrace) {
g.mu.RLock()
defer g.mu.RUnlock()
var elapsedTime float64
if scvg.ElapsedTime == 0 {
elapsedTime = time.Now().Sub(StartTime).Seconds()
} else {
elapsedTime = scvg.ElapsedTime
}
g.ScvgInuse = append(g.ScvgInuse, graphPoints{elapsedTime, float64(scvg.inuse)})
g.ScvgIdle = append(g.ScvgIdle, graphPoints{elapsedTime, float64(scvg.idle)})
g.ScvgSys = append(g.ScvgSys, graphPoints{elapsedTime, float64(scvg.sys)})
g.ScvgReleased = append(g.ScvgReleased, graphPoints{elapsedTime, float64(scvg.released)})
g.ScvgConsumed = append(g.ScvgConsumed, graphPoints{elapsedTime, float64(scvg.consumed)})
}