Skip to content

Conversation

@Tejas3772
Copy link

This commit adds a new Avocado testcase to dynamically run all perf stat options that are currently present in the system help but missing from kernel source tests.

Features include:

  • Automatic extraction of perf stat --help options.
  • Filtering out options already covered in kernel perf tests.
  • Minimal resource generation for options that require inputs.
  • Special handling for metric groups, topdown, transaction, PID, and TID.
  • Minimal workloads created dynamically to avoid errors.
  • Logging of unknown or failed options with exit codes.

This testcase helps ensure coverage of all perf stat options and detects any discrepancies between help output and available kernel tests.

@Tejas3772 Tejas3772 force-pushed the stat branch 2 times, most recently from 156ee44 to 4496802 Compare September 3, 2025 07:54
@Tejas3772
Copy link
Author

stat.log

@Tejas3772 Tejas3772 force-pushed the stat branch 3 times, most recently from cdf851b to 9549b1d Compare November 17, 2025 21:47
@Tejas3772
Copy link
Author

stat.log
with yaml file

@Tejas3772
Copy link
Author

without yaml file
noyamlstat.log

@Tejas3772 Tejas3772 force-pushed the stat branch 2 times, most recently from 2c78a89 to 1f5b9bd Compare November 17, 2025 22:44
@Naresh-ibm Naresh-ibm self-assigned this Nov 18, 2025
This commit adds a new Avocado testcase to dynamically run all
perf stat options that are currently present in the system help
but missing from kernel source tests.

Features include:
- Automatic extraction of perf stat --help options.
- Filtering out options already covered in kernel perf tests.
- Minimal resource generation for options that require inputs.
- Special handling for metric groups, topdown, transaction, PID,
  and TID.
- Minimal workloads created dynamically to avoid errors.
- Logging of unknown or failed options with exit codes.

This testcase helps ensure coverage of all perf stat options and
detects any discrepancies between help output and available kernel
tests.

Signed-off-by: Tejas Manhas <Tejas.Manhas1@ibm.com>
Comment on lines +4 to +5
--output: "/tmp/perf_out.txt"
-o: "/tmp/perf_out.txt"
Copy link
Contributor

Choose a reason for hiding this comment

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

--output/-o is used with perf stat record to store stat data into perf.data file

Checks for dependencies and packages and Compiles
final stat options options that are not used to be run
"""
self.log.info("Setting up PerfStatOptions test...")
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

self.cancel(f"{pkg} is required for this test")

if self.detected_distro.name in [
'rhel', 'centos', 'fedora', 'rocky', 'almalinux']:
Copy link
Contributor

Choose a reason for hiding this comment

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

please see if you really need 'rocky', 'almalinux'

if not os.path.exists(self.sourcedir):
self.cancel(f"{self.sourcedir} not found, cannot build tools/perf")

self.log.info(f"Building tools/perf in {self.sourcedir}")
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

self.log.info(f"Building tools/perf in {self.sourcedir}")
if build.make(self.sourcedir):
self.fail("tools/perf build failed, check logs")
self.log.info(f"Using Linux source directory: {self.sourcedir}")
Copy link
Contributor

Choose a reason for hiding this comment

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

same

events_dir = "events_dir"
if os.path.exists(events_dir):
try:
import shutil
Copy link
Contributor

Choose a reason for hiding this comment

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

move to import section

Comment on lines +206 to +210
# Input data for perf
if opt in ["--input"]:
process.run(
f"mkdir -p events_dir && echo -e 'cycles,instructions' > {minimal}",
shell=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

--input (perf.data file) option is to use with perf stat report

[stdlog] 2025-11-18 03:07:02,823 avocado.utils.process process          L0662 INFO | Running 'perf stat --input events_dir/events.txt sleep 5'
[stdlog] 2025-11-18 03:07:02,825 avocado.utils.process process          L0711 INFO | Command perf stat --input events_dir/events.txt sleep 5 running on a thread
[stdlog] 2025-11-18 03:07:02,831 avocado.utils.process process          L0475 DEBUG| [stderr]   Error: unknown option `input'

# Flags that require a dependent event
flags_with_deps = [
"-b", "-u",
"-s", "--metric-only",
Copy link
Contributor

Choose a reason for hiding this comment

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

can you fix this

[stdlog] 2025-11-18 03:07:32,914 avocado.utils.process process          L0662 INFO | Running 'perf stat --metric_only sleep 5'
[stdlog] 2025-11-18 03:07:32,915 avocado.utils.process process          L0711 INFO | Command perf stat --metric_only sleep 5 running on a thread
[stdlog] 2025-11-18 03:07:32,922 avocado.utils.process process          L0475 DEBUG| [stderr]   Error: unknown option `metric_only'

Comment on lines +213 to +216
if opt in ["--post", "--pre"] and not os.path.exists(minimal):
with open(minimal, "w") as f:
f.write("#!/bin/bash\nsleep 0.1\n")
os.chmod(minimal, 0o755)
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to use --pre and --post in the same command and it can be anything as simple as echo
perf stat --pre "echo pre-run" --post "echo post-run" sleep 1 or
perf stat --pre "date +%s" --post "date +%s" ls

Comment on lines +252 to +254
if ret == 129 or "unknown option" in err.lower():
self.log.info(f"Skipping option {opt}: unknown option")
self.unknown_options.add(opt)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove this check bcoz it results in false pass
test will never fail with incorrect options/failures also

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.

3 participants