Skip to content

Commit

Permalink
Added support of counters for perfetto tracing backend
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Dec 14, 2023
1 parent f055605 commit 21bdb63
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/tracing/perfetto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand Down
6 changes: 2 additions & 4 deletions src/tracing/perfetto/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
#endif

#include <perfetto.h>
#include <tracing/registry.h>

PERFETTO_DEFINE_CATEGORIES(perfetto::Category("Matter").SetDescription("Matter trace events"));

#define MATTER_TRACE_BEGIN(label, group) TRACE_EVENT_BEGIN("Matter", label, "class_name", group)
#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)
20 changes: 19 additions & 1 deletion src/tracing/perfetto/perfetto_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(counters[counterId]) //
);
}

void PerfettoBackend::LogMessageSend(MessageSendInfo & info)
{
const char * messageType = "UNKNOWN";
Expand Down
5 changes: 5 additions & 0 deletions src/tracing/perfetto/perfetto_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
#pragma once

#include <atomic>
#include <tracing/backend.h>
#include <unordered_map>

#include <memory>
#include <perfetto.h>
Expand Down Expand Up @@ -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<std::string, std::atomic<int>> counters;
};

} // namespace Perfetto
Expand Down

0 comments on commit 21bdb63

Please sign in to comment.