hrydgard / minitrace

Simple C/C++ library for producing JSON traces suitable for Chrome's built-in trace viewer (about:tracing).
MIT License
370 stars 63 forks source link

Minitrace events don't take ownership of their names or categories #19

Closed DethRaid closed 4 years ago

DethRaid commented 4 years ago

Minitrace events don't take ownership of their names or their categories - they copy the pointer to their names and categories, instead of copying the name or category itself. This means that if, for example, I want to use the data of a C++ string as an event name, I have to either ensure that the lifetime of the string extends until I flush to the trace file, or I have to copy the name/category somewhere where it will stay alive that long. This is cumbersome

I'm working on a patch to add an option to make minitrace copy the category and name, then free that memory after writing the events to a log file. I just wanted to open an issue about this early in case there's some part of this that I missed

hrydgard commented 4 years ago

I generally just use this with const strings which have infinite life time, but sure, I'll take a compile time option that adds internal string storage. And I see you already made a PR #20 , so that's good :)