Skip to content

Commit

Permalink
Made the perfetto backend implementation more inline:
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Dec 19, 2023
1 parent cfb0e5f commit 986e61d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void CASESession::OnResponseTimeout(ExchangeContext * ec)
{
VerifyOrReturn(ec != nullptr, ChipLogError(SecureChannel, "CASESession::OnResponseTimeout was called by null exchange"));
VerifyOrReturn(mExchangeCtxt == ec, ChipLogError(SecureChannel, "CASESession::OnResponseTimeout exchange doesn't match"));
MATTER_TRACE_COUNTER("casetimeout","CASE");
MATTER_TRACE_COUNTER("casetimeout", "CASESession");
ChipLogError(SecureChannel, "CASESession timed out while waiting for a response from the peer. Current state was %u",
to_underlying(mState));
// Discard the exchange so that Clear() doesn't try aborting it. The
Expand Down Expand Up @@ -743,7 +743,7 @@ CHIP_ERROR CASESession::SendSigma1()
CHIP_ERROR CASESession::HandleSigma1_and_SendSigma2(System::PacketBufferHandle && msg)
{
MATTER_TRACE_SCOPE("HandleSigma1_and_SendSigma2", "CASESession");
MATTER_TRACE_COUNTER("sigma1cnt", "CASE");
MATTER_TRACE_COUNTER("sigma1cnt", "CASESession");

ReturnErrorOnFailure(HandleSigma1(std::move(msg)));

Expand Down Expand Up @@ -964,7 +964,7 @@ CHIP_ERROR CASESession::SendSigma2Resume()
CHIP_ERROR CASESession::SendSigma2()
{
MATTER_TRACE_SCOPE("SendSigma2", "CASESession");
MATTER_TRACE_COUNTER("sigma2cnt","CASE");
MATTER_TRACE_COUNTER("sigma2cnt", "CASESession");

VerifyOrReturnError(GetLocalSessionId().HasValue(), CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mFabricsTable != nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand Down Expand Up @@ -1560,7 +1560,7 @@ CHIP_ERROR CASESession::SendSigma3c(SendSigma3Data & data, CHIP_ERROR status)
CHIP_ERROR CASESession::HandleSigma3a(System::PacketBufferHandle && msg)
{
MATTER_TRACE_SCOPE("HandleSigma3", "CASESession");
MATTER_TRACE_COUNTER("sigma3cnt","CASE");
MATTER_TRACE_COUNTER("sigma3cnt", "CASESession");
CHIP_ERROR err = CHIP_NO_ERROR;
System::PacketBufferTLVReader tlvReader;
TLV::TLVReader decryptedDataTlvReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define MATTER_TRACE_BEGIN(label, group) ::chip::Tracing::Internal::Begin(label, group)
#define MATTER_TRACE_END(label, group) ::chip::Tracing::Internal::End(label, group)
#define MATTER_TRACE_INSTANT(label, group) ::chip::Tracing::Internal::Instant(label, group)
#define MATTER_TRACE_COUNTER(label, group) ::chip::Tracing::Internal::Counter(label, group)

namespace chip {
namespace Tracing {
Expand Down
6 changes: 6 additions & 0 deletions src/tracing/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
::chip::Tracing::Internal::LogNodeDiscoveryFailed(_trace_data); \
} while (false)

#define MATTER_TRACE_COUNTER(label, group) \
do \
{ \
::chip::Tracing::Internal::Counter(label, group); \
} while (false)

#else // MATTER_TRACING_ENABLED

#define _MATTER_TRACE_DISABLE(...) \
Expand Down
1 change: 0 additions & 1 deletion src/tracing/perfetto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ static_library("perfetto") {
public_deps = [
":perfetto_tracing",
"${chip_root}/src/lib/address_resolve",
"${chip_root}/src/tracing",
"${chip_root}/src/transport",
"${chip_root}/third_party/perfetto:sdk",
]
Expand Down
2 changes: 0 additions & 2 deletions src/tracing/perfetto/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
#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) ::chip::Tracing::Internal::Counter(label, group)
13 changes: 7 additions & 6 deletions src/tracing/perfetto/perfetto_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include <lib/address_resolve/TracingStructs.h>
#include <lib/core/ErrorStr.h>
#include <lib/support/StringBuilder.h>
#include <transport/TracingStructs.h>

#include <lib/support/logging/TextOnlyLogging.h>
#include <matter/tracing/macros_impl.h>
#include <perfetto.h>
#include <transport/TracingStructs.h>

namespace chip {
namespace Tracing {
Expand Down Expand Up @@ -55,7 +55,7 @@ void PerfettoBackend::LogMessageReceived(MessageReceivedInfo & info)
void PerfettoBackend::TraceCounter(const char * label, const char * group)
{
std::string counterId = std::string(label);

ChipLogProgress(SecureChannel, "In trace counter");
if (counters.find(counterId) == counters.end())
{
counters[counterId] = 1;
Expand All @@ -65,14 +65,15 @@ void PerfettoBackend::TraceCounter(const char * label, const char * group)
counters[counterId]++;
}

TRACE_EVENT_INSTANT("Matter", "Counter", //
"Label", label, //
"count", static_cast<int>(counters[counterId]) //
TRACE_EVENT("Matter", "Counter", //
"Label", label, //
"count", counters[counterId] //
);
}

void PerfettoBackend::LogMessageSend(MessageSendInfo & info)
{
ChipLogProgress(SecureChannel, "In trace counter");
const char * messageType = "UNKNOWN";
switch (info.messageType)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/perfetto/perfetto_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PerfettoBackend : public ::chip::Tracing::Backend
void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override;

private:
std::unordered_map<std::string, std::atomic<int>> counters;
std::unordered_map<std::string, int> counters;
};

} // namespace Perfetto
Expand Down

0 comments on commit 986e61d

Please sign in to comment.