diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index c1e7db6df57a69..99d9f72820b8f9 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -710,15 +710,18 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re if (params.HasConnectionObject()) { - SuccessOrExitWithMetric(chip::Tracing::kMetricPASESessionBLE, err = mSystemState->BleLayer()->NewBleConnectionByObject(params.GetConnectionObject())); + SuccessOrExitWithMetric(chip::Tracing::kMetricPASESessionBLE, + err = mSystemState->BleLayer()->NewBleConnectionByObject(params.GetConnectionObject())); } else if (params.HasDiscoveredObject()) { // The RendezvousParameters argument needs to be recovered if the search succeed, so save them // for later. mRendezvousParametersForDeviceDiscoveredOverBle = params; - SuccessOrExitWithMetric(chip::Tracing::kMetricPASESessionBLE, err = mSystemState->BleLayer()->NewBleConnectionByObject( - params.GetDiscoveredObject(), this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError)); + SuccessOrExitWithMetric(chip::Tracing::kMetricPASESessionBLE, + err = mSystemState->BleLayer()->NewBleConnectionByObject(params.GetDiscoveredObject(), this, + OnDiscoveredDeviceOverBleSuccess, + OnDiscoveredDeviceOverBleError)); ExitNow(CHIP_NO_ERROR); } else if (params.HasDiscriminator()) @@ -729,8 +732,9 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re SetupDiscriminator discriminator; discriminator.SetLongValue(params.GetDiscriminator()); - SuccessOrExitWithMetric(chip::Tracing::kMetricPASESessionBLE, err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator( - discriminator, this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError)); + SuccessOrExitWithMetric(chip::Tracing::kMetricPASESessionBLE, + err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator( + discriminator, this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError)); ExitNow(CHIP_NO_ERROR); } else diff --git a/src/darwin/Framework/CHIP/MTRMetricsCollector.mm b/src/darwin/Framework/CHIP/MTRMetricsCollector.mm index aebf751fe85a7c..55935fb8b5bbe9 100644 --- a/src/darwin/Framework/CHIP/MTRMetricsCollector.mm +++ b/src/darwin/Framework/CHIP/MTRMetricsCollector.mm @@ -20,9 +20,9 @@ #include "MTRMetrics_Internal.h" #import #include +#include #include #include -#include using MetricEvent = chip::Tracing::MetricEvent; diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn index 51df8f6e1be260..9f24ad171be72a 100644 --- a/src/system/BUILD.gn +++ b/src/system/BUILD.gn @@ -218,8 +218,8 @@ static_library("system") { sources = [ "PlatformEventSupport.h", "SystemAlignSize.h", - "SystemClock.h", "SystemClock.cpp", + "SystemClock.h", "SystemError.cpp", "SystemError.h", "SystemEvent.h", diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn index 2bce4132504100..cdb50a710c9c00 100644 --- a/src/tracing/BUILD.gn +++ b/src/tracing/BUILD.gn @@ -36,17 +36,17 @@ static_library("tracing") { sources = [ "backend.h", "log_declares.h", - "registry.cpp", - "registry.h", "metric_event.h", "metric_keys.h", "metric_macros.h", + "registry.cpp", + "registry.h", ] public_deps = [ ":tracing_buildconfig", - "${chip_root}/src/lib/support", "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", ] } diff --git a/src/tracing/esp32_trace/esp32_tracing.cpp b/src/tracing/esp32_trace/esp32_tracing.cpp index 53e39a17f65808..13a9bb80c6083f 100644 --- a/src/tracing/esp32_trace/esp32_tracing.cpp +++ b/src/tracing/esp32_trace/esp32_tracing.cpp @@ -166,7 +166,8 @@ void ESP32Backend::LogMetricEvent(const MetricEvent & event) } using ValueType = MetricEvent::Value::Type; - switch (event.value().type) { + switch (event.value().type) + { 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()); diff --git a/src/tracing/json/json_tracing.cpp b/src/tracing/json/json_tracing.cpp index 06b37734a11572..156cd12d9a55db 100644 --- a/src/tracing/json/json_tracing.cpp +++ b/src/tracing/json/json_tracing.cpp @@ -303,7 +303,8 @@ void JsonBackend::LogMetricEvent(const MetricEvent & event) value["label"] = event.key(); using ValueType = MetricEvent::Value::Type; - switch (event.value().type) { + switch (event.value().type) + { case ValueType::kInt32: value["value"] = event.ValueInt32(); break; diff --git a/src/tracing/metric_event.h b/src/tracing/metric_event.h index 9edbe654a38561..1c251a8a2eabbb 100644 --- a/src/tracing/metric_event.h +++ b/src/tracing/metric_event.h @@ -17,8 +17,8 @@ #pragma once #include -#include #include +#include #include namespace chip { @@ -34,10 +34,10 @@ namespace Tracing { class MetricEvent { public: - MetricEvent(const MetricEvent&) = default; - MetricEvent(MetricEvent &&) = default; - MetricEvent &operator=(const MetricEvent&) = default; - MetricEvent &operator=(MetricEvent &&) = default; + MetricEvent(const MetricEvent &) = default; + MetricEvent(MetricEvent &&) = default; + MetricEvent & operator=(const MetricEvent &) = default; + MetricEvent & operator=(MetricEvent &&) = default; public: // This specifies the different categories of metric events that can created. In addition to @@ -53,16 +53,16 @@ class MetricEvent // This defines the different types of values that can stored when a metric is emitted struct Value { - Value(const Value&) = default; - Value(Value &&) = default; - Value &operator=(const Value&) = default; - Value &operator=(Value &&) = default; + Value(const Value &) = default; + Value(Value &&) = default; + Value & operator=(const Value &) = default; + Value & operator=(Value &&) = default; enum class Type : uint8_t { - kInt32, // int32_t - kUInt32, // uint32_t - kChipErrorCode // chip::ChipError + kInt32, // int32_t + kUInt32, // uint32_t + kChipErrorCode // chip::ChipError }; union Store @@ -85,21 +85,13 @@ class MetricEvent Value(const ChipError & err) : store(err.AsInteger()), type(Type::kChipErrorCode) {} }; - MetricEvent(Type type, MetricKey key, int32_t value = 0) : - mType(type), mKey(key), mValue(value) - {} + MetricEvent(Type type, MetricKey key, int32_t value = 0) : mType(type), mKey(key), mValue(value) {} - MetricEvent(Type type, MetricKey key, uint32_t value) : - mType(type), mKey(key), mValue(value) - {} + MetricEvent(Type type, MetricKey key, uint32_t value) : mType(type), mKey(key), mValue(value) {} - MetricEvent(Type type, MetricKey key, const ChipError & error) : - mType(type), mKey(key), mValue(error) - {} + MetricEvent(Type type, MetricKey key, const ChipError & error) : mType(type), mKey(key), mValue(error) {} - MetricEvent(Type type, MetricKey key, Value value) : - mType(type), mKey(key), mValue(value) - {} + MetricEvent(Type type, MetricKey key, Value value) : mType(type), mKey(key), mValue(value) {} MetricEvent(Type type, MetricKey key, int8_t value) : MetricEvent(type, key, int32_t(value)) {} @@ -109,35 +101,17 @@ class MetricEvent MetricEvent(Type type, MetricKey key, uint16_t value) : MetricEvent(type, key, uint32_t(value)) {} - Type type() const - { - return mType; - } + Type type() const { return mType; } - MetricKey key() const - { - return mKey; - } + MetricKey key() const { return mKey; } - Value value() const - { - return mValue; - } + Value value() const { return mValue; } - uint32_t ValueUInt32() const - { - return mValue.store.uint32_value; - } + uint32_t ValueUInt32() const { return mValue.store.uint32_value; } - int32_t ValueInt32() const - { - return mValue.store.int32_value; - } + int32_t ValueInt32() const { return mValue.store.int32_value; } - uint32_t ValueErrorCode() const - { - return mValue.store.uint32_value; - } + uint32_t ValueErrorCode() const { return mValue.store.uint32_value; } private: Type mType; @@ -164,64 +138,45 @@ inline bool LogMetricIfError(MetricKey metricKey, const ::chip::ChipError & err) /** * This utility class helps generate a Begin and End metric event within the scope of a block using RAII. - * This class is also meant to be used in expressions where ChipError object are typically used to capture + * This class is also meant to be used in expressions where ChipError object are typically used to capture * error values. */ class ScopedMetricEvent { public: - ScopedMetricEvent(const ScopedMetricEvent&) = default; - ScopedMetricEvent(ScopedMetricEvent &&) = default; - ScopedMetricEvent &operator=(const ScopedMetricEvent&) = default; - ScopedMetricEvent &operator=(ScopedMetricEvent &&) = default; + ScopedMetricEvent(const ScopedMetricEvent &) = default; + ScopedMetricEvent(ScopedMetricEvent &&) = default; + ScopedMetricEvent & operator=(const ScopedMetricEvent &) = default; + ScopedMetricEvent & operator=(ScopedMetricEvent &&) = default; - ScopedMetricEvent(MetricKey key, const ChipError & error = CHIP_NO_ERROR) : mKey(key), mError(error) + ScopedMetricEvent(MetricKey key, const ChipError & error = CHIP_NO_ERROR) : mKey(key), mError(error) { MATTER_LOG_METRIC_BEGIN(mKey); } - ~ScopedMetricEvent() - { - MATTER_LOG_METRIC_END(mKey, mError); - } + ~ScopedMetricEvent() { MATTER_LOG_METRIC_END(mKey, mError); } - operator ChipError() const - { - return mError; - } + operator ChipError() const { return mError; } - ScopedMetricEvent& operator = (const ChipError & err) + ScopedMetricEvent & operator=(const ChipError & err) { mError = err; return *this; } - friend bool operator == (const ScopedMetricEvent & event, const ChipError & err) - { - return event.mError == err; - } + friend bool operator==(const ScopedMetricEvent & event, const ChipError & err) { return event.mError == err; } - friend bool operator != (const ScopedMetricEvent & event, const ChipError & err) - { - return event.mError != err; - } + friend bool operator!=(const ScopedMetricEvent & event, const ChipError & err) { return event.mError != err; } - friend bool operator == (const ChipError & err, const ScopedMetricEvent & event) - { - return event.mError == err; - } + friend bool operator==(const ChipError & err, const ScopedMetricEvent & event) { return event.mError == err; } - friend bool operator != (const ChipError & err, const ScopedMetricEvent & event) - { - return event.mError != err; - } + friend bool operator!=(const ChipError & err, const ScopedMetricEvent & event) { return event.mError != err; } private: MetricKey mKey; ChipError mError; }; - } // namespace utils } // namespace Tracing diff --git a/src/tracing/metric_macros.h b/src/tracing/metric_macros.h index 148460392eeb27..6aa8f4279dd3be 100644 --- a/src/tracing/metric_macros.h +++ b/src/tracing/metric_macros.h @@ -17,16 +17,15 @@ */ #pragma once -#include #include #include +#include #define __LOG_METRIC_CONCAT_IMPL(a, b) a##b #define __LOG_METRIC_MACRO_CONCAT(a, b) __LOG_METRIC_CONCAT_IMPL(a, b) #if MATTER_TRACING_ENABLED - /** * @def SuccessOrExitWithMetric(kMetriKey, aStatus) * @@ -97,7 +96,8 @@ * @param[in] anAction An expression or block to execute when the * assertion fails. */ -#define VerifyOrExitWithMetric(kMetricKey, aCondition, anAction) nlEXPECT_ACTION(aCondition, exit, MATTER_LOG_METRIC(kMetricKey, anAction)) +#define VerifyOrExitWithMetric(kMetricKey, aCondition, anAction) \ + nlEXPECT_ACTION(aCondition, exit, MATTER_LOG_METRIC(kMetricKey, anAction)) /* * Utility Macros to support optional arguments for MATTER_LOG_METRIC_XYZ macros @@ -117,28 +117,27 @@ #define __MATTER_LOG_METRIC_1ARGS(key) \ do \ { \ - using Type = chip::Tracing::MetricEvent::Type; \ - ::chip::Tracing::MetricEvent _metric_event(Type::kInstantEvent, key); \ + using Type = chip::Tracing::MetricEvent::Type; \ + ::chip::Tracing::MetricEvent _metric_event(Type::kInstantEvent, key); \ ::chip::Tracing::Internal::LogMetricEvent(_metric_event); \ } while (false) // Wrapper macro that accepts metric type and key and logs an event corresponding to the type -#define __MATTER_LOG_METRIC_2ARGS(type, key) \ +#define __MATTER_LOG_METRIC_2ARGS(type, key) \ do \ { \ - ::chip::Tracing::MetricEvent _metric_event(type, key); \ - ::chip::Tracing::Internal::LogMetricEvent(_metric_event); \ + ::chip::Tracing::MetricEvent _metric_event(type, key); \ + ::chip::Tracing::Internal::LogMetricEvent(_metric_event); \ } while (false) // Wrapper macro that accepts metric type, key and value and logs the corresponding event -#define __MATTER_LOG_METRIC_3ARGS(type, key, value) \ +#define __MATTER_LOG_METRIC_3ARGS(type, key, value) \ do \ { \ - ::chip::Tracing::MetricEvent _metric_event(type, key, value); \ - ::chip::Tracing::Internal::LogMetricEvent(_metric_event); \ + ::chip::Tracing::MetricEvent _metric_event(type, key, value); \ + ::chip::Tracing::Internal::LogMetricEvent(_metric_event); \ } while (false) - //////////////////////// // Metric logging macros //////////////////////// @@ -201,7 +200,6 @@ */ #define MATTER_LOG_METRIC_END(key, ...) __MATTER_LOG_METRIC(chip::Tracing::MetricEvent::Type::kEndEvent, key, ##__VA_ARGS__) - /** * @def MATTER_LOG_METRIC_SCOPE * @@ -216,7 +214,8 @@ * * @param[in] key The key representing the metric name/event. */ -#define MATTER_LOG_METRIC_SCOPE(key) ::chip::Tracing::utils::ScopedMetricEvent __LOG_METRIC_MACRO_CONCAT(_metric_scope, __COUNTER__)(key) +#define MATTER_LOG_METRIC_SCOPE(key) \ + ::chip::Tracing::utils::ScopedMetricEvent __LOG_METRIC_MACRO_CONCAT(_metric_scope, __COUNTER__)(key) /** * @def MATTER_LOG_METRIC_SCOPE_WITH_ERROR @@ -236,7 +235,8 @@ * @param[in] errorObj The name of the object for the ScopedMetricEvent. * @param[in] errorValue The initial error code value. */ -#define MATTER_LOG_METRIC_SCOPE_WITH_ERROR(key, errorObj, errorValue) chip::Tracing::utils::ScopedMetricEvent errorObj(key, errorValue) +#define MATTER_LOG_METRIC_SCOPE_WITH_ERROR(key, errorObj, errorValue) \ + chip::Tracing::utils::ScopedMetricEvent errorObj(key, errorValue) #else // Tracing is disabled @@ -248,7 +248,6 @@ #define VerifyOrExitWithMetric(kMetricKey, aCondition, anAction) VerifyOrExit(aCondition, anAction) - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Map all MATTER_LOG_METRIC_XYZ macros to noops //////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/tracing/perfetto/perfetto_tracing.cpp b/src/tracing/perfetto/perfetto_tracing.cpp index 778f77d45b6161..71fb2a3faa04e2 100644 --- a/src/tracing/perfetto/perfetto_tracing.cpp +++ b/src/tracing/perfetto/perfetto_tracing.cpp @@ -130,7 +130,8 @@ void PerfettoBackend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo & info) void PerfettoBackend::LogMetricEvent(const MetricEvent & event) { using ValueType = MetricEvent::Value::Type; - switch (event.value().type) { + switch (event.value().type) + { case ValueType::kInt32: TRACE_EVENT_INSTANT("Matter", event.key(), "value", event.ValueInt32()); break; diff --git a/src/tracing/tracing_args.gni b/src/tracing/tracing_args.gni index 63f8f457fcfb72..d6ddb1fd2e99b8 100644 --- a/src/tracing/tracing_args.gni +++ b/src/tracing/tracing_args.gni @@ -23,7 +23,8 @@ declare_args() { # # Additionally, if tracing is enabled, the main() function has to add # backends explicitly - matter_enable_tracing_support = (current_os == "android") || (chip_device_platform == "darwin") + matter_enable_tracing_support = + current_os == "android" || chip_device_platform == "darwin" # Defines the trace backend. Current matter tracing splits the logic # into two parts: