Skip to content

sys/bus_stats: Add module to collect bus statistics #19483

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

maribu
Copy link
Member

@maribu maribu commented Apr 18, 2023

Contribution description

This adds the following modules

  • bus_stats: Common infrastructure to collect bus usage statistics
  • bus_stats_spi: SPI hooks to collect usage stats of SPI attached endpoints
    • Via linker magic wrappers are added on top of spi_acquire(), spi_release(), spi_transfer_bytes(), ... to allow collection of statistics
    • Endpoints can be registered for monitoring by adding XFA entries
  • bus_stats_i2c: Same as bus_stats_spi, but for I2C
  • shell_cmd_bus_stats: Shell command to print / clear bus statistics

The documentation provided contains details on usage, terminology, and metrics.

Testing procedure

A test application was provided in tests/sys_bus_stats that adds monitoring for BME680 and/or BMx280 sensors connected via either SPI or I2C. Additional XFA entries could be easily added to monitor communication more I2C or SPI attached devices.

Issues/PRs references

Depends on and includes: #19481 (Doc will look a bit ugly until MathJax support is added, but nothing too scary)

@maribu maribu added Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first labels Apr 18, 2023
@github-actions github-actions bot added Area: build system Area: Build system Area: doc Area: Documentation Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tests Area: tests and testing framework labels Apr 18, 2023
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 18, 2023
@maribu
Copy link
Member Author

maribu commented Apr 18, 2023

Example output of the shell command to tease the feature a bit:

> bus_stats
BME680 @ I2C bus #0 address 0x0077:
  Access time: 0 µs
  Usage: 0.0000 %
  Last access: 1176052828 µs ago
  Transfers:
    0000 B - 0001 B: 0
    0002 B - 0003 B: 0
    0004 B - 0007 B: 0
    0008 B - 0015 B: 0
    0016 B - 0031 B: 0
    0032 B - 0063 B: 0
    0064 B - 0127 B: 0
    0128 B - 0255 B: 0
    0256 B - 0511 B: 0
    0512 B -    ∞ B: 0
  Transactions:
    0000 B - 0001 B: 0
    0002 B - 0003 B: 0
    0004 B - 0007 B: 0
    0008 B - 0015 B: 0
    0016 B - 0031 B: 0
    0032 B - 0063 B: 0
    0064 B - 0127 B: 0
    0128 B - 0255 B: 0
    0256 B - 0511 B: 0
    0512 B -    ∞ B: 0
  Time of transactions:
    0000 µs - 0001 µs: 0
    0002 µs - 0003 µs: 0
    0004 µs - 0007 µs: 0
    0008 µs - 0015 µs: 0
    0016 µs - 0031 µs: 0
    0032 µs - 0063 µs: 0
    0064 µs - 0127 µs: 0
    0128 µs - 0255 µs: 0
    0256 µs - 0511 µs: 0
    0512 µs -    ∞ µs: 0
  Time between transactions:
    0000 ms - 0001 ms: 0
    0002 ms - 0003 ms: 0
    0004 ms - 0007 ms: 0
    0008 ms - 0015 ms: 0
    0016 ms - 0031 ms: 0
    0032 ms - 0063 ms: 0
    0064 ms - 0127 ms: 0
    0128 ms - 0255 ms: 0
    0256 ms - 0511 ms: 0
    0512 ms -    ∞ ms: 0
> saul read 7
Reading from #7 (bme680|SENSE_GAS)
Data:	            70 kohm
> bus_stats
BME680 @ I2C bus #0 address 0x0077:
  Access time: 590 µs
  Usage: 0.0071 %
  Last access: 2361530 µs ago
  Transfers:
    0000 B - 0001 B: 3
    0002 B - 0003 B: 0
    0004 B - 0007 B: 0
    0008 B - 0015 B: 1
    0016 B - 0031 B: 0
    0032 B - 0063 B: 0
    0064 B - 0127 B: 0
    0128 B - 0255 B: 0
    0256 B - 0511 B: 0
    0512 B -    ∞ B: 0
  Transactions:
    0000 B - 0001 B: 0
    0002 B - 0003 B: 1
    0004 B - 0007 B: 0
    0008 B - 0015 B: 0
    0016 B - 0031 B: 1
    0032 B - 0063 B: 0
    0064 B - 0127 B: 0
    0128 B - 0255 B: 0
    0256 B - 0511 B: 0
    0512 B -    ∞ B: 0
  Time of transactions:
    0000 µs - 0001 µs: 0
    0002 µs - 0003 µs: 0
    0004 µs - 0007 µs: 0
    0008 µs - 0015 µs: 0
    0016 µs - 0031 µs: 0
    0032 µs - 0063 µs: 0
    0064 µs - 0127 µs: 1
    0128 µs - 0255 µs: 0
    0256 µs - 0511 µs: 0
    0512 µs -    ∞ µs: 1
  Time between transactions:
    0000 ms - 0001 ms: 0
    0002 ms - 0003 ms: 0
    0004 ms - 0007 ms: 0
    0008 ms - 0015 ms: 0
    0016 ms - 0031 ms: 0
    0032 ms - 0063 ms: 0
    0064 ms - 0127 ms: 0
    0128 ms - 0255 ms: 0
    0256 ms - 0511 ms: 1
    0512 ms -    ∞ ms: 1

@riot-ci
Copy link

riot-ci commented Apr 18, 2023

Murdock results

✔️ PASSED

10ce514 tests/sys_bus_stats: Add test for sys/bus_stats

Artifacts

@maribu maribu removed the State: waiting for other PR State: The PR requires another PR to be merged first label Apr 19, 2023
@maribu
Copy link
Member Author

maribu commented Apr 19, 2023

I dropped the commit to enable MathJax support in Doxygen. The generated table documenting the histogram bucket sizes will look ugly without tex commands being rendered, but it's not too bad.

maribu added 5 commits April 19, 2023 12:23
There is no need for shell commands if there is no shell.
The shell_cmds module depends on the shell module. This was correctly
added to KConfig, but the Makefile dependencies missed this one. This
commit adds the missing dep.
Provide the correct CS pin to spi_acquire(); spi_acquire() itself
doesn't do any CS pin handling anyway but for statistics collecting
it is useful to have the correct SPI pin passed.
bors bot added a commit that referenced this pull request Apr 22, 2023
19485: sys/shell: Fix missing dependency r=aabadie a=maribu

### Contribution description

The shell commands depend on the shell module being use. This was already the case in KConfig, but was overlooked in the shell's `Makefile.dep`.

In addition, this uncovered that `tests/memarray` had a bogus dependency on shell commands without every using the shell.

### Testing procedure

Ideally binaries should not differ (except for debug section).

### Issues/PRs references

Split out of #19483

Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: doc Area: Documentation Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants