From 16606a48b29bbf476666e18f3b4a8afbfa722dc4 Mon Sep 17 00:00:00 2001
From: Yuanyao Zhong <82843247+yyzhong-g@users.noreply.github.com>
Date: Thu, 7 Apr 2022 15:43:52 -0400
Subject: [PATCH] Add instructions to get trace from linux lighting app.
(#17150)
---
examples/lighting-app/linux/README.md | 13 +++++++++++++
examples/platform/linux/Rpc.cpp | 2 ++
2 files changed, 15 insertions(+)
diff --git a/examples/lighting-app/linux/README.md b/examples/lighting-app/linux/README.md
index 262f1a6e2a6073..001c214ea6f5ed 100644
--- a/examples/lighting-app/linux/README.md
+++ b/examples/lighting-app/linux/README.md
@@ -16,6 +16,7 @@ To cross-compile this example on x64 host and run on **NXP i.MX 8M Mini**
- [Commandline Arguments](#command-line-args)
- [Running the Complete Example on Raspberry Pi 4](#running-complete-example)
- [Running RPC console](#running-rpc-console)
+ - [Device Tracing](#device-tracing)
@@ -136,3 +137,15 @@ To cross-compile this example on x64 host and run on **NXP i.MX 8M Mini**
`rpcs.chip.rpc.Lighting.Get()`
`rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5))`
+
+## Device Tracing
+
+Device tracing is available to analyze the device performance. To turn on
+tracing, build with RPC enabled. See [Building with RPC enabled](#building).
+
+Obtain tracing json file.
+
+```
+ $ ./{PIGWEED_REPO}/pw_trace_tokenized/py/pw_trace_tokenized/get_trace.py -s localhost:33000 \
+ -o {OUTPUT_FILE} -t {ELF_FILE} {PIGWEED_REPO}/pw_trace_tokenized/pw_trace_protos/trace_rpc.proto
+```
diff --git a/examples/platform/linux/Rpc.cpp b/examples/platform/linux/Rpc.cpp
index 6834ad2a234aa9..5a731fbc1e511a 100644
--- a/examples/platform/linux/Rpc.cpp
+++ b/examples/platform/linux/Rpc.cpp
@@ -42,6 +42,7 @@
#endif // defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE
#if defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE
+#define PW_TRACE_BUFFER_SIZE_BYTES 1024
#include "pw_trace/trace.h"
#include "pw_trace_tokenized/trace_rpc_service_nanopb.h"
@@ -102,6 +103,7 @@ void RegisterServices(pw::rpc::Server & server)
#if defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE
server.RegisterService(trace_service);
+ PW_TRACE_SET_ENABLED(true);
#endif // defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE
}