-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexample_tracer_test.go
87 lines (72 loc) · 1.63 KB
/
example_tracer_test.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
package tracing_test
import (
"fmt"
"github.com/sarchlab/akita/v3/sim"
"github.com/sarchlab/akita/v3/tracing"
)
type SampleTimeTeller struct {
time sim.VTimeInSec
}
func (t *SampleTimeTeller) CurrentTime() sim.VTimeInSec {
return t.time
}
type SampleDomain struct {
*sim.HookableBase
timeTeller sim.TimeTeller
taskIDs []int
nextID int
}
func (d *SampleDomain) Name() string {
return "sample domain"
}
func (d *SampleDomain) Start() {
tracing.StartTask(
fmt.Sprintf("%d", d.nextID),
"",
d,
"sampleTaskKind",
"something",
nil,
)
d.taskIDs = append(d.taskIDs, d.nextID)
d.nextID++
}
func (d *SampleDomain) End() {
tracing.EndTask(
fmt.Sprintf("%d", d.taskIDs[0]),
d,
)
d.taskIDs = d.taskIDs[1:]
}
// Example for how to use standard tracers
func ExampleTracer() {
timeTeller := &SampleTimeTeller{}
domain := &SampleDomain{
HookableBase: sim.NewHookableBase(),
timeTeller: timeTeller,
}
filter := func(t tracing.Task) bool {
return t.Kind == "sampleTaskKind"
}
totalTimeTracer := tracing.NewTotalTimeTracer(timeTeller, filter)
busyTimeTracer := tracing.NewBusyTimeTracer(timeTeller, filter)
avgTimeTracer := tracing.NewAverageTimeTracer(timeTeller, filter)
tracing.CollectTrace(domain, totalTimeTracer)
tracing.CollectTrace(domain, busyTimeTracer)
tracing.CollectTrace(domain, avgTimeTracer)
timeTeller.time = 1
domain.Start()
timeTeller.time = 1.5
domain.Start()
timeTeller.time = 2
domain.End()
timeTeller.time = 3
domain.End()
fmt.Println(totalTimeTracer.TotalTime())
fmt.Println(busyTimeTracer.BusyTime())
fmt.Println(avgTimeTracer.AverageTime())
// Output:
// 2.5
// 2
// 1.25
}