From 8e0bae79baae136f59c16bbd36e367afe545cd94 Mon Sep 17 00:00:00 2001 From: shripad621git Date: Tue, 6 Feb 2024 18:41:40 +0530 Subject: [PATCH] Added metric support --- .../wifi-network-diagnostics-server.cpp | 1 + src/tracing/backend.h | 1 + src/tracing/esp32_trace/esp32_tracing.cpp | 13 +++++++++++++ src/tracing/esp32_trace/esp32_tracing.h | 4 ++++ .../include/matter/tracing/macros_impl.h | 1 + src/tracing/json/json_tracing.cpp | 11 +++++++++++ src/tracing/json/json_tracing.h | 1 + src/tracing/macros.h | 1 + .../include/matter/tracing/macros_impl.h | 1 + .../none/include/matter/tracing/macros_impl.h | 1 + .../perfetto/include/matter/tracing/macros_impl.h | 2 ++ src/tracing/registry.cpp | 8 ++++++++ src/tracing/registry.h | 1 + 13 files changed, 46 insertions(+) diff --git a/src/app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.cpp b/src/app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.cpp index bd02f36d731cf2..f116def50c089a 100644 --- a/src/app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.cpp +++ b/src/app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.cpp @@ -163,6 +163,7 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::ReadWiFiRssi(AttributeValueEncoder & aEncod { rssi.SetNonNull(value); ChipLogProgress(Zcl, "The current RSSI of the Node’s Wi-Fi radio in dB: %d", value); + MATTER_TRACE_METRIC("wifi_rssi", value); } else { diff --git a/src/tracing/backend.h b/src/tracing/backend.h index 3d8bec8ada501f..fde2c681eab45a 100644 --- a/src/tracing/backend.h +++ b/src/tracing/backend.h @@ -64,6 +64,7 @@ class Backend : public ::chip::IntrusiveListNodeBase<> virtual void TraceInstant(const char * label, const char * group) {} virtual void TraceCounter(const char * label) {} + virtual void TraceMetric(const char * label, long int value) {} virtual void LogMessageSend(MessageSendInfo &) { TraceInstant("MessageSent", "Messaging"); } virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant("MessageReceived", "Messaging"); } diff --git a/src/tracing/esp32_trace/esp32_tracing.cpp b/src/tracing/esp32_trace/esp32_tracing.cpp index 7937772606eec0..1b8268be73961b 100644 --- a/src/tracing/esp32_trace/esp32_tracing.cpp +++ b/src/tracing/esp32_trace/esp32_tracing.cpp @@ -153,6 +153,19 @@ void ESP32Backend::TraceCounter(const char * label) { ::Insights::ESPInsightsCounter::GetInstance(label)->ReportMetrics(); } + +void ESP32Backend::TraceMetric(const char * label, long int value) +{ + if (!mRegistered) + { + esp_diag_metrics_register("SYS_MTR" /*Tag of metrics */, label /* Unique key 8 */, label /* label displayed on dashboard */, + "insights.mtr" /* hierarchical path */, ESP_DIAG_DATA_TYPE_INT /* data_type */); + mRegistered = true; + } + ESP_LOGI("mtr", "The value of %s is %ld ", label, value); + esp_diag_metrics_add_int(label, value); +} + void ESP32Backend::TraceBegin(const char * label, const char * group) { HashValue hashValue = MurmurHash(group); diff --git a/src/tracing/esp32_trace/esp32_tracing.h b/src/tracing/esp32_trace/esp32_tracing.h index 6d9a277e06561d..f7a682ebca566e 100644 --- a/src/tracing/esp32_trace/esp32_tracing.h +++ b/src/tracing/esp32_trace/esp32_tracing.h @@ -29,6 +29,7 @@ class ESP32Backend : public ::chip::Tracing::Backend void TraceInstant(const char * label, const char * group) override; void TraceCounter(const char * label) override; + void TraceMetric(const char * label, long int value) override; void LogMessageSend(MessageSendInfo &) override; void LogMessageReceived(MessageReceivedInfo &) override; @@ -36,6 +37,9 @@ class ESP32Backend : public ::chip::Tracing::Backend void LogNodeLookup(NodeLookupInfo &) override; void LogNodeDiscovered(NodeDiscoveredInfo &) override; void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override; + +private: + bool mRegistered = false; }; } // namespace Insights diff --git a/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h b/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h index b95c20754237a1..8ebde173d8297b 100644 --- a/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h +++ b/src/tracing/esp32_trace/include/matter/tracing/macros_impl.h @@ -29,6 +29,7 @@ #define MATTER_TRACE_END(label, group) ::chip::Tracing::Internal::End(label, group) #define MATTER_TRACE_INSTANT(label, group) ::chip::Tracing::Internal::Instant(label, group) #define MATTER_TRACE_COUNTER(label) ::chip::Tracing::Internal::Counter(label) +#define MATTER_TRACE_METRIC(label, value) ::chip::Tracing::Internal::Metric(label, value) namespace chip { namespace Tracing { diff --git a/src/tracing/json/json_tracing.cpp b/src/tracing/json/json_tracing.cpp index af66e12a61a50b..0dfdba525fa021 100644 --- a/src/tracing/json/json_tracing.cpp +++ b/src/tracing/json/json_tracing.cpp @@ -295,6 +295,17 @@ void JsonBackend::TraceCounter(const char * label) OutputValue(value); } +void JsonBackend::TraceMetric(const char * label, long int val) +{ + ::Json::Value value; + value["label"] = label; + value["val"] = val; + + // Output the metric + + OutputValue(value); +} + void JsonBackend::LogMessageSend(MessageSendInfo & info) { ::Json::Value value; diff --git a/src/tracing/json/json_tracing.h b/src/tracing/json/json_tracing.h index 302c4bd5b5a485..efd4cd2319c026 100644 --- a/src/tracing/json/json_tracing.h +++ b/src/tracing/json/json_tracing.h @@ -52,6 +52,7 @@ class JsonBackend : public ::chip::Tracing::Backend void TraceEnd(const char * label, const char * group) override; void TraceInstant(const char * label, const char * group) override; void TraceCounter(const char * label) override; + void TraceMetric(const char * label, long int val) override; void LogMessageSend(MessageSendInfo &) override; void LogMessageReceived(MessageReceivedInfo &) override; void LogNodeLookup(NodeLookupInfo &) override; diff --git a/src/tracing/macros.h b/src/tracing/macros.h index b456137b88a166..18b80f685c4062 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -79,6 +79,7 @@ #define MATTER_TRACE_INSTANT(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_TRACE_SCOPE(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_TRACE_COUNTER(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) +#define MATTER_TRACE_METRIC(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_LOG_MESSAGE_SEND(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_LOG_MESSAGE_RECEIVED(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) diff --git a/src/tracing/multiplexed/include/matter/tracing/macros_impl.h b/src/tracing/multiplexed/include/matter/tracing/macros_impl.h index 8b3e728289dc1d..eda5f2ed5142a4 100644 --- a/src/tracing/multiplexed/include/matter/tracing/macros_impl.h +++ b/src/tracing/multiplexed/include/matter/tracing/macros_impl.h @@ -29,6 +29,7 @@ #define MATTER_TRACE_END(label, group) ::chip::Tracing::Internal::End(label, group) #define MATTER_TRACE_INSTANT(label, group) ::chip::Tracing::Internal::Instant(label, group) #define MATTER_TRACE_COUNTER(label) ::chip::Tracing::Internal::Counter(label) +#define MATTER_TRACE_METRIC(label, value) ::chip::Tracing::Internal::Metric(label, value) namespace chip { namespace Tracing { diff --git a/src/tracing/none/include/matter/tracing/macros_impl.h b/src/tracing/none/include/matter/tracing/macros_impl.h index 3119dce2a2b49f..1fc940683d75e2 100644 --- a/src/tracing/none/include/matter/tracing/macros_impl.h +++ b/src/tracing/none/include/matter/tracing/macros_impl.h @@ -32,3 +32,4 @@ #define MATTER_TRACE_INSTANT(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_TRACE_SCOPE(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_TRACE_COUNTER(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) +#define MATTER_TRACE_METRIC(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) diff --git a/src/tracing/perfetto/include/matter/tracing/macros_impl.h b/src/tracing/perfetto/include/matter/tracing/macros_impl.h index 9b05d2f3539a45..559e877db1fe11 100644 --- a/src/tracing/perfetto/include/matter/tracing/macros_impl.h +++ b/src/tracing/perfetto/include/matter/tracing/macros_impl.h @@ -37,3 +37,5 @@ PERFETTO_DEFINE_CATEGORIES(perfetto::Category("Matter").SetDescription("Matter t static int count##_label = 0; \ TRACE_COUNTER("Matter", label, ++count##_label); \ } while (0) + +#define MATTER_TRACE_METRIC(label, value) TRACE_COUNTER("Matter", label, value) diff --git a/src/tracing/registry.cpp b/src/tracing/registry.cpp index 7c43442b5b83db..1b5adad561c6e8 100644 --- a/src/tracing/registry.cpp +++ b/src/tracing/registry.cpp @@ -84,6 +84,14 @@ void Counter(const char * label) } } +void Metric(const char * label, long int value) +{ + for (auto & backend : gTracingBackends) + { + backend.TraceMetric(label, value); + } +} + void LogMessageSend(::chip::Tracing::MessageSendInfo & info) { for (auto & backend : gTracingBackends) diff --git a/src/tracing/registry.h b/src/tracing/registry.h index 083ebcb2225ad2..f769d47bfd3ed1 100644 --- a/src/tracing/registry.h +++ b/src/tracing/registry.h @@ -77,6 +77,7 @@ void Begin(const char * label, const char * group); void End(const char * label, const char * group); void Instant(const char * label, const char * group); void Counter(const char * label); +void Metric(const char * label, long int value); void LogMessageSend(::chip::Tracing::MessageSendInfo & info); void LogMessageReceived(::chip::Tracing::MessageReceivedInfo & info);