-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracer.cpp
More file actions
57 lines (46 loc) · 1.66 KB
/
Copy pathtracer.cpp
File metadata and controls
57 lines (46 loc) · 1.66 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
#include <string.h>
#include "tracer.h"
Tracer::Tracer(TraceLogger &logger, int queue_size)
:_logger(&logger)
{
configASSERT(_instance == nullptr && "Should only have one tracer!");
if (!_task_message_queue) {
_task_message_queue = xQueueCreate(queue_size, sizeof(TraceEntry_t));
configASSERT(_task_message_queue != NULL && "Task message queue could not be created");
}
_instance = this;
}
void Tracer::trace_application_exception(arduino_panic_info_t *info, void *arg) {
TraceEntry_t entry = {};
entry.trace_type = Event_t::PANIC;
entry.core_id = info->core;
entry.timestamp = micros();
entry.trace_id = _current_trace_id++;
entry.panic_entry.faulting_pc = reinterpret_cast<uint32_t>(info->pc);
strlcpy(entry.panic_entry.exception_reason, info->reason, MAX_EXCEPTION_STRING_LENGTH);
_logger->log_raw(reinterpret_cast<uint8_t *>(&entry), sizeof(entry));
}
void Tracer::trace_application_restart() {
for (int i = 0; i < NUM_CORES; ++i){
TraceEntry_t entry = {
.trace_type = Event_t::RESTART,
.core_id = i,
.timestamp = micros(),
.restart_entry = {
.restart_reason = esp_reset_reason(),
},
};
_logger->log_raw(reinterpret_cast<uint8_t *>(&entry), sizeof(entry));
}
}
void Tracer::sync_logger() {
_logger->sync(sizeof(TraceEntry_t));
}
void *Tracer::log_traces(void *args) {
TraceEntry_t entry = {};
for (;;) {
if (xQueueReceive(_task_message_queue, &entry, portMAX_DELAY) == pdTRUE) {
_logger->log_raw(reinterpret_cast<uint8_t *>(&entry), sizeof(entry));
}
}
}