Open sudara opened 1 year ago
A summary for where things ended up:
Everything works if and only if I store the compile-time string manipulation in a separately declared constexpr variable before feeding it to perfetto::StaticString
:
#define TRACE_DSP(...) \
constexpr auto pf = melatonin::compileTimePrettierFunction (WRAP_COMPILE_TIME_STRING (PERFETTO_DEBUG_FUNCTION_IDENTIFIER())); \
TRACE_EVENT ("dsp", perfetto::StaticString (pf.data()), ##__VA_ARGS__)
In other words, if i call perfetto::StaticString (melatonin::compileTimePrettierFunction...
things shift to runtime on msvc/clang.
Not sure if this is compiler behavior (it chooses runtime if it can) or a perfetto limitation (i.e. adding another constexpr ctor would help?) but I'm up and running for now!
Hi there!
I don't expect any action, but just wanted to bubble up a feature I'm trying to build in my perfetto integration for the JUCE C++ framework.
A DX/usability improvement I've been trying to provide are some friendlier macros that don't require manual labelling, they just use the current function name.
So instead of
TRACE_EVENT ("myCategory", "myFunctionName")
I pepper codebase with something likeTRACE_DSP()
with a compile-time derived function name and a fixed category ("dsp" in this case).I was hoping to use
PERFETTO_DEBUG_FUNCTION_IDENTIFIER()
to grab the function identifier, but it's of course.... human-unfriendly and needs trimming.Doing this at compile time turns out to be a bit annoying, and since it's no longer a literal, it makes
StaticString
complain:My last effort was to wrap
PERFETTO_DEBUG_FUNCTION_IDENTIFIER()
in a lambda so it can behave as a template parameter. This.... just about seems to work?I'm not sure what my "ask" is here, just noting in case anyone has a suggestion, are doing similar things or have a solution that's less hacky. I'm not quite smart enough to know if there's a way for
StaticString
itself to be happier for my use case. The issue seems to be even though my logic is happily compile-time when run in isolation, it ends up running in a runtime context (or at least triggering the static_assert) when passing toStaticString
.