Skip to content

Commit

Permalink
Restyler fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anush-apple committed Feb 22, 2024
1 parent 26d0698 commit 5cb87a9
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 110 deletions.
14 changes: 9 additions & 5 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRMetricsCollector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "MTRMetrics_Internal.h"
#import <MTRUnfairLock.h>
#include <platform/Darwin/Tracing.h>
#include <system/SystemClock.h>
#include <tracing/metric_event.h>
#include <tracing/registry.h>
#include <system/SystemClock.h>

using MetricEvent = chip::Tracing::MetricEvent;

Expand Down
2 changes: 1 addition & 1 deletion src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ static_library("system") {
sources = [
"PlatformEventSupport.h",
"SystemAlignSize.h",
"SystemClock.h",
"SystemClock.cpp",
"SystemClock.h",
"SystemError.cpp",
"SystemError.h",
"SystemEvent.h",
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

Expand Down
3 changes: 2 additions & 1 deletion src/tracing/esp32_trace/esp32_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
115 changes: 35 additions & 80 deletions src/tracing/metric_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#pragma once

#include <lib/core/CHIPError.h>
#include <tracing/metric_macros.h>
#include <tracing/metric_keys.h>
#include <tracing/metric_macros.h>
#include <tracing/registry.h>

namespace chip {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)) {}

Expand All @@ -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;
Expand All @@ -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
Expand Down
31 changes: 15 additions & 16 deletions src/tracing/metric_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
*/
#pragma once

#include <matter/tracing/build_config.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CodeUtils.h>
#include <matter/tracing/build_config.h>

#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)
*
Expand Down Expand Up @@ -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
Expand All @@ -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
////////////////////////
Expand Down Expand Up @@ -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
*
Expand All @@ -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
Expand All @@ -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

Expand All @@ -248,7 +248,6 @@

#define VerifyOrExitWithMetric(kMetricKey, aCondition, anAction) VerifyOrExit(aCondition, anAction)


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Map all MATTER_LOG_METRIC_XYZ macros to noops
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 5cb87a9

Please sign in to comment.