From cfb0e5fc6925a5b4358616583f426c863c6c04e9 Mon Sep 17 00:00:00 2001 From: shripad621git Date: Thu, 14 Dec 2023 17:23:36 +0530 Subject: [PATCH] Added support of counters for perfetto tracing backend --- src/tracing/perfetto/BUILD.gn | 5 ++++- .../include/matter/tracing/macros_impl.h | 6 ++---- src/tracing/perfetto/perfetto_tracing.cpp | 20 ++++++++++++++++++- src/tracing/perfetto/perfetto_tracing.h | 5 +++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/tracing/perfetto/BUILD.gn b/src/tracing/perfetto/BUILD.gn index 64d4cd1d5d947b..b1b210c2b38dc8 100644 --- a/src/tracing/perfetto/BUILD.gn +++ b/src/tracing/perfetto/BUILD.gn @@ -25,7 +25,10 @@ config("tracing") { source_set("perfetto_tracing") { public = [ "include/matter/tracing/macros_impl.h" ] - public_deps = [ "${chip_root}/third_party/perfetto:sdk" ] + public_deps = [ + "${chip_root}/src/tracing", + "${chip_root}/third_party/perfetto:sdk", + ] public_configs = [ ":tracing" ] } diff --git a/src/tracing/perfetto/include/matter/tracing/macros_impl.h b/src/tracing/perfetto/include/matter/tracing/macros_impl.h index ec663d90dbd750..3a08b0b4645def 100644 --- a/src/tracing/perfetto/include/matter/tracing/macros_impl.h +++ b/src/tracing/perfetto/include/matter/tracing/macros_impl.h @@ -23,6 +23,7 @@ #endif #include +#include PERFETTO_DEFINE_CATEGORIES(perfetto::Category("Matter").SetDescription("Matter trace events")); @@ -30,7 +31,4 @@ PERFETTO_DEFINE_CATEGORIES(perfetto::Category("Matter").SetDescription("Matter t #define MATTER_TRACE_END(label, group) TRACE_EVENT_END("Matter") #define MATTER_TRACE_INSTANT(label, group) TRACE_EVENT_INSTANT("Matter", label, "class_name", group) #define MATTER_TRACE_SCOPE(label, group) TRACE_EVENT("Matter", label, "class_name", group) -#define MATTER_TRACE_COUNTER(label, group) \ - do \ - { \ - } while (false) +#define MATTER_TRACE_COUNTER(label, group) ::chip::Tracing::Internal::Counter(label, group) diff --git a/src/tracing/perfetto/perfetto_tracing.cpp b/src/tracing/perfetto/perfetto_tracing.cpp index 791fe26b95f38c..305d1b533afce0 100644 --- a/src/tracing/perfetto/perfetto_tracing.cpp +++ b/src/tracing/perfetto/perfetto_tracing.cpp @@ -52,7 +52,25 @@ void PerfettoBackend::LogMessageReceived(MessageReceivedInfo & info) ); } -void PerfettoBackend::TraceCounter(const char * label, const char * group) {} +void PerfettoBackend::TraceCounter(const char * label, const char * group) +{ + std::string counterId = std::string(label); + + if (counters.find(counterId) == counters.end()) + { + counters[counterId] = 1; + } + else + { + counters[counterId]++; + } + + TRACE_EVENT_INSTANT("Matter", "Counter", // + "Label", label, // + "count", static_cast(counters[counterId]) // + ); +} + void PerfettoBackend::LogMessageSend(MessageSendInfo & info) { const char * messageType = "UNKNOWN"; diff --git a/src/tracing/perfetto/perfetto_tracing.h b/src/tracing/perfetto/perfetto_tracing.h index 1ffcc6ffd1f797..3337fe7c0336b0 100644 --- a/src/tracing/perfetto/perfetto_tracing.h +++ b/src/tracing/perfetto/perfetto_tracing.h @@ -17,7 +17,9 @@ */ #pragma once +#include #include +#include #include #include @@ -45,6 +47,9 @@ class PerfettoBackend : public ::chip::Tracing::Backend void LogNodeLookup(NodeLookupInfo &) override; void LogNodeDiscovered(NodeDiscoveredInfo &) override; void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override; + +private: + std::unordered_map> counters; }; } // namespace Perfetto