-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (53 loc) · 1.87 KB
/
main.go
File metadata and controls
61 lines (53 loc) · 1.87 KB
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
package main
import (
"math/rand"
"time"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/module/metrics/example"
"github.com/onflow/flow-go/module/trace"
"github.com/onflow/flow-go/utils/unittest"
)
// main runs a local tracer server on the machine and starts monitoring some metrics for sake of execution, which
// increases result approvals counter and checked chunks counter 100 times each
func main() {
example.WithMetricsServer(func(logger zerolog.Logger) {
tracer, err := trace.NewTracer(logger, "collection", "test", trace.SensitivityCaptureAll)
if err != nil {
panic(err)
}
collector := struct {
*metrics.HotstuffCollector
*metrics.ExecutionCollector
*metrics.NetworkCollector
}{
HotstuffCollector: metrics.NewHotstuffCollector("some_chain_id"),
ExecutionCollector: metrics.NewExecutionCollector(tracer),
NetworkCollector: metrics.NewNetworkCollector(unittest.Logger()),
}
diskTotal := rand.Int63n(1024 * 1024 * 1024)
for i := 0; i < 1000; i++ {
blockID := unittest.BlockFixture().ID()
collector.StartBlockReceivedToExecuted(blockID)
duration := time.Duration(rand.Int31n(2000)) * time.Millisecond
// adds a random delay for execution duration, between 0 and 2 seconds
time.Sleep(duration)
collector.ExecutionBlockExecuted(
duration,
module.ExecutionResultStats{
ComputationUsed: uint64(rand.Int63n(1e6)),
MemoryUsed: uint64(rand.Int63n(1e6)),
EventCounts: 2,
EventSize: 100,
NumberOfCollections: 1,
NumberOfTransactions: 1,
})
diskIncrease := rand.Int63n(1024 * 1024)
diskTotal += diskIncrease
collector.ExecutionStateStorageDiskTotal(diskTotal)
collector.ExecutionStorageStateCommitment(diskIncrease)
collector.FinishBlockReceivedToExecuted(blockID)
}
})
}