-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjit.go
More file actions
170 lines (145 loc) · 3.99 KB
/
Copy pathjit.go
File metadata and controls
170 lines (145 loc) · 3.99 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package prof
// Frontend identifies the compiler frontend that produced native code.
type Frontend uint8
// Trigger identifies why compilation started.
type Trigger uint8
// EntryKind identifies a native entry point's role.
type EntryKind uint8
// CaptureOutcome identifies the result of a trace capture attempt.
type CaptureOutcome uint8
// CaptureReason identifies why trace capture did not complete normally.
type CaptureReason uint8
// CompileOutcome identifies the result of a compile attempt.
type CompileOutcome uint8
// CompileReason identifies why compilation did not emit native code.
type CompileReason uint8
// ExitReason identifies why native execution returned to the interpreter.
type ExitReason uint8
// Counter is a pre-resolved runtime metric handle.
type Counter struct {
value uint64
}
const (
FrontendNone Frontend = iota
FrontendStatic
FrontendTrace
)
const (
TriggerNone Trigger = iota
TriggerHot
TriggerSideExit
)
const (
EntryNone EntryKind = iota
EntryStart
EntryCall
EntryLoop
)
const (
CaptureOutcomeNone CaptureOutcome = iota
CaptureOutcomePublished
CaptureOutcomePartial
CaptureOutcomeRejected
)
const (
CaptureReasonNone CaptureReason = iota
CaptureReasonAttemptLimit
CaptureReasonInvalidAnchor
CaptureReasonHostCall
CaptureReasonTailClosure
CaptureReasonUnsupportedOp
CaptureReasonNestedTerminal
CaptureReasonStepTrap
CaptureReasonOpLimit
)
const (
CompileOutcomeNone CompileOutcome = iota
CompileOutcomeEmitted
CompileOutcomeEmpty
CompileOutcomeRejected
CompileOutcomeError
)
const (
CompileReasonNone CompileReason = iota
CompileReasonNoInput
CompileReasonNoPlan
CompileReasonInvalidPlan
CompileReasonLoweringRejected
CompileReasonRegisterPressure
CompileReasonBranchRange
CompileReasonBackendUnavailable
CompileReasonError
)
const (
ExitNone ExitReason = iota
ExitGuardKind
ExitGuardShape
ExitGuardBounds
ExitGuardValue
ExitColdBranch
ExitTraceCut
ExitTerminalOp
ExitLoop
)
// OpcodeNone marks an exit that cannot be attributed to an opcode.
const OpcodeNone = -1
// RecordCapture records one cold-path trace capture result.
func (c *Collector) RecordCapture(fn, ip int, outcome CaptureOutcome, reason CaptureReason) {
key := captureKey{fn: fn, ip: ip, outcome: outcome, reason: reason}
register(&c.jit.captures, key).value++
}
// RecordCompile records one cold-path compile result.
func (c *Collector) RecordCompile(
fn, ip int,
trigger Trigger,
frontend Frontend,
outcome CompileOutcome,
reason CompileReason,
) {
key := compileKey{
fn: fn, ip: ip,
trigger: trigger, frontend: frontend,
outcome: outcome, reason: reason,
}
register(&c.jit.compiles, key).value++
}
// RecordEmit records one emitted native entry and its generated byte count.
func (c *Collector) RecordEmit(fn, ip int, kind EntryKind, frontend Frontend, size int) {
key := entryKey{fn: fn, ip: ip, kind: kind, frontend: frontend}
register(&c.jit.emits, key).value++
if size > 0 {
register(&c.jit.bytes, key).value += uint64(size)
}
}
// RegisterEntry returns the stable counter for one native entry row.
func (c *Collector) RegisterEntry(fn, ip int, kind EntryKind, frontend Frontend) *Counter {
key := entryKey{fn: fn, ip: ip, kind: kind, frontend: frontend}
return register(&c.jit.entries, key)
}
// RegisterExit returns the stable counter for one native exit row.
func (c *Collector) RegisterExit(
fn, ip int,
kind EntryKind,
frontend Frontend,
reason ExitReason,
opcode int,
) *Counter {
if opcode < 0 || opcode > 255 {
opcode = OpcodeNone
}
key := exitKey{
entryKey: entryKey{fn: fn, ip: ip, kind: kind, frontend: frontend},
reason: reason,
opcode: opcode,
}
return register(&c.jit.exits, key)
}
// RegisterYield returns the stable counter for one native yield row.
func (c *Collector) RegisterYield(fn, ip int, kind EntryKind, frontend Frontend) *Counter {
key := entryKey{fn: fn, ip: ip, kind: kind, frontend: frontend}
return register(&c.jit.yields, key)
}
// Inc increments a pre-resolved counter without allocating.
func (c *Counter) Inc() {
c.value++
}