Skip to content

Commit ca37e2e

Browse files
committed
[#99460] docs: live_tracing: Added description of updated live tracing server
Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
1 parent ece06ac commit ca37e2e

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

docs/source/library.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Zephelin can be used to analyze:
1919
* AI runtimes
2020
* Multithreaded applications
2121

22-
## Data collected by Zephelin
22+
(zephelin-trace-collection)=
23+
## Zephelin trace collection
2324

2425
```{pipeline_manager}
2526
:spec: ./zephelin-flow-spec.json

docs/source/live_tracing.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
# Real-time tracing
1+
# Live tracing of events from the board
22

33
This chapter covers the usage of [Zephelin Trace Viewer](visual_interface) for live visualization of traces being gathered during application execution.
44

55
Real-time visualization requires running a local Python server responsible for ingesting CTF traces, parsing them into TEF, and forwarding them to the visualizer.
66

7+
## Real-time tracing server structure
8+
9+
```{pipeline_manager} Live tracing diagram
10+
:spec: ./zephelin-flow-spec.json
11+
:graph: ./zephelin-flow-graph-live.json
12+
:preview: true
13+
```
14+
15+
Compared to diagram from {ref}`zephelin-trace-collection`, instead of saving and converting complete CTF traces to TEF format and uploading them to Zephelin Trace Viewer, we continuously deliver traces over TCP to a Zephelin's server, convert them chunk by chunk to TEF format and deliver to Zephelin Trace Viewer over Remote Procedure Calls (RPC).
16+
17+
The Zephelin's server consists of:
18+
19+
* [Trace Handler](https://github.com/antmicro/zephelin/blob/main/server/handlers/trace_handler.py) - configures Parser Proxy, `libbtrace` live plugin and RPC Dispatcher and controls delivery of traces and commands to the Zephelin Trace Viewer.
20+
* [RPC Dispatcher](https://github.com/antmicro/zephelin/blob/main/server/rpc_dispatcher.py) - sends and receives messages from Zephelin Trace Viewer.
21+
* [Stream Parser Proxy](https://github.com/antmicro/zephelin/blob/main/server/handlers/trace_handler.py) - collects data from `west zpl-<backend>-capture` over TCP and subdivides it to the commands' stream and traces.
22+
Traces are delivered to `libbtrace` live plugin.
23+
* [`libbtrace` live plugin](https://github.com/antmicro/libbtrace/tree/main/src/plugins/ctf/live-src) - receives parts of CTF traces and converts them to parts of TEF messages that are later delivered to Trace Handler.
24+
725
## Prerequisites
826

927
Before running the server, you need to install required backend dependencies and compile the frontend visualizer.
1028

1129
### Install server dependencies
1230

13-
Apart from regular dependencies of Zephelin, server dependencies need to be installed as well with the following command:
31+
Apart from installing Zephelin's dependencies (see {ref}`setting-up-workspace`), server dependencies need to be installed as well with the following command:
1432

1533
```bash
1634
pip install -r server/requirements.txt
@@ -62,6 +80,7 @@ You can customize the server's networking interfaces, and specify trace parsing
6280
* `--tcp-server-port`- Port of the Zephelin TCP socket for CTF trace ingestion (Default: `5000`).
6381
* `--backend-host` - Address where the backend API and visualizer are hosted (Default: `127.0.0.1`).
6482
* `--backend-port` - Port where the backend API and visualizer are hosted (Default: `8000`).
83+
* `--bt-port` - Port used by `libbtrace` live plugin to collect pure CTF traces (Default: `42674`).
6584
* `--frontend-directory` - Path to compiled frontend directory.
6685
* `--build-dir` - Path to the traced application build directory.
6786
* `--tflm-model-paths` - Paths to the TFLM models.
@@ -71,6 +90,13 @@ You can customize the server's networking interfaces, and specify trace parsing
7190
* `--tvm-model-op-remove-suffix` - Regex pattern used for removing TVM operator suffixes.
7291
* `--verbosity` - Set the logging verbosity level (`DEBUG, INFO, WARNING, ERROR, CRITICAL`).
7392

93+
### Additional configuration options for tests
94+
95+
There is a possibility to run the server in a mock mode, where TEF traces are delivered as inputs and sent to the website at specified speed:
96+
97+
* `--mock-trace-file` - Path to the TEF/JSON trace file to use for the mock.
98+
* `--mock-playback-speed` - Playback speed multiplier for the mock.
99+
74100
## Providing traces to the server
75101

76102
Once the server is running, it listens for CTF traces on the TCP socket.
@@ -119,6 +145,33 @@ In the end, run collection of traces from:
119145
west zpl-uart-capture <path-to-uart> 115200 ./trace-hw.ctf --send-to-remote 127.0.0.1:5000
120146
```
121147

148+
## Communication flow
149+
150+
Server implementation in `server/run_backend.py` consists of following access points:
151+
152+
* `<tcp_server_host>:<tcp_server_port>` - allows communication between `west` capture subcommands and the server.
153+
* `<backend_host>:<backend_port>` - this hosts the website loaded from `--frontend-directory` directory and configures communication between website and server.
154+
* `127.0.0.1:<bt_port>` - allows delivery of pure CTF events to the `libbtrace` live plugin (it is a one-way communication).
155+
156+
As in file-based Zephelin flow, the traces are first collected and sent by the board to the host using a selected backend (e.g. UART).
157+
After this, `west zpl-<backend>-capture` command with `--send-to-remote` flag configured to e.g. `127.0.0.1:5000` will send CTF traces with additional data (such as `_zpl_ctf_start__` start tag) to a given address.
158+
159+
This address should match `--tcp-server-host` and `--tcp-server-port` settings in the `server/run_backend.py` script.
160+
[`Stream Parser Proxy`](https://github.com/antmicro/zephelin/blob/main/server/handlers/trace_handler.py) will receive packets sent by the `west` subcommand and subdivide them into commands (such as restart the viewer based on start tag) that should be sent as RPC commands to the website, and pure CTF events.
161+
162+
Pure CTF events are sent to [`libbtrace` live plugin](https://github.com/antmicro/libbtrace/tree/main/src/plugins/ctf/live-src) over `--bt-port` port on loopback (e.g. `127.0.0.1:42674`), for fast conversion to TEF events in C++.
163+
The plugin communicates with the `libbtrace` module running in the server, delivering `bt2` messages with parts of parsed TEF events - it is not socket-based communication.
164+
165+
:::{note}
166+
It is possible to deliver pure CTF events directly to `libbtrace` live plugin by sending events directly to `--bt-port`, skipping the `Stream Parser Proxy`.
167+
:::
168+
169+
Those `bt2` messages are delivered to the [`Trace Handler`](https://github.com/antmicro/zephelin/blob/main/server/handlers/trace_handler.py).
170+
Trace Handler performs final adjustments of the TEF events and sends them to the website.
171+
172+
In the meantime, [`RPC Dispatcher`](https://github.com/antmicro/zephelin/blob/main/server/rpc_dispatcher.py) allows sending calls between server and website, and controls the state of the Zephelin Trace Viewer using procedures described in {ref}`server-api-reference`.
173+
174+
(server-api-reference)=
122175
## Server API reference
123176

124177
The Zephelin real-time tracing server supports the following JSON-RPC requests sent as rpc_request WebSocket event:

0 commit comments

Comments
 (0)