-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathgoRoutinesProcessor.go
69 lines (55 loc) · 1.59 KB
/
goRoutinesProcessor.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 goroutine
import (
"bytes"
"strings"
"time"
"github.com/ElrondNetwork/elrond-go/debug"
)
const newRoutineMarker = "\n\n"
type goRoutinesProcessor struct {
}
// NewGoRoutinesProcessor creates a new GoRoutinesProcessor
func NewGoRoutinesProcessor() *goRoutinesProcessor {
return &goRoutinesProcessor{}
}
// ProcessGoRoutineBuffer processes a new go routine stack dump based on the previous data
func (grp *goRoutinesProcessor) ProcessGoRoutineBuffer(
previousData map[string]debug.GoRoutineHandlerMap,
buffer *bytes.Buffer,
) map[string]debug.GoRoutineHandlerMap {
allGoRoutinesString := buffer.String()
splits := strings.Split(allGoRoutinesString, newRoutineMarker)
oldGoRoutines := make(debug.GoRoutineHandlerMap)
newGoRoutines := make(debug.GoRoutineHandlerMap)
if previousData[oldRoutine] == nil {
previousData[oldRoutine] = make(debug.GoRoutineHandlerMap)
}
for k, val := range previousData[newRoutine] {
previousData[oldRoutine][k] = val
}
currentTime := time.Now()
for _, st := range splits {
gId := getGoroutineId(st)
if len(gId) == 0 {
continue
}
val, ok := previousData[oldRoutine][gId]
if !ok {
newGoRoutines[gId] = &goRoutineData{
id: gId,
firstOccurrence: currentTime,
stackTrace: st,
}
continue
}
oldGoRoutines[val.ID()] = val
}
latestData := make(map[string]debug.GoRoutineHandlerMap)
latestData[newRoutine] = newGoRoutines
latestData[oldRoutine] = oldGoRoutines
return latestData
}
// IsInterfaceNil checks if the interface is nil
func (grp *goRoutinesProcessor) IsInterfaceNil() bool {
return grp == nil
}