Skip to content

Commit

Permalink
New Tracing Approach
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Jul 17, 2023
1 parent b6caecf commit 8e1500e
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -414,6 +415,9 @@ if (CONFIG_SEC_CERT_DAC_PROVIDER)
list(APPEND chip_libraries $<TARGET_FILE:${esp32_secure_cert_mgr_lib}>)
endif()

idf_component_get_property(esp_insights_lib espressif__esp_insights COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${esp_insights_lib}>)

idf_component_get_property(lwip_lib lwip COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${lwip_lib}>)

Expand Down
4 changes: 4 additions & 0 deletions config/esp32/components/chip/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ dependencies:
version: "2.0.3"
rules:
- if: "idf_version >=4.4"

espressif/esp_insights:
version: "1.0.0"

3 changes: 3 additions & 0 deletions src/tracing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -56,5 +58,6 @@ source_set("macros") {

if (matter_enable_tracing_support) {
public_deps += [ matter_trace_config ]
print("MATTER_TRACING_PATH =${matter_trace_config}")
}
}
31 changes: 31 additions & 0 deletions src/tracing/esp32_trace/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}


73 changes: 73 additions & 0 deletions src/tracing/esp32_trace/include/matter/tracing/macros_impl.cpp
Original file line number Diff line number Diff line change
@@ -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 <esp_insights.h>
#include "esp_heap_caps.h"
//#include <system/SystemClock.h>

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

53 changes: 53 additions & 0 deletions src/tracing/esp32_trace/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
@@ -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__)


2 changes: 1 addition & 1 deletion src/tracing/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// MATTER_TRACE_END(label, group)
// MATTER_TRACE_INSTANT(label, group)
// MATTER_TRACE_SCOPE(label, group)
#include <matter/tracing/macros_impl.h>
#include <tracing/esp32_trace/include/matter/tracing/macros_impl.h>
#include <tracing/log_declares.h>
#include <tracing/registry.h>

Expand Down
13 changes: 10 additions & 3 deletions src/tracing/tracing_args.gni
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_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
Expand All @@ -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:
Expand All @@ -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"
}
}

0 comments on commit 8e1500e

Please sign in to comment.