-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a counter trace macro to the tracing for getting insights from…
… counters in chip and implemented the macro for ESP32 platform... (#30591) * Set up the tracing to support counter macro and added the macro to none and multiplexed * Added the support of counter macro for esp32 * Added the support of counter macro in perfetto * Added support of counters for json backend and few traces * Restyled the code * Added few counter traces * Refactored some code * Addressed Review Comments * Removed the group from counter trace macro * Refactored some code * Addressed the string and class documentation related review comments
- Loading branch information
1 parent
33aedbc
commit 64dca43
Showing
20 changed files
with
200 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <string.h> | ||
#include <tracing/esp32_trace/counter.h> | ||
|
||
using namespace chip; | ||
|
||
namespace Insights { | ||
|
||
// This is a one time allocation for counters. It is not supposed to be freed. | ||
ESPInsightsCounter * ESPInsightsCounter::mHead = nullptr; | ||
|
||
ESPInsightsCounter * ESPInsightsCounter::GetInstance(const char * label) | ||
{ | ||
ESPInsightsCounter * current = mHead; | ||
|
||
while (current != nullptr) | ||
{ | ||
if (strcmp(current->label, label) == 0) | ||
{ | ||
current->instanceCount++; | ||
return current; | ||
} | ||
current = current->mNext; | ||
} | ||
|
||
// Allocate a new instance if counter is not present in the list. | ||
void * ptr = Platform::MemoryAlloc(sizeof(ESPInsightsCounter)); | ||
VerifyOrDie(ptr != nullptr); | ||
|
||
ESPInsightsCounter * newInstance = new (ptr) ESPInsightsCounter(label); | ||
newInstance->mNext = mHead; | ||
mHead = newInstance; | ||
|
||
return newInstance; | ||
} | ||
|
||
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 */, "insights.cnt" /* 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); | ||
} | ||
|
||
} // namespace Insights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <esp_diagnostics_metrics.h> | ||
#include <esp_log.h> | ||
#include <lib/support/CHIPMem.h> | ||
#include <lib/support/CHIPMemString.h> | ||
#include <string.h> | ||
|
||
namespace Insights { | ||
|
||
/* | ||
* | ||
* This class is used to monotonically increment the counters as per the label of the counter macro | ||
* 'MATTER_TRACE_COUNTER(label)' and report the metrics to esp-insights. | ||
* As per the label of the counter macro, it adds the counter in the linked list with the name label if not | ||
* present and returns the same instance and increments the value if the counter is already present | ||
* in the list. | ||
*/ | ||
|
||
class ESPInsightsCounter | ||
{ | ||
private: | ||
static ESPInsightsCounter * mHead; // head of the counter list | ||
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) : label(labelParam), instanceCount(1), mNext(nullptr) {} | ||
|
||
public: | ||
static ESPInsightsCounter * GetInstance(const char * label); | ||
|
||
int GetInstanceCount() const; | ||
|
||
void ReportMetrics(); | ||
}; | ||
|
||
} // namespace Insights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.