-
Notifications
You must be signed in to change notification settings - Fork 130
perf_stat.py: Add testcase for present and unused options #3050
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
base: master
Are you sure you want to change the base?
Conversation
156ee44 to
4496802
Compare
cdf851b to
9549b1d
Compare
|
stat.log |
|
without yaml file |
2c78a89 to
1f5b9bd
Compare
79eeb7a to
63b9dba
Compare
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>
| --output: "/tmp/perf_out.txt" | ||
| -o: "/tmp/perf_out.txt" |
There was a problem hiding this comment.
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...") |
There was a problem hiding this comment.
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']: |
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to import section
| # Input data for perf | ||
| if opt in ["--input"]: | ||
| process.run( | ||
| f"mkdir -p events_dir && echo -e 'cycles,instructions' > {minimal}", | ||
| shell=True) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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'
| 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) |
There was a problem hiding this comment.
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
| if ret == 129 or "unknown option" in err.lower(): | ||
| self.log.info(f"Skipping option {opt}: unknown option") | ||
| self.unknown_options.add(opt) |
There was a problem hiding this comment.
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
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:
This testcase helps ensure coverage of all perf stat options and detects any discrepancies between help output and available kernel tests.