forked from sarchlab/akita
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusytimetracer_test.go
147 lines (116 loc) · 4.18 KB
/
busytimetracer_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package tracing
import (
"fmt"
"github.com/sarchlab/akita/v3/sim"
gomock "github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gmeasure"
)
var _ = Describe("BusyTimeTracer", func() {
var (
mockCtrl *gomock.Controller
timeTeller *MockTimeTeller
t *BusyTimeTracer
)
BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
timeTeller = NewMockTimeTeller(mockCtrl)
t = NewBusyTimeTracer(timeTeller, nil)
})
AfterEach(func() {
mockCtrl.Finish()
})
It("should track busy time, one task", func() {
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1))
t.StartTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2))
t.EndTask(Task{ID: "1"})
Expect(t.BusyTime()).To(Equal(sim.VTimeInSec(1.0)))
})
It("should track busy time, two tasks", func() {
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1))
t.StartTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2))
t.EndTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(3))
t.StartTask(Task{ID: "2"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(4))
t.EndTask(Task{ID: "2"})
Expect(t.BusyTime()).To(Equal(sim.VTimeInSec(2.0)))
})
It("should track busy time, two tasks adjacent", func() {
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1))
t.StartTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2))
t.EndTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2))
t.StartTask(Task{ID: "2"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(3))
t.EndTask(Task{ID: "2"})
Expect(t.BusyTime()).To(Equal(sim.VTimeInSec(2.0)))
})
It("should track busy time, two tasks overlap", func() {
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1))
t.StartTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1.5))
t.StartTask(Task{ID: "2"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2))
t.EndTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2.5))
t.EndTask(Task{ID: "2"})
Expect(t.BusyTime()).To(Equal(sim.VTimeInSec(1.5)))
})
It("should track busy time, four tasks", func() {
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1))
t.StartTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1.1))
t.StartTask(Task{ID: "2"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1.2))
t.EndTask(Task{ID: "2"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1.9))
t.StartTask(Task{ID: "3"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2))
t.EndTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2.1))
t.EndTask(Task{ID: "3"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(3.1))
t.StartTask(Task{ID: "4"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(3.2))
t.EndTask(Task{ID: "4"})
Expect(t.BusyTime()).To(BeNumerically("~", 1.2))
})
It("should be able to terminate all the tasks", func() {
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1))
t.StartTask(Task{ID: "1"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1.1))
t.StartTask(Task{ID: "2"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(1.9))
t.StartTask(Task{ID: "3"})
timeTeller.EXPECT().CurrentTime().Return(sim.VTimeInSec(2.1))
t.EndTask(Task{ID: "3"})
t.TerminateAllTasks(3.5)
Expect(t.BusyTime()).To(BeNumerically("~", 2.5, 0.01))
})
It("measure busy time tracer", func() {
experiment := gmeasure.NewExperiment("Busy Time Tracer Performance")
AddReportEntry(experiment.Name, experiment)
experiment.MeasureDuration("runtime", func() {
for i := 0; i < 10000; i++ {
taskID := fmt.Sprintf("%d", i)
timeTeller.EXPECT().CurrentTime().
Return(sim.VTimeInSec(i * 2))
t.StartTask(Task{
ID: taskID,
})
timeTeller.EXPECT().CurrentTime().
Return(sim.VTimeInSec(i*2 + 1))
t.EndTask((Task{
ID: taskID,
EndTime: sim.VTimeInSec(i*2 + 1),
}))
}
Expect(t.BusyTime()).To(BeNumerically("~", 10000, 0.01))
})
})
})