Commit graph

13 commits

Author SHA1 Message Date
Yong Cong Sin
44c070fdcd subsys/profiling: fix extra frame in the traces
Check if the frame is within the text address before saving
into the buffer, this eliminates the extra, uninitialized frame
at the end of the unwind.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
42362c6fcc subsys/profiling: relocate stack unwind backends
Relocate stack unwind backends from `arch/` to perf's
`backends/` folder, just like logging/shell/..

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
74537fc87a subsys/profiling: SYS_INIT not required
The timer & dwork can be statically initialized,
SYS_INIT is not strictly required.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
af7eb76ba4 subsys/profiling: shell cmd function should be static
These shell cmd function should be static.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
e330971ec5 subsys/profiling: kill timer in a single place
Currently, the timer is stopped:
- in the timer handler, when the buffer is full, or
- in work handler, when time's up

In any cases, the work handler is bounded to run to print
the message, so we can kill the timer there instead.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
d68642c732 subsys/profiling: add some util cmds
Added:
- `clear` to discard the buffer without printing
- `info` to print info about the buffer and if the
  profiler is running

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
8fc6d8adf2 subsys/profiling: use a more universal message when perf is running
"Perf is already running" works for `record` but is a little
strange when doing `printbuf`, so remove the "already" to
make it more universal.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
d4cd1be390 subsys/profiling: reset buf_full flag when we empty the buf
The `buf_full` flag is set when it is full, but dumping the
buf currently only resets the `idx`, this means that the perf
command only works when the buffer hasn't been full before.

Reset the flag when we clear the buffer.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
f213b5b95f subsys/profiling: remove unused declaration
`PERF_EVENT_TRACING_BUF_OVERFLOW` isn't used, remove it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
0065a81a38 subsys/profiling: remove cmd_perf as it is not doing anything
`cmd_perf` isn't doing anything meaningful, remove it so that
the help message will be printed when invoked. Updated
the help message of the main command.

```
uart:~$ perf
perf - Lightweight profiler
Subcommands:
  record    : Start recording for <duration> ms on <frequency> Hz
             Usage: record <duration> <frequency>

  printbuf  : Print the perf buffer
```

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Yong Cong Sin
cd3b8dd938 subsys/profiling: no need to explicitly set idx to 0
static perf_data is zero-initialized by default, there's no
need to explicitly set `idx` to `0`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-20 14:45:23 +02:00
Benjamin Cabé
3735ae94a1 profiling: doc: clean up grammar/spelling
Clean up documentation pages for the new perf tool
as they contained several typos, grammar errors, and
duplicated content between main doc page and sample
page

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-08-16 16:30:07 +01:00
Mikhail Kushnerov
e50d1190fa profiling: Add perf tool
Add profiling subsystem.

Add perf util based on periodic stack unwinding. Perf from Linux
was taken as a reference.

The operation of module is based on frame pointer usage and saving
registers during interruption handling.
The unwinding function stay in timer as expiry functioin so is called
during interruption handling. Thus the function have access to saved
registers (program counter and frame pointer in particular) of the current
thread and use it to unwind the thread stack.
Timer starting and results printing function are made as shell commands
for conveniency.

Originally-by: Yonatan Goldschmidt <yon.goldschmidt@gmail.com>
Signed-off-by: Mikhail Kushnerov <m.kushnerov@yadro.com>
2024-08-13 18:28:44 -04:00