forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ec98c8
commit aa8a820
Showing
11 changed files
with
335 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <lib/support/CHIPCounter.h> | ||
|
||
#if CONFIG_ENABLE_ESP_INSIGHTS_COUNTERS | ||
#include <matter/tracing/ESP32Counter.h> | ||
#else | ||
|
||
namespace chip { | ||
|
||
template <typename T> | ||
class AdvanceCounter : public Counter<T> | ||
{ | ||
public: | ||
AdvanceCounter(const char *label=NULL,const char *group=NULL) : mCounterValue(0) {} | ||
~AdvanceCounter() override{}; | ||
CHIP_ERROR Init(T aStartValue) | ||
{ | ||
return CHIP_NO_ERROR; | ||
} | ||
CHIP_ERROR Advance() override | ||
{ | ||
return CHIP_NO_ERROR; | ||
} | ||
T GetValue() override { return mCounterValue; } | ||
|
||
protected: | ||
T mCounterValue; | ||
const char* mlabel; | ||
const char* mgroup; | ||
}; | ||
|
||
} | ||
#endif |
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
149 changes: 149 additions & 0 deletions
149
src/tracing/esp32_trace/include/matter/tracing/ESP32Counter.h
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,149 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* Copyright (c) 2016-2017 Nest Labs, Inc. | ||
* 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_variables.h> | ||
#include <esp_err.h> | ||
#include <esp_log.h> | ||
#include <lib/core/CHIPError.h> | ||
#include <lib/support/CHIPCounter.h> | ||
#include <string.h> | ||
|
||
#define PATH "mtr.cntr" | ||
#define space_conc(str1, str2) #str1 " " #str2 | ||
|
||
namespace chip { | ||
// #if CONFIG_ENABLE_ESP_INSIGHTS_COUNTERS | ||
template <typename T> | ||
class AdvanceCounter : public Counter<T> | ||
{ | ||
public: | ||
AdvanceCounter(const char * label = NULL, const char * group = NULL) : mCounterValue(0) | ||
{ | ||
if (label) | ||
{ | ||
mlabel = label; | ||
} | ||
if (group) | ||
{ | ||
mgroup = group; | ||
} | ||
} | ||
~AdvanceCounter() override{}; | ||
|
||
/** | ||
* @brief | ||
* Initialize a MonotonicallyIncreasingCounter object. | ||
* | ||
* @param[in] aStartValue The starting value of the counter. | ||
* | ||
* @return A CHIP error code if something fails, CHIP_NO_ERROR otherwise | ||
*/ | ||
CHIP_ERROR Init(T aStartValue) | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
mCounterValue = aStartValue; | ||
|
||
return err; | ||
} | ||
|
||
/** | ||
* @brief | ||
* Advance the value of the counter. | ||
* | ||
* @return A CHIP error code if something fails, CHIP_NO_ERROR otherwise | ||
*/ | ||
CHIP_ERROR Advance() override | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
mCounterValue++; | ||
if (!isRegistered()) | ||
{ | ||
if (mlabel && mgroup) | ||
{ | ||
|
||
esp_err_t err1 = esp_diag_variable_register(mgroup, mlabel, mlabel, PATH, ESP_DIAG_DATA_TYPE_INT); | ||
if (err1 == ESP_OK) | ||
{ | ||
printf("Success"); | ||
registered = true; | ||
} | ||
else | ||
{ | ||
ESP_LOGE("CNT", "Registration failed, err: %d", err1); | ||
printf("Fail"); | ||
} | ||
esp_diag_variable_add_int(mlabel, (uint32_t) mCounterValue); | ||
} | ||
} | ||
|
||
printf("registerd %d", registered); | ||
if (mlabel) | ||
{ | ||
esp_diag_variable_add_int(mlabel, (uint32_t) mCounterValue); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
/** | ||
* @brief | ||
* Get the current value of the counter. | ||
* | ||
* @return The current value of the counter. | ||
*/ | ||
T GetValue() override { return mCounterValue; } | ||
|
||
protected: | ||
T mCounterValue; | ||
const char * mlabel; | ||
const char * mgroup; | ||
bool registered = false; | ||
bool isRegistered() { return registered; } | ||
}; | ||
/* | ||
#else | ||
template <typename T> | ||
class AdvanceCounter : public Counter<T> | ||
{ | ||
public: | ||
AdvanceCounter(const char *label=NULL,const char *group=NULL) : mCounterValue(0) {} | ||
~AdvanceCounter() override{}; | ||
CHIP_ERROR Init(T aStartValue) | ||
{ | ||
return CHIP_NO_ERROR; | ||
} | ||
CHIP_ERROR Advance() override | ||
{ | ||
return CHIP_NO_ERROR; | ||
} | ||
T GetValue() override { return mCounterValue; } | ||
protected: | ||
T mCounterValue; | ||
const char* mlabel; | ||
const char* mgroup; | ||
}; | ||
#endif | ||
*/ | ||
} // namespace chip | ||
|
||
// namespace chip |
30 changes: 30 additions & 0 deletions
30
src/tracing/esp32_trace/include/matter/tracing/counter.cpp
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,30 @@ | ||
#include "counter.h" | ||
|
||
namespace Insights{ | ||
InstantObject* InstantObject::m_head = nullptr; | ||
|
||
InstantObject* InstantObject::getInstance(const char* label, const char* group) { | ||
|
||
InstantObject* current = m_head; | ||
InstantObject* previous = nullptr; | ||
|
||
while (current != nullptr) { | ||
if (strcmp(current->label, label) == 0 && strcmp(current->group, group) == 0) { | ||
current->instanceCount++; | ||
return current; | ||
} | ||
previous = current; | ||
current = current->m_next; | ||
} | ||
|
||
InstantObject* newInstance = new InstantObject(label, group); | ||
newInstance->m_next = m_head; | ||
m_head = newInstance; | ||
return newInstance; | ||
} | ||
|
||
int InstantObject::getInstanceCount() const { | ||
return instanceCount; | ||
} | ||
|
||
} |
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,42 @@ | ||
#include <esp_diagnostics_metrics.h> | ||
#include <iostream> | ||
#include <lib/support/CHIPCounter.h> | ||
#include <string.h> | ||
|
||
#define PATH1 "sys.cnt" | ||
namespace Insights { | ||
class InstantObject | ||
{ | ||
private: | ||
static InstantObject * m_head; | ||
char label[50]; | ||
char group[50]; | ||
int instanceCount; | ||
InstantObject * m_next; | ||
bool registered = false; | ||
|
||
InstantObject(const char * labelParam, const char * groupParam) : instanceCount(1), m_next(nullptr) | ||
{ | ||
strncpy(label, labelParam, sizeof(label)); | ||
strncpy(group, groupParam, sizeof(group)); | ||
} | ||
|
||
public: | ||
static InstantObject * getInstance(const char * label, const char * group); | ||
|
||
int getInstanceCount() const; | ||
|
||
void traceInstant() | ||
{ | ||
std::cout << "Trace instant: Label=" << label << ", Group=" << group << ", Instance Count=" << instanceCount << std::endl; | ||
if (!registered) | ||
{ | ||
esp_diag_metrics_register("SYS_CNT", label, label, PATH1, ESP_DIAG_DATA_TYPE_UINT); | ||
registered = true; | ||
} | ||
std::cout << "Label ------" << label << "Count---" << 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
Oops, something went wrong.