When running the tracing_example, my program crashes when a trace session is stopped with the following error message:
terminate called after throwing an instance of 'St9bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)
The crash happens on line line 87: app.StopTraceSession(); When using the debugger, I found out that the program crashes when the trace aggregator thread is joined in app.cc:218.
After the crash, a data1.perfetto file is created but only contains ~30 loops for me. This made me suspect that the crash might be due to a small stack size as you mentioned in your blog (part 4).
Note that this crash also occurs when I try to implement tracing in my own code, i.e. not just the tracing_example program.
Fix: increase thread stack size
Edit: this "fix" might make the problem occur less often, but not disappear (see this comment).
The default stack size set in ThreadConfig is 8 MB. Increasing the stack size to 16 MB caused fixed the crash for me. I did this by adding the following line to the thread_config section in tracing_example/main.cc:64:
int main() {
cactus_rt::CyclicThreadConfig thread_config;
thread_config.period_ns = 1'000'000;
thread_config.cpu_affinity = std::vector<size_t>{2};
thread_config.SetFifoScheduler(80);
thread_config.stack_size = 16 * 1024 * 1024; // <--- set larger stack size
...
After this fix, the program does not crash for me anymore and a correct data1.perfetto file is created with the entire trace.
When running the
tracing_example, my program crashes when a trace session is stopped with the following error message:The crash happens on line line 87:
app.StopTraceSession();When using the debugger, I found out that the program crashes when the trace aggregator thread is joined inapp.cc:218.After the crash, a
data1.perfettofile is created but only contains ~30 loops for me. This made me suspect that the crash might be due to a small stack size as you mentioned in your blog (part 4).Note that this crash also occurs when I try to implement tracing in my own code, i.e. not just the
tracing_exampleprogram.Fix:increase thread stack sizeEdit: this "fix" might make the problem occur less often, but not disappear (see this comment).
The default stack size set in
ThreadConfigis 8 MB. Increasing the stack size to 16 MB caused fixed the crash for me. I did this by adding the following line to thethread_configsection intracing_example/main.cc:64:After this fix, the program does not crash for me anymore and a correct
data1.perfettofile is created with the entire trace.