summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell/lib/perf_brstack_max.py
blob: cc065f07cfedd479108f4dd33c2bfa6e4dcc209d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()