-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracerutils.go
65 lines (52 loc) · 1.54 KB
/
tracerutils.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
package main
import (
"fmt"
"reflect"
"time"
"golang.org/x/net/context"
)
func (s *Server) clean(ctx context.Context) error {
process := s.calls
s.calls = nil
for _, events := range process {
for _, marked := range s.markedIds {
if events.Events[0].Id == marked.LongRunningId {
list := fmt.Sprintf("%v/%v %v %v %v [%v]", events.Events[0].Server, events.Events[0].Binary, events.Events[0].Timestamp, events.Events[0].Call, time.Millisecond*time.Duration(marked.RunningTimeInMs), marked.Request)
list += fmt.Sprintf("\nRequest: %v", marked.RequestMessage)
for _, ev := range events.Events {
list += "\n" + fmt.Sprintf("%v/%v %v %v", ev.Server, ev.Binary, time.Nanosecond*time.Duration(ev.Timestamp-events.Events[0].Timestamp), ev.Call)
}
list += fmt.Sprintf("\nGenerated from %v", marked.LongRunningId)
s.RaiseIssue(ctx, "Long Running Trace", list, false)
s.config.LastMarkSent = time.Now().Unix()
s.save(ctx)
}
}
eventStart := ""
times := time.Now().UnixNano()
if events.Events != nil {
for _, ev := range events.Events {
if ev != nil && ev.Timestamp < times {
times = ev.Timestamp
eventStart = ev.Call
}
}
}
s.counts[eventStart]++
}
most := ""
mostCalls := 0
allCalls := 0
for c, count := range s.counts {
allCalls += count
if count > mostCalls {
most = c
mostCalls = count
}
}
s.Log(fmt.Sprintf("Most calls: %v", mostCalls))
s.allCalls = int64(allCalls)
s.mostCalled = most
s.Log(fmt.Sprintf("Calls: %v", reflect.ValueOf(s.counts).MapKeys()))
return nil
}