From e99179e4808f822e3af7885f471d89ebda61b8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Wed, 11 Sep 2024 21:36:40 +0000 Subject: [PATCH] Bug 1918045 - add a macro to reduce code duplication in Perfetto.h, r=denispal. Differential Revision: https://phabricator.services.mozilla.com/D221839 --- tools/performance/Perfetto.h | 178 +++++++---------------------------- 1 file changed, 32 insertions(+), 146 deletions(-) diff --git a/tools/performance/Perfetto.h b/tools/performance/Perfetto.h index 893442976d08..ebc0a7b28c93 100644 --- a/tools/performance/Perfetto.h +++ b/tools/performance/Perfetto.h @@ -184,155 +184,41 @@ struct AddDebugAnnotationImpl< }; // Specialize the various string representations. -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const mozilla::ProfilerString8View& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.StringView().data()); - } -}; +# define ADD_DEBUG_STRING_ANNOTATION_IMPL(templatetype, stringtype, \ + paramtype, getter) \ + template \ + struct AddDebugAnnotationImpl { \ + static void call(perfetto::EventContext& ctx, const char* const aKey, \ + const paramtype aValue) { \ + auto* arg = ctx.event()->add_debug_annotations(); \ + arg->set_name(aKey); \ + arg->set_string_value(getter); \ + } \ + }; -template -struct AddDebugAnnotationImpl> { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsAutoCStringN& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; +# define ADD_DEBUG_STRING_ANNOTATION(type, getter) \ + ADD_DEBUG_STRING_ANNOTATION_IMPL(, type, type&, getter) -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsCString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; +ADD_DEBUG_STRING_ANNOTATION(mozilla::ProfilerString8View, + aValue.StringView().data()) +ADD_DEBUG_STRING_ANNOTATION_IMPL(size_t N, nsAutoCStringN, + nsAutoCStringN&, aValue.get()) +ADD_DEBUG_STRING_ANNOTATION(nsCString, aValue.get()) +ADD_DEBUG_STRING_ANNOTATION(nsAutoCString, aValue.get()) +ADD_DEBUG_STRING_ANNOTATION(nsTLiteralString, aValue.get()) +ADD_DEBUG_STRING_ANNOTATION(nsPrintfCString, aValue.get()) +ADD_DEBUG_STRING_ANNOTATION(NS_ConvertUTF16toUTF8, aValue.get()) +ADD_DEBUG_STRING_ANNOTATION(nsTDependentString, aValue.get()) -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsAutoCString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; - -template <> -struct AddDebugAnnotationImpl> { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsTLiteralString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsPrintfCString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const NS_ConvertUTF16toUTF8& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; - -template <> -struct AddDebugAnnotationImpl> { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsTDependentString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue.get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsACString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(nsAutoCString(aValue).get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const std::string& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue); - } -}; - -template -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const char* aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(aValue); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const mozilla::ProfilerString16View& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(NS_ConvertUTF16toUTF8(aValue).get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsAString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(NS_ConvertUTF16toUTF8(aValue).get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsAString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(NS_ConvertUTF16toUTF8(aValue).get()); - } -}; - -template <> -struct AddDebugAnnotationImpl { - static void call(perfetto::EventContext& ctx, const char* const aKey, - const nsString& aValue) { - auto* arg = ctx.event()->add_debug_annotations(); - arg->set_name(aKey); - arg->set_string_value(NS_ConvertUTF16toUTF8(aValue).get()); - } -}; +ADD_DEBUG_STRING_ANNOTATION(nsACString, nsAutoCString(aValue).get()) +ADD_DEBUG_STRING_ANNOTATION(std::string, aValue) +ADD_DEBUG_STRING_ANNOTATION_IMPL(size_t N, char[N], char*, aValue) +ADD_DEBUG_STRING_ANNOTATION(mozilla::ProfilerString16View, + NS_ConvertUTF16toUTF8(aValue).get()) +ADD_DEBUG_STRING_ANNOTATION(nsAString, NS_ConvertUTF16toUTF8(aValue).get()) +ADD_DEBUG_STRING_ANNOTATION_IMPL(, const nsAString&, nsAString&, + NS_ConvertUTF16toUTF8(aValue).get()) +ADD_DEBUG_STRING_ANNOTATION(nsString, NS_ConvertUTF16toUTF8(aValue).get()) // Main helper call that dispatches to proper specialization. template