diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index d35791cf1ed3c0..cda06f3b1f2409 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -140,6 +140,7 @@ if(CONFIG_ENABLE_PW_RPC) chip_gn_arg_append("pw_rpc_CONFIG" "\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc:disable_global_mutex\"") endif() + if (CONFIG_BUILD_CHIP_TESTS) chip_gn_arg_bool("chip_build_tests" "true") endif() @@ -414,6 +415,9 @@ if (CONFIG_SEC_CERT_DAC_PROVIDER) list(APPEND chip_libraries $) endif() +idf_component_get_property(esp_insights_lib espressif__esp_insights COMPONENT_LIB) +list(APPEND chip_libraries $) + idf_component_get_property(lwip_lib lwip COMPONENT_LIB) list(APPEND chip_libraries $) diff --git a/config/esp32/components/chip/idf_component.yml b/config/esp32/components/chip/idf_component.yml index 82c7fe3fc81338..a0bc2891fe4d12 100644 --- a/config/esp32/components/chip/idf_component.yml +++ b/config/esp32/components/chip/idf_component.yml @@ -15,3 +15,7 @@ dependencies: version: "2.0.3" rules: - if: "idf_version >=4.4" + + espressif/esp_insights: + version: "1.0.0" + diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn index 84af8b09ef2449..f70c0afe274376 100644 --- a/src/tracing/BUILD.gn +++ b/src/tracing/BUILD.gn @@ -26,6 +26,8 @@ buildconfig_header("tracing_buildconfig") { # to be set, that provides matter/tracing/macros_impl.h defines = [ "MATTER_TRACING_ENABLED=${matter_enable_tracing_support}" ] + print("MATTER_TRACING_ENABLED =${matter_enable_tracing_support}") + } config("multiplexed_tracing") { @@ -56,5 +58,6 @@ source_set("macros") { if (matter_enable_tracing_support) { public_deps += [ matter_trace_config ] + print("MATTER_TRACING_PATH =${matter_trace_config}") } } diff --git a/src/tracing/esp32_trace/BUILD.gn b/src/tracing/esp32_trace/BUILD.gn new file mode 100644 index 00000000000000..a61c99a30b00d7 --- /dev/null +++ b/src/tracing/esp32_trace/BUILD.gn @@ -0,0 +1,31 @@ +# +#Copyright (c) 2023 Project CHIP Authors +# +# 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. + + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("tracing") { + include_dirs = [ "include" ] +} + +source_set("esp32_trace") { + public = [ "include/matter/tracing/macros_impl.h" ] + sources = ["include/matter/tracing/macros_impl.cpp"] + public_configs = [ ":tracing" ] + public_deps = [ "${chip_root}/src/system" ] +} + + diff --git a/src/tracing/esp32_trace/include/matter/tracing/macros_impl.cpp b/src/tracing/esp32_trace/include/matter/tracing/macros_impl.cpp new file mode 100644 index 00000000000000..621fa4e4616a32 --- /dev/null +++ b/src/tracing/esp32_trace/include/matter/tracing/macros_impl.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * + * 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 "macros_impl.h" +#include +#include "esp_heap_caps.h" + //#include + +namespace Insights { + +ESP32Backend::ESP32Backend(const char * str, ...) +{ + va_list args; + va_start(args, str); + var1 = str; + var2= va_arg(args,const char *); + + if (var2 != NULL) + { + ESP_DIAG_EVENT("MTR_TRC", "Entry - %s - %s", var1, var2); + } + else + { + ESP_DIAG_EVENT("MTR_TRC", "Entry - %s", var1); + } + + // chip::System::Clock::Timestamp start = chip::System::SystemClock().GetMonotonicTimestamp(); + // start_time = chip::System::Clock::Milliseconds32(start).count(); + int start_min_heap =heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT); + int largest_free_block = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + int start_free_heap = heap_caps_get_free_size(MALLOC_CAP_8BIT); + //ESP_DIAG_EVENT("MTR_TRC","Start time - %5lu Start Min Free heap - %5d - Largest Free Block - %5d Start free heap -%5d ", start_time, start_min_heap, largest_free_block, start_free_heap); + ESP_DIAG_EVENT("MTR_TRC", " Start Min Free heap - %5d - Largest Free Block - %5d Start free heap -%5d", start_min_heap, largest_free_block, start_free_heap); + +} + +ESP32Backend::~ESP32Backend() +{ + if(var2!=NULL) + { + ESP_DIAG_EVENT("MTR_TRC", "Exit - %s - %s", var1, var2); + } + else + { + ESP_DIAG_EVENT("MTR_TRC", "Exit - %s", var1); + } + + //chip::System::Clock::Timestamp end = chip::System::SystemClock().GetMonotonicTimestamp(); + //long unsigned int end_time = chip::System::Clock::Milliseconds32(end).count(); + //long unsigned int time_elapsed = end_time -start_time; + int end_minimum_free_heap = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT); + int end_largest_free_block = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + int end_free_heap = heap_caps_get_free_size(MALLOC_CAP_8BIT); + //ESP_DIAG_EVENT("MTR_TRC","Time Elapsed - %5lu - End Min Free heap - %5d - End Largest Free Block %5d - End free Heap - %5d",time_elapsed, end_minimum_free_heap, end_largest_free_block, end_free_heap); + ESP_DIAG_EVENT("MTR_TRC","- End Min Free heap - %5d - End Largest Free Block %5d - End free Heap - %5d", end_minimum_free_heap, end_largest_free_block, end_free_heap); + +} +}//Insights + diff --git a/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h b/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h new file mode 100644 index 00000000000000..65c7d59870e068 --- /dev/null +++ b/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2023 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. + */ +#pragma once + +/* Ensure we do not have double tracing macros defined */ +#if defined(MATTER_TRACE_BEGIN) +#error "Tracing macros seem to be double defined" +#endif + +namespace Insights { +class ESP32Backend { +public: + ESP32Backend(const char* str, ...); + ~ESP32Backend(); + +private: + //long unsigned int start_time; + const char* var1; + const char* var2; +}; +} + +#define MATTER_TRACE_SCOPE(...) \ + do { \ + Insights::ESP32Backend backend(__VA_ARGS__); \ + } while (0) + + +#define _MATTER_TRACE_DISABLE(...) \ + do \ + { \ + } while (false) + +#define MATTER_TRACE_BEGIN(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) +#define MATTER_TRACE_END(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) +#define MATTER_TRACE_INSTANT(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) + + diff --git a/src/tracing/macros.h b/src/tracing/macros.h index 5f836e44d373bc..f093c6cbcfd56d 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -26,7 +26,7 @@ // MATTER_TRACE_END(label, group) // MATTER_TRACE_INSTANT(label, group) // MATTER_TRACE_SCOPE(label, group) -#include +#include #include #include diff --git a/src/tracing/tracing_args.gni b/src/tracing/tracing_args.gni index e62a4e21410955..2f27875d470723 100644 --- a/src/tracing/tracing_args.gni +++ b/src/tracing/tracing_args.gni @@ -14,6 +14,7 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") import("${build_root}/config/compiler/compiler.gni") +import("${chip_root}/src/platform/device.gni") declare_args() { # Tracing can have a non-zero size impact to binaries. We try to make @@ -22,7 +23,7 @@ declare_args() { # # Additionally, if tracing is enabled, the main() function has to add # backends explicitly - matter_enable_tracing_support = current_os == "android" + matter_enable_tracing_support = current_os == "android" || chip_device_platform == "esp32" # Defines the trace backend. Current matter tracing splits the logic # into two parts: @@ -45,10 +46,16 @@ declare_args() { # # TODO: cpp_standard check is not ideal, it should be >= 17, # however for now this is what we use in compilations - if ((current_os == "linux" || current_os == "android") && + + if (chip_device_platform == "esp32") { + matter_trace_config = "${chip_root}/src/tracing/esp32_trace:esp32_trace" + } + + else if ((current_os == "linux" || current_os == "android") && cpp_standard == "gnu++17") { matter_trace_config = "${chip_root}/src/tracing/perfetto:perfetto_tracing" - } else { + } + else { matter_trace_config = "${chip_root}/src/tracing/none" } }