summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell/lib/perf_brstack_max.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/shell/lib/perf_brstack_max.py')
-rw-r--r--tools/perf/tests/shell/lib/perf_brstack_max.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/perf/tests/shell/lib/perf_brstack_max.py b/tools/perf/tests/shell/lib/perf_brstack_max.py
new file mode 100644
index 000000000000..cc065f07cfed
--- /dev/null
+++ b/tools/perf/tests/shell/lib/perf_brstack_max.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# SPDX-License-Identifier: GPL-2.0
+# Determine the maximum size of branch stacks in a perf.data file.
+
+import argparse
+import sys
+
+import perf
+
+def main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument("-i", "--input", default="perf.data", help="Input file name")
+ args = ap.parse_args()
+
+ bmax = 0
+
+ def process_event(sample):
+ nonlocal bmax
+ try:
+ brstack = sample.brstack
+ if brstack:
+ n = len(list(brstack))
+ if n > bmax:
+ bmax = n
+ except AttributeError:
+ pass
+
+ session = None
+ try:
+ session = perf.session(perf.data(args.input), sample=process_event)
+ session.process_events()
+ print("max brstack", bmax)
+ except Exception as e:
+ print(f"Error processing events: {e}", file=sys.stderr)
+ sys.exit(1)
+ finally:
+ session = None
+
+if __name__ == "__main__":
+ main()