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

Instruction tracing #10

Merged
merged 34 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9bc938d
Callstacks for PX4
Apr 25, 2024
37ec004
added muleboard to devices
May 3, 2024
638d1c6
Testing some metrics on the software debugging info (itm)
May 3, 2024
515cf48
big metric update for work queues and functions
Jun 5, 2024
d6a6864
parallel trace with etm and itm
Jun 6, 2024
03163be
added thread priority display
Jun 11, 2024
a6b3a6c
updated metrics to reduce computation time complexity
Jun 26, 2024
579b8f5
nuttx callstack compatibility update
Jul 11, 2024
62ae8ca
full callstack with threads seems to work nuttx example
Jul 12, 2024
818a9eb
nuttX Simple finished
Jul 15, 2024
8d16537
thread switch works completely
Jul 16, 2024
db4b457
gdb script updated to switch data pin 3 config
Jul 16, 2024
fd221af
Fixed loadelf dwarf function read -> made call stack more robust
Aug 16, 2024
a793a71
Bug fix
Aug 22, 2024
00d0866
added heap diff to metrics
Aug 26, 2024
b368cc1
Working ETM trace on PX4/STM32F7
Sep 20, 2024
af19846
added caching of cs dissasemble
Sep 24, 2024
e7af2f9
Improved readability
Oct 1, 2024
b5ce71f
Improved caching and readability
Oct 1, 2024
4f4a7c4
added code coverage tool
Oct 16, 2024
af5e6cf
Small fixes + readme for trace and metrics
Oct 23, 2024
d9e169b
typos in readme
Oct 23, 2024
94c0fb0
more typos
Oct 23, 2024
d8d814e
Updated CRoaring include
Oct 23, 2024
0a3b5eb
Added CMake to build
Oct 23, 2024
740a8c0
Fix include
Oct 23, 2024
25210e0
meson update
Oct 23, 2024
8b0bd8d
fix include
Oct 23, 2024
f502879
update meson
Oct 23, 2024
d7f36ca
Meson update
Oct 24, 2024
6b0ea9f
fix linux build bug
Oct 24, 2024
c429d51
gitignore update
Oct 24, 2024
03b12bd
added conda environment
Oct 29, 2024
a65caa3
removed cycle count print
Oct 29, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: sudo apt-get update
- run: sudo apt-get install -y libusb-1.0-0-dev libzmq3-dev meson libsdl2-dev libdwarf-dev libdw-dev libelf-dev libcapstone-dev python3-pip ninja-build protobuf-compiler
- run: sudo apt-get install -y libusb-1.0-0-dev libzmq3-dev meson libsdl2-dev libdwarf-dev libdw-dev libelf-dev libcapstone-dev python3-pip ninja-build protobuf-compiler cmake
- run: sudo pip3 install meson==1.2.0
- uses: actions/checkout@v3
- run: meson setup ./build
Expand All @@ -27,7 +27,7 @@ jobs:
name: Build and Test Orbetto on macOS
runs-on: macos-13
steps:
- run: brew install zmq sdl2 libelf protobuf meson ninja capstone dwarfutils
- run: brew install zmq sdl2 libelf protobuf meson ninja capstone dwarfutils cmake
- uses: actions/checkout@v3
- run: meson setup ./build
working-directory: ext/orbetto
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ dist/
/ext/orbetto/subprojects/orbuculum
/ext/orbetto/subprojects/libdwarf*
/ext/orbetto/subprojects/packagecache
/ext/orbetto/subprojects/CRoaring
/ext/orbetto/*.perf
/ext/orbetto/*.gz
/ext/orbetto/*.debug
/ext/orbetto/*.zip
/ext/orbetto/*.roar
/ext/orbetto/trace.swo
15 changes: 13 additions & 2 deletions ext/orbetto/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ perfbuf_sources = cpp_gen.process(proto_sources, preserve_path_from: meson.curre
# Compile and link the protobuf source files
perfbuf_lib = static_library('perfbuf', sources: perfbuf_sources, dependencies: [dependency('protobuf')])

# Specify the include directory for Roaring Bitmap
cmake = import('cmake')
rm = cmake.subproject('croaring')
# Fetch the dependency object
message('CMake targets:\n - ' + '\n - '.join(rm.target_list()))
rm_dep1 = rm.dependency('roaring-headers-cpp')
rm_dep2 = rm.dependency('roaring-headers')
rm_dep = rm.dependency('roaring')
rm_inc = rm.get_variable('roaring_headers_cpp_inc') + rm.get_variable('roaring_headers_inc')


# Clone the orbuculum git repository
orbuculum = subproject('orbuculum')
liborb = orbuculum.get_variable('liborb')
Expand All @@ -24,8 +35,8 @@ git_version_info_h = orbuculum.get_variable('git_version_info_h')
# Compile and link everything together
executable('orbetto',
sources: ['src/orbetto.cpp', 'src/device.cpp', git_version_info_h],
include_directories: ['src'] + perfbuf_lib.private_dir_include() + orbinc,
dependencies: [dependency('protobuf')] + orbuculum.get_variable('dependencies'),
include_directories: ['src'] + perfbuf_lib.private_dir_include() + orbinc + rm_inc,
dependencies: [dependency('protobuf')] + orbuculum.get_variable('dependencies') + [rm_dep] + [rm_dep1] + [rm_dep2],
link_with: [liborb, perfbuf_lib],
install: true,
)
54 changes: 54 additions & 0 deletions ext/orbetto/metrics/METRICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Trace Metrics with Plotly in Dash

As explained in the TRACE.md readme, perfetto is a very useful tool for displaying trace data,
but is limited in data size and display variability.
Therefore, as a proof of concept, some metrics are calculated in Python.
We use the perfbuf file generated by orbetto, the SQL trace processor from perfetto
and a program counter bitmap generated by CRoaring in orbetto.

## Visualising metrics:

To start the local dash server you need to pass a perfbuf file when analysing itm data or a bitmap for statement data.
niklaut marked this conversation as resolved.
Show resolved Hide resolved
Depending on which argument you pass, different metrics can be displayed. Use -h to see all options.
If you are using the -diff flag, you will need to provide a second perfbuf file to display the metrics based on the difference between the
between the two files. This is very useful for comparing different versions or settings between two runs.

```sh
# cd orbetto/metrics
# two metrics
python3 metrics.py -f /path/to/orbetto.perf -wq -dwq
# difference between two traces on one metric
python3 metrics.py -f /path/to/orbetto_1.perf -f2 /path/to/orbetto_1.perf -hp -diff
# Code coverage for pc bitmap (beta not completely accurate)
python3 metrics.py -bm /path/to/bitmap.roar -elf /path/to/elf_file.elf -cc
```

Once executed, copy the https address into your browser and use the plotly interface to display the desired plot.

Note: Some metrics take a while to calculate (mainly code coverage).

## Advanced metrics and goal

There are already some simple statistical techniques included that can detect outliers, but the bigger picture of this work
is to do regression testing and fuzzing with statistics derived from the instruction trace. For example:
- Regularity of sensor readings [Done].
- Comm link throughputs
- Scheduling latency vs timeouts [Done].
- Thread progress vs semaphores
- Callstack changes (code coverage) [Done].

All these metrics need to be combined into a large latent space that can be diffed (a kind of distance measure) between different versions of PX4
to detect bugs in the code before it flies.

## GCOV

There has been a quick investigation to use a more advanced and also tested tool. The most common is gcov, which is a
test coverage programme from GCC.
niklaut marked this conversation as resolved.
Show resolved Hide resolved
Two files are required for gcov to display code coverage:
- .gcno, which is an advanced source file you get when compiling with the GCC -ftest-coverage option
- .gcda, which is created when the GCC -fprofile-arcs option is run.

It should be simple to get the .gcno file as the flag is already a compile option in PX4.
Theoretically it should be possible to reverse engineer the .gcda file just from the PC values,
(documentation can be found here: https://github.com/gcc-mirror/gcc/blob/master/gcc/gcov-io.h)
However, it is unclear how long this will take and how robust it will be.
Loading
Loading