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 ae1136b
Showing
4 changed files
with
188 additions
and
0 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
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 |
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 |