Skip to content

Commit

Permalink
Code Review: Rename LogMetric to LogMetricEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
anush-apple committed Feb 21, 2024
1 parent ff0944c commit 74cf29b
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/darwin/Framework/CHIP/MTRMetricsCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void InitializeMetricsCollection();
/**
* A representation of metrics data for an operation.
*/
MTR_NEWLY_AVAILABLE
@interface MTRMetricsCollector : NSObject

- (instancetype)init NS_UNAVAILABLE;
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 @@ -109,7 +109,7 @@ + (instancetype)sharedInstance
singleton = [[MTRMetricsCollector alloc] init];
if (singleton) {
chip::Tracing::Register(singleton->_tracingBackend);
singleton->_tracingBackend.SetLogEventClientCallback(^(MetricEvent event) {
singleton->_tracingBackend.SetMetricEventHandler(^(MetricEvent event) {
if (singleton) {
[singleton handleMetricEvent:event];
}
Expand Down
8 changes: 4 additions & 4 deletions src/platform/Darwin/Tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ namespace Tracing {
public:
DarwinTracingBackend();

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

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

private:
LogEventClientCallback mClientCallback;
MetricEventHandler mClientCallback;
};

} // namespace signposts
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Darwin/Tracing.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ os_log_t GetMatterSignpostLogger()
{
}

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

void DarwinTracingBackend::LogEvent(MetricEvent & event)
void DarwinTracingBackend::LogMetricEvent(MetricEvent & event)
{
// Pass along to the client to handle the event
if (mClientCallback) {
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Backend : public ::chip::IntrusiveListNodeBase<>
virtual void LogNodeLookup(NodeLookupInfo &) { TraceInstant("Lookup", "DNSSD"); }
virtual void LogNodeDiscovered(NodeDiscoveredInfo &) { TraceInstant("Node Discovered", "DNSSD"); }
virtual void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) { TraceInstant("Discovery Failed", "DNSSD"); }
virtual void LogEvent(MetricEvent &) { TraceInstant("Metric Event", "Metric"); }
virtual void LogMetricEvent(MetricEvent &) { TraceInstant("Metric Event", "Metric"); }
};

} // namespace Tracing
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/esp32_trace/esp32_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void ESP32Backend::TraceCounter(const char * label)
::Insights::ESPInsightsCounter::GetInstance(label)->ReportMetrics();
}

void ESP32Backend::LogEvent(MetricEvent & event)
void ESP32Backend::LogMetricEvent(MetricEvent & event)
{
if (!mRegistered)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/esp32_trace/esp32_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ESP32Backend : public ::chip::Tracing::Backend
void LogNodeLookup(NodeLookupInfo &) override;
void LogNodeDiscovered(NodeDiscoveredInfo &) override;
void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override;
void LogEvent(MetricEvent &) override;
void LogMetricEvent(MetricEvent &) override;

private:
bool mRegistered = false;
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void JsonBackend::TraceCounter(const char * label)
OutputValue(value);
}

void JsonBackend::LogEvent(MetricEvent & event)
void JsonBackend::LogMetricEvent(MetricEvent & event)
{
::Json::Value value;
value["label"] = event.key;
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/json/json_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class JsonBackend : public ::chip::Tracing::Backend
void LogNodeLookup(NodeLookupInfo &) override;
void LogNodeDiscovered(NodeDiscoveredInfo &) override;
void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override;
void LogEvent(MetricEvent &) override;
void LogMetricEvent(MetricEvent &) override;
void Close() override { CloseFile(); }

private:
Expand Down
14 changes: 8 additions & 6 deletions src/tracing/metric_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ namespace Tracing {
*/
struct MetricEvent
{
// Metric tag type
// This specifies the different categories of metric events that can created. In addition to
// emitting an event, events paired with a Begin and End are used to track duration for the
// event. An instant event just represents a one shot event.
enum class Tag
{
Begin, // Implies tracking a duration
End, // Implies tracking a duration
Begin, // Marks the begin of an event. This is typically tied with an End event.
End, // Marks the end of an event. This is typically preceeded with a Begin event.
Instant // No duration
};

// Value for the metric
// This defines the different types of values that can stored when a metric is emitted
struct Value
{
enum class Type : uint8_t
Expand Down Expand Up @@ -100,7 +102,7 @@ struct MetricEvent

namespace Internal {

void LogEvent(::chip::Tracing::MetricEvent & event);
void LogMetricEvent(::chip::Tracing::MetricEvent & event);

} // namespace Internal

Expand All @@ -117,7 +119,7 @@ inline bool logMetricIfError(const ::chip::ChipError & err, MetricKey metricKey)
{
using Tag = chip::Tracing::MetricEvent::Tag;
::chip::Tracing::MetricEvent _metric_event(Tag::Instant, metricKey, err);
::chip::Tracing::Internal::LogEvent(_metric_event);
::chip::Tracing::Internal::LogMetricEvent(_metric_event);
}
return success;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/metric_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{ \
using Tag = chip::Tracing::MetricEvent::Tag; \
::chip::Tracing::MetricEvent _metric_event(Tag::Instant, chip::Tracing::kMetric##key); \
::chip::Tracing::Internal::LogEvent(_metric_event); \
::chip::Tracing::Internal::LogMetricEvent(_metric_event); \
} while (false)

// Wrapper macro that accepts metric tag and key and logs an event corresponding to the tag
Expand All @@ -83,7 +83,7 @@
{ \
using Tag = chip::Tracing::MetricEvent::Tag; \
::chip::Tracing::MetricEvent _metric_event(tag, chip::Tracing::kMetric##key); \
::chip::Tracing::Internal::LogEvent(_metric_event); \
::chip::Tracing::Internal::LogMetricEvent(_metric_event); \
} while (false)

// Wrapper macro that accepts metric tag, key and value and logs the corresponding event
Expand All @@ -92,7 +92,7 @@
{ \
using Tag = chip::Tracing::MetricEvent::Tag; \
::chip::Tracing::MetricEvent _metric_event(tag, chip::Tracing::kMetric##key, value); \
::chip::Tracing::Internal::LogEvent(_metric_event); \
::chip::Tracing::Internal::LogMetricEvent(_metric_event); \
} while (false)

/**
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/perfetto/perfetto_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void PerfettoBackend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo & info)
);
}

void PerfettoBackend::LogEvent(MetricEvent & event)
void PerfettoBackend::LogMetricEvent(MetricEvent & event)
{
TRACE_COUNTER("Matter", event.key, event.value.store.int32_value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/perfetto/perfetto_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PerfettoBackend : public ::chip::Tracing::Backend
void LogNodeLookup(NodeLookupInfo &) override;
void LogNodeDiscovered(NodeDiscoveredInfo &) override;
void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override;
void LogEvent(MetricEvent &) override;
void LogMetricEvent(MetricEvent &) override;
};

} // namespace Perfetto
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ void LogNodeDiscoveryFailed(::chip::Tracing::NodeDiscoveryFailedInfo & info)
}
}

void LogEvent(::chip::Tracing::MetricEvent & event)
void LogMetricEvent(::chip::Tracing::MetricEvent & event)
{
for (auto & backend : gTracingBackends)
{
backend.LogEvent(event);
backend.LogMetricEvent(event);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tracing/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void LogMessageReceived(::chip::Tracing::MessageReceivedInfo & info);
void LogNodeLookup(::chip::Tracing::NodeLookupInfo & info);
void LogNodeDiscovered(::chip::Tracing::NodeDiscoveredInfo & info);
void LogNodeDiscoveryFailed(::chip::Tracing::NodeDiscoveryFailedInfo & info);
void LogEvent(::chip::Tracing::MetricEvent & event);
void LogMetricEvent(::chip::Tracing::MetricEvent & event);

} // namespace Internal

Expand Down

0 comments on commit 74cf29b

Please sign in to comment.