Skip to content

Commit

Permalink
Refactored some code
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Feb 2, 2024
1 parent 21e8cb6 commit 4fc8ddb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class WiFiDiagnosticsDelegate : public DeviceLayer::WiFiDiagnosticsDelegate
{
MATTER_TRACE_SCOPE("OnDisconnectionDetected", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnDisconnectionDetected");

for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
{
// If WiFi Network Diagnostics cluster is implemented on this endpoint
Expand Down
1 change: 1 addition & 0 deletions src/protocols/secure_channel/CASEServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ void CASEServer::OnSessionEstablishmentError(CHIP_ERROR err)
{
MATTER_TRACE_SCOPE("OnSessionEstablishmentError", "CASEServer");
ChipLogError(Inet, "CASE Session establishment failed: %" CHIP_ERROR_FORMAT, err.Format());

MATTER_TRACE_SCOPE("CASEFail", "CASESession");
PrepareForSessionEstablishment();
}
Expand Down
35 changes: 32 additions & 3 deletions src/tracing/esp32_trace/counter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,12 +22,13 @@
using namespace chip;

namespace Insights {
// It need not be freed. One time allocation . Need to track counters till the device being online.

// This is a one time allocation for counters.
ESPInsightsCounter * ESPInsightsCounter::mHead = nullptr;

ESPInsightsCounter * ESPInsightsCounter::GetInstance(const char * label)
{
ESPInsightsCounter * current = mHead; // Provisional pointer to traverse the counter list
ESPInsightsCounter * current = mHead;

while (current != nullptr)
{
Expand Down Expand Up @@ -55,4 +56,32 @@ int ESPInsightsCounter::GetInstanceCount() const
return instanceCount;
}

void ESPInsightsCounter::ReportMetrics()
{
if (!registered)
{
esp_diag_metrics_register("SYS_CNT" /* Tag of metrics */, label /* Unique key 8 */,
label /* label displayed on dashboard */, PATH /* hierarchical path */,
ESP_DIAG_DATA_TYPE_UINT /* data_type */);
registered = true;
}
ESP_LOGI("mtr", "Label = %s Count = %d", label, instanceCount);
esp_diag_metrics_add_uint(label, instanceCount);
}

// Destructor to free the dynamically allocated memory
ESPInsightsCounter::~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
30 changes: 3 additions & 27 deletions src/tracing/esp32_trace/counter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -44,33 +44,9 @@ class ESPInsightsCounter

int GetInstanceCount() const;

void ReportMetrics()
{
if (!registered)
{
esp_diag_metrics_register("SYS_CNT" /* Tag of metrics */, label /* Unique key 8 */,
label /* label displayed on dashboard */, PATH /* hierarchical path */,
ESP_DIAG_DATA_TYPE_UINT /* data_type */);
registered = true;
}
ESP_LOGI("mtr", "Label = %s Count = %d", label, instanceCount);
esp_diag_metrics_add_uint(label, instanceCount);
}
void ReportMetrics();

// 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;
}
~ESPInsightsCounter();
};

} // namespace Insights
2 changes: 1 addition & 1 deletion src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include <lib/support/CHIPMem.h>
#include <lib/support/StringBuilder.h>
#include <lib/support/StringSplitter.h>
#include <log_json/log_json_build_config.h>
#include <transport/TracingStructs.h>

#include <json/json.h>
#include <log_json/log_json_build_config.h>

#include <errno.h>

Expand Down
1 change: 0 additions & 1 deletion src/tracing/perfetto/perfetto_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
#pragma once

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

#include <memory>
Expand Down

0 comments on commit 4fc8ddb

Please sign in to comment.