Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: Added a macro to report the metric values from the sdk to the tracing framework. #32032

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions src/tracing/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, int32_t value) {}
virtual void LogMessageSend(MessageSendInfo &) { TraceInstant("MessageSent", "Messaging"); }
virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant("MessageReceived", "Messaging"); }

Expand Down
13 changes: 13 additions & 0 deletions src/tracing/esp32_trace/esp32_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ void ESP32Backend::TraceCounter(const char * label)
{
::Insights::ESPInsightsCounter::GetInstance(label)->ReportMetrics();
}

void ESP32Backend::TraceMetric(const char * label, int32_t 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);
Expand Down
4 changes: 4 additions & 0 deletions src/tracing/esp32_trace/esp32_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ 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, int32_t value) override;

void LogMessageSend(MessageSendInfo &) override;
void LogMessageReceived(MessageReceivedInfo &) override;

void LogNodeLookup(NodeLookupInfo &) override;
void LogNodeDiscovered(NodeDiscoveredInfo &) override;
void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override;

private:
bool mRegistered = false;
};

} // namespace Insights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ void JsonBackend::TraceCounter(const char * label)
OutputValue(value);
}

void JsonBackend::TraceMetric(const char * label, int32_t val)
{
::Json::Value value;
value["label"] = label;
value["value"] = val;

OutputValue(value);
}

void JsonBackend::LogMessageSend(MessageSendInfo & info)
{
::Json::Value value;
Expand Down
1 change: 1 addition & 0 deletions src/tracing/json/json_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, int32_t val) override;
void LogMessageSend(MessageSendInfo &) override;
void LogMessageReceived(MessageReceivedInfo &) override;
void LogNodeLookup(NodeLookupInfo &) override;
Expand Down
9 changes: 9 additions & 0 deletions src/tracing/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
// MATTER_TRACE_END(label, group)
// MATTER_TRACE_INSTANT(label, group)
// MATTER_TRACE_SCOPE(label, group)

// Tracing macro to trace monotonically increasing counter values.
// MATTER_TRACE_COUNTER(label)

// Tracing macro to represent historical metric data i.e the data points which represent different
// values at different point of time.
// MATTER_TRACE_METRIC(label, value)

#include <matter/tracing/macros_impl.h>
#include <tracing/log_declares.h>
#include <tracing/registry.h>
Expand Down Expand Up @@ -79,6 +87,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__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/tracing/none/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
2 changes: 2 additions & 0 deletions src/tracing/perfetto/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions src/tracing/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ void Counter(const char * label)
}
}

void Metric(const char * label, int32_t value)
{
for (auto & backend : gTracingBackends)
{
backend.TraceMetric(label, value);
}
}

void LogMessageSend(::chip::Tracing::MessageSendInfo & info)
{
for (auto & backend : gTracingBackends)
Expand Down
1 change: 1 addition & 0 deletions src/tracing/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, int32_t value);

void LogMessageSend(::chip::Tracing::MessageSendInfo & info);
void LogMessageReceived(::chip::Tracing::MessageReceivedInfo & info);
Expand Down
Loading