From 5ea2c7d67c1f4840d04043e53fb7b62c6d17c42b Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Fri, 11 Sep 2026 23:52:50 +0000 Subject: [PATCH] Bug 2068188 - Use a string-literal wrapper type for simple payload marker field names. r=bas,profiler-reviewers,canova This avoids the need to create the `defined_name_##arg` constants which will let us add support for named arguments using string literals. It's also simpler. Differential Revision: https://phabricator.services.mozilla.com/D322682 --- tools/profiler/public/ProfilerMarkers.h | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/profiler/public/ProfilerMarkers.h b/tools/profiler/public/ProfilerMarkers.h index e9ebd8f30db6..5c475324c99f 100644 --- a/tools/profiler/public/ProfilerMarkers.h +++ b/tools/profiler/public/ProfilerMarkers.h @@ -265,11 +265,24 @@ MarkerSchema::getDefaultFormatForType() { } // namespace mozilla namespace geckoprofiler::markers { +// Wraps a string literal so that it can be used as a non-type template +// parameter. +template +struct MarkerFieldName { + char mName[N]; + + constexpr MOZ_IMPLICIT MarkerFieldName(const char (&aName)[N]) { + for (size_t i = 0; i < N; ++i) { + mName[i] = aName[i]; + } + } +}; + // This allows us to bundle the argument name and its type into a single class // so they may be passed to the SimplePayloadMarkerTemplate class. -template +template struct FieldDescription { - static constexpr const char* name = ArgName; + static constexpr const char* name = ArgName.mName; using type = ArgType; }; @@ -299,17 +312,8 @@ struct SimplePayloadMarkerTemplate }; } // namespace geckoprofiler::markers -// This defines the classes needed for the template class. -#define DEFINE_FIELD_STRUCT(arg) \ - static constexpr char defined_name_##arg[] = #arg; \ - using FieldDescription##arg = \ - geckoprofiler::markers::FieldDescription; - -#define DEFINE_FIELD_STRUCTS(...) \ - MOZ_FOR_EACH(DEFINE_FIELD_STRUCT, (), (__VA_ARGS__)) - -#define MARKER_GET_ARG_TYPE(arg) FieldDescription##arg +#define MARKER_GET_ARG_TYPE(arg) \ + ::geckoprofiler::markers::FieldDescription<#arg, decltype(arg)> // This adds a profiler marker with a schema for payload based on the arguments // passed. Note that each marker must have a unique name so you can only use @@ -330,7 +334,6 @@ struct SimplePayloadMarkerTemplate do { \ static constexpr char marker_name[] = markerName; \ static constexpr char table_label[] = label; \ - DEFINE_FIELD_STRUCTS(__VA_ARGS__) \ using SimplePayloadMarkerImpl = \ geckoprofiler::markers::SimplePayloadMarkerTemplate< \ marker_name, table_label, \