Skip to content

Commit

Permalink
Removed the group from counter trace macro
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Feb 2, 2024
1 parent f56c30d commit 21e8cb6
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ void CASESession::OnResponseTimeout(ExchangeContext * ec)
VerifyOrReturn(mExchangeCtxt == ec, ChipLogError(SecureChannel, "CASESession::OnResponseTimeout exchange doesn't match"));
ChipLogError(SecureChannel, "CASESession timed out while waiting for a response from the peer. Current state was %u",
to_underlying(mState));
MATTER_TRACE_COUNTER("CASETimeout", "CASESession");
MATTER_TRACE_COUNTER("CASETimeout");
// Discard the exchange so that Clear() doesn't try aborting it. The
// exchange will handle that.
DiscardExchange();
Expand Down Expand Up @@ -845,7 +845,7 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
ByteSpan initiatorRandom;

ChipLogProgress(SecureChannel, "Received Sigma1 msg");
MATTER_TRACE_COUNTER("Sigma1", "CASESession");
MATTER_TRACE_COUNTER("Sigma1");

bool sessionResumptionRequested = false;
ByteSpan resumptionId;
Expand Down Expand Up @@ -1102,7 +1102,7 @@ CHIP_ERROR CASESession::SendSigma2()
mState = State::kSentSigma2;

ChipLogProgress(SecureChannel, "Sent Sigma2 msg");
MATTER_TRACE_COUNTER("Sigma2", "CASESession");
MATTER_TRACE_COUNTER("Sigma2");

return CHIP_NO_ERROR;
}
Expand All @@ -1119,7 +1119,7 @@ CHIP_ERROR CASESession::HandleSigma2Resume(System::PacketBufferHandle && msg)
uint32_t decodeTagIdSeq = 0;

ChipLogDetail(SecureChannel, "Received Sigma2Resume msg");
MATTER_TRACE_COUNTER("Sigma2Resume", "CASESession");
MATTER_TRACE_COUNTER("Sigma2Resume");

uint8_t sigma2ResumeMIC[CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES];

Expand Down Expand Up @@ -1589,7 +1589,7 @@ CHIP_ERROR CASESession::HandleSigma3a(System::PacketBufferHandle && msg)
uint8_t msg_salt[kIPKSize + kSHA256_Hash_Length];

ChipLogProgress(SecureChannel, "Received Sigma3 msg");
MATTER_TRACE_COUNTER("Sigma3", "CASESession");
MATTER_TRACE_COUNTER("Sigma3");

auto helper = WorkHelper<HandleSigma3Data>::Create(*this, &HandleSigma3b, &CASESession::HandleSigma3c);
VerifyOrExit(helper, err = CHIP_ERROR_NO_MEMORY);
Expand Down
8 changes: 4 additions & 4 deletions src/protocols/secure_channel/PASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void PASESession::OnResponseTimeout(ExchangeContext * ec)
// If we were waiting for something, mNextExpectedMsg had better have a value.
ChipLogError(SecureChannel, "PASESession timed out while waiting for a response from the peer. Expected message type was %u",
to_underlying(mNextExpectedMsg.Value()));
MATTER_TRACE_COUNTER("PASETimeout", "PASESession");
MATTER_TRACE_COUNTER("PASETimeout");
// Discard the exchange so that Clear() doesn't try closing it. The
// exchange will handle that.
DiscardExchange();
Expand Down Expand Up @@ -622,7 +622,7 @@ CHIP_ERROR PASESession::HandleMsg1_and_SendMsg2(System::PacketBufferHandle && ms
}

ChipLogDetail(SecureChannel, "Sent spake2p msg2");
MATTER_TRACE_COUNTER("Pake2", "PASESession");
MATTER_TRACE_COUNTER("Pake2");

exit:

Expand Down Expand Up @@ -714,7 +714,7 @@ CHIP_ERROR PASESession::HandleMsg3(System::PacketBufferHandle && msg)
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogDetail(SecureChannel, "Received spake2p msg3");
MATTER_TRACE_COUNTER("Pake3", "PASESession");
MATTER_TRACE_COUNTER("Pake3");

mNextExpectedMsg.ClearValue();

Expand Down Expand Up @@ -875,7 +875,7 @@ CHIP_ERROR PASESession::OnMessageReceived(ExchangeContext * exchange, const Payl
DiscardExchange();
Clear();
ChipLogError(SecureChannel, "Failed during PASE session setup: %" CHIP_ERROR_FORMAT, err.Format());
MATTER_TRACE_COUNTER("PASEFail", "PASESession");
MATTER_TRACE_COUNTER("PASEFail");
// Do this last in case the delegate frees us.
NotifySessionEstablishmentError(err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Backend : public ::chip::IntrusiveListNodeBase<>
/// Trace a zero-sized event
virtual void TraceInstant(const char * label, const char * group) {}

virtual void TraceCounter(const char * label, const char * group) {}
virtual void TraceCounter(const char * label) {}
virtual void LogMessageSend(MessageSendInfo &) { TraceInstant("MessageSent", "Messaging"); }
virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant("MessageReceived", "Messaging"); }

Expand Down
10 changes: 5 additions & 5 deletions src/tracing/esp32_trace/counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
using namespace chip;

namespace Insights {
ESPInsightsCounter * ESPInsightsCounter::mHead = nullptr; // Pointer to head of the counter linked list
// It need not be freed. One time allocation . Need to track counters till the device being online.
ESPInsightsCounter * ESPInsightsCounter::mHead = nullptr;

ESPInsightsCounter * ESPInsightsCounter::GetInstance(const char * label, const char * group)
ESPInsightsCounter * ESPInsightsCounter::GetInstance(const char * label)
{

ESPInsightsCounter * current = mHead; // Provisional pointer to traverse the counter list

while (current != nullptr)
{
if (strcmp(current->label, label) == 0 && strcmp(current->group, group) == 0)
if (strcmp(current->label, label) == 0)
{
current->instanceCount++;
return current;
Expand All @@ -43,7 +43,7 @@ ESPInsightsCounter * ESPInsightsCounter::GetInstance(const char * label, const c
void * ptr = Platform::MemoryAlloc(sizeof(ESPInsightsCounter));
VerifyOrDie(ptr != nullptr);

ESPInsightsCounter * newInstance = new (ptr) ESPInsightsCounter(label, group);
ESPInsightsCounter * newInstance = new (ptr) ESPInsightsCounter(label);
newInstance->mNext = mHead;
mHead = newInstance;

Expand Down
26 changes: 20 additions & 6 deletions src/tracing/esp32_trace/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <esp_log.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPMemString.h>
#include <string.h>

#define PATH "insights.cnt"

Expand All @@ -28,20 +29,18 @@ class ESPInsightsCounter
{
private:
static ESPInsightsCounter * mHead; // head of the counter list
char label[50]; // unique key
char group[50];
const char * label; // unique key
int instanceCount;
ESPInsightsCounter * mNext; // pointer to point to the next entry in the list
bool registered = false;

ESPInsightsCounter(const char * labelParam, const char * groupParam) : instanceCount(1), mNext(nullptr)
ESPInsightsCounter(const char * labelParam) : instanceCount(1), mNext(nullptr)
{
chip::Platform::CopyString(label, sizeof(label), labelParam);
chip::Platform::CopyString(group, sizeof(group), groupParam);
label = chip::Platform::MemoryAllocString(labelParam, strlen(labelParam));
}

public:
static ESPInsightsCounter * GetInstance(const char * label, const char * group);
static ESPInsightsCounter * GetInstance(const char * label);

int GetInstanceCount() const;

Expand All @@ -57,6 +56,21 @@ class ESPInsightsCounter
ESP_LOGI("mtr", "Label = %s Count = %d", label, instanceCount);
esp_diag_metrics_add_uint(label, instanceCount);
}

// Destructor to free the dynamically allocated memory
~ESPInsightsCounter()
{
chip::Platform::MemoryFree((void *) label);

ESPInsightsCounter * current = mHead;
while (current)
{
ESPInsightsCounter * next = current->mNext;
chip::Platform::MemoryFree((void *) current);
current = next;
}
mHead = nullptr;
}
};

} // namespace Insights
4 changes: 2 additions & 2 deletions src/tracing/esp32_trace/esp32_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ void ESP32Backend::LogNodeDiscovered(NodeDiscoveredInfo & info) {}

void ESP32Backend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo & info) {}

void ESP32Backend::TraceCounter(const char * label, const char * group)
void ESP32Backend::TraceCounter(const char * label)
{
::Insights::ESPInsightsCounter::GetInstance(label, group)->ReportMetrics();
::Insights::ESPInsightsCounter::GetInstance(label)->ReportMetrics();
}
void ESP32Backend::TraceBegin(const char * label, const char * group)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/esp32_trace/esp32_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ESP32Backend : public ::chip::Tracing::Backend
/// Trace a zero-sized event
void TraceInstant(const char * label, const char * group) override;

void TraceCounter(const char * label, const char * group) override;
void TraceCounter(const char * label) override;

void LogMessageSend(MessageSendInfo &) override;
void LogMessageReceived(MessageReceivedInfo &) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#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)
#define MATTER_TRACE_COUNTER(label) ::chip::Tracing::Internal::Counter(label)

namespace chip {
namespace Tracing {
Expand Down
3 changes: 1 addition & 2 deletions src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void JsonBackend::TraceInstant(const char * label, const char * group)
OutputValue(value);
}

void JsonBackend::TraceCounter(const char * label, const char * group)
void JsonBackend::TraceCounter(const char * label)
{
std::string counterId = std::string(label);
if (mCounters.find(counterId) == mCounters.end())
Expand All @@ -289,7 +289,6 @@ void JsonBackend::TraceCounter(const char * label, const char * group)
::Json::Value value;
value["event"] = "TraceCounter";
value["label"] = label;
value["group"] = group;
value["count"] = mCounters[counterId];

// Output the counter event
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/json/json_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class JsonBackend : public ::chip::Tracing::Backend
void TraceBegin(const char * label, const char * group) override;
void TraceEnd(const char * label, const char * group) override;
void TraceInstant(const char * label, const char * group) override;
void TraceCounter(const char * label, const char * group) override;
void TraceCounter(const char * label) override;
void LogMessageSend(MessageSendInfo &) override;
void LogMessageReceived(MessageReceivedInfo &) override;
void LogNodeLookup(NodeLookupInfo &) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#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)
#define MATTER_TRACE_COUNTER(label) ::chip::Tracing::Internal::Counter(label)

namespace chip {
namespace Tracing {
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/perfetto/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ PERFETTO_DEFINE_CATEGORIES(perfetto::Category("Matter").SetDescription("Matter t
#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) \
#define MATTER_TRACE_COUNTER(label) \
do \
{ \
static int count##_label##_group = 0; \
TRACE_COUNTER("Matter", perfetto::CounterTrack(label), ++count##_label##_group); \
static int count##_label = 0; \
TRACE_COUNTER("Matter", label, ++count##_label); \
} while (0)
4 changes: 2 additions & 2 deletions src/tracing/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ void Instant(const char * label, const char * group)
}
}

void Counter(const char * label, const char * group)
void Counter(const char * label)
{
for (auto & backend : gTracingBackends)
{
backend.TraceCounter(label, group);
backend.TraceCounter(label);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tracing/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace Internal {
void Begin(const char * label, const char * group);
void End(const char * label, const char * group);
void Instant(const char * label, const char * group);
void Counter(const char * label, const char * group);
void Counter(const char * label);

void LogMessageSend(::chip::Tracing::MessageSendInfo & info);
void LogMessageReceived(::chip::Tracing::MessageReceivedInfo & info);
Expand Down

0 comments on commit 21e8cb6

Please sign in to comment.