eclipse-iceoryx / iceoryx2

Eclipse iceoryx2â„¢ - true zero-copy inter-process-communication in pure Rust
https://iceoryx.io
Apache License 2.0
1.03k stars 40 forks source link

CLI for introspecting memory usage from the terminal #414

Open orecham opened 1 month ago

orecham commented 1 month ago

Brief feature description

Make it possible to fetch statistics related to memory usage of an iox2 system from the CLI

Detailed information

Nice to haves:

  1. Memory usage of allocated memory per-service (max samples, used samples)
  2. Memory usage of entire iox2 system (how many storages? what size are they and how much is in use?)
zmostafa commented 1 month ago

@orecham dou have a sample for how the output shall look like? also, to help me kick off, this will be an aggregation of the data found under /tmp/iceoryx2/.../iox2_node.details for each running node/service? or is there other sources to look for for getting this data?

orecham commented 1 month ago

@zmostafa This one might be a little bit challenging, but if you are willing to dive into the internals a little bit, it should be OK 😄 .

I am not extremely familiar with that corner of the code base, but at a high level, I think something like the following would be required (needs to be verified):

  1. Add functionality to the ShmAllocator trait to track usage in addition to their capacity
    1. Thread-safety needs to be considered here, an atomic for the usage metric should be sufficient I think
    2. Maintaining the usage metric would also add (small) overhead, so maybe it should also be behind an opt-in feature flag or something to allow users to choose to run with or without this additional overhead
  2. Add functionality to the DynamicStorage trait to retrieve this usage and capacity via the used ShmAllocator
  3. Add functionality to ServiceState and NodeState structs to retrieve the usage and capacity of the underlying DynamicStorage used for their data
    1. It should be possible for a process accessing the states with read-only access to see the metrics so they would need to be stored in the storage somehow

Then in the CLI:

  1. List all services/nodes
  2. Retrieve their capacity and usage
  3. Pretty print these metrics per-service, maybe also % usage (e.g. iox2 memory show —services)
  4. Pretty print these metrics per-node, maybe also % usage (e.g. iox2 memory show —nodes)
  5. Optional: Pretty print the total memory capacity reserved for iceoryx2 and the usage (e.g. iox2 memory show —total)
  6. Print all 3-5 if no flags specified (e.g. iox2 memory show)
  7. Optional: If you are feeling adventurous, launching a terminal ui (e.g. with iox2 memory watch) to monitor this live could be cool

If you have different ideas feel free to take some creative liberties. Also, you don‘t need to do everything at once, could start with e.g. only showing memory used by services.

@elfenpiff @elBoberido Could you provide some additional pointers / point out any oversights.

elBoberido commented 3 weeks ago

@orecham I'm also not yet that familiar with that part and we need to wait for input from @elfenpiff

cc @zmostafa