Skip to content

Commit

Permalink
Added metric support
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Feb 9, 2024
1 parent 4c4d8bf commit 5a44f18
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ Status MoveToLevel(EndpointId endpointId, const Commands::MoveToLevel::Decodable
{
ChipLogProgress(Zcl, "%s MOVE_TO_LEVEL %x %2x %x %x", "RX level-control:", level, transitionTime.Value(), optionsMask.Raw(),
optionsOverride.Raw());
MATTER_TRACE_METRIC("level",level);
}

return moveToLevelHandler(endpointId, Commands::MoveToLevel::Id, level, transitionTime,
Expand Down
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, long int 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, 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);
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, long int 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
11 changes: 11 additions & 0 deletions src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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, long int val) override;
void LogMessageSend(MessageSendInfo &) override;
void LogMessageReceived(MessageReceivedInfo &) override;
void LogNodeLookup(NodeLookupInfo &) override;
Expand Down
1 change: 1 addition & 0 deletions src/tracing/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
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, long int 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, long int value);

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

0 comments on commit 5a44f18

Please sign in to comment.