-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrace_forge.c
More file actions
47 lines (42 loc) · 1.03 KB
/
trace_forge.c
File metadata and controls
47 lines (42 loc) · 1.03 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
#include "trace/trace_forge.h"
#include "arch/x86/timer.h"
#include "types.h"
static trace_forge_state_t state;
static trace_event_t events[256];
static uint32_t head = 0;
static uint32_t count = 0;
void trace_forge_init(void) {
state.events = 0;
state.dropped = 0;
head = 0;
count = 0;
for (uint32_t i = 0; i < 256; ++i) {
events[i].tag = 0;
events[i].value = 0;
events[i].tick = 0;
}
}
void trace_forge_emit(uint32_t tag, uint32_t value) {
state.events++;
events[head].tag = tag;
events[head].value = value;
events[head].tick = timer_get_ticks();
head = (head + 1) % 256;
if (count < 256) {
count++;
} else {
state.dropped++;
}
}
trace_forge_state_t trace_forge_state(void) {
return state;
}
uint32_t trace_forge_get(uint32_t index, trace_event_t* out) {
if (!out || index >= count) {
return 0;
}
uint32_t start = (head + 256 - count) % 256;
uint32_t slot = (start + index) % 256;
*out = events[slot];
return 1;
}