Skip to content

Commit

Permalink
Merge branch 'master' into android_icd_checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo authored Mar 7, 2024
2 parents ff03d3f + c2f58e4 commit 505ad4f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 13 deletions.
10 changes: 10 additions & 0 deletions config/nrfconnect/chip-gn/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"
Expand All @@ -25,5 +26,14 @@ default_args = {
target_cpu = "arm"
target_os = "zephyr"

pw_sys_io_BACKEND = dir_pw_sys_io_stdio
pw_assert_BACKEND = dir_pw_assert_log
pw_log_BACKEND = dir_pw_log_basic

pw_build_LINK_DEPS = [
"$dir_pw_assert:impl",
"$dir_pw_log:impl",
]

import("${chip_root}/config/nrfconnect/chip-gn/args.gni")
}
2 changes: 1 addition & 1 deletion scripts/setup/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ghapi==1.0.3
# via -r requirements.memory.txt
humanfriendly==10.0
# via coloredlogs
idf-component-manager==1.2.2
idf-component-manager==1.5.2
# via -r requirements.esp32.txt
idna==3.4
# via requests
Expand Down
3 changes: 3 additions & 0 deletions scripts/tools/check_includes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
'src/tracing/json/json_tracing.cpp': {'string', 'sstream'},
'src/tracing/json/json_tracing.h': {'fstream', 'unordered_map'},

# esp32 tracing
'src/tracing/esp32_trace/esp32_tracing.h': {'unordered_map'},

# Not intended for embedded clients
'src/app/PendingResponseTrackerImpl.h': {'unordered_set'},

Expand Down
3 changes: 2 additions & 1 deletion src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ if (chip_build_tests) {
if (chip_monolithic_tests) {
# TODO [PW_MIGRATION] Remove this if after migartion to PW_TEST is completed for all platforms
# TODO [PW_MIGRATION] There will be a list of already migrated platforms
if (chip_device_platform == "esp32") {
if (chip_device_platform == "esp32" ||
chip_device_platform == "nrfconnect") {
deps += [ "${chip_root}/src/lib/support:pw_tests_wrapper" ]
}
build_monolithic_library = true
Expand Down
2 changes: 2 additions & 0 deletions src/test_driver/nrfconnect/main/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTest.h>
#include <lib/support/UnitTestRegistration.h>
#include <platform/CHIPDeviceLayer.h>

Expand All @@ -35,6 +36,7 @@ extern "C" int main(void)

LOG_INF("Starting CHIP tests!");
int status = RunRegisteredUnitTests();
status += chip::test::RunAllTests();
LOG_INF("CHIP test status: %d", status);

_exit(status);
Expand Down
56 changes: 46 additions & 10 deletions src/tracing/esp32_trace/esp32_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <algorithm>
#include <esp_err.h>
#include <esp_heap_caps.h>
#include <esp_insights.h>
#include <esp_log.h>
Expand Down Expand Up @@ -134,10 +135,7 @@ void RemoveHashFromPermitlist(const char * str)
#define LOG_HEAP_INFO(label, group, entry_exit) \
do \
{ \
ESP_DIAG_EVENT("MTR_TRC", "%s - %s - %s Min Free heap - %u - LFB - %u Start free heap - %u", entry_exit, label, group, \
heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT), \
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT), \
heap_caps_get_free_size(MALLOC_CAP_8BIT)); \
ESP_DIAG_EVENT("MTR_TRC", "%s - %s - %s", entry_exit, label, group); \
} while (0)

void ESP32Backend::LogMessageReceived(MessageReceivedInfo & info) {}
Expand All @@ -155,34 +153,71 @@ void ESP32Backend::TraceCounter(const char * label)
::Insights::ESPInsightsCounter::GetInstance(label)->ReportMetrics();
}

void ESP32Backend::RegisterMetric(const char * key, ValueType type)
{
// Check for the same key will not have two different types.
if (mRegisteredMetrics.find(key) != mRegisteredMetrics.end())
{
if (mRegisteredMetrics[key] != type)
{
ESP_LOGE("SYS.MTR", "Type mismatch for metric key %s", key);
return;
}
}

switch (type)
{
case ValueType::kUInt32:
esp_diag_metrics_register("SYS_MTR" /*Tag of metrics */, key /* Unique key 8 */, key /* label displayed on dashboard */,
"insights.mtr" /* hierarchical path */, ESP_DIAG_DATA_TYPE_UINT /* data_type */);
break;

case ValueType::kInt32:
esp_diag_metrics_register("SYS_MTR" /*Tag of metrics */, key /* Unique key 8 */, key /* label displayed on dashboard */,
"insights.mtr" /* hierarchical path */, ESP_DIAG_DATA_TYPE_INT /* data_type */);
break;

case ValueType::kChipErrorCode:
esp_diag_metrics_register("SYS_MTR" /*Tag of metrics */, key /* Unique key 8 */, key /* label displayed on dashboard */,
"insights.mtr" /* hierarchical path */, ESP_DIAG_DATA_TYPE_UINT /* data_type */);
break;

case ValueType::kUndefined:
ESP_LOGE("mtr", "failed to register %s as its value is undefined", key);
break;
}

mRegisteredMetrics[key] = type;
}

void ESP32Backend::LogMetricEvent(const MetricEvent & event)
{
if (!mRegistered)
if (mRegisteredMetrics.find(event.key()) == mRegisteredMetrics.end())
{
esp_diag_metrics_register("SYS_MTR" /*Tag of metrics */, event.key() /* Unique key 8 */,
event.key() /* label displayed on dashboard */, "insights.mtr" /* hierarchical path */,
ESP_DIAG_DATA_TYPE_INT /* data_type */);
mRegistered = true;
RegisterMetric(event.key(), event.ValueType());
}

using ValueType = MetricEvent::Value::Type;
switch (event.ValueType())
{
case ValueType::kInt32:
ESP_LOGI("mtr", "The value of %s is %ld ", event.key(), event.ValueInt32());
esp_diag_metrics_add_int(event.key(), event.ValueInt32());
break;

case ValueType::kUInt32:
ESP_LOGI("mtr", "The value of %s is %lu ", event.key(), event.ValueUInt32());
esp_diag_metrics_add_uint(event.key(), event.ValueUInt32());
break;

case ValueType::kChipErrorCode:
ESP_LOGI("mtr", "The value of %s is error with code %lu ", event.key(), event.ValueErrorCode());
esp_diag_metrics_add_uint(event.key(), event.ValueErrorCode());
break;

case ValueType::kUndefined:
ESP_LOGI("mtr", "The value of %s is undefined", event.key());
break;

default:
ESP_LOGI("mtr", "The value of %s is of an UNKNOWN TYPE", event.key());
break;
Expand Down Expand Up @@ -211,6 +246,7 @@ void ESP32Backend::TraceInstant(const char * label, const char * group)
{
ESP_DIAG_EVENT("MTR_TRC", "Instant : %s -%s", label, group);
}

} // namespace Insights
} // namespace Tracing
} // namespace chip
6 changes: 5 additions & 1 deletion src/tracing/esp32_trace/esp32_tracing.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <lib/core/CHIPError.h>
#include <tracing/backend.h>
#include <tracing/metric_event.h>
#include <unordered_map>

#include <memory>
namespace chip {
Expand Down Expand Up @@ -39,7 +41,9 @@ class ESP32Backend : public ::chip::Tracing::Backend
void LogMetricEvent(const MetricEvent &) override;

private:
bool mRegistered = false;
using ValueType = MetricEvent::Value::Type;
std::unordered_map<const char *, ValueType> mRegisteredMetrics;
void RegisterMetric(const char * key, ValueType type);
};

} // namespace Insights
Expand Down

0 comments on commit 505ad4f

Please sign in to comment.