Skip to content

Commit

Permalink
Restyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anush-apple committed Feb 20, 2024
1 parent 4fcbbdb commit ed65bb5
Show file tree
Hide file tree
Showing 22 changed files with 155 additions and 170 deletions.
9 changes: 5 additions & 4 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,9 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
// The RendezvousParameters argument needs to be recovered if the search succeed, so save them
// for later.
mRendezvousParametersForDeviceDiscoveredOverBle = params;
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByObject(params.GetDiscoveredObject(), this,
OnDiscoveredDeviceOverBleSuccess,
OnDiscoveredDeviceOverBleError), PASESessionBLE);
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByObject(
params.GetDiscoveredObject(), this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError),
PASESessionBLE);
ExitNow(CHIP_NO_ERROR);
}
else if (params.HasDiscriminator())
Expand All @@ -730,7 +730,8 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
SetupDiscriminator discriminator;
discriminator.SetLongValue(params.GetDiscriminator());
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator(
discriminator, this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError), PASESessionBLE);
discriminator, this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError),
PASESessionBLE);
ExitNow(CHIP_NO_ERROR);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRMetrics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/
#import "MTRLogging_Internal.h"
#include <MTRMetrics.h>
#include <Foundation/Foundation.h>
#import "MTRMetrics_Internal.h"
#include <Foundation/Foundation.h>
#include <MTRMetrics.h>
#import <Matter/MTRDefines.h>

@implementation MTRMetrics {
Expand Down
1 change: 0 additions & 1 deletion src/darwin/Framework/CHIP/MTRMetricsCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <MTRDefines.h>
#import <Matter/MTRMetrics.h>


NS_ASSUME_NONNULL_BEGIN

void InitializeMetricsCollection();
Expand Down
49 changes: 24 additions & 25 deletions src/darwin/Framework/CHIP/MTRMetricsCollector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/

#import "MTRMetricsCollector.h"
#include <tracing/metric_event.h>
#include <platform/Darwin/Tracing.h>
#include <tracing/registry.h>
#import <MTRUnfairLock.h>
#import "MTRLogging_Internal.h"
#include "MTRMetrics_Internal.h"
#import <MTRUnfairLock.h>
#include <platform/Darwin/Tracing.h>
#include <tracing/metric_event.h>
#include <tracing/registry.h>

using MetricEvent = chip::Tracing::MetricEvent;

Expand All @@ -31,28 +31,25 @@

void InitializeMetricsCollection()
{
if ([MTRMetricsCollector sharedInstance])
{
if ([MTRMetricsCollector sharedInstance]) {
MTR_LOG_INFO("Initialized metrics collection backend for Darwin");
}
}


@implementation MTRMetricsData {
chip::System::Clock::Microseconds64 _timePoint;
chip::System::Clock::Microseconds64 _duration;
}

- (instancetype)initWithMetricEvent:(const MetricEvent&) event
- (instancetype)initWithMetricEvent:(const MetricEvent &)event
{
if (!(self = [super init])) {
return nil;
}

if (event.value.type == MetricEvent::Value::Type::Signed32Type) {
_value = [NSNumber numberWithInteger:event.value.store.int32_value];
}
else {
} else {
_value = [NSNumber numberWithUnsignedInteger:event.value.store.uint32_value];
}
_timePoint = event.timePoint;
Expand Down Expand Up @@ -113,10 +110,10 @@ + (instancetype)sharedInstance
if (singleton) {
chip::Tracing::Register(singleton->_tracingBackend);
singleton->_tracingBackend.SetLogEventClientCallback(^(MetricEvent event) {
if (singleton) {
[singleton handleMetricEvent:event];
}
});
if (singleton) {
[singleton handleMetricEvent:event];
}
});
}
});
return singleton;
Expand All @@ -135,9 +132,12 @@ - (instancetype)init
static inline NSString * suffixNameForMetricTag(MetricEvent::Tag tag)
{
switch (tag) {
case MetricEvent::Tag::Begin: return @"-begin";
case MetricEvent::Tag::End: return @"-end";
case MetricEvent::Tag::Instant: return @"-instant";
case MetricEvent::Tag::Begin:
return @"-begin";
case MetricEvent::Tag::End:
return @"-end";
case MetricEvent::Tag::Instant:
return @"-instant";
}
}

Expand All @@ -149,24 +149,23 @@ - (instancetype)init
- (void)handleMetricEvent:(MetricEvent)event
{
MTR_LOG_INFO("Received metric event, key: %s, type: %hhu value: %d",
event.key,
event.value.type,
(event.value.type == MetricEvent::Value::Type::Signed32Type) ? event.value.store.int32_value : event.value.store.uint32_value);
event.key,
event.value.type,
(event.value.type == MetricEvent::Value::Type::Signed32Type) ? event.value.store.int32_value : event.value.store.uint32_value);

std::lock_guard lock(_lock);

// Create the new metric key based event type
auto metricsKey = [NSString stringWithFormat:@"%s%@", event.key, suffixNameForMetricTag(event)];
MTRMetricsData *data = [[MTRMetricsData alloc] initWithMetricEvent:event];
MTRMetricsData * data = [[MTRMetricsData alloc] initWithMetricEvent:event];

// If End event, compute its duration using the Begin event
if (event.tag == MetricEvent::Tag::End) {
auto metricsBeginKey = [NSString stringWithFormat:@"%s%@", event.key, suffixNameForMetricTag(MetricEvent::Tag::Begin)];
MTRMetricsData * beginMetric = _metricsDataCollection[metricsBeginKey];
if (beginMetric) {
[data setDurationFromMetricData:beginMetric];
}
else {
} else {
// Unbalanced end
MTR_LOG_ERROR("Unable to find Begin event corresponding to Metric Event: %s", event.key);
}
Expand All @@ -189,14 +188,14 @@ - (MTRMetrics *)metricSnapshot:(BOOL)resetCollection
std::lock_guard lock(_lock);

// Copy the MTRMetrics as NSDictionary
MTRMetrics *metrics = [[MTRMetrics alloc] initWithCapacity:[_metricsDataCollection count]];
MTRMetrics * metrics = [[MTRMetrics alloc] initWithCapacity:[_metricsDataCollection count]];
for (NSString * key in _metricsDataCollection) {
[metrics setValue:[_metricsDataCollection[key] toDictionary] forKey:key];
}

// Clear curent stats, if specified
if (resetCollection) {
[_metricsDataCollection removeAllObjects];
[_metricsDataCollection removeAllObjects];
}
return metrics;
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/support/CodeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ constexpr inline const _T & max(const _T & a, const _T & b)
* result of the expression aStatus.
*
*/
#define SuccessOrExit(aStatus,...) nlEXPECT(LOG_METRIC_FOR_SUCCESS_OR_EXIT((aStatus), ##__VA_ARGS__), exit)
#define SuccessOrExit(aStatus, ...) nlEXPECT(LOG_METRIC_FOR_SUCCESS_OR_EXIT((aStatus), ##__VA_ARGS__), exit)

/**
* @def VerifyOrExit(aCondition, anAction)
Expand Down Expand Up @@ -429,7 +429,8 @@ constexpr inline const _T & max(const _T & a, const _T & b)
* result of the expression anAction.
*
*/
#define VerifyOrExit(aCondition, anAction,...) nlEXPECT_ACTION(aCondition, exit, LOG_METRIC_FOR_VERIFY_OR_EXIT_ACTION(anAction, ##__VA_ARGS__))
#define VerifyOrExit(aCondition, anAction, ...) \
nlEXPECT_ACTION(aCondition, exit, LOG_METRIC_FOR_VERIFY_OR_EXIT_ACTION(anAction, ##__VA_ARGS__))

/**
* @def ExitNow(...)
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ static_library("Darwin") {

source_set("tracing") {
sources = [
"Tracing.mm",
"Tracing.h",
"Tracing.mm",
]

deps = [
Expand Down
62 changes: 32 additions & 30 deletions src/platform/Darwin/Tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
#include <os/signpost.h>
#include <tracing/backend.h>

#define MATTER_TRACE_BEGIN(label,group) os_signpost_interval_begin(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_END(label,group) os_signpost_interval_end(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_INSTANT(label,group) os_signpost_event_emit(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_BEGIN(label, group) os_signpost_interval_begin(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_END(label, group) os_signpost_interval_end(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_INSTANT(label, group) os_signpost_event_emit(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)

#define MATTER_TRACE_COUNTER(label) \
do \
{ \
static unsigned int count##_label = 0; \
os_signpost_event_emit(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, label, "%u", ++count##_label); \
#define MATTER_TRACE_COUNTER(label) \
do { \
static unsigned int count##_label = 0; \
os_signpost_event_emit(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, label, "%u", ++count##_label); \
} while (0)

#define _CONCAT_IMPL(a, b) a##b
Expand All @@ -41,35 +40,38 @@

namespace chip {
namespace Tracing {
namespace signposts {
namespace signposts {

os_log_t GetMatterSignpostLogger();
os_log_t GetMatterSignpostLogger();

class Scoped
{
public:
inline Scoped(const char * label, const char * group) : mLabel(label), mGroup(group) { os_signpost_interval_begin(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, MATTER_SDK_SIGNPOST_NAME, "%s-%s", group, label); }
inline ~Scoped() { os_signpost_interval_end(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, MATTER_SDK_SIGNPOST_NAME, "%s-%s", mGroup, mLabel); }
class Scoped {
public:
inline Scoped(const char * label, const char * group)
: mLabel(label)
, mGroup(group)
{
os_signpost_interval_begin(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, MATTER_SDK_SIGNPOST_NAME, "%s-%s", group, label);
}
inline ~Scoped() { os_signpost_interval_end(__DARWIN_MATTER_SIGNPOST_LOGGER(), OS_SIGNPOST_ID_EXCLUSIVE, MATTER_SDK_SIGNPOST_NAME, "%s-%s", mGroup, mLabel); }

private:
const char * mLabel;
const char * mGroup;
};
private:
const char * mLabel;
const char * mGroup;
};

class DarwinTracingBackend : public ::chip::Tracing::Backend
{
public:
DarwinTracingBackend();
class DarwinTracingBackend : public ::chip::Tracing::Backend {
public:
DarwinTracingBackend();

typedef void (^LogEventClientCallback)(MetricEvent event);
typedef void (^LogEventClientCallback)(MetricEvent event);

void SetLogEventClientCallback(LogEventClientCallback callback);
void LogEvent(MetricEvent & event) override;
void SetLogEventClientCallback(LogEventClientCallback callback);
void LogEvent(MetricEvent & event) override;

private:
LogEventClientCallback mClientCallback;
};
private:
LogEventClientCallback mClientCallback;
};

} // namespace signposts
} // namespace signposts
} // namespace Tracing
} // namespace chip
42 changes: 21 additions & 21 deletions src/platform/Darwin/Tracing.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@

namespace chip {
namespace Tracing {
namespace signposts {
os_log_t GetMatterSignpostLogger()
{
static dispatch_once_t onceToken;
static os_log_t logger;
namespace signposts {
os_log_t GetMatterSignpostLogger()
{
static dispatch_once_t onceToken;
static os_log_t logger;
dispatch_once(&onceToken, ^{
logger = os_log_create("com.csa.matter.signposts", "com.csa.matter.sdk");
});
return logger;
}
}

DarwinTracingBackend::DarwinTracingBackend()
: mClientCallback(nullptr)
{}
DarwinTracingBackend::DarwinTracingBackend()
: mClientCallback(nullptr)
{
}

void DarwinTracingBackend::SetLogEventClientCallback(LogEventClientCallback callback)
{
mClientCallback = callback;
}
void DarwinTracingBackend::SetLogEventClientCallback(LogEventClientCallback callback)
{
mClientCallback = callback;
}

void DarwinTracingBackend::LogEvent(MetricEvent & event)
{
// Pass along to the client to handle the event
if (mClientCallback) {
mClientCallback(event);
void DarwinTracingBackend::LogEvent(MetricEvent & event)
{
// Pass along to the client to handle the event
if (mClientCallback) {
mClientCallback(event);
}
}
}

} // namespace signposts
} // namespace signposts
} // namespace Tracing
} // namespace chip

6 changes: 2 additions & 4 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ source_set("system_config_header") {
}

source_set("system_clock") {
sources = [
"SystemClock.h",
]
sources = [ "SystemClock.h" ]
}

static_library("system") {
Expand Down Expand Up @@ -263,8 +261,8 @@ static_library("system") {
cflags = [ "-Wconversion" ]

public_deps = [
":system_config_header",
":system_clock",
":system_config_header",
"${chip_root}/src/lib/core:error",
"${chip_root}/src/lib/support",
"${chip_root}/src/platform:platform_config_header",
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ static_library("tracing") {
]

public_deps = [
":tracing_buildconfig",
":metrics",
":tracing_buildconfig",
"${chip_root}/src/lib/support",
]
}

source_set("metrics") {
sources = [
"metric_event.h",
"metric_macros.h",
"metric_keys.h",
"metric_macros.h",
]

public_deps = [
Expand Down
2 changes: 0 additions & 2 deletions src/tracing/darwin/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@
#error "Tracing macros seem to be double defined"
#endif


#include <platform/Darwin/Tracing.h>

Loading

0 comments on commit ed65bb5

Please sign in to comment.