Skip to content

ze: make sampling interval configurable - #525

Open
matheus-mcosta wants to merge 1 commit into
argonne-lcf:develfrom
matheus-mcosta:sampling-interval
Open

ze: make sampling interval configurable#525
matheus-mcosta wants to merge 1 commit into
argonne-lcf:develfrom
matheus-mcosta:sampling-interval

Conversation

@matheus-mcosta

Copy link
Copy Markdown

The Level Zero sampling is currently hardcoded every 50 ms. This change lets users select the interval at runtime through iprof -i MS or iprof --sample-interval MS.

  • Added -i MS and --sample-interval MS to the iprof CLI.
  • Require --sample and the ze backend when an interval is supplied.
  • Pass the selected value through LTTNG_UST_ZE_SAMPLING_ENERGY_PERIOD_MS.
  • Convert milliseconds into normalized timespec seconds/nanoseconds in the ZE sampler.
  • Keep the existing combined callback unchanged. The interval applies to frequency, energy, engine, fabric-port, and memory telemetry.
  • Added sampling integration coverage for help output, both aliases, propagation, invalid values, and required options.

Comment on lines +3 to +6
@test "sampling_interval_help" {
run iprof --help

[ "$status" -eq 0 ]

@TApplencourt TApplencourt Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use run !

If invoked with one of the following as the first argument, run will perform an implicit check on the exit status of the invoked command:

    -N  expect exit status N (0-255), fail if otherwise
    ! expect nonzero exit status (1-255), fail if command succeeds

(https://bats-core.readthedocs.io/en/stable/writing-tests.html#run-test-other-commands)

Lol I choose the wrong tests to do that. In the test where we do state neq 0 I mean :)

[ "$status" -eq 0 ]
[[ "$output" == *"-i, --sample-interval MS"* ]]
[[ "$output" == *"Default: 50"* ]]
[[ "$output" == *"frequency, energy, engine, fabric-port, and memory"* ]]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we do this kind of test any where else? I think it's bad idea to put the default on the help. If we change the default, we will need to change it here too.

Comment on lines +12 to +22
@test "sampling_interval_is_passed_to_ze_sampler" {
for option in -i --sample-interval; do
trace="sampling_interval_trace_${option#-}"
rm -rf "$trace"

LTTNG_UST_ZE_LIBZE_LOADER=/dev/null \
iprof --no-analysis --sample --backends ze "$option" 125 \
--trace-output "$trace" -- \
bash -c 'test "$LTTNG_UST_ZE_SAMPLING_ENERGY_PERIOD_MS" = 125'
done
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sur what this is doing, we can remove it I think

Comment on lines 47 to 55
@test "sampling_heartbeat" {
rm -rf heartbeat_trace

LTTNG_UST_ZE_SAMPLING_ENERGY=0 LTTNG_UST_SAMPLING_HEARTBEAT=1 \
iprof --no-analysis --sample --trace-output heartbeat_trace -- bash -c 'sleep 2'

babeltrace_thapi --no-restrict heartbeat_trace | grep "{foo: 16}"
[ $(babeltrace_thapi --no-restrict heartbeat_trace | grep -c "{foo: 32}") == 1 ]
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a test like thi. Where we sleep and change the LTTNG_UST_ZE_SAMPLING_HEARBEAT_PERIOD_MS and assert the correct count.

Maybe we can have a macro

void thapi_register_sampling_with_end("STR", default, f) {
  if (getenv("LTTNG_UST_SAMPLING_{str}_MS")) {
    struct timespec interval;
    interval.tv_sec = 1;
    interval.tv_nsec = 0;
    Read_env
    plugin_handle_heartbeat = thapi_register_sampling(&f, &interval);
  }

And we can use that for all the sampling?

Comment thread xprof/xprof.rb.in
begin
parser.parse!(into: options)
options[:'backend-names'] = options[:backends].map { |name_level| name_level.split(':').first }
if options.include?(:'sample-interval')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We sampling other thing like CXI should be do like name_level? sample_interval ze:121012, cxi:22323, heart_bit:1212 and if user just do --sample-interval *:1000 we apply it everywhere?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should do multiple mappings in the format of --sample-interval <sample>:<MS>, for example --sample-interval ze:125,cxi:250? and apply to all if --sample-interval '*:100'?
This could lead to better control over the sampling granularity

@TApplencourt TApplencourt Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. We do that for the backend:level already (like if you want mpi + level zero on the same table you can do --backend mpi:0,ze:0

Oh I guess we can do that for --sampling to a --sampling BACKEND:MS who enable it. So no need for another option, we just extend the current one.

Sorry , I make you do big change :D But it seem far better API wize

(and --sample versus --sampling I have no clue which one is best...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants