Skip to content

Commit

Permalink
Approach 1
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Oct 3, 2023
1 parent 1ec98c8 commit ae1136b
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,11 @@ menu "CHIP Device Layer"
ESP Insights is a remote diagnostics solution to monitor the health of ESP devices in the field.
Enabling the above option will enable the esp32 specific tracing functionality and report the
diagnostic information to the insights cloud.

config ENABLE_ESP_INSIGHTS_COUNTERS
bool "Enable Counters"
depends on ESP_INSIGHTS_ENABLED
default y

endmenu

Expand Down
2 changes: 2 additions & 0 deletions src/lib/support/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static_library("support") {
"IniEscaping.cpp",
"IniEscaping.h",
"Iterators.h",
"LabeledCounter.h",
"LifetimePersistedCounter.h",
"ObjectLifeCycle.h",
"PersistedCounter.h",
Expand Down Expand Up @@ -177,6 +178,7 @@ static_library("support") {
"${nlio_root}:nlio",
]


# These are needed because we include CHIPCore.h, which uses config
# options for src/ble and src/inet, however we cannot depend on those
# directly as such a dependency is cyclic.
Expand Down
32 changes: 32 additions & 0 deletions src/lib/support/LabeledCounter.h
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 src/tracing/esp32_trace/include/matter/tracing/ESP32Counter.h
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

0 comments on commit ae1136b

Please sign in to comment.