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
This commit is contained in:
Jeff Muizelaar
2026-09-11 23:55:04 +00:00
committed by jmuizelaar@mozilla.com
parent a87e28e039
commit 5ea2c7d67c
+17 -14
View File
@@ -265,11 +265,24 @@ MarkerSchema::getDefaultFormatForType<nsCString>() {
} // namespace mozilla
namespace geckoprofiler::markers {
// Wraps a string literal so that it can be used as a non-type template
// parameter.
template <size_t N>
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 <const char* ArgName, typename ArgType>
template <MarkerFieldName ArgName, typename ArgType>
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<defined_name_##arg, \
decltype(arg)>;
#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, \