-
Notifications
You must be signed in to change notification settings - Fork 179
/
metrics.go
59 lines (47 loc) · 1.93 KB
/
metrics.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
package fvm
import (
"time"
"github.com/onflow/cadence/runtime/ast"
)
// A MetricsCollector accumulates performance metrics reported by the Cadence runtime.
//
// A single collector instance will sum all reported values. For example, the "parsed" field will be
// incremented each time a program is parsed.
type MetricsCollector struct {
parsed time.Duration
checked time.Duration
interpreted time.Duration
}
// NewMetricsCollectors returns a new runtime metrics collector.
func NewMetricsCollector() *MetricsCollector {
return &MetricsCollector{}
}
func (m *MetricsCollector) Parsed() time.Duration { return m.parsed }
func (m *MetricsCollector) Checked() time.Duration { return m.checked }
func (m *MetricsCollector) Interpreted() time.Duration { return m.interpreted }
type metricsCollector struct {
*MetricsCollector
}
func (m metricsCollector) ProgramParsed(location ast.Location, duration time.Duration) {
if m.MetricsCollector != nil {
m.parsed += duration
}
}
func (m metricsCollector) ProgramChecked(location ast.Location, duration time.Duration) {
if m.MetricsCollector != nil {
m.checked += duration
}
}
func (m metricsCollector) ProgramInterpreted(location ast.Location, duration time.Duration) {
if m.MetricsCollector != nil {
m.interpreted += duration
}
}
func (m metricsCollector) ValueEncoded(duration time.Duration) {}
func (m metricsCollector) ValueDecoded(duration time.Duration) {}
type noopMetricsCollector struct{}
func (m noopMetricsCollector) ProgramParsed(location ast.Location, duration time.Duration) {}
func (m noopMetricsCollector) ProgramChecked(location ast.Location, duration time.Duration) {}
func (m noopMetricsCollector) ProgramInterpreted(location ast.Location, duration time.Duration) {}
func (m noopMetricsCollector) ValueEncoded(duration time.Duration) {}
func (m noopMetricsCollector) ValueDecoded(duration time.Duration) {}