perf: Reorganize scripting support
Subsystems (4)
[email protected]
AI reviewRe: [PATCH v6 39/59] perf intel-pt-events: Port intel-pt-events/libxed to use python module
In reply to Ian RogersSashiko AI review found 5 potential issue(s): - [Critical] Immediate crash due to AttributeError when accessing thread ID. - [High] Unhandled TypeError crashing the parser when symbol resolution…
Sashiko AI review found 5 potential issue(s):
- [Critical] Immediate crash due to AttributeError when accessing thread ID.
- [High] Unhandled TypeError crashing the parser when symbol resolution fails.
- [High] Silently dropped IPC metrics and missing fields due to API mismatch.
- [High] Missing bounds check leading to struct.error crashes on undersized buffers.
- [Medium] Context switch trace is dead code and non-functional.
--
commit 81d0ab603e985e90ebd28a2436d0f5d74d75f30f
Author: Ian Rogers <[email protected]>
perf intel-pt-events: Port intel-pt-events/libxed to use python module
This commit ports the intel-pt-events.py script to use the newer perf Python module, refactoring it into a class-based structure. It eliminates global state, drops Python 2 compatibility checks, and updates libxed.py methods to snake_case.
tools/perf/python/intel-pt-events.py new file +0 -0
[ ... ]
Review
Quoted 3 lines
(quoted diff) +3
-0+ def print_ptwrite(self, raw_buf: bytes) -> None: + """Print PTWRITE data.""" + data = struct.unpack_from("<IQ", raw_buf)
Will this code raise an unhandled struct.error exception and abort the processing loop if a malformed perf.data trace provides a raw_buf smaller than 12 bytes, or an empty byte string? This pattern also appears in print_mwait, print_pwrx, and other similar functions.
[ ... ]
Review
Quoted 6 lines
(quoted diff) +6
-0+ def common_start_str(self, comm: str, sample: perf.sample_event) -> str: + """Return common start string for display.""" + ts = sample.sample_time + cpu = sample.sample_cpu + pid = sample.sample_pid + tid = sample.tid
Does the perf.sample_event C extension expose this property as sample_tid rather than tid? If so, will accessing sample.tid raise an AttributeError on the first event and crash the script?
[ ... ]
Review
Quoted 8 lines
(quoted diff) +8
-0+ def print_common_ip(self, sample: perf.sample_event, symbol: str, dso: str) -> None: + """Print IP and symbol info.""" + ip = sample.sample_ip + offs = f"+{sample.symoff:#x}" if hasattr(sample, "symoff") else "" + cyc_cnt = getattr(sample, "cyc_cnt", 0) + if cyc_cnt: + insn_cnt = getattr(sample, "insn_cnt", 0) + ipc_str = f" IPC: {insn_cnt / cyc_cnt:#.2f} ({insn_cnt}/{cyc_cnt})"
Have these legacy metric fields been renamed in the new perf Python module API? If the module exports them as sample_cyc_count and sample_insn_count instead of cyc_cnt and insn_cnt, getattr will always return 0 and silently bypass the IPC string generation. Other legacy fields like symoff and flags_disp might also be missing from the new API.
[ ... ]
Review
Quoted 9 lines
(quoted diff) +9
-0+ def print_srccode(self, comm: str, sample: perf.sample_event, + symbol: str, dso: str, with_insn: bool) -> None: + """Print source code info.""" + ip = sample.sample_ip + if symbol == "[unknown]": + start_str = self.common_start_str(comm, sample) + (f"{ip:x}").rjust(16).ljust(40) + else: + offs = f"+{sample.symoff:#x}" if hasattr(sample, "symoff") else "" + start_str = self.common_start_str(comm, sample) + (symbol + offs).ljust(40)
If symbol resolution fails in the C extension and pyrf_sample_event__get_symbol returns None instead of "[unknown]", will the comparison symbol == "[unknown]" evaluate to False? This would cause the else branch to execute, attempting to concatenate None with a string (offs), which would raise a TypeError.
[ ... ]
Quoted 5 lines
(quoted diff) +5
-0+if __name__ == "__main__": + ap = argparse.ArgumentParser() + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + ap.add_argument("--insn-trace", action='store_true') + ap.add_argument("--src-trace", action='store_true')
Review
Quoted 10 lines
(quoted diff) +10
-0+ ap.add_argument("--all-switch-events", action='store_true') + ap.add_argument("--interleave", type=int, nargs='?', const=4, default=0) + args = ap.parse_args() + + analyzer = IntelPTAnalyzer(args) + + try: + session = perf.session(perf.data(args.input), sample=analyzer.process_event) + analyzer.session = session + session.process_events()
Are context switch events functional with this configuration? The script accepts the --all-switch-events argument and checks the self.switch_str dictionary when processing samples, but the perf.session setup only registers the sample callback. Is there a missing callback registration needed to populate the dictionary with context switch events?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=39
Ian Rogers
reviewerPATCH v6 40/59 perf net_dropmonitor: Port net_dropmonitor to use python module
In reply to Ian RogersPorted from tools/perf/scripts/python/.
- Refactored the script to use a class structure (DropMonitor) to encapsulate state.
- Used perf.session for event processing instead of legacy global handlers.
- Maintained the manual /proc/kallsyms reading and binary search for symbol resolution as in the original script.
- Cleaned up Python 2 compatibility artifacts.
---
v2:
1. Fixed Sorting of Locations: Kept location as an integer in the drop_log dictionary keys so that they are sorted numerically rather than lexicographically when generating the report.
2. Fixed Interrupt Handling: Moved the call to get_kallsyms_table() and print_drop_table() outside the try-except block. This ensures that the reporting phase happens exactly once, even if the user interrupts the trace with Ctrl-C.
--- tools/perf/python/net_dropmonitor.py | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tools/perf/python/net_dropmonitor.py
tools/perf/python/net_dropmonitor.py new file +58 -0
@@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +""" +Monitor the system for dropped packets and produce a report of drop locations and counts. +Ported from tools/perf/scripts/python/net_dropmonitor.py +""" + +import argparse +from collections import defaultdict +import sys +import perf + + +class DropMonitor: + """Monitors dropped packets and aggregates counts by location.""" + + def __init__(self): + self.drop_log: dict[tuple[str, int], int] = defaultdict(int) + self.unhandled: dict[str, int] = defaultdict(int) + + def print_drop_table(self) -> None: + """Print aggregated results.""" + print(f"{'LOCATION':>25} {'OFFSET':>25} {'COUNT':>25}") + for (sym, off) in sorted(self.drop_log.keys()): + print(f"{sym:>25} {off:>25d} {self.drop_log[(sym, off)]:>25d}") + + def process_event(self, sample: perf.sample_event) -> None: + """Process a single sample event.""" + if str(sample.evsel) != "evsel(skb:kfree_skb)": + return + + try: + symbol = getattr(sample, "symbol", "[unknown]") + symoff = getattr(sample, "symoff", 0) + self.drop_log[(symbol, symoff)] += 1 + except AttributeError: + self.unhandled[str(sample.evsel)] += 1 + + +if __name__ == "__main__": + ap = argparse.ArgumentParser( + description="Monitor the system for dropped packets and produce a " + "report of drop locations and counts.") + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + args = ap.parse_args() + + monitor = DropMonitor() + + try: + session = perf.session(perf.data(args.input), sample=monitor.process_event) + session.process_events() + except KeyboardInterrupt: + print("\nStopping trace...") + except Exception as e: + print(f"Error processing events: {e}") + sys.exit(1) + + monitor.print_drop_table()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 40/59] perf net_dropmonitor: Port net_dropmonitor to use python module
Sashiko AI review found 3 potential issue(s): - [High] Functional regression: script attributes drops to the tracepoint execution site instead of the actual drop location. - [Medium] Missing…
Sashiko AI review found 3 potential issue(s):
- [High] Functional regression: script attributes drops to the tracepoint execution site instead of the actual drop location.
- [Medium] Missing /proc/kallsyms logic contradicting the commit message.
- [Low] Unreachable except AttributeError block due to getattr defaults.
--
commit 2c6558b3bdb56c40c812f2bf2afa2daa4406fa15
Author: Ian Rogers <[email protected]>
perf net_dropmonitor: Port net_dropmonitor to use python module
This commit ports the net_dropmonitor python script to use a class structure and the perf.session API instead of legacy global handlers. It also cleans up Python 2 compatibility artifacts.
Quoted 2 lines
- Maintained the manual
/proc/kallsymsreading and binary search for symbol resolution as in the original script.
The commit message states that manual /proc/kallsyms reading and binary search for symbol resolution are maintained. However, the patch replaces this logic entirely with sample.symbol and sample.symoff.
Is this description accurate, or was the commit message not updated to match the code?
Quoted 6 lines
tools/perf/python/net_dropmonitor.py new file +0
-0@@ -0,0 +1,58 @@
[ ... ]
tools/perf/python/net_dropmonitor.py line 34
Quoted 8 lines
tools/perf/python/net_dropmonitor.py new file +8
-0+ def process_event(self, sample: perf.sample_event) -> None: + """Process a single sample event.""" + if str(sample.evsel) != "evsel(skb:kfree_skb)": + return + + try: + symbol = getattr(sample, "symbol", "[unknown]") + symoff = getattr(sample, "symoff", 0)
Will this use the instruction pointer of the event itself (typically within kfree_skb) instead of the actual drop location?
The original script aggregated packet drops by examining the location tracepoint argument, which points to the network driver or subsystem that dropped the packet. Using sample.symbol and sample.symoff attributes all packet drops to kfree_skb itself rather than their true source.
tools/perf/python/net_dropmonitor.py line 36
Quoted 2 lines
tools/perf/python/net_dropmonitor.py new file +2
-0+ self.drop_log[(symbol, symoff)] += 1 + except AttributeError:
Is this exception block reachable?
Because getattr() is used with a default value, it won't raise an AttributeError if the attribute is missing. Events without symbols will be recorded under the ('[unknown]', 0) key in self.drop_log instead of incrementing self.unhandled.
Quoted 1 line
+ self.unhandled[str(sample.evsel)] += 1
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=40
Ian Rogers
reviewerPATCH v6 41/59 perf netdev-times: Port netdev-times to use python module
In reply to Ian RogersPorted from tools/perf/scripts/python/.
- Refactored the script to use a class structure (NetDevTimesAnalyzer) to encapsulate state.
- Used perf.session for event collection and processed them in time order at the end to match legacy behavior.
- Extracted tracepoint fields directly from sample attributes.
- Moved format string constants to module level.
- Cleaned up Python 2 compatibility artifacts (like cmp_to_key).
---
v2: Corrected Field Names: Fixed getattr calls for skblen and dev_name
to use "len" and "name" respectively, as exposed by the actual tracepoints.
--- tools/perf/python/netdev-times.py | 472 ++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) create mode 100755 tools/perf/python/netdev-times.py
tools/perf/python/netdev-times.py new file +472 -0
@@ -0,0 +1,472 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +""" +Display a process of packets and processed time. +It helps us to investigate networking or network device. + +Ported from tools/perf/scripts/python/netdev-times.py +""" + +import argparse +from collections import defaultdict +import sys +from typing import Optional +import perf + +# Format for displaying rx packet processing +PF_IRQ_ENTRY = " irq_entry(+%.3fmsec irq=%d:%s)" +PF_SOFT_ENTRY = " softirq_entry(+%.3fmsec)" +PF_NAPI_POLL = " napi_poll_exit(+%.3fmsec %s)" +PF_JOINT = " |" +PF_WJOINT = " | |" +PF_NET_RECV = " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)" +PF_NET_RX = " |---netif_rx(+%.3fmsec skb=%x)" +PF_CPY_DGRAM = " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)" +PF_KFREE_SKB = " | kfree_skb(+%.3fmsec location=%x)" +PF_CONS_SKB = " | consume_skb(+%.3fmsec)" + + +class NetDevTimesAnalyzer: + """Analyzes network device events and prints charts.""" + + def __init__(self, cfg: argparse.Namespace): + self.args = cfg + self.session: Optional[perf.session] = None + self.show_tx = cfg.tx or (not cfg.tx and not cfg.rx) + self.show_rx = cfg.rx or (not cfg.tx and not cfg.rx) + self.dev = cfg.dev + self.debug = cfg.debug + self.buffer_budget = 65536 + self.irq_dic: dict[int, list[dict]] = defaultdict(list) + self.net_rx_dic: dict[int, dict] = {} + self.receive_hunk_list: list[dict] = [] + self.rx_skb_list: list[dict] = [] + self.tx_queue_list: list[dict] = [] + self.tx_xmit_list: list[dict] = [] + self.tx_free_list: list[dict] = [] + + self.buffer_budget = 65536 + self.of_count_rx_skb_list = 0 + self.of_count_tx_queue_list = 0 + self.of_count_tx_xmit_list = 0 + + def diff_msec(self, src: int, dst: int) -> float: + """Calculate a time interval(msec) from src(nsec) to dst(nsec).""" + return (dst - src) / 1000000.0 + + def print_transmit(self, hunk: dict) -> None: + """Display a process of transmitting a packet.""" + if self.dev and hunk['dev'].find(self.dev) < 0: + return + queue_t_sec = hunk['queue_t'] // 1000000000 + queue_t_usec = hunk['queue_t'] % 1000000000 // 1000 + print(f"{hunk['dev']:7s} {hunk['len']:5d} " + f"{queue_t_sec:6d}.{queue_t_usec:06d}sec " + f"{self.diff_msec(hunk['queue_t'], hunk['xmit_t']):12.3f}msec " + f"{self.diff_msec(hunk['xmit_t'], hunk['free_t']):12.3f}msec") + + def print_receive(self, hunk: dict) -> None: + """Display a process of received packets and interrupts.""" + show_hunk = False + irq_list = hunk['irq_list'] + if not irq_list: + return + cpu = irq_list[0]['cpu'] + base_t = irq_list[0]['irq_ent_t'] + + if self.dev: + for irq in irq_list: + if irq['name'].find(self.dev) >= 0: + show_hunk = True + break + else: + show_hunk = True + + if not show_hunk: + return + + base_t_sec = base_t // 1000000000 + base_t_usec = base_t % 1000000000 // 1000 + print(f"{base_t_sec}.{base_t_usec:06d}sec cpu={cpu}") + for irq in irq_list: + print(PF_IRQ_ENTRY % + (self.diff_msec(base_t, irq['irq_ent_t']), + irq['irq'], irq['name'])) + print(PF_JOINT) + irq_event_list = irq['event_list'] + for irq_event in irq_event_list: + if irq_event['event'] == 'netif_rx': + print(PF_NET_RX % + (self.diff_msec(base_t, irq_event['time']), + irq_event['skbaddr'])) + print(PF_JOINT) + + print(PF_SOFT_ENTRY % self.diff_msec(base_t, hunk['sirq_ent_t'])) + print(PF_JOINT) + event_list = hunk['event_list'] + for i, event in enumerate(event_list): + if event['event_name'] == 'napi_poll': + print(PF_NAPI_POLL % + (self.diff_msec(base_t, event['event_t']), + event['dev'])) + if i == len(event_list) - 1: + print("") + else: + print(PF_JOINT) + else: + print(PF_NET_RECV % + (self.diff_msec(base_t, event['event_t']), + event['skbaddr'], + event['len'])) + if 'comm' in event: + print(PF_WJOINT) + print(PF_CPY_DGRAM % + (self.diff_msec(base_t, event['comm_t']), + event['pid'], event['comm'])) + elif 'handle' in event: + print(PF_WJOINT) + if event['handle'] == "kfree_skb": + print(PF_KFREE_SKB % + (self.diff_msec(base_t, event['comm_t']), + event['location'])) + elif event['handle'] == "consume_skb": + print(PF_CONS_SKB % + self.diff_msec(base_t, event['comm_t'])) + print(PF_JOINT) + + def handle_irq_handler_entry(self, event: dict) -> None: + """Handle irq:irq_handler_entry event.""" + time = event['time'] + cpu = event['cpu'] + irq = event['irq'] + irq_name = event['irq_name'] + irq_record = {'irq': irq, 'name': irq_name, 'cpu': cpu, + 'irq_ent_t': time, 'event_list': []} + self.irq_dic[cpu].append(irq_record) + + def handle_irq_handler_exit(self, event: dict) -> None: + """Handle irq:irq_handler_exit event.""" + time = event['time'] + cpu = event['cpu'] + irq = event['irq'] + if cpu not in self.irq_dic or not self.irq_dic[cpu]: + return + irq_record = self.irq_dic[cpu].pop() + if irq != irq_record['irq']: + return + irq_record['irq_ext_t'] = time + # if an irq doesn't include NET_RX softirq, drop. + if irq_record['event_list']: + self.irq_dic[cpu].append(irq_record) + + def handle_irq_softirq_raise(self, event: dict) -> None: + """Handle irq:softirq_raise event.""" + time = event['time'] + cpu = event['cpu'] + if cpu not in self.irq_dic or not self.irq_dic[cpu]: + return + irq_record = self.irq_dic[cpu].pop() + irq_record['event_list'].append({'time': time, 'event': 'sirq_raise'}) + self.irq_dic[cpu].append(irq_record) + + def handle_irq_softirq_entry(self, event: dict) -> None: + """Handle irq:softirq_entry event.""" + time = event['time'] + cpu = event['cpu'] + self.net_rx_dic[cpu] = {'sirq_ent_t': time, 'event_list': []} + + def handle_irq_softirq_exit(self, event: dict) -> None: + """Handle irq:softirq_exit event.""" + time = event['time'] + cpu = event['cpu'] + irq_list = [] + event_list = [] + sirq_ent_t = None + + if cpu in self.irq_dic: + irq_list = self.irq_dic[cpu] + del self.irq_dic[cpu] + if cpu in self.net_rx_dic: + sirq_ent_t = self.net_rx_dic[cpu]['sirq_ent_t'] + event_list = self.net_rx_dic[cpu]['event_list'] + del self.net_rx_dic[cpu] + if not irq_list or not event_list or sirq_ent_t is None: + return + rec_data = {'sirq_ent_t': sirq_ent_t, 'sirq_ext_t': time, + 'irq_list': irq_list, 'event_list': event_list} + self.receive_hunk_list.append(rec_data) + + def handle_napi_poll(self, event: dict) -> None: + """Handle napi:napi_poll event.""" + time = event['time'] + cpu = event['cpu'] + dev_name = event['dev_name'] + work = event['work'] + budget = event['budget'] + if cpu in self.net_rx_dic: + event_list = self.net_rx_dic[cpu]['event_list'] + rec_data = {'event_name': 'napi_poll', + 'dev': dev_name, 'event_t': time, + 'work': work, 'budget': budget} + event_list.append(rec_data) + + def handle_netif_rx(self, event: dict) -> None: + """Handle net:netif_rx event.""" + time = event['time'] + cpu = event['cpu'] + skbaddr = event['skbaddr'] + skblen = event['skblen'] + dev_name = event['dev_name'] + if cpu not in self.irq_dic or not self.irq_dic[cpu]: + return + irq_record = self.irq_dic[cpu].pop() + irq_record['event_list'].append({'time': time, 'event': 'netif_rx', + 'skbaddr': skbaddr, 'skblen': skblen, + 'dev_name': dev_name}) + self.irq_dic[cpu].append(irq_record) + + def handle_netif_receive_skb(self, event: dict) -> None: + """Handle net:netif_receive_skb event.""" + time = event['time'] + cpu = event['cpu'] + skbaddr = event['skbaddr'] + skblen = event['skblen'] + if cpu in self.net_rx_dic: + rec_data = {'event_name': 'netif_receive_skb', + 'event_t': time, 'skbaddr': skbaddr, 'len': skblen} + event_list = self.net_rx_dic[cpu]['event_list'] + event_list.append(rec_data) + self.rx_skb_list.insert(0, rec_data) + if len(self.rx_skb_list) > self.buffer_budget: + self.rx_skb_list.pop() + self.of_count_rx_skb_list += 1 + + def handle_net_dev_queue(self, event: dict) -> None: + """Handle net:net_dev_queue event.""" + time = event['time'] + skbaddr = event['skbaddr'] + skblen = event['skblen'] + dev_name = event['dev_name'] + skb = {'dev': dev_name, 'skbaddr': skbaddr, 'len': skblen, 'queue_t': time} + self.tx_queue_list.insert(0, skb) + if len(self.tx_queue_list) > self.buffer_budget: + self.tx_queue_list.pop() + self.of_count_tx_queue_list += 1 + + def handle_net_dev_xmit(self, event: dict) -> None: + """Handle net:net_dev_xmit event.""" + time = event['time'] + skbaddr = event['skbaddr'] + rc = event['rc'] + if rc == 0: # NETDEV_TX_OK + for i, skb in enumerate(self.tx_queue_list): + if skb['skbaddr'] == skbaddr: + skb['xmit_t'] = time + self.tx_xmit_list.insert(0, skb) + del self.tx_queue_list[i] + if len(self.tx_xmit_list) > self.buffer_budget: + self.tx_xmit_list.pop() + self.of_count_tx_xmit_list += 1 + return + + def handle_kfree_skb(self, event: dict) -> None: + """Handle skb:kfree_skb event.""" + time = event['time'] + skbaddr = event['skbaddr'] + comm = event['comm'] + pid = event['pid'] + location = event['location'] + for i, skb in enumerate(self.tx_queue_list): + if skb['skbaddr'] == skbaddr: + del self.tx_queue_list[i] + return + for i, skb in enumerate(self.tx_xmit_list): + if skb['skbaddr'] == skbaddr: + skb['free_t'] = time + self.tx_free_list.append(skb) + del self.tx_xmit_list[i] + return + for i, rec_data in enumerate(self.rx_skb_list): + if rec_data['skbaddr'] == skbaddr: + rec_data.update({'handle': "kfree_skb", + 'comm': comm, 'pid': pid, 'comm_t': time, 'location': location}) + del self.rx_skb_list[i] + return + + def handle_consume_skb(self, event: dict) -> None: + """Handle skb:consume_skb event.""" + time = event['time'] + skbaddr = event['skbaddr'] + for i, skb in enumerate(self.tx_xmit_list): + if skb['skbaddr'] == skbaddr: + skb['free_t'] = time + self.tx_free_list.append(skb) + del self.tx_xmit_list[i] + return + + def handle_skb_copy_datagram_iovec(self, event: dict) -> None: + """Handle skb:skb_copy_datagram_iovec event.""" + time = event['time'] + skbaddr = event['skbaddr'] + comm = event['comm'] + pid = event['pid'] + for i, rec_data in enumerate(self.rx_skb_list): + if skbaddr == rec_data['skbaddr']: + rec_data.update({'handle': "skb_copy_datagram_iovec", + 'comm': comm, 'pid': pid, 'comm_t': time}) + del self.rx_skb_list[i] + return + + + + def print_summary(self) -> None: + """Print charts.""" + + # display receive hunks + if self.show_rx: + for hunk in self.receive_hunk_list: + self.print_receive(hunk) + + # display transmit hunks + if self.show_tx: + print(" dev len Qdisc " + " netdevice free") + for hunk in self.tx_free_list: + self.print_transmit(hunk) + + if self.debug: + print("debug buffer status") + print("----------------------------") + print(f"xmit Qdisc:remain:{len(self.tx_queue_list)} " + f"overflow:{self.of_count_tx_queue_list}") + print(f"xmit netdevice:remain:{len(self.tx_xmit_list)} " + f"overflow:{self.of_count_tx_xmit_list}") + print(f"receive:remain:{len(self.rx_skb_list)} " + f"overflow:{self.of_count_rx_skb_list}") + + def handle_single_event(self, event: dict) -> None: + """Handle a single processed event.""" + name = event['name'] + if name == 'irq:softirq_exit': + self.handle_irq_softirq_exit(event) + elif name == 'irq:softirq_entry': + self.handle_irq_softirq_entry(event) + elif name == 'irq:softirq_raise': + self.handle_irq_softirq_raise(event) + elif name == 'irq:irq_handler_entry': + self.handle_irq_handler_entry(event) + elif name == 'irq:irq_handler_exit': + self.handle_irq_handler_exit(event) + elif name == 'napi:napi_poll': + self.handle_napi_poll(event) + elif name == 'net:netif_receive_skb': + self.handle_netif_receive_skb(event) + elif name == 'net:netif_rx': + self.handle_netif_rx(event) + elif name == 'skb:skb_copy_datagram_iovec': + self.handle_skb_copy_datagram_iovec(event) + elif name == 'net:net_dev_queue': + self.handle_net_dev_queue(event) + elif name == 'net:net_dev_xmit': + self.handle_net_dev_xmit(event) + elif name == 'skb:kfree_skb': + self.handle_kfree_skb(event) + elif name == 'skb:consume_skb': + self.handle_consume_skb(event) + + def process_event(self, sample: perf.sample_event) -> None: + """Process events directly on-the-fly.""" + name = str(sample.evsel) + pid = sample.sample_pid + if hasattr(self, 'session') and self.session: + comm = self.session.find_thread(pid).comm() + else: + comm = "Unknown" + event_data = { + 'name': name[6:-1] if name.startswith("evsel(") else name, + 'time': sample.sample_time, + 'cpu': sample.sample_cpu, + 'pid': pid, + 'comm': comm, + } + + # Extract specific fields based on event type + if name.startswith("evsel(irq:softirq_"): + event_data['vec'] = getattr(sample, "vec", 0) + # Filter for NET_RX + try: + if perf.symbol_str("irq:softirq_entry", "vec", # type: ignore + event_data['vec']) != "NET_RX": + return + except AttributeError: + # Fallback if symbol_str not available or fails + if event_data['vec'] != 3: # NET_RX_SOFTIRQ is usually 3 + return + elif name == "evsel(irq:irq_handler_entry)": + event_data['irq'] = getattr(sample, "irq", -1) + event_data['irq_name'] = getattr(sample, "name", "[unknown]") + elif name == "evsel(irq:irq_handler_exit)": + event_data['irq'] = getattr(sample, "irq", -1) + event_data['ret'] = getattr(sample, "ret", 0) + elif name == "evsel(napi:napi_poll)": + event_data['napi'] = getattr(sample, "napi", 0) + event_data['dev_name'] = getattr(sample, "dev_name", "[unknown]") + event_data['work'] = getattr(sample, "work", 0) + event_data['budget'] = getattr(sample, "budget", 0) + elif name in ("evsel(net:netif_receive_skb)", "evsel(net:netif_rx)", + "evsel(net:net_dev_queue)"): + event_data['skbaddr'] = getattr(sample, "skbaddr", 0) + event_data['skblen'] = getattr(sample, "len", 0) + event_data['dev_name'] = getattr(sample, "name", "[unknown]") + elif name == "evsel(net:net_dev_xmit)": + event_data['skbaddr'] = getattr(sample, "skbaddr", 0) + event_data['skblen'] = getattr(sample, "len", 0) + event_data['rc'] = getattr(sample, "rc", 0) + event_data['dev_name'] = getattr(sample, "name", "[unknown]") + elif name == "evsel(skb:kfree_skb)": + event_data['skbaddr'] = getattr(sample, "skbaddr", 0) + event_data['location'] = getattr(sample, "location", 0) + event_data['protocol'] = getattr(sample, "protocol", 0) + event_data['reason'] = getattr(sample, "reason", 0) + elif name == "evsel(skb:consume_skb)": + event_data['skbaddr'] = getattr(sample, "skbaddr", 0) + event_data['location'] = getattr(sample, "location", 0) + elif name == "evsel(skb:skb_copy_datagram_iovec)": + event_data['skbaddr'] = getattr(sample, "skbaddr", 0) + event_data['skblen'] = getattr(sample, "skblen", 0) + + self.handle_single_event(event_data) + + +if __name__ == "__main__": + ap = argparse.ArgumentParser(description="Display a process of packets and processed time.") + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + ap.add_argument("tx", nargs="?", help="show only tx chart") + ap.add_argument("rx", nargs="?", help="show only rx chart") + ap.add_argument("dev", nargs="?", help="show only specified device") + ap.add_argument("debug", nargs="?", help="work with debug mode. It shows buffer status.") + args = ap.parse_args() + + parsed_args = argparse.Namespace(tx=False, rx=False, dev=None, debug=False, input=args.input) + + for arg in sys.argv[1:]: + if arg == 'tx': + parsed_args.tx = True + elif arg == 'rx': + parsed_args.rx = True + elif arg.startswith('dev='): + parsed_args.dev = arg[4:] + elif arg == 'debug': + parsed_args.debug = True + + analyzer = NetDevTimesAnalyzer(parsed_args) + + try: + session = perf.session(perf.data(parsed_args.input), sample=analyzer.process_event) + analyzer.session = session + session.process_events() + analyzer.print_summary() + except KeyboardInterrupt: + analyzer.print_summary() + except Exception as e: + print(f"Error processing events: {e}")
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 41/59] perf netdev-times: Port netdev-times to use python module
Sashiko AI review found 5 potential issue(s): - [High] Inconsistent event name matching logic leads to KeyError crashes on environments lacking the 'evsel(' wrapper. - [High] Dropped packets…
Sashiko AI review found 5 potential issue(s):
- [High] Inconsistent event name matching logic leads to KeyError crashes on environments lacking the 'evsel(' wrapper.
- [High] Dropped packets (kfree_skb) are incorrectly printed as successfully copied datagrams.
- [High] Missing 'consume_skb' handling for received SKBs leads to missed consumption events.
- [Medium] Argument parsing logic is disconnected from argparse definitions.
- [Medium] Softirq chunks that process zero packets are silently dropped.
--
commit 86da247cad062132ea413c0ac8dffb4e7574d66d
Author: Ian Rogers <[email protected]>
perf netdev-times: Port netdev-times to use python module
This patch ports the legacy Python script netdev-times.py to a Python 3 module using a class-based structure. It utilizes the perf.session API to process events and collect traces.
Quoted 6 lines
tools/perf/python/netdev-times.py new file +0
-0@@ -0,0 +1,472 @@
[ ... ]
tools/perf/python/netdev-times.py line 126
Quoted 11 lines
tools/perf/python/netdev-times.py new file +11
-0+ else: + print(PF_NET_RECV % + (self.diff_msec(base_t, event['event_t']), + event['skbaddr'], + event['len'])) + if 'comm' in event: + print(PF_WJOINT) + print(PF_CPY_DGRAM % + (self.diff_msec(base_t, event['comm_t']), + event['pid'], event['comm'])) + elif 'handle' in event:
When handle_kfree_skb() processes an event, it updates rec_data with both 'handle' and 'comm':
rec_data.update({'handle': "kfree_skb",
'comm': comm, ...})Will this cause kfree_skb events to match the "if 'comm' in event" condition and mistakenly print as successfully copied datagrams?
[ ... ]
Quoted 7 lines
tools/perf/python/netdev-times.py new file +7
-0+ def handle_irq_softirq_exit(self, event: dict) -> None: + """Handle irq:softirq_exit event.""" + time = event['time'] + cpu = event['cpu'] + irq_list = [] + event_list = [] + sirq_ent_t = None
tools/perf/python/netdev-times.py line 194
Quoted 10 lines
tools/perf/python/netdev-times.py new file +10
-0+ + if cpu in self.irq_dic: + irq_list = self.irq_dic[cpu] + del self.irq_dic[cpu] + if cpu in self.net_rx_dic: + sirq_ent_t = self.net_rx_dic[cpu]['sirq_ent_t'] + event_list = self.net_rx_dic[cpu]['event_list'] + del self.net_rx_dic[cpu] + if not irq_list or not event_list or sirq_ent_t is None: + return
If a softirq execution processes no packets, event_list will be an empty list. Since an empty list evaluates to false in Python, will this cause chunks that process zero packets to be silently dropped?
[ ... ]
tools/perf/python/netdev-times.py line 305
Quoted 10 lines
tools/perf/python/netdev-times.py new file +10
-0+ def handle_consume_skb(self, event: dict) -> None: + """Handle skb:consume_skb event.""" + time = event['time'] + skbaddr = event['skbaddr'] + for i, skb in enumerate(self.tx_xmit_list): + if skb['skbaddr'] == skbaddr: + skb['free_t'] = time + self.tx_free_list.append(skb) + del self.tx_xmit_list[i] + return
Does this logic miss consumption events for received SKBs?
Unlike handle_kfree_skb(), which searches rx_skb_list for a matching skbaddr, this function only iterates over tx_xmit_list. Could this leave received SKBs in rx_skb_list without marking them as consumed?
[ ... ]
Quoted 9 lines
tools/perf/python/netdev-times.py new file +9
-0+ def process_event(self, sample: perf.sample_event) -> None: + """Process events directly on-the-fly.""" + name = str(sample.evsel) + pid = sample.sample_pid + if hasattr(self, 'session') and self.session: + comm = self.session.find_thread(pid).comm() + else: + comm = "Unknown" + event_data = {
tools/perf/python/netdev-times.py line 395
Quoted 10 lines
tools/perf/python/netdev-times.py new file +10
-0+ 'name': name[6:-1] if name.startswith("evsel(") else name, + 'time': sample.sample_time, + 'cpu': sample.sample_cpu, + 'pid': pid, + 'comm': comm, + } + + # Extract specific fields based on event type + if name.startswith("evsel(irq:softirq_"): + event_data['vec'] = getattr(sample, "vec", 0)
Is it possible for the environment's perf bindings to omit the "evsel(" wrapper?
If name does not start with "evsel(", event_data['name'] will remain unwrapped, so it can still successfully route via handle_single_event().
However, the "if name.startswith('evsel(')" branches here will be skipped, meaning fields like 'irq' or 'skbaddr' won't be extracted.
Will this lead to KeyError crashes in handler functions like handle_irq_handler_entry() when they try to access those missing fields?
[ ... ]
Quoted 10 lines
tools/perf/python/netdev-times.py new file +10
-0+if __name__ == "__main__": + ap = argparse.ArgumentParser(description="Display a process of packets and processed time.") + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + ap.add_argument("tx", nargs="?", help="show only tx chart") + ap.add_argument("rx", nargs="?", help="show only rx chart") + ap.add_argument("dev", nargs="?", help="show only specified device") + ap.add_argument("debug", nargs="?", help="work with debug mode. It shows buffer status.") + args = ap.parse_args() + + parsed_args = argparse.Namespace(tx=False, rx=False, dev=None, debug=False, input=args.input)
tools/perf/python/netdev-times.py line 460
Quoted 10 lines
tools/perf/python/netdev-times.py new file +10
-0+ + for arg in sys.argv[1:]: + if arg == 'tx': + parsed_args.tx = True + elif arg == 'rx': + parsed_args.rx = True + elif arg.startswith('dev='): + parsed_args.dev = arg[4:] + elif arg == 'debug': + parsed_args.debug = True
Is it intentional to manually iterate over sys.argv[1:] after setting up and calling ap.parse_args()?
This approach seems to disconnect the argument parsing from the argparse definitions. Valid argparse invocations, such as passing a device name positionally, appear to be ignored.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=41
Ian Rogers
reviewerPATCH v6 42/59 perf powerpc-hcalls: Port powerpc-hcalls to use python module
In reply to Ian RogersPorted from tools/perf/scripts/python/.
- Refactored the script to use a class structure (HCallAnalyzer) to encapsulate state.
- Used perf.session for event processing.
- Tracked hcall entry and exit to calculate duration and aggregate statistics.
- Moved the large hcall_table to a module-level constant HCALL_TABLE.
- Cleaned up Python 2 compatibility artifacts.
--- tools/perf/python/powerpc-hcalls.py | 211 ++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100755 tools/perf/python/powerpc-hcalls.py
tools/perf/python/powerpc-hcalls.py new file +211 -0
@@ -0,0 +1,211 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0+ +""" +Hypervisor call statistics + +Copyright (C) 2018 Ravi Bangoria, IBM Corporation +Ported from tools/perf/scripts/python/powerpc-hcalls.py +""" + +import argparse +from collections import defaultdict +import perf + +# Hypervisor call table +HCALL_TABLE = { + 4: 'H_REMOVE', + 8: 'H_ENTER', + 12: 'H_READ', + 16: 'H_CLEAR_MOD', + 20: 'H_CLEAR_REF', + 24: 'H_PROTECT', + 28: 'H_GET_TCE', + 32: 'H_PUT_TCE', + 36: 'H_SET_SPRG0', + 40: 'H_SET_DABR', + 44: 'H_PAGE_INIT', + 48: 'H_SET_ASR', + 52: 'H_ASR_ON', + 56: 'H_ASR_OFF', + 60: 'H_LOGICAL_CI_LOAD', + 64: 'H_LOGICAL_CI_STORE', + 68: 'H_LOGICAL_CACHE_LOAD', + 72: 'H_LOGICAL_CACHE_STORE', + 76: 'H_LOGICAL_ICBI', + 80: 'H_LOGICAL_DCBF', + 84: 'H_GET_TERM_CHAR', + 88: 'H_PUT_TERM_CHAR', + 92: 'H_REAL_TO_LOGICAL', + 96: 'H_HYPERVISOR_DATA', + 100: 'H_EOI', + 104: 'H_CPPR', + 108: 'H_IPI', + 112: 'H_IPOLL', + 116: 'H_XIRR', + 120: 'H_MIGRATE_DMA', + 124: 'H_PERFMON', + 220: 'H_REGISTER_VPA', + 224: 'H_CEDE', + 228: 'H_CONFER', + 232: 'H_PROD', + 236: 'H_GET_PPP', + 240: 'H_SET_PPP', + 244: 'H_PURR', + 248: 'H_PIC', + 252: 'H_REG_CRQ', + 256: 'H_FREE_CRQ', + 260: 'H_VIO_SIGNAL', + 264: 'H_SEND_CRQ', + 272: 'H_COPY_RDMA', + 276: 'H_REGISTER_LOGICAL_LAN', + 280: 'H_FREE_LOGICAL_LAN', + 284: 'H_ADD_LOGICAL_LAN_BUFFER', + 288: 'H_SEND_LOGICAL_LAN', + 292: 'H_BULK_REMOVE', + 304: 'H_MULTICAST_CTRL', + 308: 'H_SET_XDABR', + 312: 'H_STUFF_TCE', + 316: 'H_PUT_TCE_INDIRECT', + 332: 'H_CHANGE_LOGICAL_LAN_MAC', + 336: 'H_VTERM_PARTNER_INFO', + 340: 'H_REGISTER_VTERM', + 344: 'H_FREE_VTERM', + 348: 'H_RESET_EVENTS', + 352: 'H_ALLOC_RESOURCE', + 356: 'H_FREE_RESOURCE', + 360: 'H_MODIFY_QP', + 364: 'H_QUERY_QP', + 368: 'H_REREGISTER_PMR', + 372: 'H_REGISTER_SMR', + 376: 'H_QUERY_MR', + 380: 'H_QUERY_MW', + 384: 'H_QUERY_HCA', + 388: 'H_QUERY_PORT', + 392: 'H_MODIFY_PORT', + 396: 'H_DEFINE_AQP1', + 400: 'H_GET_TRACE_BUFFER', + 404: 'H_DEFINE_AQP0', + 408: 'H_RESIZE_MR', + 412: 'H_ATTACH_MCQP', + 416: 'H_DETACH_MCQP', + 420: 'H_CREATE_RPT', + 424: 'H_REMOVE_RPT', + 428: 'H_REGISTER_RPAGES', + 432: 'H_DISABLE_AND_GETC', + 436: 'H_ERROR_DATA', + 440: 'H_GET_HCA_INFO', + 444: 'H_GET_PERF_COUNT', + 448: 'H_MANAGE_TRACE', + 468: 'H_FREE_LOGICAL_LAN_BUFFER', + 472: 'H_POLL_PENDING', + 484: 'H_QUERY_INT_STATE', + 580: 'H_ILLAN_ATTRIBUTES', + 592: 'H_MODIFY_HEA_QP', + 596: 'H_QUERY_HEA_QP', + 600: 'H_QUERY_HEA', + 604: 'H_QUERY_HEA_PORT', + 608: 'H_MODIFY_HEA_PORT', + 612: 'H_REG_BCMC', + 616: 'H_DEREG_BCMC', + 620: 'H_REGISTER_HEA_RPAGES', + 624: 'H_DISABLE_AND_GET_HEA', + 628: 'H_GET_HEA_INFO', + 632: 'H_ALLOC_HEA_RESOURCE', + 644: 'H_ADD_CONN', + 648: 'H_DEL_CONN', + 664: 'H_JOIN', + 676: 'H_VASI_STATE', + 688: 'H_ENABLE_CRQ', + 696: 'H_GET_EM_PARMS', + 720: 'H_SET_MPP', + 724: 'H_GET_MPP', + 748: 'H_HOME_NODE_ASSOCIATIVITY', + 756: 'H_BEST_ENERGY', + 764: 'H_XIRR_X', + 768: 'H_RANDOM', + 772: 'H_COP', + 788: 'H_GET_MPP_X', + 796: 'H_SET_MODE', + 61440: 'H_RTAS', +} + + +class HCallAnalyzer: + """Analyzes hypervisor calls and aggregates statistics.""" + + def __init__(self): + # output: {opcode: {'min': min, 'max': max, 'time': time, 'cnt': cnt}} + self.output = defaultdict(lambda: {'time': 0, 'cnt': 0, 'min': float('inf'), 'max': 0}) + # d_enter: {pid: (opcode, nsec)} + self.d_enter: dict[int, tuple[int, int]] = {} + self.print_ptrn = '%-28s%10s%10s%10s%10s' + + def hcall_table_lookup(self, opcode: int) -> str: + """Lookup hcall name by opcode.""" + return HCALL_TABLE.get(opcode, str(opcode)) + + def process_event(self, sample: perf.sample_event) -> None: + """Process a single sample event.""" + name = str(sample.evsel) + pid = sample.sample_pid + time = sample.time + opcode = getattr(sample, "opcode", -1) + + if opcode == -1: + return + + if name == "evsel(powerpc:hcall_entry)": + self.d_enter[pid] = (opcode, time) + elif name == "evsel(powerpc:hcall_exit)": + if pid in self.d_enter: + opcode_entry, time_entry = self.d_enter[pid] + if opcode_entry == opcode: + diff = time - time_entry + del self.d_enter[pid] + + stats = self.output[opcode] + stats['time'] += diff + stats['cnt'] += 1 + if diff < stats['min']: + stats['min'] = diff + if diff > stats['max']: + stats['max'] = diff + + def print_summary(self) -> None: + """Print aggregated statistics.""" + print(self.print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')) + print('-' * 68) + for opcode in sorted(self.output.keys()): + h_name = self.hcall_table_lookup(opcode) + stats = self.output[opcode] + time = stats['time'] + cnt = stats['cnt'] + min_t = stats['min'] + max_t = stats['max'] + + # Avoid float representation for large integers if possible, + # or use formatted strings. Legacy used time//cnt. + avg_t = time // cnt if cnt > 0 else 0 + + # If min was not updated, it remains inf, but cnt should be > 0 if in output + if min_t == float('inf'): + min_t = 0 + + print(self.print_ptrn % (h_name, cnt, int(min_t), int(max_t), avg_t)) + + +if __name__ == "__main__": + ap = argparse.ArgumentParser(description="Hypervisor call statistics") + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + args = ap.parse_args() + + analyzer = HCallAnalyzer() + + try: + session = perf.session(perf.data(args.input), sample=analyzer.process_event) + session.process_events() + analyzer.print_summary() + except KeyboardInterrupt: + analyzer.print_summary() + except Exception as e: + print(f"Error processing events: {e}")
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 42/59] perf powerpc-hcalls: Port powerpc-hcalls to use python module
Sashiko AI review found 2 potential issue(s): - [Medium] The ported powerpc-hcalls script incorrectly tracks hypercall state by `sample_pid` instead of CPU or thread ID, corrupting statistics for…
Sashiko AI review found 2 potential issue(s):
- [Medium] The ported powerpc-hcalls script incorrectly tracks hypercall state by sample_pid instead of CPU or thread ID, corrupting statistics for multi-threaded virtual machines.
- [Medium] The powerpc-hcalls script attempts to access a non-existent sample.time attribute, causing an AttributeError that aborts event processing. --
commit af2c8e27d359ae456d9222ea9cdb2ce0d235611b
Author: Ian Rogers <[email protected]>
perf powerpc-hcalls: Port powerpc-hcalls to use python module
This commit ports the powerpc-hcalls script to use the perf python module. It refactors the script to use a class structure and tracks hypercall entry/exit to calculate duration and aggregate statistics.
Quoted 5 lines
tools/perf/python/powerpc-hcalls.py new file +0
-0
[ ... ]
Quoted 2 lines
tools/perf/python/powerpc-hcalls.py new file +2
-0+class HCallAnalyzer: + """Analyzes hypervisor calls and aggregates statistics."""
[ ... ]
tools/perf/python/powerpc-hcalls.py line 150
Quoted 4 lines
tools/perf/python/powerpc-hcalls.py new file +4
-0+ def process_event(self, sample: perf.sample_event) -> None: + """Process a single sample event.""" + name = str(sample.evsel) + pid = sample.sample_pid
Will using sample_pid (which corresponds to the Thread Group ID) cause statistics to be corrupted for multi-threaded virtual machines?
Since QEMU uses multiple vCPU threads under a single process, concurrent hypercalls from different vCPUs might share the same sample_pid and overwrite each other's entry state in self.d_enter.
Should this use sample.sample_tid or CPU ID to track individual threads instead?
Quoted 1 line
+ time = sample.time
Does the perf Python API expose the timestamp as sample.time?
Looking at the perf Python extension, the timestamp is typically exposed as sample.sample_time. If the time attribute doesn't exist, will it raise an AttributeError and cause the script to fail on the first event?
Quoted 7 lines
tools/perf/python/powerpc-hcalls.py new file +7
-0+ opcode = getattr(sample, "opcode", -1) + + if opcode == -1: + return + + if name == "evsel(powerpc:hcall_entry)": + self.d_enter[pid] = (opcode, time)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=42
Ian Rogers
reviewerPATCH v6 43/59 perf sched-migration: Port sched-migration/SchedGui to use python module
In reply to Ian RogersPorted from tools/perf/scripts/python/ and its Util lib.
- Refactored sched-migration.py to use a class structure (SchedMigrationAnalyzer) to encapsulate state.
- Used perf.session for event processing.
- Ported SchedGui.py to the same directory to keep it as a local dependency.
- Made wxPython dependency optional in sched-migration.py, printing a message if it's missing instead of failing with ImportError.
- Cleaned up Python 2 compatibility artifacts.
---
v2:
tools/perf/python/SchedGui.py:
- Python 3 Compatibility: Fixed TypeError issues caused by float division in Python 3 when wxPython expected integers. Used integer division ( // ) and explicit int() casts for scrollbar and size calculations.
- wxPython Phoenix API Updates:
- Replaced deprecated SetDimensions() with SetSize() .
- Replaced removed GetPositionTuple() with GetPosition() in on_mouse_down.
- Fixed wx.PaintDC creation in on_paint to use event.GetEventObject() to ensure valid DC creation regardless of which window triggered the event.
- Layout and Rendering Fixes:
- Replaced static layout with a wx.SplitterWindow to physically separate the drawing area from the text area, preventing them from overlapping and restoring scrollbar functionality.
- Adjusted the initial sash position to give 3/4 of the height to the drawing area.
- Replaced wx.StaticText with a multiline wx.TextCtrl for the summary area to allow text selection and simpler value updates.
- Added CPU labels ("CPU ") drawn at the left edge of the visible area in on_paint .
- Added background clearing ( dc.Clear() ) in on_paint to avoid "ghosting" of old text and rectangles when scrolling.
tools/perf/python/sched-migration.py:
- Fixed a bug where sharing a snapshot in find_time_slice caused data mutation across calls.
- Added safety checks to handle empty data cases (e.g., when intervals have no events).
- Fixed fallbacks in fill_zone when search conditions fail to find a matching time slice.
--- tools/perf/python/SchedGui.py | 219 +++++++++++++ tools/perf/python/sched-migration.py | 469 +++++++++++++++++++++++++++ 2 files changed, 688 insertions(+) create mode 100755 tools/perf/python/SchedGui.py create mode 100755 tools/perf/python/sched-migration.py
tools/perf/python/SchedGui.py new file +219 -0
@@ -0,0 +1,219 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# SchedGui.py - Python extension for perf script, basic GUI code for +# traces drawing and overview. +# +# Copyright (C) 2010 by Frederic Weisbecker <[email protected]> +# +# Ported to modern directory structure. + +try: + import wx # type: ignore +except ImportError: + raise ImportError("You need to install the wxpython lib for this script") + + +class RootFrame(wx.Frame): + Y_OFFSET = 100 + RECT_HEIGHT = 100 + RECT_SPACE = 50 + EVENT_MARKING_WIDTH = 5 + + def __init__(self, sched_tracer, title, parent=None, id=-1): + wx.Frame.__init__(self, parent, id, title) + + (self.screen_width, self.screen_height) = wx.GetDisplaySize() + self.screen_width -= 10 + self.screen_height -= 10 + self.zoom = 0.5 + self.scroll_scale = 20 + self.sched_tracer = sched_tracer + self.sched_tracer.set_root_win(self) + (self.ts_start, self.ts_end) = sched_tracer.interval() + self.update_width_virtual() + self.nr_rects = sched_tracer.nr_rectangles() + 1 + self.height_virtual = RootFrame.Y_OFFSET + \ + (self.nr_rects * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) + + # whole window panel + self.panel = wx.Panel(self, size=(self.screen_width, self.screen_height)) + + # scrollable container + # Create SplitterWindow + self.splitter = wx.SplitterWindow(self.panel, style=wx.SP_3D) + + # scrollable container (Top) + self.scroll = wx.ScrolledWindow(self.splitter) + self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, + int(self.width_virtual // self.scroll_scale), + int(self.height_virtual // self.scroll_scale)) + self.scroll.EnableScrolling(True, True) + self.scroll.SetFocus() + + # scrollable drawing area + self.scroll_panel = wx.Panel(self.scroll, + size=(self.screen_width - 15, self.screen_height // 2)) + self.scroll_panel.Bind(wx.EVT_PAINT, self.on_paint) + self.scroll_panel.Bind(wx.EVT_KEY_DOWN, self.on_key_press) + self.scroll_panel.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down) + self.scroll.Bind(wx.EVT_KEY_DOWN, self.on_key_press) + self.scroll.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down) + + self.scroll_panel.SetSize(int(self.width_virtual), int(self.height_virtual)) + + # Create a separate panel for text (Bottom) + self.text_panel = wx.Panel(self.splitter) + self.text_sizer = wx.BoxSizer(wx.VERTICAL) + self.txt = wx.TextCtrl(self.text_panel, -1, "Click a bar to see details", + style=wx.TE_MULTILINE) + self.text_sizer.Add(self.txt, 1, wx.EXPAND | wx.ALL, 5) + self.text_panel.SetSizer(self.text_sizer) + + # Split the window + self.splitter.SplitHorizontally(self.scroll, self.text_panel, (self.screen_height * 3) // 4) + + # Main sizer to layout splitter + self.main_sizer = wx.BoxSizer(wx.VERTICAL) + self.main_sizer.Add(self.splitter, 1, wx.EXPAND) + self.panel.SetSizer(self.main_sizer) + + self.scroll.Fit() + self.Fit() + + self.Show(True) + + def us_to_px(self, val): + return val / (10 ** 3) * self.zoom + + def px_to_us(self, val): + return (val / self.zoom) * (10 ** 3) + + def scroll_start(self): + (x, y) = self.scroll.GetViewStart() + return (x * self.scroll_scale, y * self.scroll_scale) + + def scroll_start_us(self): + (x, y) = self.scroll_start() + return self.px_to_us(x) + + def paint_rectangle_zone(self, nr, color, top_color, start, end): + offset_px = self.us_to_px(start - self.ts_start) + width_px = self.us_to_px(end - start) + + offset_py = RootFrame.Y_OFFSET + (nr * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) + width_py = RootFrame.RECT_HEIGHT + + dc = self.dc + + if top_color is not None: + (r, g, b) = top_color + top_color = wx.Colour(r, g, b) + brush = wx.Brush(top_color, wx.SOLID) + dc.SetBrush(brush) + dc.DrawRectangle(int(offset_px), int(offset_py), + int(width_px), RootFrame.EVENT_MARKING_WIDTH) + width_py -= RootFrame.EVENT_MARKING_WIDTH + offset_py += RootFrame.EVENT_MARKING_WIDTH + + (r, g, b) = color + color = wx.Colour(r, g, b) + brush = wx.Brush(color, wx.SOLID) + dc.SetBrush(brush) + dc.DrawRectangle(int(offset_px), int(offset_py), int(width_px), int(width_py)) + + def update_rectangles(self, dc, start, end): + start += self.ts_start + end += self.ts_start + self.sched_tracer.fill_zone(start, end) + + def on_paint(self, event): + window = event.GetEventObject() + dc = wx.PaintDC(window) + + # Clear background to avoid ghosting + dc.SetBackground(wx.Brush(window.GetBackgroundColour())) + dc.Clear() + + self.dc = dc + + width = min(self.width_virtual, self.screen_width) + (x, y) = self.scroll_start() + start = self.px_to_us(x) + end = self.px_to_us(x + width) + self.update_rectangles(dc, start, end) + + # Draw CPU labels at the left edge of the visible area + (x_scroll, _) = self.scroll_start() + for nr in range(self.nr_rects): + offset_py = RootFrame.Y_OFFSET + (nr * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) + dc.DrawText(f"CPU {nr}", x_scroll + 10, offset_py + 10) + + def rect_from_ypixel(self, y): + y -= RootFrame.Y_OFFSET + rect = y // (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE) + height = y % (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE) + + if rect < 0 or rect > self.nr_rects - 1 or height > RootFrame.RECT_HEIGHT: + return -1 + + return rect + + def update_summary(self, txt): + self.txt.SetValue(txt) + self.text_panel.Layout() + self.splitter.Layout() + self.text_panel.Refresh() + + def on_mouse_down(self, event): + pos = event.GetPosition() + x, y = pos.x, pos.y + rect = self.rect_from_ypixel(y) + if rect == -1: + return + + t = self.px_to_us(x) + self.ts_start + + self.sched_tracer.mouse_down(rect, t) + + def update_width_virtual(self): + self.width_virtual = self.us_to_px(self.ts_end - self.ts_start) + + def __zoom(self, x): + self.update_width_virtual() + (xpos, ypos) = self.scroll.GetViewStart() + xpos = int(self.us_to_px(x) // self.scroll_scale) + self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, + int(self.width_virtual // self.scroll_scale), + int(self.height_virtual // self.scroll_scale), + xpos, ypos) + self.Refresh() + + def zoom_in(self): + x = self.scroll_start_us() + self.zoom *= 2 + self.__zoom(x) + + def zoom_out(self): + x = self.scroll_start_us() + self.zoom /= 2 + self.__zoom(x) + + def on_key_press(self, event): + key = event.GetRawKeyCode() + if key == ord("+"): + self.zoom_in() + return + if key == ord("-"): + self.zoom_out() + return + + key = event.GetKeyCode() + (x, y) = self.scroll.GetViewStart() + if key == wx.WXK_RIGHT: + self.scroll.Scroll(x + 1, y) + elif key == wx.WXK_LEFT: + self.scroll.Scroll(x - 1, y) + elif key == wx.WXK_DOWN: + self.scroll.Scroll(x, y + 1) + elif key == wx.WXK_UP: + self.scroll.Scroll(x, y - 1)
tools/perf/python/sched-migration.py new file +469 -0
469 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v6 44/59 perf sctop: Port sctop to use python module
In reply to Ian RogersThis commit ports sctop.py from tools/perf/scripts/python/ to tools/perf/python/ using a class-based structure. It also adds live mode support using the LiveSession helper with a fallback strategy for tracepoint names.
---
v5:
1. Fix Fallback Logic: Check __syscall_nr and nr fields for syscall ID if id is missing on fallback tracepoints.
2. Fix Thread Lookup Crash: Added try-except block around session.process() to handle missing PIDs gracefully.
--- tools/perf/python/sctop.py | 186 +++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100755 tools/perf/python/sctop.py
tools/perf/python/sctop.py new file +186 -0
@@ -0,0 +1,186 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +""" +System call top + +Periodically displays system-wide system call totals, broken down by +syscall. If a [comm] arg is specified, only syscalls called by +[comm] are displayed. If an [interval] arg is specified, the display +will be refreshed every [interval] seconds. The default interval is +3 seconds. + +Ported from tools/perf/scripts/python/sctop.py +""" + +import argparse +from collections import defaultdict +import sys +import threading +from typing import Optional +import perf +from perf_live import LiveSession + + + + +class SCTopAnalyzer: + """Periodically displays system-wide system call totals.""" + + def __init__(self, for_comm: str | None, interval: int, offline: bool = False): + self.for_comm = for_comm + self.interval = interval + self.syscalls: dict[int, int] = defaultdict(int) + self.lock = threading.Lock() + self.stop_event = threading.Event() + self.thread = threading.Thread(target=self.print_syscall_totals) + self.offline = offline + self.last_print_time: int | None = None + self.session: Optional[perf.session] = None + + def syscall_name(self, syscall_id: int) -> str: + """Lookup syscall name by ID.""" + try: + return perf.syscall_name(syscall_id) + except Exception: # pylint: disable=broad-exception-caught + pass + return str(syscall_id) + + def process_event(self, sample: perf.sample_event) -> None: + """Collect syscall events.""" + name = str(sample.evsel) + syscall_id = getattr(sample, "id", -1) + if syscall_id == -1: + syscall_id = getattr(sample, "__syscall_nr", -1) + if syscall_id == -1: + syscall_id = getattr(sample, "nr", -1) + + if syscall_id == -1: + return + + comm = "Unknown" + if hasattr(self, 'session') and self.session: + try: + proc = self.session.find_thread(sample.sample_pid) + if proc: + comm = proc.comm() + except (TypeError, AttributeError): + pass + else: + comm = getattr(sample, "comm", "Unknown") + + if name in ("evsel(raw_syscalls:sys_enter)", "evsel(syscalls:sys_enter)"): + if self.for_comm is not None and comm != self.for_comm: + return + with self.lock: + self.syscalls[syscall_id] += 1 + + if self.offline and hasattr(sample, "time"): + interval_ns = self.interval * (10 ** 9) + if self.last_print_time is None: + self.last_print_time = sample.time + elif sample.time - self.last_print_time >= interval_ns: + self.print_current_totals() + self.last_print_time = sample.time + + def print_current_totals(self): + """Print current syscall totals.""" + # Clear terminal + print("\x1b[2J\x1b[H", end="") + + if self.for_comm is not None: + print(f"\nsyscall events for {self.for_comm}:\n") + else: + print("\nsyscall events:\n") + + print(f"{'event':40s} {'count':10s}") + print(f"{'-' * 40:40s} {'-' * 10:10s}") + + with self.lock: + current_syscalls = list(self.syscalls.items()) + self.syscalls.clear() + + current_syscalls.sort(key=lambda kv: (kv[1], kv[0]), reverse=True) + + for syscall_id, val in current_syscalls: + print(f"{self.syscall_name(syscall_id):<40s} {val:10d}") + + def print_syscall_totals(self): + """Periodically print syscall totals.""" + while not self.stop_event.is_set(): + self.print_current_totals() + self.stop_event.wait(self.interval) + # Print final batch + self.print_current_totals() + + def start(self): + """Start the background thread.""" + self.thread.start() + + def stop(self): + """Stop the background thread.""" + self.stop_event.set() + self.thread.join() + + +def main(): + """Main function.""" + ap = argparse.ArgumentParser(description="System call top") + ap.add_argument("args", nargs="*", help="[comm] [interval] or [interval]") + ap.add_argument("-i", "--input", help="Input file name") + args = ap.parse_args() + + for_comm = None + default_interval = 3 + interval = default_interval + + if len(args.args) > 2: + print("Usage: perf script -s sctop.py [comm] [interval]") + sys.exit(1) + + if len(args.args) > 1: + for_comm = args.args[0] + try: + interval = int(args.args[1]) + except ValueError: + print(f"Invalid interval: {args.args[1]}") + sys.exit(1) + elif len(args.args) > 0: + try: + interval = int(args.args[0]) + except ValueError: + for_comm = args.args[0] + interval = default_interval + + analyzer = SCTopAnalyzer(for_comm, interval, offline=bool(args.input)) + + if not args.input: + analyzer.start() + + try: + if args.input: + session = perf.session(perf.data(args.input), sample=analyzer.process_event) + analyzer.session = session + session.process_events() + else: + try: + live_session = LiveSession( + "raw_syscalls:sys_enter", sample_callback=analyzer.process_event + ) + except OSError: + live_session = LiveSession( + "syscalls:sys_enter", sample_callback=analyzer.process_event + ) + live_session.run() + except KeyboardInterrupt: + pass + except IOError as e: + print(f"Error: {e}") + finally: + if args.input: + analyzer.print_current_totals() + else: + analyzer.stop() + + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 44/59] perf sctop: Port sctop to use python module
Sashiko AI review found 5 potential issue(s): - [High] Filtering by command name (`for_comm`) silently drops all events in live mode. - [Medium] Terminal is cleared during fast offline processing…
Sashiko AI review found 5 potential issue(s):
- [High] Filtering by command name (for_comm) silently drops all events in live mode.
- [Medium] Terminal is cleared during fast offline processing, hiding all but the final interval.
- [Medium] Error messages printed in the main exception block are immediately erased from the terminal.
- [Medium] The interval argument lacks validation against zero or negative values, leading to infinite loops or terminal spam.
- [Low] Misleading usage message instructing execution via perf script.
--
commit 1d0230890ca491ddc08c37ac65574ba53c7bac25
Author: Ian Rogers <[email protected]>
perf sctop: Port sctop to use python module
This commit ports sctop.py from tools/perf/scripts/python/ to tools/perf/python/ using a class-based structure. It also adds live mode support using the LiveSession helper with a fallback strategy for tracepoint names.
Quoted 6 lines
tools/perf/python/sctop.py new file +0
-0@@ -0,0 +1,186 @@
[ ... ]
tools/perf/python/sctop.py line 69
Quoted 10 lines
tools/perf/python/sctop.py new file +10
-0+ comm = "Unknown" + if hasattr(self, 'session') and self.session: + try: + proc = self.session.find_thread(sample.sample_pid) + if proc: + comm = proc.comm() + except (TypeError, AttributeError): + pass + else: + comm = getattr(sample, "comm", "Unknown")
In live mode, analyzer.session is None, so this falls back to getattr(sample, "comm", "Unknown"). Since LiveSession reads raw RECORD_SAMPLE events without maintaining a thread map, will sample.comm always evaluate to "Unknown"?
tools/perf/python/sctop.py line 73
Quoted 4 lines
tools/perf/python/sctop.py new file +4
-0+ + if name in ("evsel(raw_syscalls:sys_enter)", "evsel(syscalls:sys_enter)"): + if self.for_comm is not None and comm != self.for_comm: + return
If sample.comm is always "Unknown" in live mode, will filtering by command name silently drop all events and present an empty screen?
[ ... ]
tools/perf/python/sctop.py line 88
Quoted 10 lines
tools/perf/python/sctop.py new file +10
-0+ if self.last_print_time is None: + self.last_print_time = sample.time + elif sample.time - self.last_print_time >= interval_ns: + self.print_current_totals() + self.last_print_time = sample.time + + def print_current_totals(self): + """Print current syscall totals.""" + # Clear terminal + print("\x1b[2J\x1b[H", end="")
In offline mode, events are processed as fast as they can be read. Does clearing the terminal here cause the screen to flash and hide all but the final interval's data from the user?
[ ... ]
tools/perf/python/sctop.py line 137
Quoted 6 lines
tools/perf/python/sctop.py new file +6
-0+ for_comm = None + default_interval = 3 + interval = default_interval + + if len(args.args) > 2: + print("Usage: perf script -s sctop.py [comm] [interval]")
This isn't a bug, but since this has been ported to a standalone Python script, is this usage message misleading?
tools/perf/python/sctop.py line 149
Quoted 12 lines
tools/perf/python/sctop.py new file +12
-0+ sys.exit(1) + + if len(args.args) > 1: + for_comm = args.args[0] + try: + interval = int(args.args[1]) + except ValueError: + print(f"Invalid interval: {args.args[1]}") + sys.exit(1) + elif len(args.args) > 0: + try: + interval = int(args.args[0])
Is it possible for the interval to be zero or negative here?
If 0 or a negative number is provided, in live mode self.stop_event.wait(self.interval) will return immediately. Will this cause the background thread to spin in a tight loop and max out a CPU core?
Quoted 3 lines
tools/perf/python/sctop.py new file +3
-0+ except ValueError: + for_comm = args.args[0] + interval = default_interval
[ ... ]
tools/perf/python/sctop.py line 182
Quoted 10 lines
tools/perf/python/sctop.py new file +10
-0+ live_session.run() + except KeyboardInterrupt: + pass + except IOError as e: + print(f"Error: {e}") + finally: + if args.input: + analyzer.print_current_totals() + else: + analyzer.stop()
If an IOError occurs, the error message is printed. However, the finally block either calls analyzer.print_current_totals() (in offline mode) or unblocks the background thread which calls it (in live mode).
Since print_current_totals() unconditionally clears the screen with "\x1b[2J\x1b[H", will this immediately erase the error message and hide the failure reason from the user?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=44
Ian Rogers
reviewerPATCH v6 45/59 perf stackcollapse: Port stackcollapse to use python module
In reply to Ian RogersModernize the legacy stackcollapse.py trace script by refactoring it into a class-based architecture (StackCollapseAnalyzer). The script uses perf.session for event processing and aggregates call stacks to produce output suitable for flame graphs.
---
v2:
- Fixed Callchain Check: Replaced hasattr(sample, "callchain") with getattr(sample, "callchain", None) and checked if it is not None . This avoids attempting to iterate over None when a sample lacks a callchain, which would raise a TypeError.
- Fixed Comm Resolution: The code already used self.session.process(sample.sample_pid).comm() to resolve the command name using the session object (if available), avoiding the missing comm attribute on perf.sample_event.
- Code Cleanup: Broke a long line in process_event to satisfy pylint.
--- tools/perf/python/stackcollapse.py | 126 +++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 tools/perf/python/stackcollapse.py
tools/perf/python/stackcollapse.py new file +126 -0
@@ -0,0 +1,126 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +""" +stackcollapse.py - format perf samples with one line per distinct call stack + +This script's output has two space-separated fields. The first is a semicolon +separated stack including the program name (from the "comm" field) and the +function names from the call stack. The second is a count: + + swapper;start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 2 + +The file is sorted according to the first field. + +Ported from tools/perf/scripts/python/stackcollapse.py +""" + +import argparse +from collections import defaultdict +import sys +import perf + + +class StackCollapseAnalyzer: + """Accumulates call stacks and prints them collapsed.""" + + def __init__(self, args: argparse.Namespace) -> None: + self.args = args + self.lines: dict[str, int] = defaultdict(int) + + def tidy_function_name(self, sym: str, dso: str) -> str: + """Beautify function names based on options.""" + if sym is None: + sym = "[unknown]" + + sym = sym.replace(";", ":") + if self.args.tidy_java: + # Beautify Java signatures + sym = sym.replace("<", "") + sym = sym.replace(">", "") + if sym.startswith("L") and "/" in sym: + sym = sym[1:] + try: + sym = sym[:sym.index("(")] + except ValueError: + pass + + if self.args.annotate_kernel and dso == "[kernel.kallsyms]": + return sym + "_[k]" + return sym + + def process_event(self, sample: perf.sample_event) -> None: + """Collect call stack for each sample.""" + stack = [] + callchain = getattr(sample, "callchain", None) + if callchain is not None: + for node in callchain: + stack.append(self.tidy_function_name(node.symbol, node.dso)) + else: + # Fallback if no callchain + sym = getattr(sample, "symbol", "[unknown]") + dso = getattr(sample, "dso", "[unknown]") + stack.append(self.tidy_function_name(sym, dso)) + + if self.args.include_comm: + if hasattr(self, 'session') and self.session: + comm = self.session.find_thread(sample.sample_pid).comm() + else: + comm = "Unknown" + comm = comm.replace(" ", "_") + sep = "-" + if self.args.include_pid: + comm = f"{comm}{sep}{getattr(sample, 'sample_pid', 0)}" + sep = "/" + if self.args.include_tid: + comm = f"{comm}{sep}{getattr(sample, 'sample_tid', 0)}" + stack.append(comm) + + stack_string = ";".join(reversed(stack)) + self.lines[stack_string] += 1 + + def print_totals(self) -> None: + """Print sorted collapsed stacks.""" + for stack in sorted(self.lines): + print(f"{stack} {self.lines[stack]}") + + +def main(): + """Main function.""" + ap = argparse.ArgumentParser( + description="Format perf samples with one line per distinct call stack" + ) + ap.add_argument("-i", "--input", default="perf.data", help="Input file name") + ap.add_argument("--include-tid", action="store_true", help="include thread id in stack") + ap.add_argument("--include-pid", action="store_true", help="include process id in stack") + ap.add_argument("--no-comm", dest="include_comm", action="store_false", default=True, + help="do not separate stacks according to comm") + ap.add_argument("--tidy-java", action="store_true", help="beautify Java signatures") + ap.add_argument("--kernel", dest="annotate_kernel", action="store_true", + help="annotate kernel functions with _[k]") + + args = ap.parse_args() + + if args.include_tid and not args.include_comm: + print("requesting tid but not comm is invalid", file=sys.stderr) + sys.exit(1) + if args.include_pid and not args.include_comm: + print("requesting pid but not comm is invalid", file=sys.stderr) + sys.exit(1) + + analyzer = StackCollapseAnalyzer(args) + + try: + session = perf.session(perf.data(args.input), sample=analyzer.process_event) + analyzer.session = session + session.process_events() + except IOError as e: + print(f"Error: {e}", file=sys.stderr) + sys.exit(1) + except KeyboardInterrupt: + pass + + analyzer.print_totals() + + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 45/59] perf stackcollapse: Port stackcollapse to use python module
Sashiko AI review found 1 potential issue(s): - [Medium] Unhandled TypeError in stackcollapse.py when resolving unknown threads causes the script to crash. --
Sashiko AI review found 1 potential issue(s):
- [Medium] Unhandled TypeError in stackcollapse.py when resolving unknown threads causes the script to crash. --
commit 702f12c8a01187fcead25d5d7f9e4ce41f1f01ae
Author: Ian Rogers <[email protected]>
perf stackcollapse: Port stackcollapse to use python module
This commit modernizes the legacy stackcollapse.py trace script by refactoring it into a class-based architecture. It uses perf.session for event processing and aggregates call stacks to produce output suitable for flame graphs.
Quoted 5 lines
tools/perf/python/stackcollapse.py new file +0
-0
[ ... ]
Quoted 1 line
+ def
process_event(self, sample: perf.sample_event)-> None:
[ ... ]
tools/perf/python/stackcollapse.py line 66
Quoted 3 lines
tools/perf/python/stackcollapse.py new file +3
-0+ if self.args.include_comm: + if hasattr(self, 'session') and self.session: + comm = self.session.find_thread(sample.sample_pid).comm()
Will this crash the script if the thread cannot be found?
The Python extension function pyrf_session__find_thread() in tools/perf/util/python.c raises a TypeError if the thread lookup fails:
tools/perf/util/python.c:pyrf_session__find_thread() {
...
thread = machine__findnew_thread(machine, -1, pid);
if (thread == NULL) {
PyErr_Format(PyExc_TypeError, "Fail to find thread for mac %d and pid %d",
machine->pid, pid);
return NULL;
}
...
}If perf.data contains samples with unmapped or unresolved PIDs, won't calling self.session.find_thread() without a try-except block result in an unhandled TypeError and terminate the script?
Quoted 3 lines
tools/perf/python/stackcollapse.py new file +3
-0+ else: + comm = "Unknown" + comm = comm.replace(" ", "_")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=45
Ian Rogers
reviewerPATCH v6 46/59 perf task-analyzer: Port task-analyzer to use python module
In reply to Ian RogersPorted task-analyzer.py from tools/perf/scripts/python to tools/perf/python. Refactored to class-based architecture. Added support for both file mode (using perf.session) and live mode (using evlist.read_on_cpu). Accesses tracepoint fields directly from sample object.
Update task-analyzer testing to use command rather than script version, this allows the perf.data file not to be in the same directory as the test is run.
---
v2:
- Fixed CSV Color Corruption: Updated _check_color() to disable colors immediately if --csv or --csv-summary is enabled, preventing ANSI escape codes from corrupting CSV output even if stdout is a TTY.
- Fixed _record_cleanup Conditions: Updated the cleanup condition to check for summary_extended and summary_only as well as summary . Also added a hard limit of 1000 entries to prevent unbounded memory growth in live mode.
- Fixed Filter/Limit Mutual Exclusivity: Rewrote _limit_filtered() to evaluate both --filter-tasks and --limit-to-tasks correctly when both are specified, instead of returning early and making the limit check unreachable.
- Fixed TID vs PID in process_event : Used self.session.process(prev_pid).pid to resolve the actual Process ID (TGID) for the previous task, instead of incorrectly passing the Thread ID (TID) as the PID to _handle_task_finish() .
- Fixed Conflicting CSV Headers: Removed the hardcoded semicolon-delimited headers written in run() , as they conflicted with the comma- separated headers written by _print_header() .
- Updated test expectations.
--- tools/perf/python/task-analyzer.py | 547 +++++++++++++++++++ tools/perf/tests/shell/test_task_analyzer.sh | 79 +-- 2 files changed, 592 insertions(+), 34 deletions(-) create mode 100755 tools/perf/python/task-analyzer.py
tools/perf/python/task-analyzer.py new file +547 -0
@@ -0,0 +1,547 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# task-analyzer.py - comprehensive perf tasks analysis +# Copyright (c) 2022, Hagen Paul Pfeifer <[email protected]> +# Licensed under the terms of the GNU GPL License version 2 +# +# Usage: +# +# perf record -e sched:sched_switch -a -- sleep 10 +# perf script report task-analyzer +# +"""Comprehensive perf tasks analysis.""" + +import argparse +from contextlib import contextmanager +import decimal +import os +import string +import sys +from typing import Any, Optional +import perf + + +# Columns will have a static size to align everything properly +# Support of 116 days of active update with nano precision +LEN_SWITCHED_IN = len("9999999.999999999") +LEN_SWITCHED_OUT = len("9999999.999999999") +LEN_CPU = len("000") +LEN_PID = len("maxvalue") +LEN_TID = len("maxvalue") +LEN_COMM = len("max-comms-length") +LEN_RUNTIME = len("999999.999") +# Support of 3.45 hours of timespans +LEN_OUT_IN = len("99999999999.999") +LEN_OUT_OUT = len("99999999999.999") +LEN_IN_IN = len("99999999999.999") +LEN_IN_OUT = len("99999999999.999") + +class Timespans: + """Tracks elapsed time between occurrences of the same task.""" + def __init__(self, args: argparse.Namespace, time_unit: str) -> None: + self.args = args + self.time_unit = time_unit + self._last_start: Optional[decimal.Decimal] = None + self._last_finish: Optional[decimal.Decimal] = None + self.current = { + 'out_out': decimal.Decimal(-1), + 'in_out': decimal.Decimal(-1), + 'out_in': decimal.Decimal(-1), + 'in_in': decimal.Decimal(-1) + } + if args.summary_extended: + self._time_in: decimal.Decimal = decimal.Decimal(-1) + self.max_vals = { + 'out_in': decimal.Decimal(-1), + 'at': decimal.Decimal(-1), + 'in_out': decimal.Decimal(-1), + 'in_in': decimal.Decimal(-1), + 'out_out': decimal.Decimal(-1) + } + + def feed(self, task: 'Task') -> None: + """Calculate timespans from chronological task occurrences.""" + if not self._last_finish: + self._last_start = task.time_in(self.time_unit) + self._last_finish = task.time_out(self.time_unit) + return + assert self._last_start is not None + assert self._last_finish is not None + self._time_in = task.time_in() + time_in = task.time_in(self.time_unit) + time_out = task.time_out(self.time_unit) + self.current['in_in'] = time_in - self._last_start + self.current['out_in'] = time_in - self._last_finish + self.current['in_out'] = time_out - self._last_start + self.current['out_out'] = time_out - self._last_finish + if self.args.summary_extended: + self.update_max_entries() + self._last_finish = task.time_out(self.time_unit) + self._last_start = task.time_in(self.time_unit) + + def update_max_entries(self) -> None: + """Update maximum timespans.""" + self.max_vals['in_in'] = max(self.max_vals['in_in'], self.current['in_in']) + self.max_vals['out_out'] = max(self.max_vals['out_out'], self.current['out_out']) + self.max_vals['in_out'] = max(self.max_vals['in_out'], self.current['in_out']) + if self.current['out_in'] > self.max_vals['out_in']: + self.max_vals['out_in'] = self.current['out_in'] + self.max_vals['at'] = self._time_in + +class Task: + """Handles information of a given task.""" + def __init__(self, task_id: str, tid: int, cpu: int, comm: str) -> None: + self.id = task_id + self.tid = tid + self.cpu = cpu + self.comm = comm + self.pid: Optional[int] = None + self._time_in: Optional[decimal.Decimal] = None + self._time_out: Optional[decimal.Decimal] = None + + def schedule_in_at(self, time_ns: int) -> None: + """Set schedule in time.""" + self._time_in = decimal.Decimal(time_ns) / decimal.Decimal(1e9) + + def schedule_out_at(self, time_ns: int) -> None: + """Set schedule out time.""" + self._time_out = decimal.Decimal(time_ns) / decimal.Decimal(1e9) + + def time_out(self, unit: str = "s") -> decimal.Decimal: + """Return schedule out time.""" + factor = TaskAnalyzer.time_uniter(unit) + return self._time_out * decimal.Decimal(factor) if self._time_out else decimal.Decimal(0) + + def time_in(self, unit: str = "s") -> decimal.Decimal: + """Return schedule in time.""" + factor = TaskAnalyzer.time_uniter(unit) + return self._time_in * decimal.Decimal(factor) if self._time_in else decimal.Decimal(0) + + def runtime(self, unit: str = "us") -> decimal.Decimal: + """Return runtime.""" + factor = TaskAnalyzer.time_uniter(unit) + if self._time_out and self._time_in: + return (self._time_out - self._time_in) * decimal.Decimal(factor) + return decimal.Decimal(0) + + def update_pid(self, pid: int) -> None: + """Update PID.""" + self.pid = pid + +class TaskAnalyzer: + """Main class for task analysis.""" + + _COLORS = { + "grey": "\033[90m", + "red": "\033[91m", + "green": "\033[92m", + "yellow": "\033[93m", + "blue": "\033[94m", + "violet": "\033[95m", + "reset": "\033[0m", + } + + def __init__(self, args: argparse.Namespace) -> None: + self.args = args + self.db: dict[str, Any] = {} + self.session: Optional[perf.session] = None + self.time_unit = "s" + if args.ns: + self.time_unit = "ns" + elif args.ms: + self.time_unit = "ms" + self._init_db() + self._check_color() + self.fd_task = sys.stdout + self.fd_sum = sys.stdout + + @contextmanager + def open_output(self, filename: str, default: Any): + """Context manager for file or stdout.""" + if filename: + with open(filename, "w", encoding="utf-8") as f: + yield f + else: + yield default + + def _init_db(self) -> None: + self.db["running"] = {} + self.db["cpu"] = {} + self.db["tid"] = {} + self.db["global"] = [] + if self.args.summary or self.args.summary_extended or self.args.summary_only: + self.db["task_info"] = {} + self.db["runtime_info"] = {} + self.db["task_info"]["pid"] = len("PID") + self.db["task_info"]["tid"] = len("TID") + self.db["task_info"]["comm"] = len("Comm") + self.db["runtime_info"]["runs"] = len("Runs") + self.db["runtime_info"]["acc"] = len("Accumulated") + self.db["runtime_info"]["max"] = len("Max") + self.db["runtime_info"]["max_at"] = len("Max At") + self.db["runtime_info"]["min"] = len("Min") + self.db["runtime_info"]["mean"] = len("Mean") + self.db["runtime_info"]["median"] = len("Median") + if self.args.summary_extended: + self.db["inter_times"] = {} + self.db["inter_times"]["out_in"] = len("Out-In") + self.db["inter_times"]["inter_at"] = len("At") + self.db["inter_times"]["out_out"] = len("Out-Out") + self.db["inter_times"]["in_in"] = len("In-In") + self.db["inter_times"]["in_out"] = len("In-Out") + + def _check_color(self) -> None: + """Check if color should be enabled.""" + if self.args.csv or self.args.csv_summary: + TaskAnalyzer._COLORS = {k: "" for k in TaskAnalyzer._COLORS} + return + if sys.stdout.isatty() and self.args.stdio_color != "never": + return + TaskAnalyzer._COLORS = {k: "" for k in TaskAnalyzer._COLORS} + + @staticmethod + def time_uniter(unit: str) -> float: + """Return time unit factor.""" + picker = {"s": 1, "ms": 1e3, "us": 1e6, "ns": 1e9} + return picker[unit] + + def _task_id(self, pid: int, cpu: int) -> str: + return f"{pid}-{cpu}" + + def _filter_non_printable(self, unfiltered: str) -> str: + filtered = "" + for char in unfiltered: + if char in string.printable: + filtered += char + return filtered + + def _prepare_fmt_precision(self) -> tuple[int, int]: + if self.args.ns: + return 0, 9 + return 3, 6 + + def _prepare_fmt_sep(self) -> tuple[str, int]: + if self.args.csv or self.args.csv_summary: + return ",", 0 + return " ", 1 + + def _fmt_header(self) -> str: + separator, fix_csv_align = self._prepare_fmt_sep() + fmt = f"{{:>{LEN_SWITCHED_IN*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_SWITCHED_OUT*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_CPU*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_PID*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_TID*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_COMM*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_RUNTIME*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_OUT_IN*fix_csv_align}}}" + if self.args.extended_times: + fmt += f"{separator}{{:>{LEN_OUT_OUT*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_IN_IN*fix_csv_align}}}" + fmt += f"{separator}{{:>{LEN_IN_OUT*fix_csv_align}}}" + return fmt + + def _fmt_body(self) -> str: + separator, fix_csv_align = self._prepare_fmt_sep() + decimal_precision, time_precision = self._prepare_fmt_precision() + fmt = f"{{}}{{:{LEN_SWITCHED_IN*fix_csv_align}.{decimal_precision}f}}" + fmt += f"{separator}{{:{LEN_SWITCHED_OUT*fix_csv_align}.{decimal_precision}f}}" + fmt += f"{separator}{{:{LEN_CPU*fix_csv_align}d}}" + fmt += f"{separator}{{:{LEN_PID*fix_csv_align}d}}" + fmt += f"{separator}{{}}{{:{LEN_TID*fix_csv_align}d}}{{}}" + fmt += f"{separator}{{}}{{:>{LEN_COMM*fix_csv_align}}}" + fmt += f"{separator}{{:{LEN_RUNTIME*fix_csv_align}.{time_precision}f}}" + if self.args.extended_times: + fmt += f"{separator}{{:{LEN_OUT_IN*fix_csv_align}.{time_precision}f}}" + fmt += f"{separator}{{:{LEN_OUT_OUT*fix_csv_align}.{time_precision}f}}" + fmt += f"{separator}{{:{LEN_IN_IN*fix_csv_align}.{time_precision}f}}" + fmt += f"{separator}{{:{LEN_IN_OUT*fix_csv_align}.{time_precision}f}}{{}}" + else: + fmt += f"{separator}{{:{LEN_OUT_IN*fix_csv_align}.{time_precision}f}}{{}}" + return fmt + + def _print_header(self) -> None: + fmt = self._fmt_header() + header = ["Switched-In", "Switched-Out", "CPU", "PID", "TID", "Comm", + "Runtime", "Time Out-In"] + if self.args.extended_times: + header += ["Time Out-Out", "Time In-In", "Time In-Out"] + self.fd_task.write(fmt.format(*header) + "\n") + + def _print_task_finish(self, task: Task) -> None: + c_row_set = "" + c_row_reset = "" + out_in: Any = -1 + out_out: Any = -1 + in_in: Any = -1 + in_out: Any = -1 + fmt = self._fmt_body() + + if str(task.tid) in self.args.highlight_tasks_map: + c_row_set = TaskAnalyzer._COLORS[self.args.highlight_tasks_map[str(task.tid)]] + c_row_reset = TaskAnalyzer._COLORS["reset"] + if task.comm in self.args.highlight_tasks_map: + c_row_set = TaskAnalyzer._COLORS[self.args.highlight_tasks_map[task.comm]] + c_row_reset = TaskAnalyzer._COLORS["reset"] + + c_tid_set = "" + c_tid_reset = "" + if task.pid == task.tid: + c_tid_set = TaskAnalyzer._COLORS["grey"] + c_tid_reset = TaskAnalyzer._COLORS["reset"] + + if task.tid in self.db["tid"]: + last_tid_task = self.db["tid"][task.tid][-1] + timespan_gap_tid = Timespans(self.args, self.time_unit) + timespan_gap_tid.feed(last_tid_task) + timespan_gap_tid.feed(task) + out_in = timespan_gap_tid.current['out_in'] + out_out = timespan_gap_tid.current['out_out'] + in_in = timespan_gap_tid.current['in_in'] + in_out = timespan_gap_tid.current['in_out'] + + if self.args.extended_times: + line_out = fmt.format(c_row_set, task.time_in(), task.time_out(), task.cpu, + task.pid, c_tid_set, task.tid, c_tid_reset, c_row_set, task.comm, + task.runtime(self.time_unit), out_in, out_out, in_in, in_out, + c_row_reset) + "\n" + else: + line_out = fmt.format(c_row_set, task.time_in(), task.time_out(), task.cpu, + task.pid, c_tid_set, task.tid, c_tid_reset, c_row_set, task.comm, + task.runtime(self.time_unit), out_in, c_row_reset) + "\n" + self.fd_task.write(line_out) + + def _record_cleanup(self, _list: list[Any]) -> list[Any]: + need_summary = (self.args.summary or self.args.summary_extended or + self.args.summary_only) + if not need_summary and len(_list) > 1: + return _list[len(_list) - 1:] + if len(_list) > 1000: + return _list[len(_list) - 1000:] + return _list + + def _record_by_tid(self, task: Task) -> None: + tid = task.tid + if tid not in self.db["tid"]: + self.db["tid"][tid] = [] + self.db["tid"][tid].append(task) + self.db["tid"][tid] = self._record_cleanup(self.db["tid"][tid]) + + def _record_by_cpu(self, task: Task) -> None: + cpu = task.cpu + if cpu not in self.db["cpu"]: + self.db["cpu"][cpu] = [] + self.db["cpu"][cpu].append(task) + self.db["cpu"][cpu] = self._record_cleanup(self.db["cpu"][cpu]) + + def _record_global(self, task: Task) -> None: + self.db["global"].append(task) + self.db["global"] = self._record_cleanup(self.db["global"]) + + def _handle_task_finish(self, tid: int, cpu: int, time_ns: int, pid: int) -> None: + if tid == 0: + return + _id = self._task_id(tid, cpu) + if _id not in self.db["running"]: + return + task = self.db["running"][_id] + task.schedule_out_at(time_ns) + task.update_pid(pid) + del self.db["running"][_id] + + if not self._limit_filtered(tid, pid, task.comm) and not self.args.summary_only: + self._print_task_finish(task) + self._record_by_tid(task) + self._record_by_cpu(task) + self._record_global(task) + + def _handle_task_start(self, tid: int, cpu: int, comm: str, time_ns: int) -> None: + if tid == 0: + return + if tid in self.args.tid_renames: + comm = self.args.tid_renames[tid] + _id = self._task_id(tid, cpu) + if _id in self.db["running"]: + return + task = Task(_id, tid, cpu, comm) + task.schedule_in_at(time_ns) + self.db["running"][_id] = task + + def _limit_filtered(self, tid: int, pid: int, comm: str) -> bool: + """Filter tasks based on CLI arguments.""" + match_filter = False + if self.args.filter_tasks: + if (str(tid) in self.args.filter_tasks or + str(pid) in self.args.filter_tasks or + comm in self.args.filter_tasks): + match_filter = True + + match_limit = False + if self.args.limit_to_tasks: + if (str(tid) in self.args.limit_to_tasks or + str(pid) in self.args.limit_to_tasks or + comm in self.args.limit_to_tasks): + match_limit = True + + if self.args.filter_tasks and match_filter: + return True + if self.args.limit_to_tasks and not match_limit: + return True + return False + + def _is_within_timelimit(self, time_ns: int) -> bool: + if not self.args.time_limit: + return True + time_s = decimal.Decimal(time_ns) / decimal.Decimal(1e9) + lower_bound, upper_bound = self.args.time_limit.split(":") + if lower_bound and time_s < decimal.Decimal(lower_bound): + return False + if upper_bound and time_s > decimal.Decimal(upper_bound): + return False + return True + + def process_event(self, sample: perf.sample_event) -> None: + """Process sched:sched_switch events.""" + if "sched:sched_switch" not in str(sample.evsel): + return + + time_ns = sample.sample_time + if not self._is_within_timelimit(time_ns): + return + + # Access tracepoint fields directly from sample object + try: + prev_pid = sample.prev_pid + next_pid = sample.next_pid + next_comm = sample.next_comm + common_cpu = sample.sample_cpu + except AttributeError: + # Fallback or ignore if fields are not available + return + + next_comm = self._filter_non_printable(next_comm) + + # Task finish for previous task + if self.session: + prev_tgid = self.session.find_thread(prev_pid).pid # type: ignore + else: + prev_tgid = prev_pid # Fallback + self._handle_task_finish(prev_pid, common_cpu, time_ns, prev_tgid) + # Task start for next task + self._handle_task_start(next_pid, common_cpu, next_comm, time_ns) + + def print_summary(self) -> None: + """Calculate and print summary.""" + need_summary = (self.args.summary or self.args.summary_extended or + self.args.summary_only or self.args.csv_summary) + if not need_summary: + return + + # Simplified summary logic for brevity, full logic can be ported if needed + print("\nSummary (Simplified)", file=self.fd_sum) + if self.args.summary_extended: + print("Inter Task Times", file=self.fd_sum) + # ... port full Summary class logic here ... + + def _run_file(self) -> None: + if not self.args.summary_only: + self._print_header() + + session = perf.session(perf.data(self.args.input), sample=self.process_event) + self.session = session + session.process_events() + + self.print_summary() + + def _run_live(self) -> None: + if not self.args.summary_only: + self._print_header() + + cpus = perf.cpu_map() + threads = perf.thread_map(-1) + evlist = perf.parse_events("sched:sched_switch", cpus, threads) + evlist.config() + + evlist.open() + evlist.mmap() + evlist.enable() + + print("Live mode started. Press Ctrl+C to stop.", file=sys.stderr) + try: + while True: + evlist.poll(timeout=-1) + for cpu in cpus: + while True: + event = evlist.read_on_cpu(cpu) + if not event: + break + if not isinstance(event, perf.sample_event): + continue + self.process_event(event) + except KeyboardInterrupt: + print("\nStopping live mode...", file=sys.stderr) + finally: + evlist.close() + self.print_summary() + + def run(self) -> None: + """Run the session.""" + with self.open_output(self.args.csv, sys.stdout) as fd_task: + with self.open_output(self.args.csv_summary, sys.stdout) as fd_sum: + self.fd_task = fd_task + self.fd_sum = fd_sum + + + if not os.path.exists(self.args.input) and self.args.input == "perf.data": + self._run_live() + else: + self._run_file() + +def main() -> None: + """Main function.""" + parser = argparse.ArgumentParser(description="Analyze tasks behavior") + parser.add_argument("-i", "--input", default="perf.data", help="Input file name") + parser.add_argument("--time-limit", default="", help="print tasks only in time window") + parser.add_argument("--summary", action="store_true", + help="print additional runtime information") + parser.add_argument("--summary-only", action="store_true", + help="print only summary without traces") + parser.add_argument("--summary-extended", action="store_true", + help="print extended summary") + parser.add_argument("--ns", action="store_true", help="show timestamps in nanoseconds") + parser.add_argument("--ms", action="store_true", help="show timestamps in milliseconds") + parser.add_argument("--extended-times", action="store_true", + help="Show elapsed times between schedule in/out") + parser.add_argument("--filter-tasks", default="", help="filter tasks by tid, pid or comm") + parser.add_argument("--limit-to-tasks", default="", help="limit output to selected tasks") + parser.add_argument("--highlight-tasks", default="", help="colorize special tasks") + parser.add_argument("--rename-comms-by-tids", default="", help="rename task names by using tid") + parser.add_argument("--stdio-color", default="auto", choices=["always", "never", "auto"], + help="configure color output") + parser.add_argument("--csv", default="", help="Write trace to file") + parser.add_argument("--csv-summary", default="", help="Write summary to file") + + args = parser.parse_args() + args.tid_renames = {} + args.highlight_tasks_map = {} + args.filter_tasks = args.filter_tasks.split(",") if args.filter_tasks else [] + args.limit_to_tasks = args.limit_to_tasks.split(",") if args.limit_to_tasks else [] + + if args.rename_comms_by_tids: + for item in args.rename_comms_by_tids.split(","): + tid, name = item.split(":") + args.tid_renames[int(tid)] = name + + if args.highlight_tasks: + for item in args.highlight_tasks.split(","): + parts = item.split(":") + if len(parts) == 1: + parts.append("red") + key, color = parts[0], parts[1] + args.highlight_tasks_map[key] = color + + analyzer = TaskAnalyzer(args) + analyzer.run() + +if __name__ == "__main__": + main()
tools/perf/tests/shell/test_task_analyzer.sh +45 -34
155 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 46/59] perf task-analyzer: Port task-analyzer to use python module
Sashiko AI review found 7 potential issue(s): - [High] The `print_summary` method is implemented as a placeholder stub, removing actual summary processing. - [High] Script crashes with an…
Sashiko AI review found 7 potential issue(s):
- [High] The print_summary method is implemented as a placeholder stub, removing actual summary processing.
- [High] Script crashes with an AttributeError when a task's thread is not found in the perf session.
- [High] Live mode processes events out of chronological order, corrupting inter-task time tracking.
- [Medium] Trace lists are unconditionally truncated to 1000 items, causing inaccurate summaries.
- [Low] Missing CLI argument validation causes unhandled ValueError and KeyError crashes.
- [Low] The CSV separator character was silently changed from a semicolon (;) to a comma (,).
- [Low] The --stdio-color always argument is ignored when standard output is piped.
--
commit 5196cbf2ad4b6c11d39c0a5d7c84c508146141e7
Author: Ian Rogers <[email protected]>
perf task-analyzer: Port task-analyzer to use python module
This commit ports task-analyzer.py to tools/perf/python and refactors it to a class-based architecture. It also adds support for file mode using perf.session and live mode using evlist.read_on_cpu.
Quoted 5 lines
tools/perf/python/task-analyzer.py new file +0
-0
[ ... ]
tools/perf/python/task-analyzer.py line 200
Quoted 8 lines
tools/perf/python/task-analyzer.py new file +8
-0+ def _check_color(self) -> None: + """Check if color should be enabled.""" + if self.args.csv or self.args.csv_summary: + TaskAnalyzer._COLORS = {k: "" for k in TaskAnalyzer._COLORS} + return + if sys.stdout.isatty() and self.args.stdio_color != "never": + return + TaskAnalyzer._COLORS = {k: "" for k in TaskAnalyzer._COLORS}
If standard output is piped, sys.stdout.isatty() is false, which causes the color mappings to be cleared. Does this unintentionally ignore the --stdio-color always argument?
[ ... ]
tools/perf/python/task-analyzer.py line 226
Quoted 4 lines
tools/perf/python/task-analyzer.py new file +4
-0+ def _prepare_fmt_sep(self) -> tuple[str, int]: + if self.args.csv or self.args.csv_summary: + return ",", 0 + return " ", 1
This isn't a bug, but the CSV separator was changed from a semicolon to a comma. Was this change intentional?
[ ... ]
tools/perf/python/task-analyzer.py line 321
Quoted 8 lines
tools/perf/python/task-analyzer.py new file +8
-0+ def _record_cleanup(self, _list: list[Any]) -> list[Any]: + need_summary = (self.args.summary or self.args.summary_extended or + self.args.summary_only) + if not need_summary and len(_list) > 1: + return _list[len(_list) - 1:] + if len(_list) > 1000: + return _list[len(_list) - 1000:] + return _list
Does truncating the list to 1000 items silently discard task occurrences during file-based processing?
It seems this might cause the subsequent summary calculations to only analyze a small fraction of large traces, leading to inaccurate statistics.
[ ... ]
tools/perf/python/task-analyzer.py line 396
Quoted 5 lines
tools/perf/python/task-analyzer.py new file +5
-0+ def _is_within_timelimit(self, time_ns: int) -> bool: + if not self.args.time_limit: + return True + time_s = decimal.Decimal(time_ns) / decimal.Decimal(1e9) + lower_bound, upper_bound = self.args.time_limit.split(":")
Does this split operation raise an unhandled ValueError if the user provides malformed input without a colon, such as --time-limit 123?
[ ... ]
Quoted 8 lines
tools/perf/python/task-analyzer.py new file +8
-0+ def process_event(self, sample: perf.sample_event) -> None: + """Process sched:sched_switch events.""" + if "sched:sched_switch" not in str(sample.evsel): + return + + time_ns = sample.sample_time + if not self._is_within_timelimit(time_ns): + return
[ ... ]
tools/perf/python/task-analyzer.py line 428
Quoted 5 lines
tools/perf/python/task-analyzer.py new file +5
-0+ # Task finish for previous task + if self.session: + prev_tgid = self.session.find_thread(prev_pid).pid # type: ignore + else: + prev_tgid = prev_pid # Fallback
If a thread is missing due to lost events or tracing starting after process initialization, find_thread() can return None. Will accessing .pid here raise an unhandled AttributeError and crash the analysis?
Quoted 6 lines
tools/perf/python/task-analyzer.py new file +6
-0+ self._handle_task_finish(prev_pid, common_cpu, time_ns, prev_tgid) + # Task start for next task + self._handle_task_start(next_pid, common_cpu, next_comm, time_ns) + + def print_summary(self) -> None: + """Calculate and print summary."""
tools/perf/python/task-analyzer.py line 444
Quoted 10 lines
tools/perf/python/task-analyzer.py new file +10
-0+ need_summary = (self.args.summary or self.args.summary_extended or + self.args.summary_only or self.args.csv_summary) + if not need_summary: + return + + # Simplified summary logic for brevity, full logic can be ported if needed + print("\nSummary (Simplified)", file=self.fd_sum) + if self.args.summary_extended: + print("Inter Task Times", file=self.fd_sum) + # ... port full Summary class logic here ...
The summary processing appears to be replaced with a stub that only prints placeholders. Does this cause the --summary and --summary-extended arguments to lose their expected functionality?
[ ... ]
Quoted 15 lines
tools/perf/python/task-analyzer.py new file +15
-0+ def _run_live(self) -> None: + if not self.args.summary_only: + self._print_header() + + cpus = perf.cpu_map() + threads = perf.thread_map(-1) + evlist = perf.parse_events("sched:sched_switch", cpus, threads) + evlist.config() + + evlist.open() + evlist.mmap() + evlist.enable() + + print("Live mode started. Press Ctrl+C to stop.", file=sys.stderr) + try:
tools/perf/python/task-analyzer.py line 480
Quoted 10 lines
tools/perf/python/task-analyzer.py new file +10
-0+ while True: + evlist.poll(timeout=-1) + for cpu in cpus: + while True: + event = evlist.read_on_cpu(cpu) + if not event: + break + if not isinstance(event, perf.sample_event): + continue + self.process_event(event)
By draining each CPU's ring buffer entirely before moving to the next, are the events processed out of chronological order?
The Timespans class expects chronological occurrences, so processing them sequentially by CPU might corrupt the time tracking and result in negative inter-task times.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=46
Ian Rogers
reviewerPATCH v6 47/59 perf failed-syscalls: Port failed-syscalls to use python module
In reply to Ian RogersPort the legacy Perl script failed-syscalls.pl to a python script using the perf module in tools/perf/python.
The new script uses a class-based architecture and leverages the perf.session API for event processing, making it a standalone script that reads perf.data files.
It filters for sys_exit events, checks for failed syscalls (where return value ret < 0), and aggregates counts per command name.
Complications:
- The script is designed for file-based processing using perf.session.
- pylint warns about the module name not being snake_case, but it is kept for consistency with the original script name.
--- tools/perf/python/failed-syscalls.py | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 tools/perf/python/failed-syscalls.py
tools/perf/python/failed-syscalls.py new file +78 -0
@@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +"""Failed system call counts.""" + +import argparse +from collections import defaultdict +import sys +from typing import Optional +import perf + +class FailedSyscalls: + """Tracks and displays failed system call totals.""" + def __init__(self, comm: Optional[str] = None) -> None: + self.failed_syscalls: dict[str, int] = defaultdict(int) + self.for_comm = comm + self.session: Optional[perf.session] = None + self.unhandled: dict[str, int] = defaultdict(int) + + def process_event(self, sample: perf.sample_event) -> None: + """Process sys_exit events.""" + event_name = str(sample.evsel) + if not event_name.startswith("evsel(syscalls:sys_exit_") and \ + not event_name.startswith("evsel(raw_syscalls:sys_exit_"): + return + + try: + ret = sample.ret + except AttributeError: + self.unhandled[event_name] += 1 + return + + if ret >= 0: + return + + pid = sample.sample_pid + assert self.session is not None + try: + comm = self.session.find_thread(pid).comm() + except Exception: # pylint: disable=broad-except + comm = "unknown" + + if self.for_comm and comm != self.for_comm: + return + + self.failed_syscalls[comm] += 1 + + def print_totals(self) -> None: + """Print summary table.""" + print("\nfailed syscalls by comm:\n") + print(f"{'comm':<20s} {'# errors':>10s}") + print(f"{'-'*20} {'-'*10}") + + for comm, val in sorted(self.failed_syscalls.items(), + key=lambda kv: (kv[1], kv[0]), reverse=True): + print(f"{comm:<20s} {val:10d}") + + def run(self, input_file: str) -> None: + """Run the session.""" + self.session = perf.session(perf.data(input_file), sample=self.process_event) + self.session.process_events() + self.print_totals() + +def main() -> None: + """Main function.""" + parser = argparse.ArgumentParser(description="Trace failed syscalls") + parser.add_argument("comm", nargs="?", help="Filter by command name") + parser.add_argument("-i", "--input", default="perf.data", help="Input file") + args = parser.parse_args() + + analyzer = FailedSyscalls(args.comm) + try: + analyzer.run(args.input) + except IOError as e: + print(e, file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 47/59] perf failed-syscalls: Port failed-syscalls to use python module
Sashiko AI review found 1 potential issue(s): - [Medium] The script incorrectly filters out `raw_syscalls:sys_exit` events because it requires the event name to end with an underscore. --
Sashiko AI review found 1 potential issue(s):
- [Medium] The script incorrectly filters out raw_syscalls:sys_exit events because it requires the event name to end with an underscore. --
commit d0669a431485bb5878875ee3c2d4a44c47d0f2ae
Author: Ian Rogers <[email protected]>
perf failed-syscalls: Port failed-syscalls to use python module
This commit ports the legacy failed-syscalls.pl Perl script to Python using the perf module. It leverages the perf.session API to filter sys_exit events, track failed system calls, and aggregate the counts per command name.
Quoted 5 lines
tools/perf/python/failed-syscalls.py new file +0
-0
[ ... ]
tools/perf/python/failed-syscalls.py line 23
Quoted 5 lines
tools/perf/python/failed-syscalls.py new file +5
-0+ def process_event(self, sample: perf.sample_event) -> None: + """Process sys_exit events.""" + event_name = str(sample.evsel) + if not event_name.startswith("evsel(syscalls:sys_exit_") and \ + not event_name.startswith("evsel(raw_syscalls:sys_exit_"):
Will this condition unintentionally drop raw_syscalls:sys_exit events?
The stringified event name for raw syscall exits is "evsel(raw_syscalls:sys_exit)", which does not have a trailing underscore. Because the startswith check here specifically includes the trailing underscore, it looks like traces recorded with raw_syscalls:sys_exit will be discarded prematurely, leaving the script with empty output.
Quoted 1 line
+ return
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=47
Ian Rogers
reviewerPATCH v6 48/59 perf rw-by-file: Port rw-by-file to use python module
In reply to Ian RogersPort the legacy Perl script rw-by-file.pl to a python script using the perf module in tools/perf/python.
The new script uses a class-based architecture and leverages the perf.session API for event processing.
It tracks read and write activity by file descriptor for a given program name, aggregating bytes requested/written and total counts.
Complications:
- Had to split long lines in __init__ to satisfy pylint.
- pylint warns about the module name not being snake_case, but it is kept for consistency with the original script name.
---
v2:
- Fixed Substring Matching: Replaced if "sys_enter_read" in
event_name: with an exact match against syscalls:sys_enter_read and raw_syscalls:sys_enter_read using sample.evsel.name . This prevents variants like readv or readlink from incorrectly triggering the read logic. Similar fixes were applied for write events.
- Fixed Silent Error Dropping: Instead of silently returning when expected fields are missing (causing AttributeError ), the script now increments the self.unhandled counter for that event. This ensures that missing data or unexpected event variants are reported to the user instead of quietly skewing the results.
v6:
- Fixed AttributeError by using str(sample.evsel) to get event name.
--- tools/perf/python/rw-by-file.py | 103 ++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 tools/perf/python/rw-by-file.py
tools/perf/python/rw-by-file.py new file +103 -0
@@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Display r/w activity for files read/written to for a given program.""" + +import argparse +from collections import defaultdict +import sys +from typing import Optional, Dict +import perf + +class RwByFile: + """Tracks and displays read/write activity by file descriptor.""" + def __init__(self, comm: str) -> None: + self.for_comm = comm + self.reads: Dict[int, Dict[str, int]] = defaultdict( + lambda: {"bytes_requested": 0, "total_reads": 0} + ) + self.writes: Dict[int, Dict[str, int]] = defaultdict( + lambda: {"bytes_written": 0, "total_writes": 0} + ) + self.unhandled: Dict[str, int] = defaultdict(int) + self.session: Optional[perf.session] = None + + def process_event(self, sample: perf.sample_event) -> None: + """Process events.""" + event_name = str(sample.evsel)[6:-1] + + pid = sample.sample_pid + assert self.session is not None + try: + comm = self.session.find_thread(pid).comm() + except Exception: # pylint: disable=broad-except + comm = "unknown" + + if comm != self.for_comm: + return + + if event_name in ("syscalls:sys_enter_read", "raw_syscalls:sys_enter_read"): + try: + fd = sample.fd + count = sample.count + self.reads[fd]["bytes_requested"] += count + self.reads[fd]["total_reads"] += 1 + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("syscalls:sys_enter_write", "raw_syscalls:sys_enter_write"): + try: + fd = sample.fd + count = sample.count + self.writes[fd]["bytes_written"] += count + self.writes[fd]["total_writes"] += 1 + except AttributeError: + self.unhandled[event_name] += 1 + else: + self.unhandled[event_name] += 1 + + def print_totals(self) -> None: + """Print summary tables.""" + print(f"file read counts for {self.for_comm}:\n") + print(f"{'fd':>6s} {'# reads':>10s} {'bytes_requested':>15s}") + print(f"{'-'*6} {'-'*10} {'-'*15}") + + for fd, data in sorted(self.reads.items(), + key=lambda kv: kv[1]["bytes_requested"], reverse=True): + print(f"{fd:6d} {data['total_reads']:10d} {data['bytes_requested']:15d}") + + print(f"\nfile write counts for {self.for_comm}:\n") + print(f"{'fd':>6s} {'# writes':>10s} {'bytes_written':>15s}") + print(f"{'-'*6} {'-'*10} {'-'*15}") + + for fd, data in sorted(self.writes.items(), + key=lambda kv: kv[1]["bytes_written"], reverse=True): + print(f"{fd:6d} {data['total_writes']:10d} {data['bytes_written']:15d}") + + if self.unhandled: + print("\nunhandled events:\n") + print(f"{'event':<40s} {'count':>10s}") + print(f"{'-'*40} {'-'*10}") + for event_name, count in self.unhandled.items(): + print(f"{event_name:<40s} {count:10d}") + + def run(self, input_file: str) -> None: + """Run the session.""" + self.session = perf.session(perf.data(input_file), sample=self.process_event) + self.session.process_events() + self.print_totals() + +def main() -> None: + """Main function.""" + parser = argparse.ArgumentParser(description="Trace r/w activity by file") + parser.add_argument("comm", help="Filter by command name") + parser.add_argument("-i", "--input", default="perf.data", help="Input file") + args = parser.parse_args() + + analyzer = RwByFile(args.comm) + try: + analyzer.run(args.input) + except IOError as e: + print(e, file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v6 49/59 perf rw-by-pid: Port rw-by-pid to use python module
In reply to Ian RogersPort the legacy Perl script rw-by-pid.pl to a python script using the perf module in tools/perf/python.
The new script uses a class-based architecture and leverages the perf.session API for event processing.
It tracks read and write activity by PID for all processes, aggregating bytes requested, bytes read, total reads, and errors.
Complications:
- Refactored process_event to extract helper methods (_handle_sys_enter_read, etc.) to reduce the number of branches and satisfy pylint.
- Split long lines to comply with line length limits.
- pylint warns about the module name not being snake_case, but it is kept for consistency with the original script name.
---
v2:
- Fixed Substring Matching: Replaced loose substring checks like if "sys_enter_read" in event_name: with exact matches against syscalls:sys_enter_read and raw_syscalls:sys_enter_read using sample.evsel.name . This prevents unrelated syscalls with similar names (like readahead ) from being incorrectly aggregated. Similar fixes were applied for exit events and write events.
- Inlined Handlers and Tracked Errors: Inlined the _handle_sys_* helper methods into process_event() to make error handling easier. Now, if a sample lacks expected fields (raising AttributeError ), it is added to the self.unhandled tracker instead of being silently dropped, providing better visibility to the user.
- Code Cleanup: Fixed trailing whitespace and added a pylint disable comment for too-many-branches caused by the inlining.
v6:
- Fixed AttributeError by using str(sample.evsel) to get event name.
--- tools/perf/python/rw-by-pid.py | 158 +++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 tools/perf/python/rw-by-pid.py
tools/perf/python/rw-by-pid.py new file +158 -0
@@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Display r/w activity for all processes.""" + +import argparse +from collections import defaultdict +import sys +from typing import Optional, Dict, List, Tuple, Any +import perf + +class RwByPid: + """Tracks and displays read/write activity by PID.""" + def __init__(self) -> None: + self.reads: Dict[int, Dict[str, Any]] = defaultdict( + lambda: { + "bytes_requested": 0, + "bytes_read": 0, + "total_reads": 0, + "comm": "", + "errors": defaultdict(int), + } + ) + self.writes: Dict[int, Dict[str, Any]] = defaultdict( + lambda: { + "bytes_written": 0, + "total_writes": 0, + "comm": "", + "errors": defaultdict(int), + } + ) + self.unhandled: Dict[str, int] = defaultdict(int) + self.session: Optional[perf.session] = None + + def process_event(self, sample: perf.sample_event) -> None: # pylint: disable=too-many-branches + """Process events.""" + event_name = str(sample.evsel)[6:-1] + pid = sample.sample_pid + + assert self.session is not None + try: + comm = self.session.find_thread(pid).comm() + except Exception: # pylint: disable=broad-except + comm = "unknown" + + if event_name in ("syscalls:sys_enter_read", "raw_syscalls:sys_enter_read"): + try: + count = sample.count + self.reads[pid]["bytes_requested"] += count + self.reads[pid]["total_reads"] += 1 + self.reads[pid]["comm"] = comm + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("syscalls:sys_exit_read", "raw_syscalls:sys_exit_read"): + try: + ret = sample.ret + if ret > 0: + self.reads[pid]["bytes_read"] += ret + else: + self.reads[pid]["errors"][ret] += 1 + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("syscalls:sys_enter_write", "raw_syscalls:sys_enter_write"): + try: + count = sample.count + self.writes[pid]["bytes_written"] += count + self.writes[pid]["total_writes"] += 1 + self.writes[pid]["comm"] = comm + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("syscalls:sys_exit_write", "raw_syscalls:sys_exit_write"): + try: + ret = sample.ret + if ret <= 0: + self.writes[pid]["errors"][ret] += 1 + except AttributeError: + self.unhandled[event_name] += 1 + else: + self.unhandled[event_name] += 1 + + def print_totals(self) -> None: + """Print summary tables.""" + print("read counts by pid:\n") + print( + f"{'pid':>6s} {'comm':<20s} {'# reads':>10s} " + f"{'bytes_requested':>15s} {'bytes_read':>10s}" + ) + print(f"{'-'*6} {'-'*20} {'-'*10} {'-'*15} {'-'*10}") + + for pid, data in sorted(self.reads.items(), + key=lambda kv: kv[1]["bytes_read"], reverse=True): + print( + f"{pid:6d} {data['comm']:<20s} {data['total_reads']:10d} " + f"{data['bytes_requested']:15d} {data['bytes_read']:10d}" + ) + + print("\nfailed reads by pid:\n") + print(f"{'pid':>6s} {'comm':<20s} {'error #':>6s} {'# errors':>10s}") + print(f"{'-'*6} {'-'*20} {'-'*6} {'-'*10}") + + errcounts: List[Tuple[int, str, int, int]] = [] + for pid, data in self.reads.items(): + for error, count in data["errors"].items(): + errcounts.append((pid, data["comm"], error, count)) + + for pid, comm, error, count in sorted(errcounts, key=lambda x: x[3], reverse=True): + print(f"{pid:6d} {comm:<20s} {error:6d} {count:10d}") + + print("\nwrite counts by pid:\n") + print(f"{'pid':>6s} {'comm':<20s} {'# writes':>10s} {'bytes_written':>15s}") + print(f"{'-'*6} {'-'*20} {'-'*10} {'-'*15}") + + for pid, data in sorted(self.writes.items(), + key=lambda kv: kv[1]["bytes_written"], reverse=True): + print( + f"{pid:6d} {data['comm']:<20s} " + f"{data['total_writes']:10d} {data['bytes_written']:15d}" + ) + + print("\nfailed writes by pid:\n") + print(f"{'pid':>6s} {'comm':<20s} {'error #':>6s} {'# errors':>10s}") + print(f"{'-'*6} {'-'*20} {'-'*6} {'-'*10}") + + errcounts = [] + for pid, data in self.writes.items(): + for error, count in data["errors"].items(): + errcounts.append((pid, data["comm"], error, count)) + + for pid, comm, error, count in sorted(errcounts, key=lambda x: x[3], reverse=True): + print(f"{pid:6d} {comm:<20s} {error:6d} {count:10d}") + + if self.unhandled: + print("\nunhandled events:\n") + print(f"{'event':<40s} {'count':>10s}") + print(f"{'-'*40} {'-'*10}") + for event_name, count in self.unhandled.items(): + print(f"{event_name:<40s} {count:10d}") + + def run(self, input_file: str) -> None: + """Run the session.""" + self.session = perf.session(perf.data(input_file), sample=self.process_event) + self.session.process_events() + self.print_totals() + +def main() -> None: + """Main function.""" + parser = argparse.ArgumentParser(description="Trace r/w activity by PID") + parser.add_argument("-i", "--input", default="perf.data", help="Input file") + args = parser.parse_args() + + analyzer = RwByPid() + try: + analyzer.run(args.input) + except IOError as e: + print(e, file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 49/59] perf rw-by-pid: Port rw-by-pid to use python module
Sashiko AI review found 2 potential issue(s): - [Medium] Commit message and code implementation contradiction regarding pylint refactoring. - [Low] Dead code due to checking for non-existent…
Sashiko AI review found 2 potential issue(s):
- [Medium] Commit message and code implementation contradiction regarding pylint refactoring.
- [Low] Dead code due to checking for non-existent raw_syscalls tracepoints. --
commit d6f88a3734fa748dc053090f49ee9eef6f7204bf
Author: Ian Rogers <[email protected]>
perf rw-by-pid: Port rw-by-pid to use python module
This commit ports the legacy Perl script rw-by-pid.pl to a python script using the perf module in tools/perf/python. It tracks read and write activity by PID for all processes.
Quoted 4 lines
Complications:
- Refactoredprocess_eventto extract helper methods (_handle_sys_enter_read, etc.) to reduce the number of branches and satisfy pylint.
Is this description accurate?
The commit message mentions extracting helper methods like _handle_sys_enter_read to satisfy pylint. However, the implementation keeps all event processing logic within a single process_event method and bypasses the linter with a disable comment instead.
Quoted 5 lines
tools/perf/python/rw-by-pid.py new file +0
-0
[ ... ]
tools/perf/python/rw-by-pid.py line 45
Quoted 12 lines
tools/perf/python/rw-by-pid.py new file +12
-0+ def process_event(self, sample: perf.sample_event) -> None: # pylint: disable=too-many-branches + """Process events.""" + event_name = str(sample.evsel)[6:-1] + pid = sample.sample_pid + + assert self.session is not None + try: + comm = self.session.find_thread(pid).comm() + except Exception: # pylint: disable=broad-except + comm = "unknown" + + if event_name in ("syscalls:sys_enter_read", "raw_syscalls:sys_enter_read"):
Are there raw_syscalls tracepoints with the syscall name appended?
The raw_syscalls subsystem typically provides generic sys_enter and sys_exit tracepoints without the syscall name. Do these specific string checks for raw_syscalls:sys_enter_read (and the similar exit and write variants) match any real kernel tracepoints, or does this result in dead code?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=49
Ian Rogers
reviewerPATCH v6 50/59 perf rwtop: Port rwtop to use python module
In reply to Ian RogersPort the legacy Perl script rwtop.pl to a python script using the perf module in tools/perf/python.
The new script uses a class-based architecture and leverages the perf.session API for event processing.
It periodically displays system-wide r/w call activity, broken down by PID, refreshed every interval.
Complications:
- Implemented periodic display based on event timestamps (sample.sample_time) instead of relying on SIGALRM, making it robust for file-based processing.
- Used ANSI escape codes (\x1b[H\x1b[2J) to clear the terminal.
- Fixed unused imports and indentation issues identified by pylint.
- pylint warns about the module name not being snake_case, but it is kept for consistency with the original script name.
---
v2:
- Added Live Session Support: Updated main() to start a LiveSession when the input file does not exist (or is the default "perf.data" and doesn't exist). It traces read and write entry/exit tracepoints.
- Fixed Live Mode Comm Resolution: Fixed a bug in process_event() where it would attempt to use self.session to resolve the command name when running in live mode (where self.session is None ). It now falls back to f"PID({pid})" when in live mode or if resolution fails.
- Fixed Substring Matching: Replaced loose substring checks like if "sys_enter_read" in event_name: with exact matches against "evsel(syscalls:sys_enter_read)" and "evsel(raw_syscalls:sys_enter_read)" using str(sample.evsel) . This prevents unrelated syscalls with similar names (like readv or readahead ) from being incorrectly aggregated. Similar fixes were applied for exit events and write events.
- Inlined Handlers and Tracked Errors: Inlined the _handle_sys_* helper methods into process_event() . Now, if a sample lacks expected fields, it is added to the self.unhandled tracker instead of being silently ignored.
- Fixed Write Byte Counting: Updated the write exit handler to use sample.ret to count actual bytes written on success, and tracked requested bytes separately in the enter handler, matching the read behavior.
- Added Error Tables to Output: Added tables to display failed reads and writes by PID in print_totals() , which were previously tracked but never displayed.
- Fixed Offline Output (Ghosting): Removed the hardcoded ANSI clear-screen escape codes in print_totals() , as they corrupted output when processing offline trace files at CPU speed or when piping the output.
- Code Cleanup: Fixed a bug where fd was printed instead of pid in the read counts table, and broke long lines to satisfy pylint.
--- tools/perf/python/rwtop.py | 219 +++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100755 tools/perf/python/rwtop.py
tools/perf/python/rwtop.py new file +219 -0
@@ -0,0 +1,219 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Periodically displays system-wide r/w call activity, broken down by pid.""" + +import argparse +from collections import defaultdict +import os +import sys +from typing import Optional, Dict, Any +import perf +from perf_live import LiveSession + +class RwTop: + """Periodically displays system-wide r/w call activity.""" + def __init__(self, interval: int = 3, nlines: int = 20) -> None: + self.interval_ns = interval * 1000000000 + self.nlines = nlines + self.reads: Dict[int, Dict[str, Any]] = defaultdict( + lambda: { + "bytes_requested": 0, + "bytes_read": 0, + "total_reads": 0, + "comm": "", + "errors": defaultdict(int), + } + ) + self.writes: Dict[int, Dict[str, Any]] = defaultdict( + lambda: { + "bytes_requested": 0, + "bytes_written": 0, + "total_writes": 0, + "comm": "", + "errors": defaultdict(int), + } + ) + self.unhandled: Dict[str, int] = defaultdict(int) + self.session: Optional[perf.session] = None + self.last_print_time: int = 0 + + def process_event(self, sample: perf.sample_event) -> None: # pylint: disable=too-many-branches + """Process events.""" + event_name = str(sample.evsel) + pid = sample.sample_pid + sample_time = sample.sample_time + + if self.last_print_time == 0: + self.last_print_time = sample_time + + # Check if interval has passed + if sample_time - self.last_print_time >= self.interval_ns: + self.print_totals() + self.last_print_time = sample_time + + try: + comm = f"PID({pid})" if not self.session else self.session.find_thread(pid).comm() + except Exception: # pylint: disable=broad-except + comm = f"PID({pid})" + + if event_name in ("evsel(syscalls:sys_enter_read)", "evsel(raw_syscalls:sys_enter_read)"): + try: + count = sample.count + self.reads[pid]["bytes_requested"] += count + self.reads[pid]["total_reads"] += 1 + self.reads[pid]["comm"] = comm + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("evsel(syscalls:sys_exit_read)", "evsel(raw_syscalls:sys_exit_read)"): + try: + ret = sample.ret + if ret > 0: + self.reads[pid]["bytes_read"] += ret + else: + self.reads[pid]["errors"][ret] += 1 + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("evsel(syscalls:sys_enter_write)", + "evsel(raw_syscalls:sys_enter_write)"): + try: + count = sample.count + self.writes[pid]["bytes_requested"] += count + self.writes[pid]["total_writes"] += 1 + self.writes[pid]["comm"] = comm + except AttributeError: + self.unhandled[event_name] += 1 + elif event_name in ("evsel(syscalls:sys_exit_write)", "evsel(raw_syscalls:sys_exit_write)"): + try: + ret = sample.ret + if ret > 0: + self.writes[pid]["bytes_written"] += ret + else: + self.writes[pid]["errors"][ret] += 1 + except AttributeError: + self.unhandled[event_name] += 1 + else: + self.unhandled[event_name] += 1 + + def print_totals(self) -> None: + """Print summary tables.""" + print("read counts by pid:\n") + print( + f"{'pid':>6s} {'comm':<20s} {'# reads':>10s} " + f"{'bytes_req':>10s} {'bytes_read':>10s}" + ) + print(f"{'-'*6} {'-'*20} {'-'*10} {'-'*10} {'-'*10}") + + count = 0 + for pid, data in sorted(self.reads.items(), + key=lambda kv: kv[1]["bytes_read"], reverse=True): + print( + f"{pid:6d} {data['comm']:<20s} {data['total_reads']:10d} " + f"{data['bytes_requested']:10d} {data['bytes_read']:10d}" + ) + count += 1 + if count >= self.nlines: + break + + print("\nfailed reads by pid:\n") + print(f"{'pid':>6s} {'comm':<20s} {'error #':>6s} {'# errors':>10s}") + print(f"{'-'*6} {'-'*20} {'-'*6} {'-'*10}") + + errcounts = [] + for pid, data in self.reads.items(): + for error, cnt in data["errors"].items(): + errcounts.append((pid, data["comm"], error, cnt)) + + sorted_errcounts = sorted(errcounts, key=lambda x: x[3], reverse=True) + for pid, comm, error, cnt in sorted_errcounts[:self.nlines]: + print(f"{pid:6d} {comm:<20s} {error:6d} {cnt:10d}") + + print("\nwrite counts by pid:\n") + print( + f"{'pid':>6s} {'comm':<20s} {'# writes':>10s} " + f"{'bytes_req':>10s} {'bytes_written':>13s}" + ) + print(f"{'-'*6} {'-'*20} {'-'*10} {'-'*10} {'-'*13}") + + count = 0 + for pid, data in sorted(self.writes.items(), + key=lambda kv: kv[1]["bytes_written"], reverse=True): + print( + f"{pid:6d} {data['comm']:<20s} {data['total_writes']:10d} " + f"{data['bytes_requested']:10d} {data['bytes_written']:13d}" + ) + count += 1 + if count >= self.nlines: + break + + print("\nfailed writes by pid:\n") + print(f"{'pid':>6s} {'comm':<20s} {'error #':>6s} {'# errors':>10s}") + print(f"{'-'*6} {'-'*20} {'-'*6} {'-'*10}") + + errcounts = [] + for pid, data in self.writes.items(): + for error, cnt in data["errors"].items(): + errcounts.append((pid, data["comm"], error, cnt)) + + sorted_errcounts = sorted(errcounts, key=lambda x: x[3], reverse=True) + for pid, comm, error, cnt in sorted_errcounts[:self.nlines]: + print(f"{pid:6d} {comm:<20s} {error:6d} {cnt:10d}") + + # Reset counts + self.reads.clear() + self.writes.clear() + + def run(self, input_file: str) -> None: + """Run the session.""" + self.session = perf.session(perf.data(input_file), sample=self.process_event) + self.session.process_events() + + # Print final totals if there are any left + if self.reads or self.writes: + self.print_totals() + + if self.unhandled: + print("\nunhandled events:\n") + print(f"{'event':<40s} {'count':>10s}") + print(f"{'-'*40} {'-'*10}") + for event_name, count in self.unhandled.items(): + print(f"{event_name:<40s} {count:10d}") + +def main() -> None: + """Main function.""" + parser = argparse.ArgumentParser(description="Trace r/w activity by PID") + parser.add_argument( + "interval", type=int, nargs="?", default=3, help="Refresh interval in seconds" + ) + parser.add_argument("-i", "--input", default="perf.data", help="Input file") + args = parser.parse_args() + + analyzer = RwTop(args.interval) + try: + if not os.path.exists(args.input) and args.input == "perf.data": + # Live mode + events = ( + "syscalls:sys_enter_read,syscalls:sys_exit_read," + "syscalls:sys_enter_write,syscalls:sys_exit_write" + ) + try: + live_session = LiveSession(events, sample_callback=analyzer.process_event) + except OSError: + events = ( + "raw_syscalls:sys_enter_read,raw_syscalls:sys_exit_read," + "raw_syscalls:sys_enter_write,raw_syscalls:sys_exit_write" + ) + live_session = LiveSession(events, sample_callback=analyzer.process_event) + print("Live mode started. Press Ctrl+C to stop.", file=sys.stderr) + live_session.run() + else: + analyzer.run(args.input) + except IOError as e: + print(e, file=sys.stderr) + sys.exit(1) + except KeyboardInterrupt: + print("\nStopping live mode...", file=sys.stderr) + if analyzer.reads or analyzer.writes: + analyzer.print_totals() + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 50/59] perf rwtop: Port rwtop to use python module
Sashiko AI review found 4 potential issue(s): - [High] The fallback mechanism uses non-existent tracepoints (`raw_syscalls:sys_enter_read`, etc.), which will cause an unhandled exception and crash.…
Sashiko AI review found 4 potential issue(s):
- [High] The fallback mechanism uses non-existent tracepoints (raw_syscalls:sys_enter_read, etc.), which will cause an unhandled exception and crash.
- [Medium] The script incorrectly classifies a return value of 0 from read and write syscalls as an error.
- [Medium] The commit message claims to use ANSI escape codes to clear the terminal, but they are absent from the implementation.
- [Low] The unhandled events summary is not printed when exiting live mode.
--
commit c17a4dd376748fb95f0369d1ddc3004826b6a608
Author: Ian Rogers <[email protected]>
perf rwtop: Port rwtop to use python module
This commit ports the legacy Perl script rwtop.pl to a Python script using the perf module in tools/perf/python. It uses a class-based architecture and leverages the perf.session API to periodically display system-wide read and write call activity.
Quoted 1 line
- Used ANSI escape codes (\x1b[H\x1b[2J) to clear the terminal.
The commit message states that ANSI escape codes are used to clear the terminal, but they appear to be absent from the implementation in print_totals() or elsewhere. Is this intentional, or were the escape codes accidentally dropped during development?
Quoted 6 lines
tools/perf/python/rwtop.py new file +0
-0@@ -0,0 +1,219 @@
[ ... ]
tools/perf/python/rwtop.py line 73
Quoted 7 lines
tools/perf/python/rwtop.py new file +7
-0+ elif event_name in ("evsel(syscalls:sys_exit_read)", "evsel(raw_syscalls:sys_exit_read)"): + try: + ret = sample.ret + if ret > 0: + self.reads[pid]["bytes_read"] += ret + else: + self.reads[pid]["errors"][ret] += 1
Does this incorrectly classify a return value of 0 as an error?
A return value of 0 from read or write typically indicates End-Of-File (EOF) or a 0-byte transfer, which are standard, non-error conditions. True syscall errors are usually indicated by negative return values.
This might unnecessarily pollute the error statistics with false positives.
[ ... ]
tools/perf/python/rwtop.py line 91
Quoted 7 lines
tools/perf/python/rwtop.py new file +7
-0+ elif event_name in ("evsel(syscalls:sys_exit_write)", "evsel(raw_syscalls:sys_exit_write)"): + try: + ret = sample.ret + if ret > 0: + self.writes[pid]["bytes_written"] += ret + else: + self.writes[pid]["errors"][ret] += 1
Similarly, does this incorrectly classify a return value of 0 from a write syscall as an error?
[ ... ]
tools/perf/python/rwtop.py line 205
Quoted 8 lines
tools/perf/python/rwtop.py new file +8
-0+ try: + live_session = LiveSession(events, sample_callback=analyzer.process_event) + except OSError: + events = ( + "raw_syscalls:sys_enter_read,raw_syscalls:sys_exit_read," + "raw_syscalls:sys_enter_write,raw_syscalls:sys_exit_write" + ) + live_session = LiveSession(events, sample_callback=analyzer.process_event)
Can this fallback mechanism cause an unhandled exception and crash?
The raw_syscalls subsystem exposes generic sys_enter and sys_exit tracepoints, but there are no syscall-specific variants like raw_syscalls:sys_enter_read.
Because of this, the second LiveSession constructor will likely raise another OSError that is not caught, crashing the script instead of providing a graceful fallback.
[ ... ]
tools/perf/python/rwtop.py line 216
Quoted 4 lines
tools/perf/python/rwtop.py new file +4
-0+ except KeyboardInterrupt: + print("\nStopping live mode...", file=sys.stderr) + if analyzer.reads or analyzer.writes: + analyzer.print_totals()
Should this also print the unhandled events summary?
When exiting live mode via KeyboardInterrupt, only print_totals() is called. The script fails to print the unhandled events dictionary, which is normally printed when processing a perf.data file offline in run().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=50
Ian Rogers
reviewerPATCH v6 51/59 perf wakeup-latency: Port wakeup-latency to use python module
In reply to Ian RogersPort the legacy Perl script wakeup-latency.pl to a python script using the perf module in tools/perf/python.
The new script uses a class-based architecture and leverages the perf.session API for event processing.
It measures wakeup latency by tracking timestamps of sched:sched_wakeup and sched:sched_switch events.
Complications:
- Used min() and max() built-in functions instead of if blocks to satisfy pylint recommendations.
- pylint warns about the module name not being snake_case, but it is kept for consistency with the original script name.
---
v2:
- Fixed Wakeup Latency Logic: Modified the script to track wakeup timestamps per task (using sample.pid as the key) instead of per CPU. This ensures that context switches are correctly paired with the specific task that was woken up, even if multiple tasks are woken up on the same CPU or if a task is migrated to a different CPU before running.
- Prevented Memory Growth: Added del self.last_wakeup[next_pid] after successful latency calculation to prevent the dictionary from growing unbounded over time.
- Added Error Tracking: Added try-except blocks around tracepoint field access in process_event() and tracked missing fields in self. unhandled instead of ignoring them.
--- tools/perf/python/wakeup-latency.py | 88 +++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 tools/perf/python/wakeup-latency.py
tools/perf/python/wakeup-latency.py new file +88 -0
@@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Display avg/min/max wakeup latency.""" + +import argparse +from collections import defaultdict +import sys +from typing import Optional, Dict +import perf + +class WakeupLatency: + """Tracks and displays wakeup latency statistics.""" + def __init__(self) -> None: + self.last_wakeup: Dict[int, int] = defaultdict(int) + self.max_wakeup_latency = 0 + self.min_wakeup_latency = 1000000000 + self.total_wakeup_latency = 0 + self.total_wakeups = 0 + self.unhandled: Dict[str, int] = defaultdict(int) + self.session: Optional[perf.session] = None + + def process_event(self, sample: perf.sample_event) -> None: + """Process events.""" + event_name = str(sample.evsel) + sample_time = sample.sample_time + + if "sched:sched_wakeup" in event_name: + try: + pid = sample.pid + self.last_wakeup[pid] = sample_time + except AttributeError: + self.unhandled[event_name] += 1 + elif "sched:sched_switch" in event_name: + try: + next_pid = sample.next_pid + wakeup_ts = self.last_wakeup.get(next_pid, 0) + if wakeup_ts: + latency = sample_time - wakeup_ts + self.max_wakeup_latency = max(self.max_wakeup_latency, latency) + self.min_wakeup_latency = min(self.min_wakeup_latency, latency) + self.total_wakeup_latency += latency + self.total_wakeups += 1 + del self.last_wakeup[next_pid] + except AttributeError: + self.unhandled[event_name] += 1 + else: + self.unhandled[event_name] += 1 + + def print_totals(self) -> None: + """Print summary statistics.""" + print("wakeup_latency stats:\n") + print(f"total_wakeups: {self.total_wakeups}") + if self.total_wakeups: + avg = self.total_wakeup_latency // self.total_wakeups + print(f"avg_wakeup_latency (ns): {avg}") + else: + print("avg_wakeup_latency (ns): N/A") + print(f"min_wakeup_latency (ns): {self.min_wakeup_latency}") + print(f"max_wakeup_latency (ns): {self.max_wakeup_latency}") + + if self.unhandled: + print("\nunhandled events:\n") + print(f"{'event':<40s} {'count':>10s}") + print(f"{'-'*40} {'-'*10}") + for event_name, count in self.unhandled.items(): + print(f"{event_name:<40s} {count:10d}") + + def run(self, input_file: str) -> None: + """Run the session.""" + self.session = perf.session(perf.data(input_file), sample=self.process_event) + self.session.process_events() + self.print_totals() + +def main() -> None: + """Main function.""" + parser = argparse.ArgumentParser(description="Trace wakeup latency") + parser.add_argument("-i", "--input", default="perf.data", help="Input file") + args = parser.parse_args() + + analyzer = WakeupLatency() + try: + analyzer.run(args.input) + except IOError as e: + print(e, file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main()
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 51/59] perf wakeup-latency: Port wakeup-latency to use python module
Sashiko AI review found 1 potential issue(s): - [Medium] Incorrect initialization of `min_wakeup_latency` artificially caps the minimum latency at 1 second and reports an incorrect value when no…
Sashiko AI review found 1 potential issue(s):
- [Medium] Incorrect initialization of min_wakeup_latency artificially caps the minimum latency at 1 second and reports an incorrect value when no wakeups are processed. --
commit 02a26dde701533f15dfaafd348b2b2126ca947be
Author: Ian Rogers <[email protected]>
perf wakeup-latency: Port wakeup-latency to use python module
This commit ports the legacy Perl script wakeup-latency.pl to a Python script utilizing the perf module. It implements a class-based architecture to measure wakeup latency by tracking timestamps of sched:sched_wakeup and sched:sched_switch events.
Quoted 5 lines
tools/perf/python/wakeup-latency.py new file +0
-0
[ ... ]
tools/perf/python/wakeup-latency.py line 16
Quoted 6 lines
tools/perf/python/wakeup-latency.py new file +6
-0+class WakeupLatency: + """Tracks and displays wakeup latency statistics.""" + def __init__(self) -> None: + self.last_wakeup: Dict[int, int] = defaultdict(int) + self.max_wakeup_latency = 0 + self.min_wakeup_latency = 1000000000
Is it possible for the true minimum wakeup latency to exceed 1 second (1,000,000,000 ns)? By initializing the minimum latency to this hardcoded value, any actual latency greater than 1 second will be ignored since the min() calculation will prefer the initialized value, artificially capping the results.
[ ... ]
tools/perf/python/wakeup-latency.py line 58
Quoted 10 lines
tools/perf/python/wakeup-latency.py new file +10
-0+ def print_totals(self) -> None: + """Print summary statistics.""" + print("wakeup_latency stats:\n") + print(f"total_wakeups: {self.total_wakeups}") + if self.total_wakeups: + avg = self.total_wakeup_latency // self.total_wakeups + print(f"avg_wakeup_latency (ns): {avg}") + else: + print("avg_wakeup_latency (ns): N/A") + print(f"min_wakeup_latency (ns): {self.min_wakeup_latency}")
Will this output an incorrect minimum latency if no wakeups are processed? The average latency correctly handles the zero-wakeup case by printing N/A, but the minimum latency will unconditionally print the hardcoded initialization value.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=51
Ian Rogers
reviewerPATCH v6 52/59 perf test: Migrate Intel PT virtual LBR test to use Python API
In reply to Ian RogersThe Intel PT virtual LBR test used an ad-hoc Python script written on the fly to parse branch stacks. This change migrates it to use the newly added brstack iterator API in the perf Python module.
--- .../perf/tests/shell/lib/perf_brstack_max.py | 43 +++++++++++++++++++ tools/perf/tests/shell/test_intel_pt.sh | 35 +++++---------- 2 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 tools/perf/tests/shell/lib/perf_brstack_max.py
tools/perf/tests/shell/lib/perf_brstack_max.py new file +43 -0
@@ -0,0 +1,43 @@ +#!/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 os + +script_dir = os.path.dirname(os.path.abspath(__file__)) +python_dir = os.path.abspath(os.path.join(script_dir, "../../../python")) +sys.path.insert(0, python_dir) + +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 = sum(1 for _ in brstack) + if n > bmax: + bmax = n + except AttributeError: + pass + + 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) + +if __name__ == "__main__": + main()
tools/perf/tests/shell/test_intel_pt.sh +10 -25
@@ -24,7 +24,6 @@ errfile="${temp_dir}/test-err.txt" workload="${temp_dir}/workload" awkscript="${temp_dir}/awkscript" jitdump_workload="${temp_dir}/jitdump_workload" -maxbrstack="${temp_dir}/maxbrstack.py" cleanup() {
@@ -539,34 +538,20 @@ test_kernel_trace() test_virtual_lbr() { echo "--- Test virtual LBR ---" - # Check if python script is supported - libpython=$(perf version --build-options | grep python | grep -cv OFF) - if [ "${libpython}" != "1" ] ; then - echo "SKIP: python scripting is not supported" + # shellcheck source=lib/setup_python.sh + . "$(dirname "$0")"/lib/setup_python.sh + + if [ -z "$PYTHON" ] ; then + echo "SKIP: Python not found" return 2 fi - # Python script to determine the maximum size of branch stacks - cat << "_end_of_file_" > "${maxbrstack}" -from __future__ import print_function - -bmax = 0 - -def process_event(param_dict): - if "brstack" in param_dict: - brstack = param_dict["brstack"] - n = len(brstack) - global bmax - if n > bmax: - bmax = n - -def trace_end(): - print("max brstack", bmax) -_end_of_file_ - # Check if virtual lbr is working - perf_record_no_bpf -o "${perfdatafile}" --aux-sample -e '{intel_pt//,cycles}:u' uname - times_val=$(perf script -i "${perfdatafile}" --itrace=L -s "${maxbrstack}" 2>/dev/null | grep "max brstack " | cut -d " " -f 3) + perf_record_no_bpf -o "${tmpfile}" --aux-sample -e '{intel_pt//,cycles}:u' perf test -w brstack + perf inject --itrace=L -i "${tmpfile}" -o "${perfdatafile}" + output=$($PYTHON "$(dirname "$0")"/lib/perf_brstack_max.py -i "${perfdatafile}") + echo "Debug: perf_brstack_max.py output: $output" + times_val=$(echo "$output" | grep "max brstack " | cut -d " " -f 3) case "${times_val}" in [0-9]*) ;; *) times_val=0;;
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 52/59] perf test: Migrate Intel PT virtual LBR test to use Python API
Sashiko AI review found 2 potential issue(s): - [Medium] The test incorrectly fails instead of skipping when `perf` is compiled without Python scripting support. - [Medium] Hardcoded relative path…
Sashiko AI review found 2 potential issue(s):
- [Medium] The test incorrectly fails instead of skipping when perf is compiled without Python scripting support.
- [Medium] Hardcoded relative path in the Python script breaks out-of-tree builds (O=...).
--
commit 0468e87feb947646888210ed3df346abde440b42
Author: Ian Rogers <[email protected]>
perf test: Migrate Intel PT virtual LBR test to use Python API
This commit migrates the Intel PT virtual LBR test to use the newly added brstack iterator API in the perf Python module instead of generating an ad-hoc Python script.
Quoted 8 lines
tools/perf/tests/shell/lib/perf_brstack_max.py new file +2
-0@@ -0,0 +1,43 @@ +#!/usr/bin/python +# SPDX-License-Identifier: GPL-2.0
tools/perf/tests/shell/lib/perf_brstack_max.py line 12
Quoted 10 lines
tools/perf/tests/shell/lib/perf_brstack_max.py new file +10
-0+# Determine the maximum size of branch stacks in a perf.data file. + +import argparse +import sys + +import os + +script_dir = os.path.dirname(os.path.abspath(__file__)) +python_dir = os.path.abspath(os.path.join(script_dir, "../../../python")) +sys.path.insert(0, python_dir)
Does this hardcoded relative path cause regressions for out-of-tree builds?
If built with make O=/tmp/build, the compiled perf C extension is placed in the build output directory rather than the source tree. It looks like running this script in such an environment will fail to find the module and crash with a ModuleNotFoundError.
[ ... ]
Quoted 9 lines
tools/perf/tests/shell/test_intel_pt.sh +0
-1@@ -539,34 +538,20 @@ test_kernel_trace() test_virtual_lbr() { echo "--- Test virtual LBR ---" - # Check if python script is supported
tools/perf/tests/shell/test_intel_pt.sh test_kernel_trace() · line 547
Quoted 10 lines
tools/perf/tests/shell/test_intel_pt.sh +5
-3- libpython=$(perf version --build-options | grep python | grep -cv OFF) - if [ "${libpython}" != "1" ] ; then - echo "SKIP: python scripting is not supported" + # shellcheck source=lib/setup_python.sh + . "$(dirname "$0")"/lib/setup_python.sh + + if [ -z "$PYTHON" ] ; then + echo "SKIP: Python not found" return 2 fi
Could removing the explicit feature check cause false test failures when perf is built without Python support?
The original code checked perf version --build-options to ensure perf itself had Python scripting support. The new setup_python.sh only verifies the presence of a Python interpreter on the host system.
If a user tests a build lacking Python support, setup_python.sh passes, but the subsequent execution of perf_brstack_max.py crashes when attempting to import perf. This leaves stdout empty, making times_val evaluate to 0 and failing the test instead of appropriately skipping it.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=52
Ian Rogers
reviewerPATCH v6 53/59 perf: Remove libperl support, legacy Perl scripts and tests
In reply to Ian RogersRemove libperl support from perf, along with legacy Perl scripts and their corresponding tests.
---
v5:
1. Fix Buffer Overflows: Added bounds checks in check_ev_match() and find_scripts() to prevent stack and heap buffer overflows when parsing long event or script names.
--- tools/build/Makefile.feature | 1 - tools/build/feature/Makefile | 19 +- tools/build/feature/test-libperl.c | 10 - tools/perf/Documentation/perf-check.txt | 1 - tools/perf/Makefile.config | 22 +- tools/perf/Makefile.perf | 11 +- tools/perf/builtin-check.c | 2 +- tools/perf/builtin-script.c | 4 +- tools/perf/scripts/Build | 4 +- tools/perf/scripts/perl/Perf-Trace-Util/Build | 9 - .../scripts/perl/Perf-Trace-Util/Context.c | 122 --- .../scripts/perl/Perf-Trace-Util/Context.xs | 42 - .../scripts/perl/Perf-Trace-Util/Makefile.PL | 18 - .../perf/scripts/perl/Perf-Trace-Util/README | 59 -- .../Perf-Trace-Util/lib/Perf/Trace/Context.pm | 55 -- .../Perf-Trace-Util/lib/Perf/Trace/Core.pm | 192 ----- .../Perf-Trace-Util/lib/Perf/Trace/Util.pm | 94 --- .../perf/scripts/perl/Perf-Trace-Util/typemap | 1 - .../scripts/perl/bin/check-perf-trace-record | 2 - .../scripts/perl/bin/failed-syscalls-record | 3 - .../scripts/perl/bin/failed-syscalls-report | 10 - tools/perf/scripts/perl/bin/rw-by-file-record | 3 - tools/perf/scripts/perl/bin/rw-by-file-report | 10 - tools/perf/scripts/perl/bin/rw-by-pid-record | 2 - tools/perf/scripts/perl/bin/rw-by-pid-report | 3 - tools/perf/scripts/perl/bin/rwtop-record | 2 - tools/perf/scripts/perl/bin/rwtop-report | 20 - .../scripts/perl/bin/wakeup-latency-record | 6 - .../scripts/perl/bin/wakeup-latency-report | 3 - tools/perf/scripts/perl/check-perf-trace.pl | 106 --- tools/perf/scripts/perl/failed-syscalls.pl | 47 -- tools/perf/scripts/perl/rw-by-file.pl | 106 --- tools/perf/scripts/perl/rw-by-pid.pl | 184 ----- tools/perf/scripts/perl/rwtop.pl | 203 ----- tools/perf/scripts/perl/wakeup-latency.pl | 107 --- tools/perf/tests/make | 4 +- tools/perf/tests/shell/script_perl.sh | 102 --- tools/perf/ui/browsers/scripts.c | 21 +- tools/perf/util/scripting-engines/Build | 6 +- .../util/scripting-engines/trace-event-perl.c | 773 ------------------ tools/perf/util/trace-event-scripting.c | 65 -- tools/perf/util/trace-event.h | 2 +- 42 files changed, 25 insertions(+), 2431 deletions(-) delete mode 100644 tools/build/feature/test-libperl.c delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Build delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Context.c delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Context.xs delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/README delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Core.pm delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/typemap delete mode 100644 tools/perf/scripts/perl/bin/check-perf-trace-record delete mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-record delete mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-report delete mode 100644 tools/perf/scripts/perl/bin/rw-by-file-record delete mode 100644 tools/perf/scripts/perl/bin/rw-by-file-report delete mode 100644 tools/perf/scripts/perl/bin/rw-by-pid-record delete mode 100644 tools/perf/scripts/perl/bin/rw-by-pid-report delete mode 100644 tools/perf/scripts/perl/bin/rwtop-record delete mode 100644 tools/perf/scripts/perl/bin/rwtop-report delete mode 100644 tools/perf/scripts/perl/bin/wakeup-latency-record delete mode 100644 tools/perf/scripts/perl/bin/wakeup-latency-report delete mode 100644 tools/perf/scripts/perl/check-perf-trace.pl delete mode 100644 tools/perf/scripts/perl/failed-syscalls.pl delete mode 100644 tools/perf/scripts/perl/rw-by-file.pl delete mode 100644 tools/perf/scripts/perl/rw-by-pid.pl delete mode 100644 tools/perf/scripts/perl/rwtop.pl delete mode 100644 tools/perf/scripts/perl/wakeup-latency.pl delete mode 100755 tools/perf/tests/shell/script_perl.sh delete mode 100644 tools/perf/util/scripting-engines/trace-event-perl.c
tools/build/Makefile.feature +0 -1
@@ -118,7 +118,6 @@ FEATURE_TESTS_EXTRA := \ libbfd-liberty \ libbfd-liberty-z \ libopencsd \ - libperl \ cxx \ llvm \ clang \
tools/build/feature/Makefile +1 -18
@@ -30,7 +30,6 @@ FILES= \ test-libdebuginfod.bin \ test-libnuma.bin \ test-numa_num_possible_cpus.bin \ - test-libperl.bin \ test-libpython.bin \ test-libslang.bin \ test-libtraceevent.bin \
@@ -113,7 +112,7 @@ __BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $( BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang \ - $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -ldl -lz -llzma -lzstd \ + $(FLAGS_PYTHON_EMBED) -ldl -lz -llzma -lzstd \ $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null) __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
@@ -253,22 +252,6 @@ $(OUTPUT)test-gtk2-infobar.bin: grep-libs = $(filter -l%,$(1)) strip-libs = $(filter-out -l%,$(1)) -PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) -PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) -PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) -PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) -FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) - -ifeq ($(CC_NO_CLANG), 0) - PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) - PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) - PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) - FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro -endif - -$(OUTPUT)test-libperl.bin: - $(BUILD) $(FLAGS_PERL_EMBED) - $(OUTPUT)test-libpython.bin: $(BUILD) $(FLAGS_PYTHON_EMBED)
tools/build/feature/test-libperl.c deleted +0 -10
@@ -1,10 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <EXTERN.h> -#include <perl.h> - -int main (void ) -{ -perl_alloc (); - -return 0 ; -}
tools/perf/Documentation/perf-check.txt +0 -1
@@ -58,7 +58,6 @@ feature:: libLLVM / HAVE_LIBLLVM_SUPPORT libnuma / HAVE_LIBNUMA_SUPPORT libopencsd / HAVE_CSTRACE_SUPPORT - libperl / HAVE_LIBPERL_SUPPORT libpfm4 / HAVE_LIBPFM libpython / HAVE_LIBPYTHON_SUPPORT libslang / HAVE_SLANG_SUPPORT
tools/perf/Makefile.config +1 -21
@@ -820,26 +820,7 @@ ifdef GTK2 endif endif -ifdef LIBPERL - PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) - PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) - PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) - PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) - PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) - PERL_EMBED_CCOPTS := $(filter-out -flto% -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) - PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) - FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) - - $(call feature_check,libperl) - ifneq ($(feature-libperl), 1) - $(error Missing perl devel files. Please install perl-ExtUtils-Embed/libperl-dev) - else - LDFLAGS += $(PERL_EMBED_LDFLAGS) - EXTLIBS += $(PERL_EMBED_LIBADD) - CFLAGS += -DHAVE_LIBPERL_SUPPORT - $(call detected,CONFIG_LIBPERL) - endif -endif + ifeq ($(feature-timerfd), 1) CFLAGS += -DHAVE_TIMERFD_SUPPORT
@@ -1321,7 +1302,6 @@ $(call detected_var,tipdir_SQ) $(call detected_var,srcdir_SQ) $(call detected_var,LIBDIR) $(call detected_var,GTK_CFLAGS) -$(call detected_var,PERL_EMBED_CCOPTS) $(call detected_var,PYTHON_EMBED_CCOPTS) ifneq ($(BISON_FILE_PREFIX_MAP),) $(call detected_var,BISON_FILE_PREFIX_MAP)
tools/perf/Makefile.perf +2 -9
@@ -17,7 +17,7 @@ include ../scripts/utilities.mak # # Define CROSS_COMPILE as prefix name of compiler if you want cross-builds. # -# Define LIBPERL to enable perl script extension. + # # Define NO_LIBPYTHON to disable python script extension. #
@@ -1098,14 +1098,7 @@ endif $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' $(call QUIET_INSTALL, perf-iostat) \ $(INSTALL) $(OUTPUT)perf-iostat -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' -ifdef LIBPERL - $(call QUIET_INSTALL, perl-scripts) \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \ - $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \ - $(INSTALL) scripts/perl/*.pl -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'; \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'; \ - $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' -endif + ifndef NO_LIBPYTHON $(call QUIET_INSTALL, python-scripts) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \
tools/perf/builtin-check.c +1 -1
@@ -51,7 +51,7 @@ struct feature_status supported_features[] = {FEATURE_STATUS ("libLLVM" ,HAVE_LIBLLVM_SUPPORT ),FEATURE_STATUS ("libnuma" ,HAVE_LIBNUMA_SUPPORT ),FEATURE_STATUS ("libopencsd" ,HAVE_CSTRACE_SUPPORT ), -FEATURE_STATUS_TIP ("libperl" ,HAVE_LIBPERL_SUPPORT ,"Deprecated, use LIBPERL=1 and install perl-ExtUtils-Embed/libperl-dev to build with it" ), +FEATURE_STATUS ("libpfm4" ,HAVE_LIBPFM ),FEATURE_STATUS ("libpython" ,HAVE_LIBPYTHON_SUPPORT ), FEATURE_STATUS("libslang", HAVE_SLANG_SUPPORT),
tools/perf/builtin-script.c +1 -3
@@ -2621,9 +2621,7 @@ static void process_stat_interval(u64 tstamp)static void setup_scripting (void ) { -#ifdef HAVE_LIBTRACEEVENT -setup_perl_scripting (); -#endif +setup_python_scripting (); }
tools/perf/scripts/Build +1 -3
@@ -1,6 +1,4 @@ -ifeq ($(CONFIG_LIBTRACEEVENT),y) - perf-util-$(CONFIG_LIBPERL) += perl/Perf-Trace-Util/ -endif + perf-util-$(CONFIG_LIBPYTHON) += python/Perf-Trace-Util/ ifdef MYPY
tools/perf/scripts/perl/Perf-Trace-Util/Build deleted +0 -9
@@ -1,9 +0,0 @@ -perf-util-y += Context.o - -CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-bad-function-cast -Wno-declaration-after-statement -Wno-switch-enum -CFLAGS_Context.o += -Wno-unused-parameter -Wno-nested-externs -Wno-undef -CFLAGS_Context.o += -Wno-switch-default -Wno-shadow -Wno-thread-safety-analysis - -ifeq ($(CC_NO_CLANG), 1) - CFLAGS_Context.o += -Wno-unused-command-line-argument -endif
tools/perf/scripts/perl/Perf-Trace-Util/Context.c deleted +0 -122
122 lines not on this page · raw message
tools/perf/scripts/perl/Perf-Trace-Util/Context.xs deleted +0 -42
42 lines not on this page · raw message
tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL deleted +0 -18
@@ -1,18 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -use 5.010000; -use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. -WriteMakefile( - NAME => 'Perf::Trace::Context', - VERSION_FROM => 'lib/Perf/Trace/Context.pm', # finds $VERSION - PREREQ_PM => {}, # e.g., Module::Name => 1.1 - ($] >= 5.005 ? ## Add these new keywords supported since 5.005 - (ABSTRACT_FROM => 'lib/Perf/Trace/Context.pm', # retrieve abstract from module - AUTHOR => 'Tom Zanussi <[email protected]>') : ()), - LIBS => [''], # e.g., '-lm' - DEFINE => '-I ../..', # e.g., '-DHAVE_SOMETHING' - INC => '-I.', # e.g., '-I. -I/usr/include/other' - # Un-comment this if you add C files to link with later: - OBJECT => 'Context.o', # link all the C files too -);
tools/perf/scripts/perl/Perf-Trace-Util/README deleted +0 -59
59 lines not on this page · raw message
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm deleted +0 -55
55 lines not on this page · raw message
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Core.pm deleted +0 -192
192 lines not on this page · raw message
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm deleted +0 -94
94 lines not on this page · raw message
tools/perf/scripts/perl/Perf-Trace-Util/typemap deleted +0 -1
@@ -1 +0,0 @@ -struct scripting_context * T_PTR
tools/perf/scripts/perl/bin/check-perf-trace-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -a -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree
tools/perf/scripts/perl/bin/failed-syscalls-record deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -(perf record -e raw_syscalls:sys_exit $@ || \ - perf record -e syscalls:sys_exit $@) 2> /dev/null
tools/perf/scripts/perl/bin/failed-syscalls-report deleted +0 -10
@@ -1,10 +0,0 @@ -#!/bin/bash -# description: system-wide failed syscalls -# args: [comm] -if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" > /dev/null ; then - comm=$1 - shift - fi -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/perl/failed-syscalls.pl $comm
tools/perf/scripts/perl/bin/rw-by-file-record deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -perf record -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@ -
tools/perf/scripts/perl/bin/rw-by-file-report deleted +0 -10
@@ -1,10 +0,0 @@ -#!/bin/bash -# description: r/w activity for a program, by file -# args: <comm> -if [ $# -lt 1 ] ; then - echo "usage: rw-by-file <comm>" - exit -fi -comm=$1 -shift -perf script $@ -s "$PERF_EXEC_PATH"/scripts/perl/rw-by-file.pl $comm
tools/perf/scripts/perl/bin/rw-by-pid-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
tools/perf/scripts/perl/bin/rw-by-pid-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: system-wide r/w activity -perf script $@ -s "$PERF_EXEC_PATH"/scripts/perl/rw-by-pid.pl
tools/perf/scripts/perl/bin/rwtop-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
tools/perf/scripts/perl/bin/rwtop-report deleted +0 -20
@@ -1,20 +0,0 @@ -#!/bin/bash -# description: system-wide r/w top -# args: [interval] -n_args=0 -for i in "$@" -do - if expr match "$i" "-" > /dev/null ; then - break - fi - n_args=$(( $n_args + 1 )) -done -if [ "$n_args" -gt 1 ] ; then - echo "usage: rwtop-report [interval]" - exit -fi -if [ "$n_args" -gt 0 ] ; then - interval=$1 - shift -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/perl/rwtop.pl $interval
tools/perf/scripts/perl/bin/wakeup-latency-record deleted +0 -6
@@ -1,6 +0,0 @@ -#!/bin/bash -perf record -e sched:sched_switch -e sched:sched_wakeup $@ - - - -
tools/perf/scripts/perl/bin/wakeup-latency-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: system-wide min/max/avg wakeup latency -perf script $@ -s "$PERF_EXEC_PATH"/scripts/perl/wakeup-latency.pl
tools/perf/scripts/perl/check-perf-trace.pl deleted +0 -106
106 lines not on this page · raw message
tools/perf/scripts/perl/failed-syscalls.pl deleted +0 -47
47 lines not on this page · raw message
tools/perf/scripts/perl/rw-by-file.pl deleted +0 -106
106 lines not on this page · raw message
tools/perf/scripts/perl/rw-by-pid.pl deleted +0 -184
184 lines not on this page · raw message
tools/perf/scripts/perl/rwtop.pl deleted +0 -203
203 lines not on this page · raw message
tools/perf/scripts/perl/wakeup-latency.pl deleted +0 -107
107 lines not on this page · raw message
tools/perf/tests/make +2 -2
@@ -74,7 +74,7 @@ make_no_jevents := NO_JEVENTS=1 make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 make_gen_vmlinux_h := GEN_VMLINUX_H=1 -make_libperl := LIBPERL=1 + make_no_libpython := NO_LIBPYTHON=1 make_no_scripts := NO_LIBPYTHON=1 make_no_slang := NO_SLANG=1
@@ -149,7 +149,7 @@ run += make_no_jevents run += make_jevents_all run += make_no_bpf_skel run += make_gen_vmlinux_h -run += make_libperl + run += make_no_libpython run += make_no_scripts run += make_no_slang
tools/perf/tests/shell/script_perl.sh deleted +0 -102
102 lines not on this page · raw message
tools/perf/ui/browsers/scripts.c +13 -8
@@ -126,8 +126,10 @@ static int check_ev_match(int dir_fd, const char *scriptname, struct perf_sessio len =strcspn (p," \t" );if (!len)break ; +if ((size_t )len >=sizeof (evname)) + len =sizeof (evname) -1 ; -snprintf (evname, len +1 ,"%s" , p); +snprintf (evname,sizeof (evname),"%s" , p); match =0 ;evlist__for_each_entry (session->evlist, pos) {
@@ -200,14 +202,13 @@ static int find_scripts(char **scripts_array, char **scripts_path_array, int numif (!strcmp (lang_dirent->d_name,"." ) || !strcmp (lang_dirent->d_name,".." ))continue ; -#ifndef HAVE_LIBPERL_SUPPORT -if (strstr (lang_dirent->d_name,"perl" )) -continue ; -#endif +#ifndef HAVE_LIBPYTHON_SUPPORT if (strstr (lang_dirent->d_name,"python" ))continue ;#endif +if (strstr (lang_dirent->d_name,"perl" )) +continue ; lang_dir_fd =openat (scripts_dir_fd, lang_dirent->d_name,O_DIRECTORY );if (lang_dir_fd ==-1 )
@@ -218,6 +219,8 @@ static int find_scripts(char **scripts_array, char **scripts_path_array, int numcontinue ; }while ((script_dirent =readdir (lang_dir)) !=NULL ) { +int script_len; +if (script_dirent->d_type ==DT_DIR )continue ; if (script_dirent->d_type == DT_UNKNOWN &&
@@ -233,9 +236,11 @@ static int find_scripts(char **scripts_array, char **scripts_path_array, int num lang_dirent->d_name, script_dirent->d_name); temp =strchr (script_dirent->d_name,'.' ); -snprintf (scripts_array[i], - (temp - script_dirent->d_name) +1 , -"%s" , script_dirent->d_name); + script_len = temp ? (temp - script_dirent->d_name) : (int )strlen (script_dirent->d_name); + +if (script_len >=SCRIPT_NAMELEN ) + script_len =SCRIPT_NAMELEN -1 ; +snprintf (scripts_array[i], script_len +1 ,"%s" , script_dirent->d_name);if (check_ev_match (lang_dir_fd, scripts_array[i], session))continue ;
tools/perf/util/scripting-engines/Build +2 -4
@@ -1,9 +1,7 @@ -ifeq ($(CONFIG_LIBTRACEEVENT),y) - perf-util-$(CONFIG_LIBPERL) += trace-event-perl.o -endif + perf-util-$(CONFIG_LIBPYTHON) += trace-event-python.o -CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-nested-externs -Wno-undef -Wno-switch-default -Wno-bad-function-cast -Wno-declaration-after-statement -Wno-switch-enum -Wno-thread-safety-analysis + # -Wno-declaration-after-statement: The python headers have mixed code with declarations (decls after asserts, for instance) CFLAGS_trace-event-python.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-deprecated-declarations -Wno-switch-enum -Wno-declaration-after-statement
tools/perf/util/scripting-engines/trace-event-perl.c deleted +0 -773
773 lines not on this page · raw message
tools/perf/util/trace-event-scripting.c +0 -65
72 lines not on this page · raw message
tools/perf/util/trace-event.h +1 -1
@@ -116,7 +116,7 @@ extern unsigned int scripting_max_stack;struct scripting_ops *script_spec__lookup (const char *spec);int script_spec__for_each (int (*cb)(struct scripting_ops *ops,const char *spec)); -void setup_perl_scripting (void ); +void setup_python_scripting (void );struct scripting_context {
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 53/59] perf: Remove libperl support, legacy Perl scripts and tests
Sashiko AI review found 1 potential issue(s): - [Medium] Event matching logic is broken by an incorrect snprintf length argument in check_ev_match(). --
Sashiko AI review found 1 potential issue(s):
- [Medium] Event matching logic is broken by an incorrect snprintf length argument in check_ev_match(). --
commit 358c8fb5b2850826fc33a7ec1709b3b089c45e16
Author: Ian Rogers <[email protected]>
perf: Remove libperl support, legacy Perl scripts and tests
This commit removes libperl support from perf, along with the legacy Perl scripts and their corresponding tests.
Quoted 4 lines
tools/perf/ui/browsers/scripts.c +0
-0
[ ... ]
tools/perf/ui/browsers/scripts.c static int check_ev_match(int dir_fd, const char *scriptname, struct perf_sessio · line 132
Quoted 9 lines
tools/perf/ui/browsers/scripts.c +3
-1@@ -126,8 +126,10 @@ static int check_ev_match(int dir_fd, const char *scriptname, struct perf_sessio len =strcspn (p," \t" );if (!len)break ; +if ((size_t )len >=sizeof (evname)) + len =sizeof (evname) -1 ; -snprintf (evname, len +1 ,"%s" , p); +snprintf (evname,sizeof (evname),"%s" , p);
Does this snprintf call ignore the calculated len and copy the rest of the line instead?
Since p contains the remainder of the line, using sizeof(evname) instead of len + 1 will capture trailing spaces and subsequent arguments into evname. This will cause the evsel__name_is() match to fail.
Should this still use len + 1, or perhaps use %.*s with len to properly cap the parsed token?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=53
Ian Rogers
reviewerPATCH v6 54/59 perf: Remove libpython support and legacy Python scripts
In reply to Ian RogersThis commit removes embedded Python interpreter support from perf, as all legacy Python scripts have been ported to standalone Python scripts or are no longer needed.
Changes include:
- Removal of libpython detection and flags from Makefile.config.
- Removal of Python script installation rules from Makefile.perf.
- Deletion of tools/perf/util/scripting-engines/trace-event-python.c.
- Removal of Python scripting operations and setup from trace-event-scripting.c.
- Removal of setup_python_scripting() call from builtin-script.c and declaration from trace-event.h.
- Removal of Python checks in the script browser (scripts.c).
- Removal of libpython from the supported features list in builtin-check.c and Documentation/perf-check.txt.
- Deletion of the legacy Python scripts in tools/perf/scripts/python.
--- tools/perf/Documentation/perf-check.txt | 1 - tools/perf/Makefile.config | 4 - tools/perf/Makefile.perf | 7 +- tools/perf/builtin-check.c | 1 - tools/perf/scripts/Build | 2 - .../perf/scripts/python/Perf-Trace-Util/Build | 4 - .../scripts/python/Perf-Trace-Util/Context.c | 225 -- .../Perf-Trace-Util/lib/Perf/Trace/Core.py | 116 - .../lib/Perf/Trace/EventClass.py | 97 - .../lib/Perf/Trace/SchedGui.py | 184 -- .../Perf-Trace-Util/lib/Perf/Trace/Util.py | 92 - .../scripts/python/arm-cs-trace-disasm.py | 355 --- .../python/bin/compaction-times-record | 2 - .../python/bin/compaction-times-report | 4 - .../python/bin/event_analyzing_sample-record | 8 - .../python/bin/event_analyzing_sample-report | 3 - .../python/bin/export-to-postgresql-record | 8 - .../python/bin/export-to-postgresql-report | 29 - .../python/bin/export-to-sqlite-record | 8 - .../python/bin/export-to-sqlite-report | 29 - .../python/bin/failed-syscalls-by-pid-record | 3 - .../python/bin/failed-syscalls-by-pid-report | 10 - .../perf/scripts/python/bin/flamegraph-record | 2 - .../perf/scripts/python/bin/flamegraph-report | 3 - .../python/bin/futex-contention-record | 2 - .../python/bin/futex-contention-report | 4 - tools/perf/scripts/python/bin/gecko-record | 2 - tools/perf/scripts/python/bin/gecko-report | 7 - .../scripts/python/bin/intel-pt-events-record | 13 - .../scripts/python/bin/intel-pt-events-report | 3 - .../scripts/python/bin/mem-phys-addr-record | 19 - .../scripts/python/bin/mem-phys-addr-report | 3 - .../scripts/python/bin/net_dropmonitor-record | 2 - .../scripts/python/bin/net_dropmonitor-report | 4 - .../scripts/python/bin/netdev-times-record | 8 - .../scripts/python/bin/netdev-times-report | 5 - .../scripts/python/bin/powerpc-hcalls-record | 2 - .../scripts/python/bin/powerpc-hcalls-report | 2 - .../scripts/python/bin/sched-migration-record | 2 - .../scripts/python/bin/sched-migration-report | 3 - tools/perf/scripts/python/bin/sctop-record | 3 - tools/perf/scripts/python/bin/sctop-report | 24 - .../scripts/python/bin/stackcollapse-record | 8 - .../scripts/python/bin/stackcollapse-report | 3 - .../python/bin/syscall-counts-by-pid-record | 3 - .../python/bin/syscall-counts-by-pid-report | 10 - .../scripts/python/bin/syscall-counts-record | 3 - .../scripts/python/bin/syscall-counts-report | 10 - .../scripts/python/bin/task-analyzer-record | 2 - .../scripts/python/bin/task-analyzer-report | 3 - tools/perf/scripts/python/check-perf-trace.py | 84 - tools/perf/scripts/python/compaction-times.py | 311 --- .../scripts/python/event_analyzing_sample.py | 192 -- .../scripts/python/export-to-postgresql.py | 1114 --------- tools/perf/scripts/python/export-to-sqlite.py | 799 ------ .../scripts/python/failed-syscalls-by-pid.py | 79 - tools/perf/scripts/python/flamegraph.py | 267 -- tools/perf/scripts/python/futex-contention.py | 57 - tools/perf/scripts/python/gecko.py | 395 --- tools/perf/scripts/python/intel-pt-events.py | 494 ---- tools/perf/scripts/python/libxed.py | 107 - tools/perf/scripts/python/mem-phys-addr.py | 127 - tools/perf/scripts/python/net_dropmonitor.py | 78 - tools/perf/scripts/python/netdev-times.py | 473 ---- tools/perf/scripts/python/powerpc-hcalls.py | 202 -- tools/perf/scripts/python/sched-migration.py | 462 ---- tools/perf/scripts/python/sctop.py | 89 - tools/perf/scripts/python/stackcollapse.py | 127 - tools/perf/scripts/python/stat-cpi.py | 79 - .../scripts/python/syscall-counts-by-pid.py | 75 - tools/perf/scripts/python/syscall-counts.py | 65 - tools/perf/scripts/python/task-analyzer.py | 934 ------- tools/perf/tests/shell/script_python.sh | 113 - tools/perf/util/scripting-engines/Build | 8 +- .../scripting-engines/trace-event-python.c | 2209 ----------------- tools/perf/util/trace-event-scripting.c | 14 +- 76 files changed, 4 insertions(+), 10297 deletions(-) delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/Build delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/Context.c delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py delete mode 100755 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py delete mode 100755 tools/perf/scripts/python/arm-cs-trace-disasm.py delete mode 100644 tools/perf/scripts/python/bin/compaction-times-record delete mode 100644 tools/perf/scripts/python/bin/compaction-times-report delete mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-record delete mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-report delete mode 100644 tools/perf/scripts/python/bin/export-to-postgresql-record delete mode 100644 tools/perf/scripts/python/bin/export-to-postgresql-report delete mode 100644 tools/perf/scripts/python/bin/export-to-sqlite-record delete mode 100644 tools/perf/scripts/python/bin/export-to-sqlite-report delete mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-record delete mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-report delete mode 100755 tools/perf/scripts/python/bin/flamegraph-record delete mode 100755 tools/perf/scripts/python/bin/flamegraph-report delete mode 100644 tools/perf/scripts/python/bin/futex-contention-record delete mode 100644 tools/perf/scripts/python/bin/futex-contention-report delete mode 100644 tools/perf/scripts/python/bin/gecko-record delete mode 100755 tools/perf/scripts/python/bin/gecko-report delete mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record delete mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report delete mode 100644 tools/perf/scripts/python/bin/mem-phys-addr-record delete mode 100644 tools/perf/scripts/python/bin/mem-phys-addr-report delete mode 100755 tools/perf/scripts/python/bin/net_dropmonitor-record delete mode 100755 tools/perf/scripts/python/bin/net_dropmonitor-report delete mode 100644 tools/perf/scripts/python/bin/netdev-times-record delete mode 100644 tools/perf/scripts/python/bin/netdev-times-report delete mode 100644 tools/perf/scripts/python/bin/powerpc-hcalls-record delete mode 100644 tools/perf/scripts/python/bin/powerpc-hcalls-report delete mode 100644 tools/perf/scripts/python/bin/sched-migration-record delete mode 100644 tools/perf/scripts/python/bin/sched-migration-report delete mode 100644 tools/perf/scripts/python/bin/sctop-record delete mode 100644 tools/perf/scripts/python/bin/sctop-report delete mode 100755 tools/perf/scripts/python/bin/stackcollapse-record delete mode 100755 tools/perf/scripts/python/bin/stackcollapse-report delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-record delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-report delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-record delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-report delete mode 100755 tools/perf/scripts/python/bin/task-analyzer-record delete mode 100755 tools/perf/scripts/python/bin/task-analyzer-report delete mode 100644 tools/perf/scripts/python/check-perf-trace.py delete mode 100644 tools/perf/scripts/python/compaction-times.py delete mode 100644 tools/perf/scripts/python/event_analyzing_sample.py delete mode 100644 tools/perf/scripts/python/export-to-postgresql.py delete mode 100644 tools/perf/scripts/python/export-to-sqlite.py delete mode 100644 tools/perf/scripts/python/failed-syscalls-by-pid.py delete mode 100755 tools/perf/scripts/python/flamegraph.py delete mode 100644 tools/perf/scripts/python/futex-contention.py delete mode 100644 tools/perf/scripts/python/gecko.py delete mode 100644 tools/perf/scripts/python/intel-pt-events.py delete mode 100644 tools/perf/scripts/python/libxed.py delete mode 100644 tools/perf/scripts/python/mem-phys-addr.py delete mode 100755 tools/perf/scripts/python/net_dropmonitor.py delete mode 100644 tools/perf/scripts/python/netdev-times.py delete mode 100644 tools/perf/scripts/python/powerpc-hcalls.py delete mode 100644 tools/perf/scripts/python/sched-migration.py delete mode 100644 tools/perf/scripts/python/sctop.py delete mode 100755 tools/perf/scripts/python/stackcollapse.py delete mode 100644 tools/perf/scripts/python/stat-cpi.py delete mode 100644 tools/perf/scripts/python/syscall-counts-by-pid.py delete mode 100644 tools/perf/scripts/python/syscall-counts.py delete mode 100755 tools/perf/scripts/python/task-analyzer.py delete mode 100755 tools/perf/tests/shell/script_python.sh delete mode 100644 tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/Documentation/perf-check.txt +0 -1
@@ -59,7 +59,6 @@ feature:: libnuma / HAVE_LIBNUMA_SUPPORT libopencsd / HAVE_CSTRACE_SUPPORT libpfm4 / HAVE_LIBPFM - libpython / HAVE_LIBPYTHON_SUPPORT libslang / HAVE_SLANG_SUPPORT libtraceevent / HAVE_LIBTRACEEVENT libunwind / HAVE_LIBUNWIND_SUPPORT
tools/perf/Makefile.config +0 -4
@@ -852,8 +852,6 @@ else ifneq ($(feature-libpython), 1) $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev) else - LDFLAGS += $(PYTHON_EMBED_LDFLAGS) - EXTLIBS += $(PYTHON_EMBED_LIBADD) PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no") ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes) PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])')
@@ -864,8 +862,6 @@ else else $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent) endif - CFLAGS += -DHAVE_LIBPYTHON_SUPPORT - $(call detected,CONFIG_LIBPYTHON) ifeq ($(filter -fPIC,$(CFLAGS)),) # Building a shared library requires position independent code. CFLAGS += -fPIC
tools/perf/Makefile.perf +2 -5
@@ -1101,11 +1101,8 @@ endif ifndef NO_LIBPYTHON $(call QUIET_INSTALL, python-scripts) \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'; \ - $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \ - $(INSTALL) scripts/python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \ - $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \ + $(INSTALL) python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' endif $(call QUIET_INSTALL, dlfilters) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; \
tools/perf/builtin-check.c +0 -1
@@ -53,7 +53,6 @@ struct feature_status supported_features[] = {FEATURE_STATUS ("libopencsd" ,HAVE_CSTRACE_SUPPORT ),FEATURE_STATUS ("libpfm4" ,HAVE_LIBPFM ), -FEATURE_STATUS ("libpython" ,HAVE_LIBPYTHON_SUPPORT ),FEATURE_STATUS ("libslang" ,HAVE_SLANG_SUPPORT ),FEATURE_STATUS ("libtraceevent" ,HAVE_LIBTRACEEVENT ), FEATURE_STATUS_TIP("libunwind", HAVE_LIBUNWIND_SUPPORT, "Deprecated, use LIBUNWIND=1 and install libunwind-dev[el] to build with it"),
tools/perf/scripts/Build +0 -2
@@ -1,6 +1,4 @@ -perf-util-$(CONFIG_LIBPYTHON) += python/Perf-Trace-Util/ - ifdef MYPY PY_TESTS := $(shell find python -type f -name '*.py') MYPY_TEST_LOGS := $(PY_TESTS:python/%=python/%.mypy_log)
tools/perf/scripts/python/Perf-Trace-Util/Build deleted +0 -4
@@ -1,4 +0,0 @@ -perf-util-y += Context.o - -# -Wno-declaration-after-statement: The python headers have mixed code with declarations (decls after asserts, for instance) -CFLAGS_Context.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs -Wno-declaration-after-statement
tools/perf/scripts/python/Perf-Trace-Util/Context.c deleted +0 -225
225 lines not on this page · raw message
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py deleted +0 -116
116 lines not on this page · raw message
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py deleted +0 -97
97 lines not on this page · raw message
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py deleted +0 -184
184 lines not on this page · raw message
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py deleted +0 -92
92 lines not on this page · raw message
tools/perf/scripts/python/arm-cs-trace-disasm.py deleted +0 -355
355 lines not on this page · raw message
tools/perf/scripts/python/bin/compaction-times-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e compaction:mm_compaction_begin -e compaction:mm_compaction_end -e compaction:mm_compaction_migratepages -e compaction:mm_compaction_isolate_migratepages -e compaction:mm_compaction_isolate_freepages $@
tools/perf/scripts/python/bin/compaction-times-report deleted +0 -4
@@ -1,4 +0,0 @@ -#!/bin/bash -#description: display time taken by mm compaction -#args: [-h] [-u] [-p|-pv] [-t | [-m] [-fs] [-ms]] [pid|pid-range|comm-regex] -perf script -s "$PERF_EXEC_PATH"/scripts/python/compaction-times.py $@
tools/perf/scripts/python/bin/event_analyzing_sample-record deleted +0 -8
@@ -1,8 +0,0 @@ -#!/bin/bash - -# -# event_analyzing_sample.py can cover all type of perf samples including -# the tracepoints, so no special record requirements, just record what -# you want to analyze. -# -perf record $@
tools/perf/scripts/python/bin/event_analyzing_sample-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: analyze all perf samples -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/event_analyzing_sample.py
tools/perf/scripts/python/bin/export-to-postgresql-record deleted +0 -8
@@ -1,8 +0,0 @@ -#!/bin/bash - -# -# export perf data to a postgresql database. Can cover -# perf ip samples (excluding the tracepoints). No special -# record requirements, just record what you want to export. -# -perf record $@
tools/perf/scripts/python/bin/export-to-postgresql-report deleted +0 -29
@@ -1,29 +0,0 @@ -#!/bin/bash -# description: export perf data to a postgresql database -# args: [database name] [columns] [calls] -n_args=0 -for i in "$@" -do - if expr match "$i" "-" > /dev/null ; then - break - fi - n_args=$(( $n_args + 1 )) -done -if [ "$n_args" -gt 3 ] ; then - echo "usage: export-to-postgresql-report [database name] [columns] [calls]" - exit -fi -if [ "$n_args" -gt 2 ] ; then - dbname=$1 - columns=$2 - calls=$3 - shift 3 -elif [ "$n_args" -gt 1 ] ; then - dbname=$1 - columns=$2 - shift 2 -elif [ "$n_args" -gt 0 ] ; then - dbname=$1 - shift -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/export-to-postgresql.py $dbname $columns $calls
tools/perf/scripts/python/bin/export-to-sqlite-record deleted +0 -8
@@ -1,8 +0,0 @@ -#!/bin/bash - -# -# export perf data to a sqlite3 database. Can cover -# perf ip samples (excluding the tracepoints). No special -# record requirements, just record what you want to export. -# -perf record $@
tools/perf/scripts/python/bin/export-to-sqlite-report deleted +0 -29
@@ -1,29 +0,0 @@ -#!/bin/bash -# description: export perf data to a sqlite3 database -# args: [database name] [columns] [calls] -n_args=0 -for i in "$@" -do - if expr match "$i" "-" > /dev/null ; then - break - fi - n_args=$(( $n_args + 1 )) -done -if [ "$n_args" -gt 3 ] ; then - echo "usage: export-to-sqlite-report [database name] [columns] [calls]" - exit -fi -if [ "$n_args" -gt 2 ] ; then - dbname=$1 - columns=$2 - calls=$3 - shift 3 -elif [ "$n_args" -gt 1 ] ; then - dbname=$1 - columns=$2 - shift 2 -elif [ "$n_args" -gt 0 ] ; then - dbname=$1 - shift -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/export-to-sqlite.py $dbname $columns $calls
tools/perf/scripts/python/bin/failed-syscalls-by-pid-record deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -(perf record -e raw_syscalls:sys_exit $@ || \ - perf record -e syscalls:sys_exit $@) 2> /dev/null
tools/perf/scripts/python/bin/failed-syscalls-by-pid-report deleted +0 -10
@@ -1,10 +0,0 @@ -#!/bin/bash -# description: system-wide failed syscalls, by pid -# args: [comm] -if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" > /dev/null ; then - comm=$1 - shift - fi -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/failed-syscalls-by-pid.py $comm
tools/perf/scripts/python/bin/flamegraph-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -g "$@"
tools/perf/scripts/python/bin/flamegraph-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: create flame graphs -perf script -s "$PERF_EXEC_PATH"/scripts/python/flamegraph.py "$@"
tools/perf/scripts/python/bin/futex-contention-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e syscalls:sys_enter_futex -e syscalls:sys_exit_futex $@
tools/perf/scripts/python/bin/futex-contention-report deleted +0 -4
@@ -1,4 +0,0 @@ -#!/bin/bash -# description: futext contention measurement - -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/futex-contention.py
tools/perf/scripts/python/bin/gecko-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -F 99 -g "$@"
tools/perf/scripts/python/bin/gecko-report deleted +0 -7
@@ -1,7 +0,0 @@ -#!/bin/bash -# description: create firefox gecko profile json format from perf.data -if [ "$*" = "-i -" ]; then -perf script -s "$PERF_EXEC_PATH"/scripts/python/gecko.py -else -perf script -s "$PERF_EXEC_PATH"/scripts/python/gecko.py -- "$@" -fi
tools/perf/scripts/python/bin/intel-pt-events-record deleted +0 -13
@@ -1,13 +0,0 @@ -#!/bin/bash - -# -# print Intel PT Events including Power Events and PTWRITE. The intel_pt PMU -# event needs to be specified with appropriate config terms. -# -if ! echo "$@" | grep -q intel_pt ; then - echo "Options must include the Intel PT event e.g. -e intel_pt/pwr_evt,ptw/" - echo "and for power events it probably needs to be system wide i.e. -a option" - echo "For example: -a -e intel_pt/pwr_evt,branch=0/ sleep 1" - exit 1 -fi -perf record $@
tools/perf/scripts/python/bin/intel-pt-events-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: print Intel PT Events including Power Events and PTWRITE -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/intel-pt-events.py
tools/perf/scripts/python/bin/mem-phys-addr-record deleted +0 -19
@@ -1,19 +0,0 @@ -#!/bin/bash - -# -# Profiling physical memory by all retired load instructions/uops event -# MEM_INST_RETIRED.ALL_LOADS or MEM_UOPS_RETIRED.ALL_LOADS -# - -load=`perf list | grep mem_inst_retired.all_loads` -if [ -z "$load" ]; then - load=`perf list | grep mem_uops_retired.all_loads` -fi -if [ -z "$load" ]; then - echo "There is no event to count all retired load instructions/uops." - exit 1 -fi - -arg=$(echo $load | tr -d ' ') -arg="$arg:P" -perf record --phys-data -e $arg $@
tools/perf/scripts/python/bin/mem-phys-addr-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: resolve physical address samples -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/mem-phys-addr.py
tools/perf/scripts/python/bin/net_dropmonitor-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e skb:kfree_skb $@
tools/perf/scripts/python/bin/net_dropmonitor-report deleted +0 -4
@@ -1,4 +0,0 @@ -#!/bin/bash -# description: display a table of dropped frames - -perf script -s "$PERF_EXEC_PATH"/scripts/python/net_dropmonitor.py $@
tools/perf/scripts/python/bin/netdev-times-record deleted +0 -8
@@ -1,8 +0,0 @@ -#!/bin/bash -perf record -e net:net_dev_xmit -e net:net_dev_queue \ - -e net:netif_receive_skb -e net:netif_rx \ - -e skb:consume_skb -e skb:kfree_skb \ - -e skb:skb_copy_datagram_iovec -e napi:napi_poll \ - -e irq:irq_handler_entry -e irq:irq_handler_exit \ - -e irq:softirq_entry -e irq:softirq_exit \ - -e irq:softirq_raise $@
tools/perf/scripts/python/bin/netdev-times-report deleted +0 -5
@@ -1,5 +0,0 @@ -#!/bin/bash -# description: display a process of packet and processing time -# args: [tx] [rx] [dev=] [debug] - -perf script -s "$PERF_EXEC_PATH"/scripts/python/netdev-times.py $@
tools/perf/scripts/python/bin/powerpc-hcalls-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e "{powerpc:hcall_entry,powerpc:hcall_exit}" $@
tools/perf/scripts/python/bin/powerpc-hcalls-report deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/powerpc-hcalls.py
tools/perf/scripts/python/bin/sched-migration-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -m 16384 -e sched:sched_wakeup -e sched:sched_wakeup_new -e sched:sched_switch -e sched:sched_migrate_task $@
tools/perf/scripts/python/bin/sched-migration-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: sched migration overview -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/sched-migration.py
tools/perf/scripts/python/bin/sctop-record deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -(perf record -e raw_syscalls:sys_enter $@ || \ - perf record -e syscalls:sys_enter $@) 2> /dev/null
tools/perf/scripts/python/bin/sctop-report deleted +0 -24
@@ -1,24 +0,0 @@ -#!/bin/bash -# description: syscall top -# args: [comm] [interval] -n_args=0 -for i in "$@" -do - if expr match "$i" "-" > /dev/null ; then - break - fi - n_args=$(( $n_args + 1 )) -done -if [ "$n_args" -gt 2 ] ; then - echo "usage: sctop-report [comm] [interval]" - exit -fi -if [ "$n_args" -gt 1 ] ; then - comm=$1 - interval=$2 - shift 2 -elif [ "$n_args" -gt 0 ] ; then - interval=$1 - shift -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/sctop.py $comm $interval
tools/perf/scripts/python/bin/stackcollapse-record deleted +0 -8
@@ -1,8 +0,0 @@ -#!/bin/sh - -# -# stackcollapse.py can cover all type of perf samples including -# the tracepoints, so no special record requirements, just record what -# you want to analyze. -# -perf record "$@"
tools/perf/scripts/python/bin/stackcollapse-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/sh -# description: produce callgraphs in short form for scripting use -perf script -s "$PERF_EXEC_PATH"/scripts/python/stackcollapse.py "$@"
tools/perf/scripts/python/bin/syscall-counts-by-pid-record deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -(perf record -e raw_syscalls:sys_enter $@ || \ - perf record -e syscalls:sys_enter $@) 2> /dev/null
tools/perf/scripts/python/bin/syscall-counts-by-pid-report deleted +0 -10
@@ -1,10 +0,0 @@ -#!/bin/bash -# description: system-wide syscall counts, by pid -# args: [comm] -if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" > /dev/null ; then - comm=$1 - shift - fi -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/syscall-counts-by-pid.py $comm
tools/perf/scripts/python/bin/syscall-counts-record deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -(perf record -e raw_syscalls:sys_enter $@ || \ - perf record -e syscalls:sys_enter $@) 2> /dev/null
tools/perf/scripts/python/bin/syscall-counts-report deleted +0 -10
@@ -1,10 +0,0 @@ -#!/bin/bash -# description: system-wide syscall counts -# args: [comm] -if [ $# -gt 0 ] ; then - if ! expr match "$1" "-" > /dev/null ; then - comm=$1 - shift - fi -fi -perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/syscall-counts.py $comm
tools/perf/scripts/python/bin/task-analyzer-record deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/bash -perf record -e sched:sched_switch -e sched:sched_migrate_task "$@"
tools/perf/scripts/python/bin/task-analyzer-report deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/bash -# description: analyze timings of tasks -perf script -s "$PERF_EXEC_PATH"/scripts/python/task-analyzer.py -- "$@"
tools/perf/scripts/python/check-perf-trace.py deleted +0 -84
84 lines not on this page · raw message
tools/perf/scripts/python/compaction-times.py deleted +0 -311
311 lines not on this page · raw message
tools/perf/scripts/python/event_analyzing_sample.py deleted +0 -192
192 lines not on this page · raw message
tools/perf/scripts/python/export-to-postgresql.py deleted +0 -1114
1,032 lines not on this page · raw message
tools/perf/scripts/python/export-to-sqlite.py deleted +0 -799
799 lines not on this page · raw message
tools/perf/scripts/python/failed-syscalls-by-pid.py deleted +0 -79
79 lines not on this page · raw message
tools/perf/scripts/python/flamegraph.py deleted +0 -267
267 lines not on this page · raw message
tools/perf/scripts/python/futex-contention.py deleted +0 -57
57 lines not on this page · raw message
tools/perf/scripts/python/gecko.py deleted +0 -395
395 lines not on this page · raw message
tools/perf/scripts/python/intel-pt-events.py deleted +0 -494
494 lines not on this page · raw message
tools/perf/scripts/python/libxed.py deleted +0 -107
107 lines not on this page · raw message
tools/perf/scripts/python/mem-phys-addr.py deleted +0 -127
127 lines not on this page · raw message
tools/perf/scripts/python/net_dropmonitor.py deleted +0 -78
78 lines not on this page · raw message
tools/perf/scripts/python/netdev-times.py deleted +0 -473
473 lines not on this page · raw message
tools/perf/scripts/python/powerpc-hcalls.py deleted +0 -202
202 lines not on this page · raw message
tools/perf/scripts/python/sched-migration.py deleted +0 -462
462 lines not on this page · raw message
tools/perf/scripts/python/sctop.py deleted +0 -89
89 lines not on this page · raw message
tools/perf/scripts/python/stackcollapse.py deleted +0 -127
127 lines not on this page · raw message
tools/perf/scripts/python/stat-cpi.py deleted +0 -79
79 lines not on this page · raw message
tools/perf/scripts/python/syscall-counts-by-pid.py deleted +0 -75
75 lines not on this page · raw message
tools/perf/scripts/python/syscall-counts.py deleted +0 -65
65 lines not on this page · raw message
tools/perf/scripts/python/task-analyzer.py deleted +0 -934
934 lines not on this page · raw message
tools/perf/tests/shell/script_python.sh deleted +0 -113
113 lines not on this page · raw message
tools/perf/util/scripting-engines/Build +1 -7
Lines of this file are not shown. View the raw message.
tools/perf/util/scripting-engines/trace-event-python.c deleted +0 -2209
2,209 lines not on this page · raw message
tools/perf/util/trace-event-scripting.c +1 -13
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Part of the diff is not shown here. View the raw message.
Ian Rogers
reviewerPATCH v6 55/59 perf Makefile: Update Python script installation path
In reply to Ian RogersRemove libpython feature test that is now a python-module feature test. Update references from libpython to python-module accordingly.
Remove references to legacy 'scripts/python' directory and install scripts directly to 'python' directory under libexec. This aligns with the removal of embedded interpreter and move to standalone scripts.
--- tools/build/Makefile.feature | 4 ++-- tools/build/feature/Makefile | 4 ++-- tools/build/feature/test-all.c | 6 +++--- tools/build/feature/test-libpython.c | 10 ---------- tools/build/feature/test-python-module.c | 12 ++++++++++++ tools/perf/Makefile.config | 13 ++++++------- tools/perf/Makefile.perf | 10 ++++------ tools/perf/tests/make | 5 +---- 8 files changed, 30 insertions(+), 34 deletions(-) delete mode 100644 tools/build/feature/test-libpython.c create mode 100644 tools/build/feature/test-python-module.c
tools/build/Makefile.feature +2 -2
@@ -79,7 +79,7 @@ FEATURE_TESTS_BASIC := \ libelf-zstd \ libnuma \ numa_num_possible_cpus \ - libpython \ + python-module \ libslang \ libtraceevent \ libcpupower \
@@ -140,7 +140,7 @@ FEATURE_DISPLAY ?= \ libelf \ libnuma \ numa_num_possible_cpus \ - libpython \ + python-module \ libcapstone \ llvm-perf \ zlib \
tools/build/feature/Makefile +2 -2
@@ -30,7 +30,7 @@ FILES= \ test-libdebuginfod.bin \ test-libnuma.bin \ test-numa_num_possible_cpus.bin \ - test-libpython.bin \ + test-python-module.bin \ test-libslang.bin \ test-libtraceevent.bin \ test-libcpupower.bin \
@@ -252,7 +252,7 @@ $(OUTPUT)test-gtk2-infobar.bin: grep-libs = $(filter -l%,$(1)) strip-libs = $(filter-out -l%,$(1)) -$(OUTPUT)test-libpython.bin: +$(OUTPUT)test-python-module.bin: $(BUILD) $(FLAGS_PYTHON_EMBED) $(OUTPUT)test-libbfd.bin:
tools/build/feature/test-all.c +3 -3
@@ -10,8 +10,8 @@* Quirk: Python headers cannot be in arbitrary places, so keep this testcase at * the top: */ -#define main main_test_libpython -# include "test-libpython.c" +#define main main_test_python_module +# include "test-python-module.c" #undef main#define main main_test_hello
@@ -148,7 +148,7 @@int main (int argc,char *argv[]) { -main_test_libpython (); +main_test_python_module ();main_test_hello ();main_test_libelf ();main_test_gettid ();
tools/build/feature/test-libpython.c deleted +0 -10
@@ -1,10 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <Python.h> - -int main (void ) -{ -Py_Initialize (); - -return 0 ; -} -#undef _GNU_SOURCE
tools/build/feature/test-python-module.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <Python.h> + +int main (void ) +{ +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + }; +PyObject *module =PyModule_Create (&moduledef); + +return module ?0 :-1 ; +}
tools/perf/Makefile.config +6 -7
@@ -317,7 +317,7 @@ PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG)) # Python 3.8 changed the output of `python-config --ldflags` to not include the # '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for -# libpython fails if that flag is not included in LDFLAGS +# python-module fails if that flag is not included in LDFLAGS ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0) PYTHON_CONFIG_LDFLAGS := --ldflags --embed else
@@ -340,8 +340,8 @@ ifdef PYTHON_CONFIG endif endif -FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS) -FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS) +FEATURE_CHECK_CFLAGS-python-module := $(PYTHON_EMBED_CCOPTS) +FEATURE_CHECK_LDFLAGS-python-module := $(PYTHON_EMBED_LDOPTS) FEATURE_CHECK_LDFLAGS-libaio = -lrt
@@ -830,13 +830,12 @@ endif disable-python = $(eval $(disable-python_code)) define disable-python_code - CFLAGS += -DNO_LIBPYTHON $(warning $1) - NO_LIBPYTHON := 1 + NO_PYTHON_MODULE := 1 endef PYTHON_EXTENSION_SUFFIX := '.so' -ifdef NO_LIBPYTHON +ifdef NO_PYTHON_MODULE $(call disable-python,Python support disabled by user) else
@@ -849,7 +848,7 @@ else $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev) else - ifneq ($(feature-libpython), 1) + ifneq ($(feature-python-module), 1) $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev) else PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no")
tools/perf/Makefile.perf +4 -6
@@ -17,9 +17,7 @@ include ../scripts/utilities.mak # # Define CROSS_COMPILE as prefix name of compiler if you want cross-builds. # - -# -# Define NO_LIBPYTHON to disable python script extension. +# Define NO_PYTHON_MODULE to disable python script extension. # # Define PYTHON to point to the python binary if the default # `python' is not correct; for example: PYTHON=python2
@@ -1099,10 +1097,10 @@ endif $(call QUIET_INSTALL, perf-iostat) \ $(INSTALL) $(OUTPUT)perf-iostat -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' -ifndef NO_LIBPYTHON +ifndef NO_PYTHON_MODULE $(call QUIET_INSTALL, python-scripts) \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \ - $(INSTALL) python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/python'; \ + $(INSTALL) python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/python' endif $(call QUIET_INSTALL, dlfilters) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; \
tools/perf/tests/make +1 -4
@@ -75,8 +75,6 @@ make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 make_gen_vmlinux_h := GEN_VMLINUX_H=1 -make_no_libpython := NO_LIBPYTHON=1 -make_no_scripts := NO_LIBPYTHON=1 make_no_slang := NO_SLANG=1 make_no_gtk2 := NO_GTK2=1 make_no_ui := NO_SLANG=1 NO_GTK2=1
@@ -118,7 +116,7 @@ make_install_prefix_slash := install prefix=/tmp/krava/ make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1 # all the NO_* variable combined -make_minimal := NO_LIBPYTHON=1 NO_GTK2=1 +make_minimal := NO_GTK2=1 make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_BACKTRACE=1 make_minimal += NO_LIBNUMA=1 NO_LIBBIONIC=1 NO_LIBDW=1 make_minimal += NO_LIBBPF=1
@@ -150,7 +148,6 @@ run += make_jevents_all run += make_no_bpf_skel run += make_gen_vmlinux_h -run += make_no_libpython run += make_no_scripts run += make_no_slang run += make_no_gtk2
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 55/59] perf Makefile: Update Python script installation path
Sashiko AI review found 2 potential issue(s): - [Medium] Python scripts will silently disappear from the 'perf report' interactive script browser. - [Medium] The `make_no_scripts` and `make_minimal`…
Sashiko AI review found 2 potential issue(s):
- [Medium] Python scripts will silently disappear from the 'perf report' interactive script browser.
- [Medium] The make_no_scripts and make_minimal test targets in tools/perf/tests/make are silently broken, neutering build test coverage. --
commit 097e9f6a5c8c0be76822e797df41c8183e50dce1
Author: Ian Rogers <[email protected]>
perf Makefile: Update Python script installation path
This commit replaces the libpython feature test with a python-module feature test and updates the associated build configuration. It also changes the installation directory for Python scripts from the legacy scripts/python path to a direct python directory under libexec.
Quoted 3 lines
tools/perf/Makefile.perf +0
-0
[ ... ]
tools/perf/Makefile.perf endif · line 1104
Quoted 12 lines
tools/perf/Makefile.perf +3
-3@@ -1099,10 +1097,10 @@ endif $(call QUIET_INSTALL, perf-iostat) \ $(INSTALL) $(OUTPUT)perf-iostat -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' -ifndef NO_LIBPYTHON +ifndef NO_PYTHON_MODULE $(call QUIET_INSTALL, python-scripts) \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \ - $(INSTALL) python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/python'; \ + $(INSTALL) python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/python' endif
Does this regression silently drop Python scripts from the perf report interactive script browser?
Looking at tools/perf/ui/browsers/scripts.c, find_scripts() still hardcodes its search path to scripts/. Because the scripts are now installed directly under python/, the readdir loop will fail to discover them.
Additionally, the same browser code contains:
tools/perf/ui/browsers/scripts.c:find_scripts() {
...
#ifndef HAVE_LIBPYTHON_SUPPORT
if (strstr(lang_dirent->d_name, "python"))
continue;
#endif
...
}Since the libpython feature name was removed and HAVE_LIBPYTHON_SUPPORT is no longer generated, won't this check always trigger, causing the browser to unconditionally ignore Python scripts even if the directory search path were updated?
Quoted 3 lines
tools/perf/tests/make +0
-0
[ ... ]
Quoted 19 lines
tools/perf/tests/make +1
-3@@ -75,8 +75,6 @@ make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 make_gen_vmlinux_h := GEN_VMLINUX_H=1 -make_no_libpython := NO_LIBPYTHON=1 -make_no_scripts := NO_LIBPYTHON=1 make_no_slang := NO_SLANG=1 make_no_gtk2 := NO_GTK2=1 make_no_ui := NO_SLANG=1 NO_GTK2=1@@ -118,7 +116,7 @@ make_install_prefix_slash := install prefix=/tmp/krava/ make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1 # all the NO_* variable combined -make_minimal := NO_LIBPYTHON=1 NO_GTK2=1 +make_minimal := NO_GTK2=1 make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_BACKTRACE=1 make_minimal += NO_LIBNUMA=1 NO_LIBBIONIC=1 NO_LIBDW=1 make_minimal += NO_LIBBPF=1
tools/perf/tests/make run += make_jevents_all · line 151
Quoted 5 lines
tools/perf/tests/make +0
-1@@ -150,7 +148,6 @@ run += make_jevents_all run += make_no_bpf_skel run += make_gen_vmlinux_h -run += make_no_libpython run += make_no_scripts
Because the definition for make_no_scripts was removed, run += make_no_scripts will evaluate to an empty target. Does this regression cause the test harness to silently run a default build without passing NO_PYTHON_MODULE=1?
Similarly, should make_minimal have been updated to include NO_PYTHON_MODULE=1 instead of just dropping NO_LIBPYTHON=1? Without it, the test suite no longer explicitly verifies that perf builds successfully without Python support.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=55
Ian Rogers
reviewerPATCH v6 56/59 perf script: Refactor to support standalone scripts and remove legacy features
In reply to Ian Rogers- Remove -g / --gen-script option as it is no longer needed.
- Hide -s / --script option to imply running standalone scripts directly.
- Update find_script to search in 'python' instead of 'scripts/python'.
- Add support for launching standalone scripts using fork and execvp, skipping the event processing loop.
- Update list_available_scripts to look for .py files directly in 'python' directory.
- Remove all references to scripting_ops and clean up unused functions and variables.
---
v2:
- Fixed strncat buffer overflow: Updated the strncat call in find_script() to correctly use the remaining capacity of the destination buffer instead of sizeof(path) - 1 . The declaration of len was moved to the top of the function to conform to C style guidelines.
- Fixed execvp path searching: If find_script() finds a local file in the current directory without a slash, it now prepends ./ to it. This ensures that execvp() executed by the child process knows to look in the current directory rather than searching the system $PATH .
- Fixed premature loop termination in docstring parsing: Removed a check in read_script_info() that caused the loop to terminate early if any fallback description was found (like an SPDX identifier). This restores the intended behavior of searching the entire header for a better "description:" tag.
- Updated subcommands and usage: Removed "record" and "report" from the usage text and stopped passing them as valid subcommands to parse_options_subcommand() .
- Fixed lost command-line options: Reconstructed the arguments passed to the standalone script to include -i and the input file path, ensuring that the user's choice of input file is not lost.
- Added error message on execvp failure: Added a pr_err call in the child process to print a descriptive error message if execvp() fails to launch the script.
- Fixed uninitialized status in waitpid : Initialized status to 0 and verified that waitpid() successfully returned the child's PID before evaluating its exit status. Also removed unnecessary braces and fixed indentation in that block.
--- tools/perf/builtin-script.c | 767 +++++++++--------------- tools/perf/util/Build | 1 - tools/perf/util/scripting-engines/Build | 1 - tools/perf/util/trace-event-parse.c | 65 -- tools/perf/util/trace-event-scripting.c | 333 ---------- tools/perf/util/trace-event.h | 75 +-- 6 files changed, 294 insertions(+), 948 deletions(-) delete mode 100644 tools/perf/util/scripting-engines/Build delete mode 100644 tools/perf/util/trace-event-scripting.c
tools/perf/builtin-script.c +293 -474
@@ -18,6 +18,7 @@#include <sys/param.h> #include <sys/stat.h> #include <sys/types.h> +#include <sys/wait.h> #include <sys/utsname.h> #include <unistd.h>
@@ -77,7 +78,6 @@#endif static char const *script_name; -static char const *generate_script_lang;static bool reltime;static bool deltatime;static u64 initial_time;
@@ -95,6 +95,7 @@ static int max_blocks;static struct dlfilter *dlfilter;static int dlargc;static char **dlargv; +static unsigned int scripting_max_stack =PERF_MAX_STACK_DEPTH ;enum perf_output_field {PERF_OUTPUT_COMM =1ULL <<0 ,
@@ -1730,6 +1731,143 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample,return printed; } +#define SAMPLE_FLAGS_BUF_SIZE 64 +#define SAMPLE_FLAGS_STR_ALIGNED_SIZE 21 + +static int sample_flags_to_name (u32 flags,char *str,size_t size) +{ +static const struct { +u32 flags; +const char *name; + } sample_flags[] = { + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CALL ,"call" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_RETURN ,"return" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CONDITIONAL ,"jcc" }, + {PERF_IP_FLAG_BRANCH ,"jmp" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CALL |PERF_IP_FLAG_INTERRUPT ,"int" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_RETURN |PERF_IP_FLAG_INTERRUPT ,"iret" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CALL |PERF_IP_FLAG_SYSCALLRET ,"syscall" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_RETURN |PERF_IP_FLAG_SYSCALLRET ,"sysret" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_ASYNC ,"async" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CALL |PERF_IP_FLAG_ASYNC |PERF_IP_FLAG_INTERRUPT , +"hw int" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_TX_ABORT ,"tx abrt" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_TRACE_BEGIN ,"tr strt" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_TRACE_END ,"tr end" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CALL |PERF_IP_FLAG_VMENTRY ,"vmentry" }, + {PERF_IP_FLAG_BRANCH |PERF_IP_FLAG_CALL |PERF_IP_FLAG_VMEXIT ,"vmexit" }, + {0 ,NULL } + }; +static const struct { +u32 flags; +const char *name; + } branch_events[] = { + {PERF_IP_FLAG_BRANCH_MISS ,"miss" }, + {PERF_IP_FLAG_NOT_TAKEN ,"not_taken" }, + {0 ,NULL } + }; +int i; +const char *prefix; +int pos =0 , ret, ev_idx =0 ; +u32 xf = flags &PERF_ADDITIONAL_STATE_MASK ; +u32 types, events; +char xs[16 ] = {0 }; + +/* Clear additional state bits */ + flags &= ~PERF_ADDITIONAL_STATE_MASK ; + +if (flags &PERF_IP_FLAG_TRACE_BEGIN ) + prefix ="tr strt " ; +else if (flags &PERF_IP_FLAG_TRACE_END ) + prefix ="tr end " ; +else + prefix ="" ; + + ret =snprintf (str + pos, size - pos,"%s" , prefix); +if (ret <0 ) +return ret; + pos += ret; + + flags &= ~(PERF_IP_FLAG_TRACE_BEGIN |PERF_IP_FLAG_TRACE_END ); + + types = flags & ~PERF_IP_FLAG_BRANCH_EVENT_MASK ; +for (i =0 ; sample_flags[i].name; i++) { +if (sample_flags[i].flags != types) +continue ; + + ret =snprintf (str + pos, size - pos,"%s" , sample_flags[i].name); +if (ret <0 ) +return ret; + pos += ret; +break ; + } + + events = flags &PERF_IP_FLAG_BRANCH_EVENT_MASK ; +for (i =0 ; branch_events[i].name; i++) { +if (!(branch_events[i].flags & events)) +continue ; + + ret =snprintf (str + pos, size - pos, !ev_idx ?"/%s" :",%s" , + branch_events[i].name); +if (ret <0 ) +return ret; + pos += ret; + ev_idx++; + } + +/* Add an end character '/' for events */ +if (ev_idx) { + ret =snprintf (str + pos, size - pos,"/" ); +if (ret <0 ) +return ret; + pos += ret; + } + +if (!xf) +return pos; + +snprintf (xs,sizeof (xs),"(%s%s%s)" , + flags &PERF_IP_FLAG_IN_TX ?"x" :"" , + flags &PERF_IP_FLAG_INTR_DISABLE ?"D" :"" , + flags &PERF_IP_FLAG_INTR_TOGGLE ?"t" :"" ); + +/* Right align the string if its length is less than the limit */ +if ((pos +strlen (xs)) <SAMPLE_FLAGS_STR_ALIGNED_SIZE ) + ret =snprintf (str + pos, size - pos,"%*s" , + (int )(SAMPLE_FLAGS_STR_ALIGNED_SIZE - ret), xs); +else + ret =snprintf (str + pos, size - pos," %s" , xs); +if (ret <0 ) +return ret; + +return pos + ret; +} + +static int perf_sample__sprintf_flags (u32 flags,char *str,size_t sz) +{ +const char *chars =PERF_IP_FLAG_CHARS ; +const size_t n =strlen (PERF_IP_FLAG_CHARS ); +size_t i, pos =0 ; +int ret; + + ret =sample_flags_to_name (flags, str, sz); +if (ret >0 ) +return ret; + +for (i =0 ; i < n; i++, flags >>=1 ) { +if ((flags &1 ) && pos < sz) + str[pos++] = chars[i]; + } +for (; i <32 ; i++, flags >>=1 ) { +if ((flags &1 ) && pos < sz) + str[pos++] ='?' ; + } +if (pos < sz) + str[pos] =0 ; + +return pos; +} +static int perf_sample__fprintf_flags (u32 flags,FILE *fp) {char str[SAMPLE_FLAGS_BUF_SIZE ];
@@ -2571,8 +2709,6 @@ static void process_event(struct perf_script *script,fflush (fp); } -static struct scripting_ops *scripting_ops; -static void __process_stat (struct evsel *counter,u64 tstamp) {int nthreads =perf_thread_map__nr (counter->core.threads);
@@ -2607,35 +2743,14 @@ static void __process_stat(struct evsel *counter, u64 tstamp)static void process_stat (struct evsel *counter,u64 tstamp) { -if (scripting_ops && scripting_ops->process_stat) - scripting_ops->process_stat (&stat_config, counter, tstamp); -else -__process_stat (counter, tstamp); +__process_stat (counter, tstamp); } -static void process_stat_interval (u64 tstamp) +static void process_stat_interval (u64 tstamp__maybe_unused ) { -if (scripting_ops && scripting_ops->process_stat_interval) - scripting_ops->process_stat_interval (tstamp); } -static void setup_scripting (void ) -{ -setup_python_scripting (); -} - -static int flush_scripting (void ) -{ -return scripting_ops ? scripting_ops->flush_script () :0 ; -} - -static int cleanup_scripting (void ) -{ -pr_debug ("\nperf script stopped\n" ); - -return scripting_ops ? scripting_ops->stop_script () :0 ; -}static bool filter_cpu (struct perf_sample *sample) {
@@ -2708,19 +2823,7 @@ static int process_sample_event(const struct perf_tool *tool, goto out_put; } -if (scripting_ops) { -struct addr_location *addr_al_ptr =NULL ; - -if ((evsel->core.attr.sample_type &PERF_SAMPLE_ADDR ) && -sample_addr_correlates_sym (&evsel->core.attr)) { -if (!addr_al.thread) -thread__resolve (al.thread, &addr_al, sample); - addr_al_ptr = &addr_al; - } - scripting_ops->process_event (event, sample, evsel, &al, addr_al_ptr); - }else { -process_event (scr, sample, evsel, &al, &addr_al, machine); - } +process_event (scr, sample, evsel, &al, &addr_al, machine); out_put:addr_location__exit (&addr_al);
@@ -3029,8 +3132,7 @@ static int process_switch_event(const struct perf_tool *tool,if (perf_event__process_switch (tool, event, sample, machine) <0 )return -1 ; -if (scripting_ops && scripting_ops->process_switch && !filter_cpu (sample)) - scripting_ops->process_switch (event, sample, machine); +if (!script->show_switch_events)return 0 ;
@@ -3039,17 +3141,7 @@ static int process_switch_event(const struct perf_tool *tool, sample->tid); } -static int process_auxtrace_error (const struct perf_tool *tool, -struct perf_session *session, -union perf_event *event) -{ -if (scripting_ops && scripting_ops->process_auxtrace_error) { - scripting_ops->process_auxtrace_error (session, event); -return 0 ; - } -return perf_event__process_auxtrace_error (tool, session, event); -} static int process_lost_event(const struct perf_tool *tool,
@@ -3063,12 +3155,11 @@ process_lost_event(const struct perf_tool *tool,static int process_throttle_event (const struct perf_tool *tool__maybe_unused , -union perf_event *event, -struct perf_sample *sample, -struct machine *machine) +union perf_event *event__maybe_unused , +struct perf_sample *sample__maybe_unused , +struct machine *machine__maybe_unused ) { -if (scripting_ops && scripting_ops->process_throttle) - scripting_ops->process_throttle (event, sample, machine); +return 0 ; }
@@ -3211,10 +3302,9 @@ static int __cmd_script(struct perf_script *script) script->tool.mmap = process_mmap_event; script->tool.mmap2 = process_mmap2_event; } -if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch)) +if (script->show_switch_events) script->tool.context_switch = process_switch_event; -if (scripting_ops && scripting_ops->process_auxtrace_error) - script->tool.auxtrace_error = process_auxtrace_error; + script->tool.auxtrace_error = perf_event__process_auxtrace_error;if (script->show_namespace_events) script->tool.namespaces = process_namespaces_event;if (script->show_cgroup_events)
@@ -3251,96 +3341,55 @@ static int __cmd_script(struct perf_script *script)return ret; } -static int list_available_languages_cb (struct scripting_ops *ops,const char *spec) -{ -fprintf (stderr," %-42s [%s]\n" , spec, ops->name); -return 0 ; -} -static void list_available_languages (void ) -{ -fprintf (stderr,"\n" ); -fprintf (stderr,"Scripting language extensions (used in " -"perf script -s [spec:]script.[spec]):\n\n" ); -script_spec__for_each (&list_available_languages_cb); -fprintf (stderr,"\n" ); -}/* Find script file relative to current directory or exec path */ static char *find_script (const char *script) {char path[PATH_MAX ]; +char *exec_path; +size_t len; -if (!scripting_ops) { -const char *ext =strrchr (script,'.' ); +if (access (script,R_OK ) ==0 ) { +if (!strchr (script,'/' )) { +snprintf (path,sizeof (path),"./%s" , script); + script = path; + } + goto found; + } -if (!ext) -return NULL ; + exec_path =get_argv_exec_path (); +if (!exec_path) +return NULL ; - scripting_ops =script_spec__lookup (++ext); -if (!scripting_ops) -return NULL ; - } +snprintf (path,sizeof (path),"%s/python/%s" , exec_path, script); +free (exec_path); + script = path; -if (access (script,R_OK )) { -char *exec_path =get_argv_exec_path (); +if (access (path,R_OK ) ==0 ) + goto found; -if (!exec_path) -return NULL ; -snprintf (path,sizeof (path),"%s/scripts/%s/%s" , - exec_path, scripting_ops->dirname, script); -free (exec_path); - script = path; -if (access (script,R_OK )) -return NULL ; - } +/* Try with .py suffix. */ + len =strlen (path); + +strncat (path,".py" ,sizeof (path) - len -1 ); + +if (access (script,R_OK ) ==0 ) + goto found; + +/* Failure to find script. */ +return NULL ; + +found:return strdup (script); }static int parse_scriptname (const struct option *opt__maybe_unused ,const char *str,int unset__maybe_unused ) { -char spec[PATH_MAX ]; -const char *script, *ext; -int len; - -if (strcmp (str,"lang" ) ==0 ) { -list_available_languages (); -exit (0 ); - } - - script =strchr (str,':' ); -if (script) { - len = script - str; -if (len >=PATH_MAX ) { -fprintf (stderr,"invalid language specifier" ); -return -1 ; - } -strncpy (spec, str, len); - spec[len] ='\0' ; - scripting_ops =script_spec__lookup (spec); -if (!scripting_ops) { -fprintf (stderr,"invalid language specifier" ); -return -1 ; - } - script++; - }else { - script = str; - ext =strrchr (script,'.' ); -if (!ext) { -fprintf (stderr,"invalid script extension" ); -return -1 ; - } - scripting_ops =script_spec__lookup (++ext); -if (!scripting_ops) { -fprintf (stderr,"invalid script extension" ); -return -1 ; - } - } - - script_name =find_script (script); + script_name =find_script (str);if (!script_name) - script_name =strdup (script); + script_name =strdup (str);return 0 ; }
@@ -3551,16 +3600,18 @@ static struct script_desc *script_desc__new(const char *name)return s; } -static void script_desc__delete (struct script_desc *s) -{ -zfree (&s->name); -zfree (&s->half_liner); -zfree (&s->args); -free (s); -} +static void script_desc__add (struct script_desc *s) { +struct script_desc *pos; + +list_for_each_entry (pos, &script_descs, node) { +if (strcasecmp (s->name, pos->name) <0 ) { +list_add_tail (&s->node, &pos->node); +return ; + } + }list_add_tail (&s->node, &script_descs); }
@@ -3608,15 +3659,57 @@ static int read_script_info(struct script_desc *desc, const char *filename) {char line[BUFSIZ ], *p;FILE *fp; +bool in_docstring = false; +bool found_description = false; fp =fopen (filename,"r" );if (!fp)return -1 ;while (fgets (line,sizeof (line), fp)) { +static const char *const triple_quote_str[] = { +"\"\"\"" , +"'''" , +"r\"\"\"" , + }; p =skip_spaces (line);if (strlen (p) ==0 )continue ; + +if (in_docstring) { +if (strlen (p) && p[strlen (p) -1 ] =='\n' ) + p[strlen (p) -1 ] ='\0' ; + desc->half_liner =strdup (skip_spaces (p)); + in_docstring = false; + found_description = true; +break ; + } + + +for (size_t i =0 ; i <ARRAY_SIZE (triple_quote_str); i++) { +const char *quote = triple_quote_str[i]; + +if (!strstarts (p, quote)) +continue ; + + p +=strlen (quote); + p =skip_spaces (p); +if (strlen (p) >0 ) { +if (p[strlen (p) -1 ] =='\n' ) + p[strlen (p) -1 ] ='\0' ; + p =skip_spaces (p); +if (str_ends_with (p, quote)) + p[strlen (p) -strlen (quote)] ='\0' ; + desc->half_liner =strdup (skip_spaces (p)); + found_description = true; +break ; + } + in_docstring = true; +break ; + } +if (in_docstring) +continue ; +if (*p !='#' )continue ; p++;
@@ -3630,13 +3723,15 @@ static int read_script_info(struct script_desc *desc, const char *filename)if (!strncmp (p,"description:" ,strlen ("description:" ))) { p +=strlen ("description:" ); desc->half_liner =strdup (skip_spaces (p)); -continue ; + found_description = true; +break ; } -if (!strncmp (p,"args:" ,strlen ("args:" ))) { - p +=strlen ("args:" ); - desc->args =strdup (skip_spaces (p)); -continue ; +if (!found_description &&strlen (p) >0 && +strncmp (p,"SPDX-License-Identifier" ,23 )) { + desc->half_liner =strdup (p); + found_description = true; +// Don't break, maybe we find a better "description:" later! } }
@@ -3667,9 +3762,9 @@ static int list_available_scripts(const struct option *opt __maybe_unused, const char *s __maybe_unused, int unset __maybe_unused) { -struct dirent *script_dirent, *lang_dirent; -char *buf, *scripts_path, *script_path, *lang_path, *first_half; -DIR *scripts_dir, *lang_dir; +struct dirent *script_dirent; +char *buf, *scripts_path, *script_path, *first_half; +DIR *scripts_dir;struct script_desc *desc;char *script_root;
@@ -3680,10 +3775,9 @@ static int list_available_scripts(const struct option *opt __maybe_unused, } scripts_path = buf; script_path = buf +MAXPATHLEN ; - lang_path = buf +2 *MAXPATHLEN ; first_half = buf +3 *MAXPATHLEN ; -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); +snprintf (scripts_path,MAXPATHLEN ,"%s/python" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path);if (!scripts_dir) {
@@ -3695,26 +3789,24 @@ static int list_available_scripts(const struct option *opt __maybe_unused,exit (-1 ); } -for_each_lang (scripts_path, scripts_dir, lang_dirent) { -scnprintf (lang_path,MAXPATHLEN ,"%s/%s/bin" , scripts_path, - lang_dirent->d_name); - lang_dir =opendir (lang_path); -if (!lang_dir) -continue ; +while ((script_dirent =readdir (scripts_dir)) !=NULL ) { +if (script_dirent->d_type !=DT_DIR && + (script_dirent->d_type !=DT_UNKNOWN || + !is_directory (scripts_path, script_dirent))) { -for_each_script (lang_path, lang_dir, script_dirent) { - script_root =get_script_root (script_dirent,REPORT_SUFFIX ); + script_root =get_script_root (script_dirent,".py" );if (script_root) { desc =script_desc__findnew (script_root);scnprintf (script_path,MAXPATHLEN ,"%s/%s" , - lang_path, script_dirent->d_name); + scripts_path, script_dirent->d_name);read_script_info (desc, script_path);free (script_root); } } } +closedir (scripts_dir); -fprintf (stdout,"List of available trace scripts:\n" ); +fprintf (stdout,"List of available scripts:\n" );list_for_each_entry (desc, &script_descs, node) {sprintf (first_half,"%s %s" , desc->name, desc->args ? desc->args :"" );
@@ -3754,93 +3846,7 @@ static void free_dlarg(void)free (dlargv); } -static char *get_script_path (const char *script_root,const char *suffix) -{ -struct dirent *script_dirent, *lang_dirent; -char scripts_path[MAXPATHLEN ]; -char script_path[MAXPATHLEN ]; -DIR *scripts_dir, *lang_dir; -char lang_path[MAXPATHLEN ]; -char *__script_root; - -snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); - - scripts_dir =opendir (scripts_path); -if (!scripts_dir) -return NULL ; - -for_each_lang (scripts_path, scripts_dir, lang_dirent) { -scnprintf (lang_path,MAXPATHLEN ,"%s/%s/bin" , scripts_path, - lang_dirent->d_name); - lang_dir =opendir (lang_path); -if (!lang_dir) -continue ; - -for_each_script (lang_path, lang_dir, script_dirent) { - __script_root =get_script_root (script_dirent, suffix); -if (__script_root && !strcmp (script_root, __script_root)) { -free (__script_root); -closedir (scripts_dir); -scnprintf (script_path,MAXPATHLEN ,"%s/%s" , - lang_path, script_dirent->d_name); -closedir (lang_dir); -return strdup (script_path); - } -free (__script_root); - } -closedir (lang_dir); - } -closedir (scripts_dir); - -return NULL ; -} - -static bool is_top_script (const char *script_path) -{ -return ends_with (script_path,"top" ) !=NULL ; -} - -static int has_required_arg (char *script_path) -{ -struct script_desc *desc; -int n_args =0 ; -char *p; - - desc =script_desc__new (NULL ); - -if (read_script_info (desc, script_path)) - goto out; - -if (!desc->args) - goto out; - -for (p = desc->args; *p; p++) -if (*p =='<' ) - n_args++; -out: -script_desc__delete (desc); - -return n_args; -} - -static int have_cmd (int argc,const char **argv) -{ -char **__argv =calloc (argc,sizeof (const char *)); -if (!__argv) { -pr_err ("malloc failed\n" ); -return -1 ; - } - -memcpy (__argv, argv,sizeof (const char *) * argc); - argc =parse_options (argc, (const char **)__argv, record_options, -NULL ,PARSE_OPT_STOP_AT_NON_OPTION ); -free (__argv); - - system_wide = (argc ==0 ); - -return 0 ; -}static void script__setup_sample_type (struct perf_script *script) {
@@ -4026,17 +4032,13 @@ int cmd_script(int argc, const char **argv)bool show_full_info = false;bool header = false;bool header_only = false; -bool script_started = false;bool unsorted_dump = false;bool merge_deferred_callchains = true; -char *rec_script_path =NULL ; -char *rep_script_path =NULL ;struct perf_session *session;struct itrace_synth_opts itrace_synth_opts = { .set = false, .default_no_sample = true, }; -char *script_path =NULL ;const char *dlfilter_file =NULL ;const char **__argv;int i, j, err =0 ;
@@ -4057,11 +4059,10 @@ int cmd_script(int argc, const char **argv) list_available_scripts),OPT_CALLBACK_NOOPT (0 ,"list-dlfilters" ,NULL ,NULL ,"list available dlfilters" , list_available_dlfilters), -OPT_CALLBACK ('s' ,"script" ,NULL ,"name" , -"script file name (lang:script name, script name, or *)" , - parse_scriptname), -OPT_STRING ('g' ,"gen-script" , &generate_script_lang,"lang" , -"generate perf-script.xx script in specified language" ), + { .type = OPTION_CALLBACK, .short_name = 's', .long_name = "script", + .value = NULL, .argh = "name", + .help = "script file name (lang:script name, script name, or *)", + .callback = parse_scriptname, .flags = PARSE_OPT_HIDDEN },OPT_STRING (0 ,"dlfilter" , &dlfilter_file,"file" ,"filter .so file name" ),OPT_CALLBACK (0 ,"dlarg" ,NULL ,"argument" ,"filter argument" , add_dlarg),
@@ -4185,22 +4186,17 @@ int cmd_script(int argc, const char **argv)OPTS_EVSWITCH (&script.evswitch),OPT_END () }; -const char *const script_subcommands[] = {"record" ,"report" ,NULL };const char *script_usage[] = {"perf script [<options>]" , -"perf script [<options>] record <script> [<record-options>] <command>" , -"perf script [<options>] report <script> [script-args]" , -"perf script [<options>] <script> [<record-options>] <command>" , -"perf script [<options>] <top-script> [script-args]" , +"perf script [<options>] <script> [script-args]" ,NULL };struct perf_env *env;perf_set_singlethreaded (); -setup_scripting (); - argc =parse_options_subcommand (argc, argv, options, script_subcommands, script_usage, + argc =parse_options_subcommand (argc, argv, options,NULL , script_usage,PARSE_OPT_STOP_AT_NON_OPTION ); if (symbol_conf.guestmount ||
@@ -4223,21 +4219,7 @@ int cmd_script(int argc, const char **argv)if (symbol__validate_sym_arguments ())return -1 ; -if (argc >1 &&strlen (argv[0 ]) >2 &&strstarts ("record" , argv[0 ])) { - rec_script_path =get_script_path (argv[1 ],RECORD_SUFFIX ); -if (!rec_script_path) -return cmd_record (argc, argv); - } -if (argc >1 &&strlen (argv[0 ]) >2 &&strstarts ("report" , argv[0 ])) { - rep_script_path =get_script_path (argv[1 ],REPORT_SUFFIX ); -if (!rep_script_path) { -fprintf (stderr, -"Please specify a valid report script" -"(see 'perf script -l' for listing)\n" ); -return -1 ; - } - }if (reltime && deltatime) { fprintf(stderr,
@@ -4253,149 +4235,54 @@ int cmd_script(int argc, const char **argv)/* make sure PERF_EXEC_PATH is set for scripts */ set_argv_exec_path (get_argv_exec_path ()); -if (argc && !script_name && !rec_script_path && !rep_script_path) { -int live_pipe[2 ]; -int rep_args; -pid_t pid; - - rec_script_path =get_script_path (argv[0 ],RECORD_SUFFIX ); - rep_script_path =get_script_path (argv[0 ],REPORT_SUFFIX ); - -if (!rec_script_path && !rep_script_path) { - script_name =find_script (argv[0 ]); -if (script_name) { - argc -=1 ; - argv +=1 ; - goto script_found; - } -usage_with_options_msg (script_usage, options, -"Couldn't find script `%s'\n\n See perf" -" script -l for available scripts.\n" , argv[0 ]); - } - -if (is_top_script (argv[0 ])) { - rep_args = argc -1 ; - }else { -int rec_args; - - rep_args =has_required_arg (rep_script_path); - rec_args = (argc -1 ) - rep_args; -if (rec_args <0 ) { -usage_with_options_msg (script_usage, options, -"`%s' script requires options." -"\n\n See perf script -l for available " -"scripts and options.\n" , argv[0 ]); - } +if (argc && !script_name) { + script_name =find_script (argv[0 ]); +if (script_name) { + argc -=1 ; + argv +=1 ; + goto script_found; } +usage_with_options_msg (script_usage, options, +"Couldn't find script `%s'\n\n" +" See perf script -l for available scripts.\n" , argv[0 ]); + } +script_found: -if (pipe (live_pipe) <0 ) { -perror ("failed to create pipe" ); -return -1 ; - } - pid =fork (); +if (script_name) { +pid_t pid =fork ();if (pid <0 ) { -perror ("failed to fork" ); -return -1 ; +pr_err ("failed to fork\n" ); +return -errno; } - -if (!pid) { +if (pid ==0 ) {/* child */ + __argv =calloc (argc +4 ,sizeof (const char *)); j =0 ; - -dup2 (live_pipe[1 ],1 ); -close (live_pipe[0 ]); - -if (is_top_script (argv[0 ])) { - system_wide = true; - }else if (!system_wide) { -if (have_cmd (argc - rep_args, &argv[rep_args]) !=0 ) { - err =-1 ; - goto out; - } - } - - __argv =calloc (argc +6 ,sizeof (const char *));if (!__argv) { -pr_err ("malloc failed\n" ); - err = -ENOMEM ; - goto out; +exit (-ENOMEM ); } - - __argv[j++] ="/bin/sh" ; - __argv[j++] = rec_script_path; -if (system_wide) - __argv[j++] ="-a" ; - __argv[j++] ="-q" ; - __argv[j++] ="-o" ; - __argv[j++] ="-" ; -for (i = rep_args +1 ; i < argc; i++) + __argv[j++] = script_name; +if (input_name) { + __argv[j++] ="-i" ; + __argv[j++] = input_name; + } +for (i =0 ; i < argc; i++) __argv[j++] = argv[i]; __argv[j++] =NULL ; -execvp ("/bin/sh" , (char **)__argv); -free (__argv); -exit (-1 ); - } - -dup2 (live_pipe[0 ],0 ); -close (live_pipe[1 ]); - - __argv =calloc (argc +4 ,sizeof (const char *)); -if (!__argv) { -pr_err ("malloc failed\n" ); - err = -ENOMEM ; - goto out; - } - - j =0 ; - __argv[j++] ="/bin/sh" ; - __argv[j++] = rep_script_path; -for (i =1 ; i < rep_args +1 ; i++) - __argv[j++] = argv[i]; - __argv[j++] ="-i" ; - __argv[j++] ="-" ; - __argv[j++] =NULL ; - -execvp ("/bin/sh" , (char **)__argv); -free (__argv); -exit (-1 ); - } -script_found: -if (rec_script_path) - script_path = rec_script_path; -if (rep_script_path) - script_path = rep_script_path; - -if (script_path) { - j =0 ; - -if (!rec_script_path) - system_wide = false; -else if (!system_wide) { -if (have_cmd (argc -1 , &argv[1 ]) !=0 ) { - err =-1 ; - goto out; +execvp (script_name, (char **)__argv); +pr_err ("failed to execute script '%s': %s\n" , script_name,strerror (errno)); +exit (-errno); + }else {/* parent */ +int status =0 ; + +if (waitpid (pid, &status,0 ) == pid) { +if (WIFEXITED (status)) +return WEXITSTATUS (status); +else +return -1 ; } } - - __argv =calloc (argc +2 ,sizeof (const char *)); -if (!__argv) { -pr_err ("malloc failed\n" ); - err = -ENOMEM ; - goto out; - } - - __argv[j++] ="/bin/sh" ; - __argv[j++] = script_path; -if (system_wide) - __argv[j++] ="-a" ; -for (i =2 ; i < argc; i++) - __argv[j++] = argv[i]; - __argv[j++] =NULL ; - -execvp ("/bin/sh" , (char **)__argv); -free (__argv); -exit (-1 ); }if (dlfilter_file) {
@@ -4487,77 +4374,12 @@ int cmd_script(int argc, const char **argv) goto out_delete; }#endif -if (generate_script_lang) { -struct stat perf_stat; -int input; -char *filename =strdup ("perf-script" ); - -if (output_set_by_user ()) { -fprintf (stderr, -"custom fields not supported for generated scripts" ); - err = -EINVAL ; - goto out_delete; - } - - input =open (data.path,O_RDONLY );/* input_name */ -if (input <0 ) { - err = -errno; -perror ("failed to open file" ); - goto out_delete; - } - - err =fstat (input, &perf_stat); -if (err <0 ) { -perror ("failed to stat file" ); - goto out_delete; - } - -if (!perf_stat.st_size) { -fprintf (stderr,"zero-sized file, nothing to do!\n" ); - goto out_delete; - } - - scripting_ops =script_spec__lookup (generate_script_lang); -if (!scripting_ops &&ends_with (generate_script_lang,".py" )) { - scripting_ops =script_spec__lookup ("python" ); -free (filename); - filename =strdup (generate_script_lang); - filename[strlen (filename) -3 ] ='\0' ; - }else if (!scripting_ops &&ends_with (generate_script_lang,".pl" )) { - scripting_ops =script_spec__lookup ("perl" ); -free (filename); - filename =strdup (generate_script_lang); - filename[strlen (filename) -3 ] ='\0' ; - } -if (!scripting_ops) { -fprintf (stderr,"invalid language specifier '%s'\n" , generate_script_lang); - err = -ENOENT ; - goto out_delete; - } -if (!filename) { - err = -ENOMEM ; - goto out_delete; - } -#ifdef HAVE_LIBTRACEEVENT - err = scripting_ops->generate_script (session->tevent.pevent, filename); -#else - err = scripting_ops->generate_script (NULL , filename); -#endif -free (filename); - goto out_delete; - } err =dlfilter__start (dlfilter, session);if (err) goto out_delete; -if (script_name) { - err = scripting_ops->start_script (script_name, argc, argv, session); -if (err) - goto out_delete; -pr_debug ("perf script started with script %s\n\n" , script_name); - script_started = true; - } + err =perf_session__check_output_opt (session);
@@ -4587,7 +4409,6 @@ int cmd_script(int argc, const char **argv) err =__cmd_script (&script); -flush_scripting ();if (verbose >2 || debug_kmaps)perf_session__dump_kmaps (session);
@@ -4603,10 +4424,8 @@ int cmd_script(int argc, const char **argv)perf_session__delete (session);perf_script__exit (&script); -if (script_started) -cleanup_scripting (); +dlfilter__cleanup (dlfilter);free_dlarg (); -out:return err; }
tools/perf/util/Build +0 -1
@@ -94,7 +94,6 @@ perf-util-y += tool_pmu.o perf-util-y += tp_pmu.o perf-util-y += svghelper.o perf-util-y += trace-event-info.o -perf-util-y += trace-event-scripting.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event-parse.o perf-util-$(CONFIG_LIBTRACEEVENT) += trace-event-read.o
tools/perf/util/scripting-engines/Build deleted +0 -1
@@ -1 +0,0 @@ -# No embedded scripting engines
tools/perf/util/trace-event-parse.c +0 -65
71 lines not on this page · raw message
tools/perf/util/trace-event-scripting.c deleted +0 -333
333 lines not on this page · raw message
tools/perf/util/trace-event.h +1 -74
89 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 56/59] perf script: Refactor to support standalone scripts and remove legacy features
Sashiko AI review found 3 potential issue(s): - [High] Unhandled waitpid() failure causes unintended fallthrough to event processing loop. - [Medium] Memory leak in read_script_info() when…
Sashiko AI review found 3 potential issue(s):
- [High] Unhandled waitpid() failure causes unintended fallthrough to event processing loop.
- [Medium] Memory leak in read_script_info() when overwriting the fallback description.
- [Medium] Command-line filtering options for perf script are silently consumed and ignored when running standalone scripts. --
commit d39e4d4e1bcd11c4942f8ded6ea48c50e2812475
Author: Ian Rogers <[email protected]>
perf script: Refactor to support standalone scripts and remove legacy features
This commit removes the legacy -g/--gen-script option and updates the -s/--script option to imply running standalone scripts directly. It adds support for launching these scripts via fork and execvp while bypassing the normal event processing loop.
Quoted 12 lines
tools/perf/builtin-script.c +2
-1@@ -3630,13 +3723,15 @@ static int read_script_info(struct script_desc *desc, const char *filename)if (!strncmp (p,"description:" ,strlen ("description:" ))) { p +=strlen ("description:" ); desc->half_liner =strdup (skip_spaces (p)); -continue ; + found_description = true; +break ; }
tools/perf/builtin-script.c static int read_script_info(struct script_desc *desc, const char *filename) · line 3735
Quoted 10 lines
tools/perf/builtin-script.c +5
-4-if (!strncmp (p,"args:" ,strlen ("args:" ))) { - p +=strlen ("args:" ); - desc->args =strdup (skip_spaces (p)); -continue ; +if (!found_description &&strlen (p) >0 && +strncmp (p,"SPDX-License-Identifier" ,23 )) { + desc->half_liner =strdup (p); + found_description = true; +// Don't break, maybe we find a better "description:" later! }
Does this leak the desc->half_liner string? If a script has a fallback line that allocates memory here, and then a proper "description:" tag is found later in the loop, it looks like desc->half_liner is overwritten without freeing the original allocation.
[ ... ]
Quoted 4 lines
tools/perf/builtin-script.c +0
-0@@ -4185,22 +4186,17 @@ int cmd_script(int argc, const char **argv)OPTS_EVSWITCH (&script.evswitch), OPT_END() };
[ ... ]
Quoted 3 lines
tools/perf/builtin-script.c +1
-1- argc =parse_options_subcommand (argc, argv, options, script_subcommands, script_usage, + argc =parse_options_subcommand (argc, argv, options,NULL , script_usage,PARSE_OPT_STOP_AT_NON_OPTION );
[ ... ]
Quoted 1 line
tools/perf/builtin-script.c +0
-0@@ -4253,149 +4235,54 @@ int cmd_script(int argc, const char **argv)
[ ... ]
Quoted 13 lines
tools/perf/builtin-script.c +4
-4if (script_name) {pid_t pid =fork ();if (pid <0 ) { -perror ("failed to fork" ); -return -1 ; +pr_err ("failed to fork\n" ); +return -errno; } - -if (!pid) { +if (pid ==0 ) {/* child */ + __argv =calloc (argc +4 ,sizeof (const char *)); j =0 ;
[ ... ]
tools/perf/builtin-script.c int cmd_script(int argc, const char **argv) · line 4273
Quoted 6 lines
tools/perf/builtin-script.c +2
-1+for (i =0 ; i < argc; i++) __argv[j++] = argv[i]; __argv[j++] =NULL ; -execvp ("/bin/sh" , (char **)__argv); +execvp (script_name, (char **)__argv);
Since parse_options_subcommand() was already called earlier in this function, are the parsed command-line options (like --cpu or --time) getting silently discarded?
When running a standalone script, the parent process skips the perf_session event processing loop where these options are normally applied. Because argc and argv are already stripped of these options, the child script won't see them either, which might lead to filtering options being ignored without notifying the user.
tools/perf/builtin-script.c int cmd_script(int argc, const char **argv) · line 4285
Quoted 12 lines
tools/perf/builtin-script.c +10
-0+pr_err ("failed to execute script '%s': %s\n" , script_name,strerror (errno)); +exit (-errno); + }else {/* parent */ +int status =0 ; + +if (waitpid (pid, &status,0 ) == pid) { +if (WIFEXITED (status)) +return WEXITSTATUS (status); +else +return -1 ; } }
What happens if waitpid() is interrupted by a signal, like a terminal resize causing an EINTR error?
If waitpid() returns -1, the condition evaluates to false and the function continues execution instead of returning. This looks like it would inadvertently fall through to initialize a perf_session and process or dump the rest of the data file while the script is still running.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=56
Ian Rogers
reviewerPATCH v6 57/59 perf Documentation: Update for standalone Python scripts and remove obsolete data
In reply to Ian Rogers- Remove documentation for -g and -s options in perf-script.txt.
- Remove links to perf-script-perl in perf-script.txt.
- Rewrite perf-script-python.txt to describe the new standalone script usage with perf module.
- Remove obsolete perf-script-perl.txt.
v6:
- Updated perf-script-python.txt to use indented code blocks to fix man page formatting, and documented find_thread and elf_machine.
--- tools/perf/Documentation/perf-script-perl.txt | 216 ------ .../perf/Documentation/perf-script-python.txt | 713 +++--------------- tools/perf/Documentation/perf-script.txt | 70 +- 3 files changed, 96 insertions(+), 903 deletions(-) delete mode 100644 tools/perf/Documentation/perf-script-perl.txt
tools/perf/Documentation/perf-script-perl.txt deleted +0 -216
@@ -1,216 +0,0 @@ -perf-script-perl(1) -=================== - -NAME ----- -perf-script-perl - Process trace data with a Perl script - -SYNOPSIS --------- -[verse] -'perf script' [-s [Perl]:script[.pl] ] - -DESCRIPTION ------------ - -This perf script option is used to process perf script data using perf's -built-in Perl interpreter. It reads and processes the input file and -displays the results of the trace analysis implemented in the given -Perl script, if any. - -STARTER SCRIPTS ---------------- - -You can avoid reading the rest of this document by running 'perf script --g perl' in the same directory as an existing perf.data trace file. -That will generate a starter script containing a handler for each of -the event types in the trace file; it simply prints every available -field for each event in the trace file. - -You can also look at the existing scripts in -~/libexec/perf-core/scripts/perl for typical examples showing how to -do basic things like aggregate event data, print results, etc. Also, -the check-perf-script.pl script, while not interesting for its results, -attempts to exercise all of the main scripting features. - -EVENT HANDLERS --------------- - -When perf script is invoked using a trace script, a user-defined -'handler function' is called for each event in the trace. If there's -no handler function defined for a given event type, the event is -ignored (or passed to a 'trace_unhandled' function, see below) and the -next event is processed. - -Most of the event's field values are passed as arguments to the -handler function; some of the less common ones aren't - those are -available as calls back into the perf executable (see below). - -As an example, the following perf record command can be used to record -all sched_wakeup events in the system: - - # perf record -a -e sched:sched_wakeup - -Traces meant to be processed using a script should be recorded with -the above option: -a to enable system-wide collection. - -The format file for the sched_wakeup event defines the following fields -(see /sys/kernel/tracing/events/sched/sched_wakeup/format): - ----- - format: - field:unsigned short common_type; - field:unsigned char common_flags; - field:unsigned char common_preempt_count; - field:int common_pid; - - field:char comm[TASK_COMM_LEN]; - field:pid_t pid; - field:int prio; - field:int success; - field:int target_cpu; ----- - -The handler function for this event would be defined as: - ----- -sub sched::sched_wakeup -{ - my ($event_name, $context, $common_cpu, $common_secs, - $common_nsecs, $common_pid, $common_comm, - $comm, $pid, $prio, $success, $target_cpu) = @_; -} ----- - -The handler function takes the form subsystem::event_name. - -The $common_* arguments in the handler's argument list are the set of -arguments passed to all event handlers; some of the fields correspond -to the common_* fields in the format file, but some are synthesized, -and some of the common_* fields aren't common enough to to be passed -to every event as arguments but are available as library functions. - -Here's a brief description of each of the invariant event args: - - $event_name the name of the event as text - $context an opaque 'cookie' used in calls back into perf - $common_cpu the cpu the event occurred on - $common_secs the secs portion of the event timestamp - $common_nsecs the nsecs portion of the event timestamp - $common_pid the pid of the current task - $common_comm the name of the current process - -All of the remaining fields in the event's format file have -counterparts as handler function arguments of the same name, as can be -seen in the example above. - -The above provides the basics needed to directly access every field of -every event in a trace, which covers 90% of what you need to know to -write a useful trace script. The sections below cover the rest. - -SCRIPT LAYOUT -------------- - -Every perf script Perl script should start by setting up a Perl module -search path and 'use'ing a few support modules (see module -descriptions below): - ----- - use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib"; - use lib "./Perf-Trace-Util/lib"; - use Perf::Trace::Core; - use Perf::Trace::Context; - use Perf::Trace::Util; ----- - -The rest of the script can contain handler functions and support -functions in any order. - -Aside from the event handler functions discussed above, every script -can implement a set of optional functions: - -*trace_begin*, if defined, is called before any event is processed and -gives scripts a chance to do setup tasks: - ----- - sub trace_begin - { - } ----- - -*trace_end*, if defined, is called after all events have been - processed and gives scripts a chance to do end-of-script tasks, such - as display results: - ----- -sub trace_end -{ -} ----- - -*trace_unhandled*, if defined, is called after for any event that - doesn't have a handler explicitly defined for it. The standard set - of common arguments are passed into it: - ----- -sub trace_unhandled -{ - my ($event_name, $context, $common_cpu, $common_secs, - $common_nsecs, $common_pid, $common_comm) = @_; -} ----- - -The remaining sections provide descriptions of each of the available -built-in perf script Perl modules and their associated functions. - -AVAILABLE MODULES AND FUNCTIONS -------------------------------- - -The following sections describe the functions and variables available -via the various Perf::Trace::* Perl modules. To use the functions and -variables from the given module, add the corresponding 'use -Perf::Trace::XXX' line to your perf script script. - -Perf::Trace::Core Module -~~~~~~~~~~~~~~~~~~~~~~~~ - -These functions provide some essential functions to user scripts. - -The *flag_str* and *symbol_str* functions provide human-readable -strings for flag and symbolic fields. These correspond to the strings -and values parsed from the 'print fmt' fields of the event format -files: - - flag_str($event_name, $field_name, $field_value) - returns the string representation corresponding to $field_value for the flag field $field_name of event $event_name - symbol_str($event_name, $field_name, $field_value) - returns the string representation corresponding to $field_value for the symbolic field $field_name of event $event_name - -Perf::Trace::Context Module -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Some of the 'common' fields in the event format file aren't all that -common, but need to be made accessible to user scripts nonetheless. - -Perf::Trace::Context defines a set of functions that can be used to -access this data in the context of the current event. Each of these -functions expects a $context variable, which is the same as the -$context variable passed into every event handler as the second -argument. - - common_pc($context) - returns common_preempt count for the current event - common_flags($context) - returns common_flags for the current event - common_lock_depth($context) - returns common_lock_depth for the current event - -Perf::Trace::Util Module -~~~~~~~~~~~~~~~~~~~~~~~~ - -Various utility functions for use with perf script: - - nsecs($secs, $nsecs) - returns total nsecs given secs/nsecs pair - nsecs_secs($nsecs) - returns whole secs portion given nsecs - nsecs_nsecs($nsecs) - returns nsecs remainder given nsecs - nsecs_str($nsecs) - returns printable string in the form secs.nsecs - avg($total, $n) - returns average given a sum and a total number of values - -SEE ALSO --------- -linkperf:perf-script[1]
tools/perf/Documentation/perf-script-python.txt +90 -623
766 lines not on this page · raw message
tools/perf/Documentation/perf-script.txt +6 -64
92 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v6 58/59 perf python: Improve perf script -l descriptions
In reply to Ian RogersImprove the description when running "perf script -l":
``` $ perf script -l List of available scripts: ... counting Example for counting perf events. ... exported-sql-viewer exported-sql-viewer.py: view data from sql database. ... tracepoint Example showing how to enable a tracepoint and access its fields. twatch Example to show how to enable a tracepoint and access its fields. ... ```
--- tools/perf/python/counting.py | 1 + tools/perf/python/exported-sql-viewer.py | 2 +- tools/perf/python/tracepoint.py | 1 + tools/perf/python/twatch.py | 1 + 4 files changed, 4 insertions(+), 1 deletion(-)
tools/perf/python/counting.py +1 -0
@@ -1,5 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +"""Example for counting perf events.""" # -*- python -*- # -*- coding: utf-8 -*-
tools/perf/python/exported-sql-viewer.py +1 -1
@@ -1,6 +1,6 @@ #!/usr/bin/env python # SPDX-License-Identifier: GPL-2.0 -# exported-sql-viewer.py: view data from sql database +"""exported-sql-viewer.py: view data from sql database.""" # Copyright (c) 2014-2018, Intel Corporation. # To use this script you will need to have exported data using either the
tools/perf/python/tracepoint.py +1 -0
@@ -1,5 +1,6 @@ #! /usr/bin/env python # SPDX-License-Identifier: GPL-2.0 +"""Example showing how to enable a tracepoint and access its fields.""" # -*- python -*- # -*- coding: utf-8 -*-
tools/perf/python/twatch.py +1 -0
@@ -1,5 +1,6 @@ #! /usr/bin/env python # SPDX-License-Identifier: GPL-2.0-only +"""Example to show how to enable a tracepoint and access its fields.""" # -*- python -*- # -*- coding: utf-8 -*- # twatch - Experimental use of the perf python interface
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v6 59/59 perf sched stats: Fix segmentation faults in diff mode
In reply to Ian RogersAddress several segmentation fault vectors in perf sched stats diff:
1. When processing invalid or empty data files, the CPU domain maps may be NULL. Added NULL checks for cd_map1 and cd_map2 in show_schedstat_data() to fail gracefully.
2. When files contain a different number of CPUs or domains, the parallel list iteration in show_schedstat_data() could wrap around the list heads and dereference invalid memory. Added list_is_last checks to safely terminate iteration at the end of each list.
3. When summarizing CPU statistics in get_all_cpu_stats(), parallel list iteration over domains could similarly wrap around if a CPU has more domains than the first CPU. Added list_is_last check to prevent this.
4. Added bounds checks for cs1->cpu and cs2->cpu against nr1 and nr2 (passed from env->nr_cpus_avail) to prevent out-of-bounds reads from cd_map1 and cd_map2 when processing data from machines with different CPU configurations.
5. Added NULL checks for cd_info1 and cd_info2 in show_schedstat_data() to prevent crashes when a CPU has samples in the data file but no corresponding domain info in the header (which leaves the map entry NULL).
6. Added NULL checks for dinfo1 and dinfo2 in show_schedstat_data() to prevent crashes when a domain is present in the list but has no corresponding info in the CPU domain map (which leaves the entry NULL).
7. Zero-initialized the perf_data array in perf_sched__schedstat_diff() to prevent stack garbage from causing perf_data_file__fd() to attempt to use a NULL fptr when use_stdio happened to be non-zero.
--- tools/perf/builtin-sched.c | 85 +++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 16 deletions(-)
tools/perf/builtin-sched.c +69 -16
@@ -4212,12 +4212,20 @@ static int get_all_cpu_stats(struct list_head *head) cnt++;summarize_schedstat_cpu (summary_head, cptr, cnt, is_last); - tdptr = list_first_entry(&summary_head->domain_head, struct schedstat_domain, - domain_list); +if (!list_empty (&summary_head->domain_head)) + tdptr = list_first_entry(&summary_head->domain_head, struct schedstat_domain, + domain_list); +else + tdptr =NULL ;list_for_each_entry (dptr, &cptr->domain_head, domain_list) { -summarize_schedstat_domain (tdptr, dptr, cnt, is_last); - tdptr =list_next_entry (tdptr, domain_list); +if (tdptr) { +summarize_schedstat_domain (tdptr, dptr, cnt, is_last); +if (list_is_last (&tdptr->domain_list, &summary_head->domain_head)) + tdptr =NULL ; +else + tdptr =list_next_entry (tdptr, domain_list); + } } }
@@ -4225,8 +4233,8 @@ static int get_all_cpu_stats(struct list_head *head)return ret; } -static int show_schedstat_data (struct list_head *head1,struct cpu_domain_map **cd_map1, -struct list_head *head2,struct cpu_domain_map **cd_map2, +static int show_schedstat_data (struct list_head *head1,struct cpu_domain_map **cd_map1,int nr1, +struct list_head *head2,struct cpu_domain_map **cd_map2,int nr2,bool summary_only) { struct schedstat_cpu *cptr1 = list_first_entry(head1, struct schedstat_cpu, cpu_list);
@@ -4238,6 +4246,15 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **bool is_summary = true;int ret =0 ; +if (!cd_map1) { +pr_err ("Error: CPU domain map 1 is missing.\n" ); +return -1 ; + } +if (head2 && !cd_map2) { +pr_err ("Error: CPU domain map 2 is missing.\n" ); +return -1 ; + } +printf ("Description\n" );print_separator2 (SEP_LEN ,"" ,0 );printf ("%-30s-> %s\n" ,"DESC" ,"Description of the field" );
@@ -4269,12 +4286,31 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **struct cpu_domain_map *cd_info1 =NULL , *cd_info2 =NULL ; cs1 = cptr1->cpu_data; +if (cs1->cpu >= (u32 )nr1) { +pr_err ("Error: CPU %d exceeds domain map size %d\n" , cs1->cpu, nr1); +return -1 ; + } cd_info1 = cd_map1[cs1->cpu]; +if (!cd_info1) { +pr_err ("Error: CPU %d domain info is missing in map 1.\n" , cs1->cpu); +return -1 ; + }if (cptr2) { cs2 = cptr2->cpu_data; +if (cs2->cpu >= (u32 )nr2) { +pr_err ("Error: CPU %d exceeds domain map size %d\n" , cs2->cpu, nr2); +return -1 ; + } cd_info2 = cd_map2[cs2->cpu]; - dptr2 = list_first_entry(&cptr2->domain_head, struct schedstat_domain, - domain_list); +if (!cd_info2) { +pr_err ("Error: CPU %d domain info is missing in map 2.\n" , cs2->cpu); +return -1 ; + } +if (!list_empty (&cptr2->domain_head)) + dptr2 = list_first_entry(&cptr2->domain_head, struct schedstat_domain, + domain_list); +else + dptr2 =NULL ; }if (cs2 && cs1->cpu != cs2->cpu) {
@@ -4303,9 +4339,17 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map ** ds1 = dptr1->domain_data; dinfo1 = cd_info1->domains[ds1->domain]; +if (!dinfo1) { +pr_err ("Error: Domain %d info is missing for CPU %d in map 1.\n" , ds1->domain, cs1->cpu); +return -1 ; + }if (dptr2) { ds2 = dptr2->domain_data; dinfo2 = cd_info2->domains[ds2->domain]; +if (!dinfo2) { +pr_err ("Error: Domain %d info is missing for CPU %d in map 2.\n" , ds2->domain, cs2->cpu); +return -1 ; + } }if (dinfo2 && dinfo1->domain != dinfo2->domain) {
@@ -4334,14 +4378,22 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **print_domain_stats (ds1, ds2, jiffies1, jiffies2);print_separator2 (SEP_LEN ,"" ,0 ); -if (dptr2) - dptr2 =list_next_entry (dptr2, domain_list); +if (dptr2) { +if (list_is_last (&dptr2->domain_list, &cptr2->domain_head)) + dptr2 =NULL ; +else + dptr2 =list_next_entry (dptr2, domain_list); + } }if (summary_only)break ; -if (cptr2) - cptr2 =list_next_entry (cptr2, cpu_list); +if (cptr2) { +if (list_is_last (&cptr2->cpu_list, head2)) + cptr2 =NULL ; +else + cptr2 =list_next_entry (cptr2, cpu_list); + } is_summary = false; }
@@ -4523,7 +4575,7 @@ static int perf_sched__schedstat_report(struct perf_sched *sched) } cd_map = session->header.env.cpu_domain; - err =show_schedstat_data (&cpu_head, cd_map,NULL ,NULL , false); + err =show_schedstat_data (&cpu_head, cd_map, session->header.env.nr_cpus_avail,NULL ,NULL ,0 , false); } out:
@@ -4538,7 +4590,7 @@ static int perf_sched__schedstat_diff(struct perf_sched *sched,struct cpu_domain_map **cd_map0 =NULL , **cd_map1 =NULL ;struct list_head cpu_head_ses0, cpu_head_ses1;struct perf_session *session[2 ]; -struct perf_data data[2 ]; +struct perf_data data[2 ] = {0 };int ret =0 , err =0 ;static const char *defaults[] = {"perf.data.old" ,
@@ -4610,7 +4662,8 @@ static int perf_sched__schedstat_diff(struct perf_sched *sched, goto out_delete_ses0; } -show_schedstat_data (&cpu_head_ses0, cd_map0, &cpu_head_ses1, cd_map1, true); +show_schedstat_data (&cpu_head_ses0, cd_map0, session[0 ]->header.env.nr_cpus_avail, + &cpu_head_ses1, cd_map1, session[1 ]->header.env.nr_cpus_avail, true); out_delete_ses1:free_schedstat (&cpu_head_ses1);
@@ -4720,7 +4773,7 @@ static int perf_sched__schedstat_live(struct perf_sched *sched, goto out; } -show_schedstat_data (&cpu_head, cd_map,NULL ,NULL , false); +show_schedstat_data (&cpu_head, cd_map, nr,NULL ,NULL ,0 , false);free_cpu_domain_info (cd_map, sv, nr); out:free_schedstat (&cpu_head);
Signature · 1 line
2.54.0.545.g6539524ca2-goog
[email protected]
AI reviewRe: [PATCH v6 59/59] perf sched stats: Fix segmentation faults in diff mode
Sashiko AI review found 2 potential issue(s): - [High] Stale `cs2` and `ds2` pointers lead to incorrect diff computation and spurious failures when iterating lists of unequal lengths. - [High]…
Sashiko AI review found 2 potential issue(s):
- [High] Stale cs2 and ds2 pointers lead to incorrect diff computation and spurious failures when iterating lists of unequal lengths.
- [High] Missing bounds check on untrusted domain indices leads to out-of-bounds array reads.
--
commit 81cf4f4c4c1266ce2e1faa604bb84ef9cfc8657f
Author: Ian Rogers <[email protected]>
perf sched stats: Fix segmentation faults in diff mode
This commit addresses several segmentation fault vectors in perf sched stats diff mode. It adds NULL checks for CPU domain maps, uses list_is_last to prevent list iteration wraparound, and adds bounds checks for CPU IDs to handle files with varying CPU configurations.
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0
[ ... ]
Quoted 24 lines
tools/perf/builtin-sched.c +14
-2@@ -4269,12 +4286,31 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **struct cpu_domain_map *cd_info1 =NULL , *cd_info2 =NULL ; cs1 = cptr1->cpu_data; +if (cs1->cpu >= (u32 )nr1) { +pr_err ("Error: CPU %d exceeds domain map size %d\n" , cs1->cpu, nr1); +return -1 ; + } cd_info1 = cd_map1[cs1->cpu]; +if (!cd_info1) { +pr_err ("Error: CPU %d domain info is missing in map 1.\n" , cs1->cpu); +return -1 ; + }if (cptr2) { cs2 = cptr2->cpu_data; +if (cs2->cpu >= (u32 )nr2) { +pr_err ("Error: CPU %d exceeds domain map size %d\n" , cs2->cpu, nr2); +return -1 ; + } cd_info2 = cd_map2[cs2->cpu]; - dptr2 = list_first_entry(&cptr2->domain_head, struct schedstat_domain, - domain_list); +if (!cd_info2) { +pr_err ("Error: CPU %d domain info is missing in map 2.\n" , cs2->cpu);
tools/perf/builtin-sched.c static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map ** · line 4316
Quoted 10 lines
tools/perf/builtin-sched.c +7
-0+return -1 ; + } +if (!list_empty (&cptr2->domain_head)) + dptr2 = list_first_entry(&cptr2->domain_head, struct schedstat_domain, + domain_list); +else + dptr2 =NULL ; }if (cs2 && cs1->cpu != cs2->cpu) {
When cptr2 becomes NULL because the second list is shorter, cs2 is not reset to NULL at the start of the loop.
Could this cause the check here to spuriously fail and abort the diff because cs2 retains the pointer from the previous iteration?
[ ... ]
tools/perf/builtin-sched.c static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map ** · line 4341
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0@@ -4303,9 +4339,17 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map ** ds1 = dptr1->domain_data; dinfo1 = cd_info1->domains[ds1->domain];
This patch adds bounds checking for the CPU IDs, but ds1->domain is read from the data file and used directly as an array index here.
Should we also add bounds checking against cd_info1->nr_domains to prevent out-of-bounds reads if the domain index is invalid?
Quoted 14 lines
tools/perf/builtin-sched.c +8
-0+if (!dinfo1) { +pr_err ("Error: Domain %d info is missing for CPU %d in map 1.\n" , ds1->domain, cs1->cpu); +return -1 ; + }if (dptr2) { ds2 = dptr2->domain_data; dinfo2 = cd_info2->domains[ds2->domain]; +if (!dinfo2) { +pr_err ("Error: Domain %d info is missing for CPU %d in map 2.\n" , ds2->domain, cs2->cpu); +return -1 ; + } }if (dinfo2 && dinfo1->domain != dinfo2->domain) {
[ ... ]
tools/perf/builtin-sched.c static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map ** · line 4378
Quoted 2 lines
tools/perf/builtin-sched.c +0
-0@@ -4334,14 +4378,22 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **print_domain_stats (ds1, ds2, jiffies1, jiffies2);
Similarly, if dptr2 becomes NULL because the second file has fewer domains, ds2 is not reset to NULL inside the domain iteration loop.
Does this result in print_domain_stats() computing diffs using stale ds2 data from the previous domain instead of handling the domain as missing?
Quoted 11 lines
tools/perf/builtin-sched.c +6
-2print_separator2 (SEP_LEN ,"" ,0 ); -if (dptr2) - dptr2 =list_next_entry (dptr2, domain_list); +if (dptr2) { +if (list_is_last (&dptr2->domain_list, &cptr2->domain_head)) + dptr2 =NULL ; +else + dptr2 =list_next_entry (dptr2, domain_list); + } }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=59
Ian Rogers
reviewerv7 cover perf: Reorganize scripting support
In reply to Ian RogersThe perf script command has long supported running Python and Perl scripts by embedding libpython and libperl. This approach has several drawbacks:
- overhead by creating Python dictionaries for every event (whether used or not),
- complex build dependencies on specific Python/Perl versions,
- complications with threading due to perf being the interpreter,
- no clear way to run standalone scripts like ilist.py.
This series takes a different approach with some initial implementation posted as an RFC last October:
https://lore.kernel.org/linux-perf-users/[email protected]/
with the motivation coming up on the mailing list earlier:
https://lore.kernel.org/lkml/CAP-5=fWDqE8SYfOLZkg_0=4Ayx6E7O+h7uUp4NDeCFkiN4b7-w@mail.gmail.com/
The changes remove the embedded libpython and libperl support from perf entirely. Instead, they expand the existing perf Python module to provide full access to perf data files and events, allowing scripts to be run as standalone Python applications.
To demonstrate the benefits, we ported all existing Python and Perl scripts to use the new Python session API. The performance improvement is dramatic. For example, porting mem-phys-addr.py:
Before (using embedded libpython in perf script):
``` $ perf mem record a sleep 1 $ time perf script tools/perf/scripts/python/mem-phys-addr.py Event: cpu_core/mem-loads-aux/ Memory type count percentage --------------------------------------- ---------- ---------- 0-fff : Reserved 3217 100.0 real 0m3.754s user 0m0.023s sys 0m0.018s ```
After (using standalone Python script with perf module):
``` $ PYTHONPATH=/tmp/perf/python time python3 tools/perf/python/mem-phys-addr.py Event: evsel(cpu_core/mem-loads-aux/) Memory type count percentage --------------------------------------- ---------- ---------- 0-fff : Reserved 3217 100.0 real 0m0.106s user 0m0.021s sys 0m0.020s ```
This is a roughly 35x speedup!
The change is large (11291 insertions, 15964 deletions, net 4673 deletions) due to porting all existing perl and python code to the new API. Gemini was used to achieve this and to improve the code quality. Removing support may be controversial, however, the first 52 patches are additive and merging those would allow us to focus on the remaining 6 patches that finalize the new perf script behavior.
---
v7 Changes
----------
- Fixed heap out-of-bounds in pyrf_event__new by adding comprehensive size checks for all event types.
- Fixed undefined symbol syscalltbl__id when building without libtraceevent by making syscalltbl.o unconditional in Build.
- Fixed several issues in python.c:
- Handled NULL return from thread__comm_str in pyrf_thread__comm.
- Avoided swallowing exceptions in module initialization.
- Added custom tp_new methods for evlist, evsel, and data types to zero-initialize pointers and avoid crashes on re-initialization.
- Fixed lower priority review comments:
- Avoided permanent iterator exhaustion on brstack in perf_brstack_max.py by converting it to a list.
- Removed dead code (unused self.unhandled dictionary) in failed-syscalls-by-pid.py.
v6 Changes
----------
- Refactored pyrf_event__new to take evsel and session arguments, and use dynamic allocation based on the actual event size to improve memory safety and efficiency.
- Moved callchain and branch stack resolution logic from pyrf_session_tool__sample into pyrf_event__new, centralizing initialization.
- Added an optional keyword-only elf_machine argument to syscall_name and syscall_id functions to allow specifying non-host architectures, defaulting to EM_HOST.
- Renamed process method to find_thread in the Python API and C implementation for better intention-revealing naming.
- Fixed a terminal injection vulnerability in flamegraph.py by not printing unverified downloaded content in the prompt.
- Fixed CWD exposure and symlink attack risks in gecko.py by using a secure temporary directory for the HTTP server.
- Fixed a severe performance issue in event_analyzing_sample.py by removing SQLite autocommit mode and batching commits.
- Fixed AttributeError crashes in rw-by-file.py and rw-by-pid.py by correctly extracting event names.
- Fixed man page formatting issues in perf-script-python.txt by using indented code blocks.
- Updated perf.pyi stubs file to reflect all API changes.
- Verified all commit messages with checkpatch.pl and ensured lines are wrapped appropriately.
- Fixed segmentation faults in perf sched stats in diff mode.
v5 Changes
----------
Resending due to partial send of v4 due to a quota limit.
v4 Changes
----------
1. Git Fixup Cleanups
- Squashed the lingering fixup! commit remaining from the previous session back into perf check-perf-trace: Port check-perf-trace to use python module.
v3 Changes
----------
1. Memory Safety & Reference Counting Fixes
- Stored transient mmap event data inside the Python object's permanent pevent->event and invoked evsel__parse_sample() to safely point attributes into it, resolving Use-After-Free vulnerabilities.
- Nullified sample->evsel after calling evsel__put() in perf_sample__exit() to protect against potential refcount double-put crashes in error paths.
- Reordered operations inside evlist__remove() to invoke perf_evlist__remove() before reference release.
- Patched an evsel reference leak inside evlist__deliver_deferred_callchain().
2. Sashiko AI Review Cleanups
- Corrected the broken event name equality check in gecko.py to search for a substring match within the parsed event string.
- Fixed a latent AttributeError crash in task-analyzer.py by properly assigning the session instance.
- Safeguarded thread reporting in check-perf-trace.py by utilizing sample_tid instead of sample_pid, and wrapping the session thread resolution in a try-except block.
3. Omitted Minor Issues
- The minor review comments (such as permanent iterator exhaustion on brstack, or dead-code in failed-syscalls-by-pid.py) have been omitted because they do not affect correctness, lead to crashes, or require significant architectural rework.
v2 Changes
----------
1. String Match and Event Name Accuracy
- Replaced loose substring event matching across the script suite with exact matches or specific prefix constraints (syscalls:sys_exit_, evsel(skb:kfree_skb), etc.).
- Added getattr() safety checks to prevent script failures caused by unresolved attributes from older kernel traces.
2. OOM and Memory Protections
- Refactored netdev-times.py to compute and process network statistics chronologically on-the-fly, eliminating an unbounded in-memory list that caused Out-Of-Memory crashes on large files.
- Implemented threshold limits on intel-pt-events.py to cap memory allocation during event interleaving.
- Optimized export-to-sqlite.py to periodically commit database transactions (every 10,000 samples) to reduce temporary SQLite journal sizes.
3. Portability & Environment Independence
- Re-keyed internal tracking dictionaries in scripts like powerpc-hcalls.py to use thread PIDs instead of CPUs, ensuring correctness when threads migrate.
- Switched net_dropmonitor.py from host-specific /proc/kallsyms parsing to perf's built-in symbol resolution API.
- Added the --iomem parameter to mem-phys-addr.py to support offline analysis of data collected on different architectures.
4. Standalone Scripting Improvements
- Patched builtin-script.c to ensure --input parameters are successfully passed down to standalone execution pipelines via execvp().
- Guarded against string buffer overflows during .py extension path resolving.
5. Code Cleanups
- Removed stale perl subdirectories from being detected by the TUI script browser.
- Ran the entire script suite through mypy and pylint to achieve strict static type checking and resolve unreferenced variables.
Ian Rogers (59):
perf inject: Fix itrace branch stack synthesis
perf arch arm: Sort includes and add missed explicit dependencies perf arch x86: Sort includes and add missed explicit dependencies perf tests: Sort includes and add missed explicit dependencies perf script: Sort includes and add missed explicit dependencies perf util: Sort includes and add missed explicit dependencies perf python: Add missed explicit dependencies
perf evsel/evlist: Avoid unnecessary #includes
perf data: Add open flag
perf evlist: Add reference count
perf evsel: Add reference count
perf evlist: Add reference count checking
perf python: Use evsel in sample in pyrf_event
perf python: Add wrapper for perf_data file abstraction perf python: Add python session abstraction wrapping perf's session perf python: Add syscall name/id to convert syscall number and name perf python: Refactor and add accessors to sample event perf python: Add callchain support
perf python: Add config file access
perf python: Extend API for stat events in python.c
perf python: Expose brstack in sample event
perf python: Add perf.pyi stubs file
perf python: Add LiveSession helper
perf python: Move exported-sql-viewer.py and parallel-perf.py to
tools/perf/python/
perf stat-cpi: Port stat-cpi to use python module
perf mem-phys-addr: Port mem-phys-addr to use python module perf syscall-counts: Port syscall-counts to use python module perf syscall-counts-by-pid: Port syscall-counts-by-pid to use python
module
perf futex-contention: Port futex-contention to use python module perf flamegraph: Port flamegraph to use python module
perf gecko: Port gecko to use python module
perf arm-cs-trace-disasm: Port arm-cs-trace-disasm to use python
module
perf check-perf-trace: Port check-perf-trace to use python module perf compaction-times: Port compaction-times to use python module perf event_analyzing_sample: Port event_analyzing_sample to use python
module
perf export-to-sqlite: Port export-to-sqlite to use python module perf export-to-postgresql: Port export-to-postgresql to use python
module
perf failed-syscalls-by-pid: Port failed-syscalls-by-pid to use python
module
perf intel-pt-events: Port intel-pt-events/libxed to use python module perf net_dropmonitor: Port net_dropmonitor to use python module perf netdev-times: Port netdev-times to use python module perf powerpc-hcalls: Port powerpc-hcalls to use python module perf sched-migration: Port sched-migration/SchedGui to use python
module
perf sctop: Port sctop to use python module
perf stackcollapse: Port stackcollapse to use python module perf task-analyzer: Port task-analyzer to use python module perf failed-syscalls: Port failed-syscalls to use python module perf rw-by-file: Port rw-by-file to use python module
perf rw-by-pid: Port rw-by-pid to use python module
perf rwtop: Port rwtop to use python module
perf wakeup-latency: Port wakeup-latency to use python module perf test: Migrate Intel PT virtual LBR test to use Python API
perf: Remove libperl support, legacy Perl scripts and tests
perf: Remove libpython support and legacy Python scripts perf Makefile: Update Python script installation path
perf script: Refactor to support standalone scripts and remove legacy
features
perf Documentation: Update for standalone Python scripts and remove
obsolete data
perf python: Improve perf script -l descriptions
perf sched stats: Fix segmentation faults in diff mode
tools/build/Makefile.feature | 5 +-
tools/build/feature/Makefile | 23 +-
tools/build/feature/test-all.c | 6 +-
tools/build/feature/test-libperl.c | 10 -
tools/build/feature/test-libpython.c | 10 -
tools/build/feature/test-python-module.c | 12 +
tools/perf/Documentation/perf-check.txt | 2 -
tools/perf/Documentation/perf-script-perl.txt | 216 --
.../perf/Documentation/perf-script-python.txt | 713 +-----
tools/perf/Documentation/perf-script.txt | 70 +-
tools/perf/Makefile.config | 37 +-
tools/perf/Makefile.perf | 22 +-
tools/perf/arch/arm/util/cs-etm.c | 36 +-
tools/perf/arch/arm64/util/arm-spe.c | 8 +-
tools/perf/arch/arm64/util/hisi-ptt.c | 2 +-
tools/perf/arch/x86/tests/hybrid.c | 22 +-
tools/perf/arch/x86/tests/topdown.c | 2 +-
tools/perf/arch/x86/util/auxtrace.c | 2 +-
tools/perf/arch/x86/util/intel-bts.c | 26 +-
tools/perf/arch/x86/util/intel-pt.c | 38 +-
tools/perf/arch/x86/util/iostat.c | 8 +-
tools/perf/bench/evlist-open-close.c | 29 +-
tools/perf/bench/inject-buildid.c | 9 +-
tools/perf/builtin-annotate.c | 2 +-
tools/perf/builtin-check.c | 3 +-
tools/perf/builtin-ftrace.c | 14 +-
tools/perf/builtin-inject.c | 81 +-
tools/perf/builtin-kvm.c | 14 +-
tools/perf/builtin-kwork.c | 8 +-
tools/perf/builtin-lock.c | 2 +-
tools/perf/builtin-record.c | 95 +-
tools/perf/builtin-report.c | 6 +-
tools/perf/builtin-sched.c | 111 +-
tools/perf/builtin-script.c | 895 +++----
tools/perf/builtin-stat.c | 81 +-
tools/perf/builtin-top.c | 104 +-
tools/perf/builtin-trace.c | 60 +-
tools/perf/python/SchedGui.py | 219 ++
tools/perf/python/arm-cs-trace-disasm.py | 338 +++
tools/perf/python/check-perf-trace.py | 113 +
tools/perf/python/compaction-times.py | 326 +++
tools/perf/python/counting.py | 1 +
tools/perf/python/event_analyzing_sample.py | 297 +++
tools/perf/python/export-to-postgresql.py | 701 ++++++
tools/perf/python/export-to-sqlite.py | 372 +++
.../python/exported-sql-viewer.py | 6 +-
tools/perf/python/failed-syscalls-by-pid.py | 116 +
tools/perf/python/failed-syscalls.py | 78 +
tools/perf/python/flamegraph.py | 250 ++
tools/perf/python/futex-contention.py | 87 +
tools/perf/python/gecko.py | 385 +++
tools/perf/python/intel-pt-events.py | 435 ++++
tools/perf/python/libxed.py | 122 +
.../{scripts => }/python/mem-phys-addr.py | 66 +-
tools/perf/python/net_dropmonitor.py | 58 +
tools/perf/python/netdev-times.py | 472 ++++
.../{scripts => }/python/parallel-perf.py | 0
tools/perf/python/perf.pyi | 581 +++++
tools/perf/python/perf_live.py | 48 +
tools/perf/python/powerpc-hcalls.py | 211 ++
tools/perf/python/rw-by-file.py | 103 +
tools/perf/python/rw-by-pid.py | 158 ++
tools/perf/python/rwtop.py | 219 ++
tools/perf/python/sched-migration.py | 469 ++++
tools/perf/python/sctop.py | 186 ++
tools/perf/python/stackcollapse.py | 126 +
tools/perf/python/stat-cpi.py | 151 ++
tools/perf/python/syscall-counts-by-pid.py | 88 +
tools/perf/python/syscall-counts.py | 72 +
tools/perf/python/task-analyzer.py | 547 ++++
tools/perf/python/tracepoint.py | 1 +
tools/perf/python/twatch.py | 1 +
tools/perf/python/wakeup-latency.py | 88 +
tools/perf/scripts/Build | 4 -
tools/perf/scripts/perl/Perf-Trace-Util/Build | 9 -
.../scripts/perl/Perf-Trace-Util/Context.c | 122 -
.../scripts/perl/Perf-Trace-Util/Context.xs | 42 -
.../scripts/perl/Perf-Trace-Util/Makefile.PL | 18 -
.../perf/scripts/perl/Perf-Trace-Util/README | 59 -
.../Perf-Trace-Util/lib/Perf/Trace/Context.pm | 55 -
.../Perf-Trace-Util/lib/Perf/Trace/Core.pm | 192 --
.../Perf-Trace-Util/lib/Perf/Trace/Util.pm | 94 -
.../perf/scripts/perl/Perf-Trace-Util/typemap | 1 -
.../scripts/perl/bin/check-perf-trace-record | 2 -
.../scripts/perl/bin/failed-syscalls-record | 3 -
.../scripts/perl/bin/failed-syscalls-report | 10 -
tools/perf/scripts/perl/bin/rw-by-file-record | 3 -
tools/perf/scripts/perl/bin/rw-by-file-report | 10 -
tools/perf/scripts/perl/bin/rw-by-pid-record | 2 -
tools/perf/scripts/perl/bin/rw-by-pid-report | 3 -
tools/perf/scripts/perl/bin/rwtop-record | 2 -
tools/perf/scripts/perl/bin/rwtop-report | 20 -
.../scripts/perl/bin/wakeup-latency-record | 6 -
.../scripts/perl/bin/wakeup-latency-report | 3 -
tools/perf/scripts/perl/check-perf-trace.pl | 106 -
tools/perf/scripts/perl/failed-syscalls.pl | 47 -
tools/perf/scripts/perl/rw-by-file.pl | 106 -
tools/perf/scripts/perl/rw-by-pid.pl | 184 --
tools/perf/scripts/perl/rwtop.pl | 203 --
tools/perf/scripts/perl/wakeup-latency.pl | 107 -
.../perf/scripts/python/Perf-Trace-Util/Build | 4 -
.../scripts/python/Perf-Trace-Util/Context.c | 225 --
.../Perf-Trace-Util/lib/Perf/Trace/Core.py | 116 -
.../lib/Perf/Trace/EventClass.py | 97 -
.../lib/Perf/Trace/SchedGui.py | 184 --
.../Perf-Trace-Util/lib/Perf/Trace/Util.py | 92 -
.../scripts/python/arm-cs-trace-disasm.py | 355 ---
.../python/bin/compaction-times-record | 2 -
.../python/bin/compaction-times-report | 4 -
.../python/bin/event_analyzing_sample-record | 8 -
.../python/bin/event_analyzing_sample-report | 3 -
.../python/bin/export-to-postgresql-record | 8 -
.../python/bin/export-to-postgresql-report | 29 -
.../python/bin/export-to-sqlite-record | 8 -
.../python/bin/export-to-sqlite-report | 29 -
.../python/bin/failed-syscalls-by-pid-record | 3 -
.../python/bin/failed-syscalls-by-pid-report | 10 -
.../perf/scripts/python/bin/flamegraph-record | 2 -
.../perf/scripts/python/bin/flamegraph-report | 3 -
.../python/bin/futex-contention-record | 2 -
.../python/bin/futex-contention-report | 4 -
tools/perf/scripts/python/bin/gecko-record | 2 -
tools/perf/scripts/python/bin/gecko-report | 7 -
.../scripts/python/bin/intel-pt-events-record | 13 -
.../scripts/python/bin/intel-pt-events-report | 3 -
.../scripts/python/bin/mem-phys-addr-record | 19 -
.../scripts/python/bin/mem-phys-addr-report | 3 -
.../scripts/python/bin/net_dropmonitor-record | 2 -
.../scripts/python/bin/net_dropmonitor-report | 4 -
.../scripts/python/bin/netdev-times-record | 8 -
.../scripts/python/bin/netdev-times-report | 5 -
.../scripts/python/bin/powerpc-hcalls-record | 2 -
.../scripts/python/bin/powerpc-hcalls-report | 2 -
.../scripts/python/bin/sched-migration-record | 2 -
.../scripts/python/bin/sched-migration-report | 3 -
tools/perf/scripts/python/bin/sctop-record | 3 -
tools/perf/scripts/python/bin/sctop-report | 24 -
.../scripts/python/bin/stackcollapse-record | 8 -
.../scripts/python/bin/stackcollapse-report | 3 -
.../python/bin/syscall-counts-by-pid-record | 3 -
.../python/bin/syscall-counts-by-pid-report | 10 -
.../scripts/python/bin/syscall-counts-record | 3 -
.../scripts/python/bin/syscall-counts-report | 10 -
.../scripts/python/bin/task-analyzer-record | 2 -
.../scripts/python/bin/task-analyzer-report | 3 -
tools/perf/scripts/python/check-perf-trace.py | 84 -
tools/perf/scripts/python/compaction-times.py | 311 ---
.../scripts/python/event_analyzing_sample.py | 192 --
.../scripts/python/export-to-postgresql.py | 1114 ---------
tools/perf/scripts/python/export-to-sqlite.py | 799 ------
.../scripts/python/failed-syscalls-by-pid.py | 79 -
tools/perf/scripts/python/flamegraph.py | 267 --
tools/perf/scripts/python/futex-contention.py | 57 -
tools/perf/scripts/python/gecko.py | 395 ---
tools/perf/scripts/python/intel-pt-events.py | 494 ----
tools/perf/scripts/python/libxed.py | 107 -
tools/perf/scripts/python/net_dropmonitor.py | 78 -
tools/perf/scripts/python/netdev-times.py | 473 ----
tools/perf/scripts/python/powerpc-hcalls.py | 202 --
tools/perf/scripts/python/sched-migration.py | 462 ----
tools/perf/scripts/python/sctop.py | 89 -
tools/perf/scripts/python/stackcollapse.py | 127 -
tools/perf/scripts/python/stat-cpi.py | 79 -
.../scripts/python/syscall-counts-by-pid.py | 75 -
tools/perf/scripts/python/syscall-counts.py | 65 -
tools/perf/scripts/python/task-analyzer.py | 934 -------
tools/perf/tests/backward-ring-buffer.c | 26 +-
tools/perf/tests/code-reading.c | 14 +-
tools/perf/tests/dlfilter-test.c | 8 +-
tools/perf/tests/event-times.c | 6 +-
tools/perf/tests/event_update.c | 4 +-
tools/perf/tests/evsel-roundtrip-name.c | 8 +-
tools/perf/tests/evsel-tp-sched.c | 4 +-
tools/perf/tests/expand-cgroup.c | 12 +-
tools/perf/tests/hists_cumulate.c | 2 +-
tools/perf/tests/hists_filter.c | 2 +-
tools/perf/tests/hists_link.c | 2 +-
tools/perf/tests/hists_output.c | 2 +-
tools/perf/tests/hwmon_pmu.c | 21 +-
tools/perf/tests/keep-tracking.c | 10 +-
tools/perf/tests/make | 9 +-
tools/perf/tests/mmap-basic.c | 42 +-
tools/perf/tests/openat-syscall-all-cpus.c | 6 +-
tools/perf/tests/openat-syscall-tp-fields.c | 26 +-
tools/perf/tests/openat-syscall.c | 6 +-
tools/perf/tests/parse-events.c | 139 +-
tools/perf/tests/parse-metric.c | 8 +-
tools/perf/tests/parse-no-sample-id-all.c | 2 +-
tools/perf/tests/perf-record.c | 38 +-
tools/perf/tests/perf-time-to-tsc.c | 12 +-
tools/perf/tests/pfm.c | 12 +-
tools/perf/tests/pmu-events.c | 11 +-
tools/perf/tests/pmu.c | 4 +-
tools/perf/tests/sample-parsing.c | 39 +-
.../perf/tests/shell/lib/perf_brstack_max.py | 43 +
tools/perf/tests/shell/script.sh | 4 +-
tools/perf/tests/shell/script_perl.sh | 102 -
tools/perf/tests/shell/script_python.sh | 113 -
.../tests/shell/test_arm_coresight_disasm.sh | 12 +-
tools/perf/tests/shell/test_intel_pt.sh | 35 +-
tools/perf/tests/shell/test_task_analyzer.sh | 79 +-
tools/perf/tests/sw-clock.c | 20 +-
tools/perf/tests/switch-tracking.c | 10 +-
tools/perf/tests/task-exit.c | 20 +-
tools/perf/tests/time-utils-test.c | 14 +-
tools/perf/tests/tool_pmu.c | 7 +-
tools/perf/tests/topology.c | 4 +-
tools/perf/ui/browsers/annotate.c | 2 +-
tools/perf/ui/browsers/hists.c | 22 +-
tools/perf/ui/browsers/scripts.c | 21 +-
tools/perf/util/Build | 3 +-
tools/perf/util/amd-sample-raw.c | 2 +-
tools/perf/util/annotate-data.c | 2 +-
tools/perf/util/annotate.c | 10 +-
tools/perf/util/arm-spe.c | 7 +-
tools/perf/util/auxtrace.c | 14 +-
tools/perf/util/block-info.c | 4 +-
tools/perf/util/bpf_counter.c | 2 +-
tools/perf/util/bpf_counter_cgroup.c | 10 +-
tools/perf/util/bpf_ftrace.c | 9 +-
tools/perf/util/bpf_lock_contention.c | 12 +-
tools/perf/util/bpf_off_cpu.c | 44 +-
tools/perf/util/bpf_trace_augment.c | 8 +-
tools/perf/util/cgroup.c | 26 +-
tools/perf/util/cs-etm.c | 6 +-
tools/perf/util/data-convert-bt.c | 2 +-
tools/perf/util/data.c | 26 +-
tools/perf/util/data.h | 4 +-
tools/perf/util/evlist.c | 487 ++--
tools/perf/util/evlist.h | 273 +-
tools/perf/util/evsel.c | 109 +-
tools/perf/util/evsel.h | 35 +-
tools/perf/util/expr.c | 2 +-
tools/perf/util/header.c | 51 +-
tools/perf/util/header.h | 2 +-
tools/perf/util/intel-bts.c | 3 +-
tools/perf/util/intel-pt.c | 13 +-
tools/perf/util/intel-tpebs.c | 7 +-
tools/perf/util/map.h | 9 +-
tools/perf/util/metricgroup.c | 12 +-
tools/perf/util/parse-events.c | 10 +-
tools/perf/util/parse-events.y | 2 +-
tools/perf/util/perf_api_probe.c | 20 +-
tools/perf/util/pfm.c | 4 +-
tools/perf/util/print-events.c | 2 +-
tools/perf/util/print_insn.h | 5 +-
tools/perf/util/python.c | 2098 ++++++++++++++--
tools/perf/util/record.c | 11 +-
tools/perf/util/s390-sample-raw.c | 19 +-
tools/perf/util/sample-raw.c | 4 +-
tools/perf/util/sample.c | 17 +-
tools/perf/util/scripting-engines/Build | 9 -
.../util/scripting-engines/trace-event-perl.c | 773 ------
.../scripting-engines/trace-event-python.c | 2209 -----------------
tools/perf/util/session.c | 59 +-
tools/perf/util/sideband_evlist.c | 40 +-
tools/perf/util/sort.c | 2 +-
tools/perf/util/stat-display.c | 6 +-
tools/perf/util/stat-shadow.c | 24 +-
tools/perf/util/stat.c | 20 +-
tools/perf/util/stream.c | 4 +-
tools/perf/util/synthetic-events.c | 36 +-
tools/perf/util/synthetic-events.h | 6 +-
tools/perf/util/time-utils.c | 12 +-
tools/perf/util/top.c | 4 +-
tools/perf/util/trace-event-parse.c | 65 -
tools/perf/util/trace-event-scripting.c | 410 ---
tools/perf/util/trace-event.h | 75 +-
268 files changed, 11592 insertions(+), 16034 deletions(-)
delete mode 100644 tools/build/feature/test-libperl.c
delete mode 100644 tools/build/feature/test-libpython.c
create mode 100644 tools/build/feature/test-python-module.c
delete mode 100644 tools/perf/Documentation/perf-script-perl.txt
create mode 100755 tools/perf/python/SchedGui.py
create mode 100755 tools/perf/python/arm-cs-trace-disasm.py
create mode 100755 tools/perf/python/check-perf-trace.py
create mode 100755 tools/perf/python/compaction-times.py
create mode 100755 tools/perf/python/event_analyzing_sample.py
create mode 100755 tools/perf/python/export-to-postgresql.py
create mode 100755 tools/perf/python/export-to-sqlite.py
rename tools/perf/{scripts => }/python/exported-sql-viewer.py (99%)
create mode 100755 tools/perf/python/failed-syscalls-by-pid.py
create mode 100755 tools/perf/python/failed-syscalls.py
create mode 100755 tools/perf/python/flamegraph.py
create mode 100755 tools/perf/python/futex-contention.py
create mode 100755 tools/perf/python/gecko.py
create mode 100755 tools/perf/python/intel-pt-events.py
create mode 100755 tools/perf/python/libxed.py
rename tools/perf/{scripts => }/python/mem-phys-addr.py (73%)
mode change 100644 => 100755
create mode 100755 tools/perf/python/net_dropmonitor.py
create mode 100755 tools/perf/python/netdev-times.py
rename tools/perf/{scripts => }/python/parallel-perf.py (100%)
create mode 100644 tools/perf/python/perf.pyi
create mode 100755 tools/perf/python/perf_live.py
create mode 100755 tools/perf/python/powerpc-hcalls.py
create mode 100755 tools/perf/python/rw-by-file.py
create mode 100755 tools/perf/python/rw-by-pid.py
create mode 100755 tools/perf/python/rwtop.py
create mode 100755 tools/perf/python/sched-migration.py
create mode 100755 tools/perf/python/sctop.py
create mode 100755 tools/perf/python/stackcollapse.py
create mode 100755 tools/perf/python/stat-cpi.py
create mode 100755 tools/perf/python/syscall-counts-by-pid.py
create mode 100755 tools/perf/python/syscall-counts.py
create mode 100755 tools/perf/python/task-analyzer.py
create mode 100755 tools/perf/python/wakeup-latency.py
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Build
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Context.c
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Context.xs
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/Makefile.PL
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/README
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Core.pm
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm
delete mode 100644 tools/perf/scripts/perl/Perf-Trace-Util/typemap
delete mode 100644 tools/perf/scripts/perl/bin/check-perf-trace-record
delete mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-record
delete mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-report
delete mode 100644 tools/perf/scripts/perl/bin/rw-by-file-record
delete mode 100644 tools/perf/scripts/perl/bin/rw-by-file-report
delete mode 100644 tools/perf/scripts/perl/bin/rw-by-pid-record
delete mode 100644 tools/perf/scripts/perl/bin/rw-by-pid-report
delete mode 100644 tools/perf/scripts/perl/bin/rwtop-record
delete mode 100644 tools/perf/scripts/perl/bin/rwtop-report
delete mode 100644 tools/perf/scripts/perl/bin/wakeup-latency-record
delete mode 100644 tools/perf/scripts/perl/bin/wakeup-latency-report
delete mode 100644 tools/perf/scripts/perl/check-perf-trace.pl
delete mode 100644 tools/perf/scripts/perl/failed-syscalls.pl
delete mode 100644 tools/perf/scripts/perl/rw-by-file.pl
delete mode 100644 tools/perf/scripts/perl/rw-by-pid.pl
delete mode 100644 tools/perf/scripts/perl/rwtop.pl
delete mode 100644 tools/perf/scripts/perl/wakeup-latency.pl
delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/Build
delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/Context.c
delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py
delete mode 100755 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py
delete mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
delete mode 100755 tools/perf/scripts/python/arm-cs-trace-disasm.py
delete mode 100644 tools/perf/scripts/python/bin/compaction-times-record
delete mode 100644 tools/perf/scripts/python/bin/compaction-times-report
delete mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-record
delete mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-report
delete mode 100644 tools/perf/scripts/python/bin/export-to-postgresql-record
delete mode 100644 tools/perf/scripts/python/bin/export-to-postgresql-report
delete mode 100644 tools/perf/scripts/python/bin/export-to-sqlite-record
delete mode 100644 tools/perf/scripts/python/bin/export-to-sqlite-report
delete mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
delete mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
delete mode 100755 tools/perf/scripts/python/bin/flamegraph-record
delete mode 100755 tools/perf/scripts/python/bin/flamegraph-report
delete mode 100644 tools/perf/scripts/python/bin/futex-contention-record
delete mode 100644 tools/perf/scripts/python/bin/futex-contention-report
delete mode 100644 tools/perf/scripts/python/bin/gecko-record
delete mode 100755 tools/perf/scripts/python/bin/gecko-report
delete mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record
delete mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report
delete mode 100644 tools/perf/scripts/python/bin/mem-phys-addr-record
delete mode 100644 tools/perf/scripts/python/bin/mem-phys-addr-report
delete mode 100755 tools/perf/scripts/python/bin/net_dropmonitor-record
delete mode 100755 tools/perf/scripts/python/bin/net_dropmonitor-report
delete mode 100644 tools/perf/scripts/python/bin/netdev-times-record
delete mode 100644 tools/perf/scripts/python/bin/netdev-times-report
delete mode 100644 tools/perf/scripts/python/bin/powerpc-hcalls-record
delete mode 100644 tools/perf/scripts/python/bin/powerpc-hcalls-report
delete mode 100644 tools/perf/scripts/python/bin/sched-migration-record
delete mode 100644 tools/perf/scripts/python/bin/sched-migration-report
delete mode 100644 tools/perf/scripts/python/bin/sctop-record
delete mode 100644 tools/perf/scripts/python/bin/sctop-report
delete mode 100755 tools/perf/scripts/python/bin/stackcollapse-record
delete mode 100755 tools/perf/scripts/python/bin/stackcollapse-report
delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-record
delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-report
delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-record
delete mode 100644 tools/perf/scripts/python/bin/syscall-counts-report
delete mode 100755 tools/perf/scripts/python/bin/task-analyzer-record
delete mode 100755 tools/perf/scripts/python/bin/task-analyzer-report
delete mode 100644 tools/perf/scripts/python/check-perf-trace.py
delete mode 100644 tools/perf/scripts/python/compaction-times.py
delete mode 100644 tools/perf/scripts/python/event_analyzing_sample.py
delete mode 100644 tools/perf/scripts/python/export-to-postgresql.py
delete mode 100644 tools/perf/scripts/python/export-to-sqlite.py
delete mode 100644 tools/perf/scripts/python/failed-syscalls-by-pid.py
delete mode 100755 tools/perf/scripts/python/flamegraph.py
delete mode 100644 tools/perf/scripts/python/futex-contention.py
delete mode 100644 tools/perf/scripts/python/gecko.py
delete mode 100644 tools/perf/scripts/python/intel-pt-events.py
delete mode 100644 tools/perf/scripts/python/libxed.py
delete mode 100755 tools/perf/scripts/python/net_dropmonitor.py
delete mode 100644 tools/perf/scripts/python/netdev-times.py
delete mode 100644 tools/perf/scripts/python/powerpc-hcalls.py
delete mode 100644 tools/perf/scripts/python/sched-migration.py
delete mode 100644 tools/perf/scripts/python/sctop.py
delete mode 100755 tools/perf/scripts/python/stackcollapse.py
delete mode 100644 tools/perf/scripts/python/stat-cpi.py
delete mode 100644 tools/perf/scripts/python/syscall-counts-by-pid.py
delete mode 100644 tools/perf/scripts/python/syscall-counts.py
delete mode 100755 tools/perf/scripts/python/task-analyzer.py
create mode 100644 tools/perf/tests/shell/lib/perf_brstack_max.py
delete mode 100755 tools/perf/tests/shell/script_perl.sh
delete mode 100755 tools/perf/tests/shell/script_python.sh
delete mode 100644 tools/perf/util/scripting-engines/Build
delete mode 100644 tools/perf/util/scripting-engines/trace-event-perl.c
delete mode 100644 tools/perf/util/scripting-engines/trace-event-python.c
delete mode 100644 tools/perf/util/trace-event-scripting.cSignature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 1/59 perf inject: Fix itrace branch stack synthesis
When using "perf inject --itrace=L" to synthesize branch stacks from AUX data, several issues caused failures:
1. The synthesized samples were delivered without the PERF_SAMPLE_BRANCH_STACK flag if it was not in the original event's sample_type. Fixed by using sample_type | evsel->synth_sample_type in intel_pt_deliver_synth_event.
2. The record layout was misaligned because of inconsistent handling of PERF_SAMPLE_BRANCH_HW_INDEX. Fixed by explicitly writing nr and hw_idx in perf_event__synthesize_sample.
3. Modifying evsel->core.attr.sample_type early in __cmd_inject caused parse failures for subsequent records in the input file. Fixed by moving this modification to just before writing the header.
4. perf_event__repipe_sample was narrowed to only synthesize samples when branch stack injection was requested, and restored the use of perf_inject__cut_auxtrace_sample as a fallback to preserve functionality.
---
Issues fixed in v2:
1. Potential Heap Overflow in perf_event__repipe_sample : Addressed by adding a check that prints an error and returns -EFAULT if the calculated event size exceeds PERF_SAMPLE_MAX_SIZE , as you requested.
2. Header vs Payload Mismatch in __cmd_inject : Addressed by narrowing the condition so that HEADER_BRANCH_STACK is only set in the file header if add_last_branch was true.
3. NULL Pointer Dereference in intel-pt.c : Addressed by updating the condition in intel_pt_do_synth_pebs_sample to fill sample. branch_stack if it was synthesized, even if not in the original sample_type .
4. Unsafe Reads for events lacking HW_INDEX in synthetic-events.c :
Addressed by using the perf_sample__branch_entries() macro and checking sample->no_hw_idx .
5. Size mismatch in perf_event__sample_event_size : Addressed by passing branch_sample_type to it and conditioning the hw_idx size on PERF_SAMPLE_BRANCH_HW_INDEX .
--- tools/perf/bench/inject-buildid.c | 9 ++-- tools/perf/builtin-inject.c | 77 ++++++++++++++++++++++++++++-- tools/perf/tests/dlfilter-test.c | 8 +++- tools/perf/tests/sample-parsing.c | 5 +- tools/perf/util/arm-spe.c | 7 ++- tools/perf/util/cs-etm.c | 6 ++- tools/perf/util/intel-bts.c | 3 +- tools/perf/util/intel-pt.c | 13 +++-- tools/perf/util/synthetic-events.c | 25 +++++++--- tools/perf/util/synthetic-events.h | 6 ++- 10 files changed, 129 insertions(+), 30 deletions(-)
tools/perf/bench/inject-buildid.c +6 -3
@@ -228,9 +228,12 @@ static ssize_t synthesize_sample(struct bench_data *data, struct bench_dso *dso, event.header.type =PERF_RECORD_SAMPLE ; event.header.misc =PERF_RECORD_MISC_USER ; - event.header.size =perf_event__sample_event_size (&sample, bench_sample_type,0 ); - -perf_event__synthesize_sample (&event, bench_sample_type,0 , &sample); + event.header.size =perf_event__sample_event_size (&sample, bench_sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); +perf_event__synthesize_sample (&event, bench_sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , &sample);return writen (data->input_pipe[1 ], &event, event.header.size); }
tools/perf/builtin-inject.c +72 -5
105 lines not on this page · raw message
tools/perf/tests/dlfilter-test.c +6 -2
@@ -188,8 +188,12 @@ static int write_sample(struct test_data *td, u64 sample_type, u64 id, pid_t pid event->header.type =PERF_RECORD_SAMPLE ; event->header.misc =PERF_RECORD_MISC_USER ; - event->header.size =perf_event__sample_event_size (&sample, sample_type,0 ); - err =perf_event__synthesize_sample (event, sample_type,0 , &sample); + event->header.size =perf_event__sample_event_size (&sample, sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); + err =perf_event__synthesize_sample (event, sample_type, +/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , &sample);if (err)return test_result ("perf_event__synthesize_sample() failed" ,TEST_FAIL );
tools/perf/tests/sample-parsing.c +3 -2
@@ -310,7 +310,8 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) sample.read.one.lost =1 ; } - sz =perf_event__sample_event_size (&sample, sample_type, read_format); + sz =perf_event__sample_event_size (&sample, sample_type, read_format, + evsel.core.attr.branch_sample_type); bufsz = sz +4096 ;/* Add a bit for overrun checking */ event =malloc (bufsz);if (!event) {
@@ -324,7 +325,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) event->header.size = sz; err =perf_event__synthesize_sample (event, sample_type, read_format, - &sample); + evsel.core.attr.branch_sample_type, &sample);if (err) {pr_debug ("%s failed for sample_type %#" PRIx64", error %d\n" ,"perf_event__synthesize_sample" , sample_type, err);
tools/perf/util/arm-spe.c +5 -2
@@ -484,8 +484,11 @@ static void arm_spe__prep_branch_stack(struct arm_spe_queue *speq)static int arm_spe__inject_event (union perf_event *event,struct perf_sample *sample,u64 type) { - event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample); + event->header.type =PERF_RECORD_SAMPLE ; + event->header.size =perf_event__sample_event_size (sample, type,/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); +return perf_event__synthesize_sample (event, type,/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , sample); } static inline int
tools/perf/util/cs-etm.c +4 -2
@@ -1425,8 +1425,10 @@ static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq,static int cs_etm__inject_event (union perf_event *event,struct perf_sample *sample,u64 type) { - event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample); + event->header.size =perf_event__sample_event_size (sample, type,/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); +return perf_event__synthesize_sample (event, type,/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , sample); }
tools/perf/util/intel-bts.c +2 -1
@@ -303,7 +303,8 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, event.sample.header.size = bts->branches_event_size; ret =perf_event__synthesize_sample (&event, bts->branches_sample_type, -0 , &sample); +/*read_format=*/ 0 ,/*branch_sample_type=*/ 0 , + &sample);if (ret)return ret; }
tools/perf/util/intel-pt.c +9 -4
@@ -1731,8 +1731,12 @@ static void intel_pt_prep_b_sample(struct intel_pt *pt,static int intel_pt_inject_event (union perf_event *event,struct perf_sample *sample,u64 type) { - event->header.size =perf_event__sample_event_size (sample, type,0 ); -return perf_event__synthesize_sample (event, type,0 , sample); + event->header.type =PERF_RECORD_SAMPLE ; + event->header.size =perf_event__sample_event_size (sample, type,/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 ); + +return perf_event__synthesize_sample (event, type,/*read_format=*/ 0 , +/*branch_sample_type=*/ 0 , sample); } static inline int intel_pt_opt_inject(struct intel_pt *pt,
@@ -2486,7 +2490,7 @@ static int intel_pt_do_synth_pebs_sample(struct intel_pt_queue *ptq, struct evseintel_pt_add_xmm (intr_regs, pos, items, regs_mask); } -if (sample_type &PERF_SAMPLE_BRANCH_STACK ) { +if ((sample_type | evsel->synth_sample_type) &PERF_SAMPLE_BRANCH_STACK ) {if (items->mask[INTEL_PT_LBR_0_POS ] || items->mask[INTEL_PT_LBR_1_POS ] || items->mask[INTEL_PT_LBR_2_POS ]) {
@@ -2557,7 +2561,8 @@ static int intel_pt_do_synth_pebs_sample(struct intel_pt_queue *ptq, struct evse sample.transaction = txn; } - ret =intel_pt_deliver_synth_event (pt, event, &sample, sample_type); + ret =intel_pt_deliver_synth_event (pt, event, &sample, + sample_type | evsel->synth_sample_type);perf_sample__exit (&sample);return ret; }
tools/perf/util/synthetic-events.c +18 -7
@@ -1455,7 +1455,8 @@ int perf_event__synthesize_stat_round(const struct perf_tool *tool,return process (tool, (union perf_event *) &event,NULL , machine); } -size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type,u64 read_format) +size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type,u64 read_format, +u64 branch_sample_type) {size_t sz, result =sizeof (struct perf_record_sample );
@@ -1515,8 +1516,10 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (type &PERF_SAMPLE_BRANCH_STACK ) { sz = sample->branch_stack->nr *sizeof (struct branch_entry ); -/* nr, hw_idx */ - sz +=2 *sizeof (u64); +/* nr */ + sz +=sizeof (u64); +if (branch_sample_type &PERF_SAMPLE_BRANCH_HW_INDEX ) + sz +=sizeof (u64); result += sz; }
@@ -1605,7 +1608,7 @@ static __u64 *copy_read_group_values(__u64 *array, __u64 read_format, }int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, -const struct perf_sample *sample) +u64 branch_sample_type,const struct perf_sample *sample) {__u64 *array;size_t sz;
@@ -1719,9 +1722,17 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_foif (type &PERF_SAMPLE_BRANCH_STACK ) { sz = sample->branch_stack->nr *sizeof (struct branch_entry ); -/* nr, hw_idx */ - sz +=2 *sizeof (u64); -memcpy (array, sample->branch_stack, sz); + + *array++ = sample->branch_stack->nr; + +if (branch_sample_type &PERF_SAMPLE_BRANCH_HW_INDEX ) { +if (sample->no_hw_idx) + *array++ =0 ; +else + *array++ = sample->branch_stack->hw_idx; + } + +memcpy (array,perf_sample__branch_entries ((struct perf_sample *)sample), sz); array = (void *)array + sz; }
tools/perf/util/synthetic-events.h +4 -2
@@ -81,7 +81,8 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool, union perf_int perf_event__synthesize_modules (const struct perf_tool *tool,perf_event__handler_t process,struct machine *machine);int perf_event__synthesize_namespaces (const struct perf_tool *tool,union perf_event *event,pid_t pid,pid_t tgid,perf_event__handler_t process,struct machine *machine);int perf_event__synthesize_cgroups (const struct perf_tool *tool,perf_event__handler_t process,struct machine *machine); -int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format,const struct perf_sample *sample); +int perf_event__synthesize_sample (union perf_event *event,u64 type,u64 read_format, +u64 branch_sample_type,const struct perf_sample *sample);int perf_event__synthesize_stat_config (const struct perf_tool *tool,struct perf_stat_config *config,perf_event__handler_t process,struct machine *machine);int perf_event__synthesize_stat_events (struct perf_stat_config *config,const struct perf_tool *tool,struct evlist *evlist,perf_event__handler_t process,bool attrs);int perf_event__synthesize_stat_round (const struct perf_tool *tool,u64 time,u64 type,perf_event__handler_t process,struct machine *machine);
@@ -97,7 +98,8 @@ void perf_event__synthesize_final_bpf_metadata(struct perf_session *session,int perf_tool__process_synth_event (const struct perf_tool *tool,union perf_event *event,struct machine *machine,perf_event__handler_t process); -size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type,u64 read_format); +size_t perf_event__sample_event_size (const struct perf_sample *sample,u64 type, +u64 read_format,u64 branch_sample_type); int __machine__synthesize_threads(struct machine *machine, const struct perf_tool *tool, struct target *target, struct perf_thread_map *threads,
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 2/59 perf arch arm: Sort includes and add missed explicit dependencies
In reply to Ian RogersFix missing #includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code.
--- tools/perf/arch/arm/util/cs-etm.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
tools/perf/arch/arm/util/cs-etm.c +14 -12
@@ -3,10 +3,13 @@* Copyright(C) 2015 Linaro Limited. All rights reserved. * Author: Mathieu Poirier <[email protected]> */ +#include "../../../util/cs-etm.h" + +#include <errno.h> +#include <stdlib.h> -#include <api/fs/fs.h> -#include <linux/bits.h> #include <linux/bitops.h> +#include <linux/bits.h> #include <linux/compiler.h> #include <linux/coresight-pmu.h> #include <linux/kernel.h>
@@ -14,25 +17,24 @@#include <linux/string.h> #include <linux/types.h> #include <linux/zalloc.h> +#include <sys/stat.h> + +#include <api/fs/fs.h> +#include <internal/lib.h> // page_size -#include "cs-etm.h" -#include "../../../util/debug.h" -#include "../../../util/record.h" #include "../../../util/auxtrace.h" #include "../../../util/cpumap.h" +#include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/evlist.h" #include "../../../util/evsel.h" -#include "../../../util/perf_api_probe.h" #include "../../../util/evsel_config.h" +#include "../../../util/perf_api_probe.h" +#include "../../../util/pmu.h" #include "../../../util/pmus.h" -#include "../../../util/cs-etm.h" -#include <internal/lib.h> // page_size +#include "../../../util/record.h" #include "../../../util/session.h" - -#include <errno.h> -#include <stdlib.h> -#include <sys/stat.h> +#include "cs-etm.h" struct cs_etm_recording {struct auxtrace_record itr;
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 3/59 perf arch x86: Sort includes and add missed explicit dependencies
In reply to Ian RogersFix missing #includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code.
--- tools/perf/arch/x86/util/intel-bts.c | 20 +++++++++++-------- tools/perf/arch/x86/util/intel-pt.c | 29 +++++++++++++++------------- 2 files changed, 28 insertions(+), 21 deletions(-)
tools/perf/arch/x86/util/intel-bts.c +12 -8
@@ -4,26 +4,30 @@* Copyright (c) 2013-2015, Intel Corporation. */ +#include "../../../util/intel-bts.h" +#include <errno.h> -#include <linux/kernel.h> -#include <linux/types.h> +#include <linux/bitops.h> +#include <linux/kernel.h> #include <linux/log2.h> +#include <linux/types.h> #include <linux/zalloc.h> +#include <internal/lib.h> // page_size + +#include "../../../util/auxtrace.h" #include "../../../util/cpumap.h" +#include "../../../util/debug.h" #include "../../../util/event.h" -#include "../../../util/evsel.h" #include "../../../util/evlist.h" +#include "../../../util/evsel.h" #include "../../../util/mmap.h" -#include "../../../util/session.h" +#include "../../../util/pmu.h" #include "../../../util/pmus.h" -#include "../../../util/debug.h" #include "../../../util/record.h" +#include "../../../util/session.h" #include "../../../util/tsc.h" -#include "../../../util/auxtrace.h" -#include "../../../util/intel-bts.h" -#include <internal/lib.h> // page_size #define KiB (x) ((x) * 1024)#define MiB (x) ((x) * 1024 * 1024)
tools/perf/arch/x86/util/intel-pt.c +16 -13
@@ -3,36 +3,39 @@* intel_pt.c: Intel Processor Trace support * Copyright (c) 2013-2015, Intel Corporation. */ +#include "../../../util/intel-pt.h" #include <errno.h> #include <stdbool.h> -#include <linux/kernel.h> -#include <linux/types.h> +#include <linux/bitops.h> +#include <linux/err.h> +#include <linux/kernel.h> #include <linux/log2.h> +#include <linux/types.h> #include <linux/zalloc.h> -#include <linux/err.h> -#include "../../../util/session.h" +#include <api/fs/fs.h> +#include <internal/lib.h> // page_size +#include <subcmd/parse-options.h> + +#include "../../../util/auxtrace.h" +#include "../../../util/config.h" +#include "../../../util/cpumap.h" +#include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/evlist.h" #include "../../../util/evsel.h" #include "../../../util/evsel_config.h" -#include "../../../util/config.h" -#include "../../../util/cpumap.h" #include "../../../util/mmap.h" -#include <subcmd/parse-options.h> #include "../../../util/parse-events.h" -#include "../../../util/pmus.h" -#include "../../../util/debug.h" -#include "../../../util/auxtrace.h" #include "../../../util/perf_api_probe.h" +#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/record.h" +#include "../../../util/session.h" #include "../../../util/target.h" #include "../../../util/tsc.h" -#include <internal/lib.h> // page_size -#include "../../../util/intel-pt.h" -#include <api/fs/fs.h> #include "cpuid.h" #define KiB (x) ((x) * 1024)
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 4/59 perf tests: Sort includes and add missed explicit dependencies
In reply to Ian RogersFix missing #includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code.
--- tools/perf/tests/hwmon_pmu.c | 14 +++++++++----- tools/perf/tests/mmap-basic.c | 18 +++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-)
tools/perf/tests/hwmon_pmu.c +9 -5
@@ -1,15 +1,19 @@// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -#include "debug.h" -#include "evlist.h" #include "hwmon_pmu.h" -#include "parse-events.h" -#include "tests.h" +#include <errno.h> +#include <fcntl.h> -#include <sys/stat.h> #include <linux/compiler.h> #include <linux/kernel.h> #include <linux/string.h> +#include <sys/stat.h> + +#include "debug.h" +#include "evlist.h" +#include "parse-events.h" +#include "pmus.h" +#include "tests.h" static const struct test_event { const char *name;
tools/perf/tests/mmap-basic.c +11 -7
@@ -1,25 +1,29 @@// SPDX-License-Identifier: GPL-2.0 #include <errno.h> -#include <fcntl.h> #include <inttypes.h> #include <stdlib.h> + +#include <fcntl.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <perf/cpumap.h> +#include <perf/evlist.h> +#include <perf/mmap.h> #include "cpumap.h" #include "debug.h" #include "event.h" #include "evlist.h" #include "evsel.h" -#include "thread_map.h" +#include "pmu.h" +#include "pmus.h" #include "tests.h" +#include "thread_map.h" #include "util/affinity.h" #include "util/mmap.h" #include "util/sample.h" -#include <linux/err.h> -#include <linux/kernel.h> -#include <linux/string.h> -#include <perf/evlist.h> -#include <perf/mmap.h> /* * This test will generate random numbers of calls to some getpid syscalls,
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 5/59 perf script: Sort includes and add missed explicit dependencies
In reply to Ian RogersFix missing #include of pmu.h found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code. Doing this exposed a missing forward declaration of addr_location in print_insn.h, add this and sort the forward declarations.
--- tools/perf/builtin-script.c | 111 ++++++++++++++++++----------------- tools/perf/util/print_insn.h | 5 +- 2 files changed, 60 insertions(+), 56 deletions(-)
tools/perf/builtin-script.c +57 -54
@@ -1,74 +1,77 @@// SPDX-License-Identifier: GPL-2.0 -#include "builtin.h" +#include <errno.h> +#include <inttypes.h> +#include <signal.h> +#include <stdio.h> + +#include <dirent.h> +#include <fcntl.h> +#include <linux/bitmap.h> +#include <linux/compiler.h> +#include <linux/ctype.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/stringify.h> +#include <linux/time64.h> +#include <linux/unaligned.h> +#include <linux/zalloc.h> +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/utsname.h> +#include <unistd.h> +#include <perf/evlist.h> +#include <subcmd/exec-cmd.h> +#include <subcmd/pager.h> +#include <subcmd/parse-options.h> + +#include "asm/bug.h" +#include "builtin.h" +#include "perf.h" +#include "print_binary.h" +#include "print_insn.h" +#include "ui/ui.h" +#include "util/annotate.h" +#include "util/auxtrace.h" +#include "util/cgroup.h" +#include "util/color.h" #include "util/counts.h" +#include "util/cpumap.h" +#include "util/data.h" #include "util/debug.h" +#include "util/dlfilter.h" #include "util/dso.h" -#include <subcmd/exec-cmd.h> -#include "util/header.h" -#include <subcmd/parse-options.h> -#include "util/perf_regs.h" -#include "util/session.h" -#include "util/tool.h" -#include "util/map.h" -#include "util/srcline.h" -#include "util/symbol.h" -#include "util/thread.h" -#include "util/trace-event.h" +#include "util/dump-insn.h" #include "util/env.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_fprintf.h" #include "util/evswitch.h" +#include "util/header.h" +#include "util/map.h" +#include "util/mem-events.h" +#include "util/mem-info.h" +#include "util/metricgroup.h" +#include "util/path.h" +#include "util/perf_regs.h" +#include "util/pmu.h" +#include "util/record.h" +#include "util/session.h" #include "util/sort.h" -#include "util/data.h" -#include "util/auxtrace.h" -#include "util/cpumap.h" -#include "util/thread_map.h" +#include "util/srcline.h" #include "util/stat.h" -#include "util/color.h" #include "util/string2.h" +#include "util/symbol.h" #include "util/thread-stack.h" +#include "util/thread.h" +#include "util/thread_map.h" #include "util/time-utils.h" -#include "util/path.h" -#include "util/event.h" -#include "util/mem-info.h" -#include "util/metricgroup.h" -#include "ui/ui.h" -#include "print_binary.h" -#include "print_insn.h" -#include <linux/bitmap.h> -#include <linux/compiler.h> -#include <linux/kernel.h> -#include <linux/stringify.h> -#include <linux/time64.h> -#include <linux/zalloc.h> -#include <linux/unaligned.h> -#include <sys/utsname.h> -#include "asm/bug.h" -#include "util/mem-events.h" -#include "util/dump-insn.h" -#include <dirent.h> -#include <errno.h> -#include <inttypes.h> -#include <signal.h> -#include <stdio.h> -#include <sys/param.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <subcmd/pager.h> -#include <perf/evlist.h> -#include <linux/err.h> -#include "util/dlfilter.h" -#include "util/record.h" +#include "util/tool.h" +#include "util/trace-event.h" #include "util/util.h" -#include "util/cgroup.h" -#include "util/annotate.h" -#include "perf.h" -#include <linux/ctype.h> #ifdef HAVE_LIBTRACEEVENT #include <event-parse.h> #endif
tools/perf/util/print_insn.h +3 -2
@@ -5,10 +5,11 @@#include <stddef.h> #include <stdio.h> -struct perf_sample ; -struct thread ; +struct addr_location ;struct machine ;struct perf_insn ; +struct perf_sample ; +struct thread ;#define PRINT_INSN_IMM_HEX (1<<0)
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 6/59 perf util: Sort includes and add missed explicit dependencies
In reply to Ian RogersFix missing includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code.
--- tools/perf/util/bpf_off_cpu.c | 30 +++++----- tools/perf/util/bpf_trace_augment.c | 8 +-- tools/perf/util/evlist.c | 91 +++++++++++++++-------------- tools/perf/util/evsel.c | 75 ++++++++++++------------ tools/perf/util/map.h | 9 ++- tools/perf/util/perf_api_probe.c | 18 +++--- tools/perf/util/s390-sample-raw.c | 19 +++--- tools/perf/util/stat-shadow.c | 20 ++++--- tools/perf/util/stat.c | 16 +++-- 9 files changed, 152 insertions(+), 134 deletions(-)
tools/perf/util/bpf_off_cpu.c +16 -14
@@ -1,23 +1,25 @@// SPDX-License-Identifier: GPL-2.0 -#include "util/bpf_counter.h" -#include "util/debug.h" -#include "util/evsel.h" -#include "util/evlist.h" -#include "util/off_cpu.h" -#include "util/perf-hooks.h" -#include "util/record.h" -#include "util/session.h" -#include "util/target.h" -#include "util/cpumap.h" -#include "util/thread_map.h" -#include "util/cgroup.h" -#include "util/strlist.h" +#include <linux/time64.h> +#include <bpf/bpf.h> #include <bpf/btf.h> #include <internal/xyarray.h> -#include <linux/time64.h> +#include "bpf_counter.h" #include "bpf_skel/off_cpu.skel.h" +#include "cgroup.h" +#include "cpumap.h" +#include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "off_cpu.h" +#include "parse-events.h" +#include "perf-hooks.h" +#include "record.h" +#include "session.h" +#include "strlist.h" +#include "target.h" +#include "thread_map.h" #define MAX_STACKS 32#define MAX_PROC 4096
tools/perf/util/bpf_trace_augment.c +4 -4
@@ -1,11 +1,11 @@#include <bpf/libbpf.h> #include <internal/xyarray.h> -#include "util/debug.h" -#include "util/evlist.h" -#include "util/trace_augment.h" -#include "bpf_skel/augmented_raw_syscalls.skel.h" +#include "debug.h" +#include "evlist.h" +#include "parse-events.h" +#include "trace_augment.h" static struct augmented_raw_syscalls_bpf *skel;static struct evsel *bpf_output;
tools/perf/util/evlist.c +46 -45
113 lines not on this page · raw message
tools/perf/util/evsel.c +39 -36
107 lines not on this page · raw message
tools/perf/util/map.h +4 -5
@@ -2,14 +2,13 @@#ifndef __PERF_MAP_H#define __PERF_MAP_H -#include <linux/refcount.h> -#include <linux/compiler.h> -#include <linux/list.h> -#include <linux/rbtree.h> +#include <stdbool.h> #include <stdio.h> #include <string.h> -#include <stdbool.h> + +#include <linux/refcount.h> #include <linux/types.h> +#include <internal/rc_check.h> struct dso ;
tools/perf/util/perf_api_probe.c +11 -7
@@ -1,14 +1,18 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include "perf_api_probe.h" -#include "perf-sys.h" -#include "util/cloexec.h" -#include "util/evlist.h" -#include "util/evsel.h" -#include "util/parse-events.h" -#include "util/perf_api_probe.h" -#include <perf/cpumap.h> #include <errno.h> +#include <perf/cpumap.h> + +#include "cloexec.h" +#include "evlist.h" +#include "evsel.h" +#include "parse-events.h" +#include "perf-sys.h" +#include "pmu.h" +#include "pmus.h" +typedef void (*setup_probe_fn_t )(struct evsel *evsel);static int perf_do_probe_api (setup_probe_fn_t fn,struct perf_cpu cpu,const char *str)
tools/perf/util/s390-sample-raw.c +10 -9
@@ -12,25 +12,26 @@* sample was taken from. */ -#include <unistd.h> +#include <inttypes.h> #include <stdio.h> #include <string.h> -#include <inttypes.h> -#include <sys/stat.h> +#include <asm/byteorder.h> #include <linux/compiler.h> #include <linux/err.h> -#include <asm/byteorder.h> +#include <sys/stat.h> +#include <unistd.h> +#include "color.h" #include "debug.h" -#include "session.h" #include "evlist.h" -#include "color.h" #include "hashmap.h" -#include "sample-raw.h" +#include "pmu.h" +#include "pmus.h" #include "s390-cpumcf-kernel.h" -#include "util/pmu.h" -#include "util/sample.h" +#include "sample-raw.h" +#include "sample.h" +#include "session.h" static size_t ctrset_size (struct cf_ctrset_entry *set) {
tools/perf/util/stat-shadow.c +12 -8
@@ -2,20 +2,24 @@#include <errno.h> #include <math.h> #include <stdio.h> -#include "evsel.h" -#include "stat.h" + +#include <linux/zalloc.h> + +#include "cgroup.h" #include "color.h" #include "debug.h" -#include "pmu.h" -#include "rblist.h" #include "evlist.h" +#include "evsel.h" #include "expr.h" -#include "metricgroup.h" -#include "cgroup.h" -#include "units.h" +#include "hashmap.h" #include "iostat.h" -#include "util/hashmap.h" +#include "metricgroup.h" +#include "pmu.h" +#include "pmus.h" +#include "rblist.h" +#include "stat.h" #include "tool_pmu.h" +#include "units.h" static bool tool_pmu__is_time_event (const struct perf_stat_config *config,const struct evsel *evsel,int *tool_aggr_idx)
tools/perf/util/stat.c +10 -6
@@ -1,21 +1,25 @@// SPDX-License-Identifier: GPL-2.0 +#include "stat.h" +#include <errno.h> -#include <linux/err.h> #include <inttypes.h> #include <math.h> #include <string.h> + +#include <linux/err.h> +#include <linux/zalloc.h> +#include "counts.h" #include "cpumap.h" #include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "hashmap.h" #include "header.h" -#include "stat.h" +#include "pmu.h" #include "session.h" #include "target.h" -#include "evlist.h" -#include "evsel.h" #include "thread_map.h" -#include "util/hashmap.h" -#include <linux/zalloc.h> void update_stats (struct stats *stats,u64 val) {
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 7/59 perf python: Add missed explicit dependencies
In reply to Ian RogersFix missing #include of pmus.h found while cleaning the evsel/evlist header files.
--- tools/perf/util/python.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
tools/perf/util/python.c +10 -7
@@ -5,26 +5,29 @@#include <poll.h> #include <linux/err.h> #include <perf/cpumap.h> -#ifdef HAVE_LIBTRACEEVENT -#include <event-parse.h> -#endif +#include <internal/lib.h> #include <perf/mmap.h> +#include "callchain.h" #include "counts.h" +#include "event.h" #include "evlist.h" #include "evsel.h" -#include "event.h" #include "expr.h" +#include "metricgroup.h" +#include "mmap.h" +#include "pmus.h" #include "print_binary.h" #include "record.h" #include "strbuf.h" #include "thread_map.h" #include "tp_pmu.h" #include "trace-event.h" -#include "metricgroup.h" -#include "mmap.h" #include "util/sample.h" -#include <internal/lib.h> + +#ifdef HAVE_LIBTRACEEVENT +#include <event-parse.h> +#endif PyMODINIT_FUNC PyInit_perf (void );
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 8/59 perf evsel/evlist: Avoid unnecessary #includes
In reply to Ian RogersUse forward declarations and remove unnecessary #includes in evsel.h. Sort the forward declarations in evsel.h and evlist.h.
--- tools/perf/util/evlist.h | 15 +++++++++------ tools/perf/util/evsel.h | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-)
tools/perf/util/evlist.h +9 -6
@@ -2,29 +2,32 @@#ifndef __PERF_EVLIST_H#define __PERF_EVLIST_H 1 +#include <signal.h> +#include <linux/compiler.h> #include <linux/kernel.h> -#include <linux/refcount.h> #include <linux/list.h> +#include <linux/refcount.h> +#include <pthread.h> +#include <unistd.h> +#include <api/fd/array.h> #include <internal/evlist.h> #include <internal/evsel.h> #include <perf/evlist.h> +#include "affinity.h" #include "events_stats.h" #include "evsel.h" #include "rblist.h" -#include <pthread.h> -#include <signal.h> -#include <unistd.h> -struct pollfd ; -struct thread_map ;struct perf_cpu_map ;struct perf_stat_config ; +struct pollfd ;struct record_opts ;struct strbuf ;struct target ; +struct thread_map ;/* * State machine of bkw_mmap_state:
tools/perf/util/evsel.h +11 -9
@@ -2,28 +2,30 @@#ifndef __PERF_EVSEL_H#define __PERF_EVSEL_H 1 -#include <linux/list.h> #include <stdbool.h> -#include <sys/types.h> + +#include <linux/list.h> #include <linux/perf_event.h> #include <linux/types.h> +#include <sys/types.h> +#include <internal/evsel.h> #include <perf/evsel.h> +#include "symbol_conf.h" -#include "pmus.h" -#include "pmu.h" +struct bperf_follower_bpf ; +struct bperf_leader_bpf ; +struct bpf_counter_ops ;struct bpf_object ;struct cgroup ; +struct hashmap ;struct perf_counts ; +struct perf_pmu ;struct perf_stat_config ;struct perf_stat_evsel ; -union perf_event ; -struct bpf_counter_ops ;struct target ; -struct hashmap ; -struct bperf_leader_bpf ; -struct bperf_follower_bpf ; +union perf_event ;typedef int (evsel__sb_cb_t )(union perf_event *event,void *data);
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 9/59 perf data: Add open flag
In reply to Ian RogersAvoid double opens and ensure only open files are closed. This addresses some issues with python integration where the data file wants to be opened before being given to a session.
---
Changes in v2:
1. Fixed File Rotation: In perf_data__switch() , I added data->open = false; after the file is closed. This ensures that the subsequent perf_data__open() call will not exit early and will successfully open the new file.
2. Fixed Memory Leak: In open_dir() , I added a call to zfree(&data->file.path) if mkdir() fails, preventing the leak of the path string.
--- tools/perf/util/data.c | 26 ++++++++++++++++++++++---- tools/perf/util/data.h | 4 +++- 2 files changed, 25 insertions(+), 5 deletions(-)
tools/perf/util/data.c +22 -4
@@ -346,8 +346,10 @@ static int open_dir(struct perf_data *data)return -1 ;if (perf_data__is_write (data) && -mkdir (data->path,S_IRWXU ) <0 ) +mkdir (data->path,S_IRWXU ) <0 ) { +zfree (&data->file.path);return -1 ; + } ret =open_file (data);
@@ -360,9 +362,16 @@ static int open_dir(struct perf_data *data)int perf_data__open (struct perf_data *data) { -if (check_pipe (data)) +int ret; + +if (data->open)return 0 ; +if (check_pipe (data)) { + data->open = true; +return 0 ; + } +/* currently it allows stdio for pipe only */ data->file.use_stdio = false;
@@ -375,16 +384,24 @@ int perf_data__open(struct perf_data *data)if (perf_data__is_read (data)) data->is_dir =is_dir (data); -return perf_data__is_dir (data) ? -open_dir (data) :open_file_dup (data); + ret =perf_data__is_dir (data) ?open_dir (data) :open_file_dup (data); + +if (!ret) + data->open = true; + +return ret; }void perf_data__close (struct perf_data *data) { +if (!data->open) +return ; +if (perf_data__is_dir (data))perf_data__close_dir (data);perf_data_file__close (&data->file); + data->open = false; }static ssize_t perf_data_file__read (struct perf_data_file *file,void *buf,size_t size)
@@ -457,6 +474,7 @@ int perf_data__switch(struct perf_data *data,if (!at_exit) {perf_data_file__close (&data->file); + data->open = false; ret =perf_data__open (data);if (ret <0 ) goto out;
tools/perf/util/data.h +3 -1
@@ -50,6 +50,8 @@ struct perf_data {const char *path;/** @file: Underlying file to be used. */ struct perf_data_file file; +/** @open: Has the file or directory been opened. */ +bool open;/** @is_pipe: Underlying file is a pipe. */ bool is_pipe;/** @is_dir: Underlying file is a directory. */
@@ -59,7 +61,7 @@ struct perf_data {/** @in_place_update: A file opened for reading but will be written to. */ bool in_place_update;/** @mode: Read or write mode. */ -enum perf_data_mode mode; + enum perf_data_mode mode:8;struct {/** @version: perf_dir_version. */
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Ian Rogers
reviewerPATCH v7 10/59 perf evlist: Add reference count
In reply to Ian RogersThis a no-op for most of the perf tool. The reference count is set to 1 at allocation, the put will see the 1, decrement it and perform the delete. The purpose for adding the reference count is for the python code. Prior to this change the python code would clone evlists, but this has issues if events are opened, etc. This change adds a reference count for the evlists and a later change will add it to evsels. The combination is needed for the python code to operate correctly (not hit asserts in the evsel clone), but the changes are broken apart for the sake of smaller patches.
---
v2: Added evlist__put to pyrf_evlist__init in case init is called more
than once.
I double-checked trace__replay() and confirmed that trace->evlist
is not assigned to session->evlist in that function.
trace__replay creates a new session and uses its own evlist for
processing file events, leaving trace->evlist pointing to the
empty list created at startup. Therefore, the
evlist__put(trace->evlist) call in trace__exit() is safe and
correct to avoid leaking that empty list.v7:
- Added pyrf_evlist__new to zero-initialize pevlist->evlist to fix crash on re-initialization.
--- tools/perf/arch/x86/tests/hybrid.c | 2 +- tools/perf/arch/x86/tests/topdown.c | 2 +- tools/perf/arch/x86/util/iostat.c | 2 +- tools/perf/bench/evlist-open-close.c | 18 +- tools/perf/builtin-ftrace.c | 8 +- tools/perf/builtin-kvm.c | 4 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-record.c | 4 +- tools/perf/builtin-sched.c | 6 +- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-stat.c | 10 +- tools/perf/builtin-top.c | 52 ++--- tools/perf/builtin-trace.c | 26 +-- tools/perf/tests/backward-ring-buffer.c | 18 +- tools/perf/tests/code-reading.c | 4 +- tools/perf/tests/event-times.c | 4 +- tools/perf/tests/event_update.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 8 +- tools/perf/tests/expand-cgroup.c | 8 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_link.c | 2 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/hwmon_pmu.c | 2 +- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mmap-basic.c | 18 +- tools/perf/tests/openat-syscall-tp-fields.c | 18 +- tools/perf/tests/parse-events.c | 4 +- tools/perf/tests/parse-metric.c | 4 +- tools/perf/tests/parse-no-sample-id-all.c | 2 +- tools/perf/tests/perf-record.c | 18 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/pfm.c | 4 +- tools/perf/tests/pmu-events.c | 6 +- tools/perf/tests/pmu.c | 4 +- tools/perf/tests/sw-clock.c | 14 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 14 +- tools/perf/tests/tool_pmu.c | 2 +- tools/perf/tests/topology.c | 2 +- tools/perf/util/cgroup.c | 4 +- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/evlist.c | 20 +- tools/perf/util/evlist.h | 7 +- tools/perf/util/expr.c | 2 +- tools/perf/util/header.c | 12 +- tools/perf/util/metricgroup.c | 6 +- tools/perf/util/parse-events.c | 4 +- tools/perf/util/perf_api_probe.c | 2 +- tools/perf/util/python.c | 212 ++++++++------------ tools/perf/util/record.c | 2 +- tools/perf/util/session.c | 2 +- tools/perf/util/sideband_evlist.c | 16 +- 53 files changed, 279 insertions(+), 320 deletions(-)
tools/perf/arch/x86/tests/hybrid.c +1 -1
@@ -268,7 +268,7 @@ static int test_event(const struct evlist_test *e) ret = e->check (evlist); }parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
tools/perf/arch/x86/tests/topdown.c +1 -1
@@ -56,7 +56,7 @@ static int event_cb(void *state, struct pmu_event_info *info) *ret =TEST_FAIL ; } } -evlist__delete (evlist); +evlist__put (evlist);return 0 ; }
tools/perf/arch/x86/util/iostat.c +1 -1
@@ -337,7 +337,7 @@ int iostat_prepare(struct evlist *evlist, struct perf_stat_config *config)if (evlist->core.nr_entries >0 ) {pr_warning ("The -e and -M options are not supported." "All chosen events/metrics will be dropped\n" ); -evlist__delete (evlist); +evlist__put (evlist); evlist =evlist__new ();if (!evlist)return -ENOMEM ;
tools/perf/bench/evlist-open-close.c +9 -9
@@ -76,7 +76,7 @@ static struct evlist *bench__create_evlist(char *evstr, const char *uid_str)parse_events_error__exit (&err);pr_err ("Run 'perf list' for a list of valid events\n" ); ret =1 ; - goto out_delete_evlist; + goto out_put_evlist; }parse_events_error__exit (&err);if (uid_str) {
@@ -85,24 +85,24 @@ static struct evlist *bench__create_evlist(char *evstr, const char *uid_str)if (uid ==UINT_MAX ) {pr_err ("Invalid User: %s" , uid_str); ret = -EINVAL ; - goto out_delete_evlist; + goto out_put_evlist; } ret =parse_uid_filter (evlist, uid);if (ret) - goto out_delete_evlist; + goto out_put_evlist; } ret =evlist__create_maps (evlist, &opts.target);if (ret <0 ) {pr_err ("Not enough memory to create thread/cpu maps\n" ); - goto out_delete_evlist; + goto out_put_evlist; }evlist__config (evlist, &opts,NULL );return evlist; -out_delete_evlist: -evlist__delete (evlist); +out_put_evlist: +evlist__put (evlist);return NULL ; }
@@ -151,7 +151,7 @@ static int bench_evlist_open_close__run(char *evstr, const char *uid_str) evlist->core.nr_entries, evlist__count_evsel_fds(evlist));printf (" Number of iterations:\t%d\n" , iterations); -evlist__delete (evlist); +evlist__put (evlist);for (i =0 ; i < iterations; i++) {pr_debug ("Started iteration %d\n" , i);
@@ -162,7 +162,7 @@ static int bench_evlist_open_close__run(char *evstr, const char *uid_str)gettimeofday (&start,NULL ); err =bench__do_evlist_open_close (evlist);if (err) { -evlist__delete (evlist); +evlist__put (evlist);return err; }
@@ -171,7 +171,7 @@ static int bench_evlist_open_close__run(char *evstr, const char *uid_str) runtime_us =timeval2usec (&diff);update_stats (&time_stats, runtime_us); -evlist__delete (evlist); +evlist__put (evlist);pr_debug ("Iteration %d took:\t%" PRIu64"us\n" , i, runtime_us); }
tools/perf/builtin-ftrace.c +4 -4
@@ -1999,20 +1999,20 @@ int cmd_ftrace(int argc, const char **argv) ret =evlist__create_maps (ftrace.evlist, &ftrace.target);if (ret <0 ) - goto out_delete_evlist; + goto out_put_evlist;if (argc) { ret =evlist__prepare_workload (ftrace.evlist, &ftrace.target, argv, false, ftrace__workload_exec_failed_signal);if (ret <0 ) - goto out_delete_evlist; + goto out_put_evlist; } ret =cmd_func (&ftrace); -out_delete_evlist: -evlist__delete (ftrace.evlist); +out_put_evlist: +evlist__put (ftrace.evlist); out_delete_filters:delete_filter_func (&ftrace.filters);
tools/perf/builtin-kvm.c +2 -2
@@ -1811,7 +1811,7 @@ static struct evlist *kvm_live_event_list(void) out:if (err) { -evlist__delete (evlist); +evlist__put (evlist); evlist =NULL ; }
@@ -1942,7 +1942,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, out:perf_session__delete (kvm->session); kvm->session =NULL ; -evlist__delete (kvm->evlist); +evlist__put (kvm->evlist);return err; }
tools/perf/builtin-lock.c +1 -1
@@ -2145,7 +2145,7 @@ static int __cmd_contention(int argc, const char **argv) out_delete:lock_filter_finish (); -evlist__delete (con.evlist); +evlist__put (con.evlist);lock_contention_finish (&con);perf_session__delete (session);perf_env__exit (&host_env);
tools/perf/builtin-record.c +2 -2
@@ -4289,7 +4289,7 @@ int cmd_record(int argc, const char **argv) goto out;evlist__splice_list_tail (rec->evlist, &def_evlist->core.entries); -evlist__delete (def_evlist); +evlist__put (def_evlist); }if (rec->opts.target.tid && !rec->opts.no_inherit_set)
@@ -4397,7 +4397,7 @@ int cmd_record(int argc, const char **argv)auxtrace_record__free (rec->itr); out_opts:evlist__close_control (rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.ctl_fd_close); -evlist__delete (rec->evlist); +evlist__put (rec->evlist);return err; }
tools/perf/builtin-sched.c +3 -3
@@ -3829,7 +3829,7 @@ static int perf_sched__schedstat_record(struct perf_sched *sched, session =perf_session__new (&data, &sched->tool);if (IS_ERR (session)) {pr_err ("Perf session creation failed.\n" ); -evlist__delete (evlist); +evlist__put (evlist);return PTR_ERR (session); }
@@ -3925,7 +3925,7 @@ static int perf_sched__schedstat_record(struct perf_sched *sched,else fprintf (stderr,"[ perf sched stats: Failed !! ]\n" ); -evlist__delete (evlist); +evlist__put (evlist);close (fd);return err; }
@@ -4724,7 +4724,7 @@ static int perf_sched__schedstat_live(struct perf_sched *sched,free_cpu_domain_info (cd_map, sv, nr); out:free_schedstat (&cpu_head); -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/builtin-script.c +1 -1
@@ -2269,7 +2269,7 @@ static int script_find_metrics(const struct pmu_metric *pm, }pr_debug ("Found metric '%s' whose evsels match those of in the perf data\n" , pm->metric_name); -evlist__delete (metric_evlist); +evlist__put (metric_evlist); out:return 0 ; }
tools/perf/builtin-stat.c +5 -5
@@ -2113,7 +2113,7 @@ static int add_default_events(void) stat_config.user_requested_cpu_list, stat_config.system_wide, stat_config.hardware_aware_grouping) < 0) { -evlist__delete (metric_evlist); +evlist__put (metric_evlist); ret =-1 ;break ; }
@@ -2125,7 +2125,7 @@ static int add_default_events(void)metricgroup__copy_metric_events (evlist,/*cgrp=*/ NULL , &evlist->metric_events, &metric_evlist->metric_events); -evlist__delete (metric_evlist); +evlist__put (metric_evlist); }list_sort (/*priv=*/ NULL , &evlist->core.entries, default_evlist_evsel_cmp);
@@ -2146,7 +2146,7 @@ static int add_default_events(void)metricgroup__copy_metric_events (evsel_list,/*cgrp=*/ NULL , &evsel_list->metric_events, &evlist->metric_events); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
@@ -2381,7 +2381,7 @@ static int __cmd_report(int argc, const char **argv) perf_stat.session = session; stat_config.output = stderr; -evlist__delete (evsel_list); +evlist__put (evsel_list); evsel_list = session->evlist; ret =perf_session__process_events (session);
@@ -3060,7 +3060,7 @@ int cmd_stat(int argc, const char **argv)if (smi_cost && smi_reset)sysfs__write_int (FREEZE_ON_SMI_PATH ,0 ); -evlist__delete (evsel_list); +evlist__put (evsel_list);evlist__close_control (stat_config.ctl_fd, stat_config.ctl_fd_ack, &stat_config.ctl_fd_close);
tools/perf/builtin-top.c +26 -26
184 lines not on this page · raw message
tools/perf/builtin-trace.c +13 -13
@@ -4388,7 +4388,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)if (trace->summary_bpf) {if (trace_prepare_bpf_summary (trace->summary_mode) <0 ) - goto out_delete_evlist; + goto out_put_evlist;if (trace->summary_only) goto create_maps;
@@ -4456,19 +4456,19 @@ static int trace__run(struct trace *trace, int argc, const char **argv) err =evlist__create_maps (evlist, &trace->opts.target);if (err <0 ) {fprintf (trace->output,"Problems parsing the target to trace, check your options!\n" ); - goto out_delete_evlist; + goto out_put_evlist; } err =trace__symbols_init (trace, argc, argv, evlist);if (err <0 ) {fprintf (trace->output,"Problems initializing symbol libraries!\n" ); - goto out_delete_evlist; + goto out_put_evlist; }if (trace->summary_mode ==SUMMARY__BY_TOTAL && !trace->summary_bpf) { trace->syscall_stats =alloc_syscall_stats ();if (!trace->syscall_stats) - goto out_delete_evlist; + goto out_put_evlist; }evlist__config (evlist, &trace->opts, &callchain_param);
@@ -4477,7 +4477,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) err =evlist__prepare_workload (evlist, &trace->opts.target, argv, false,NULL );if (err <0 ) {fprintf (trace->output,"Couldn't run the workload!\n" ); - goto out_delete_evlist; + goto out_put_evlist; } workload_pid = evlist->workload.pid; }
@@ -4525,7 +4525,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) err =trace__expand_filters (trace, &evsel);if (err) - goto out_delete_evlist; + goto out_put_evlist; err =evlist__apply_filters (evlist, &evsel, &trace->opts.target);if (err <0 ) goto out_error_apply_filters;
@@ -4642,12 +4642,12 @@ static int trace__run(struct trace *trace, int argc, const char **argv) } } -out_delete_evlist: +out_put_evlist:trace_cleanup_bpf_summary ();delete_syscall_stats (trace->syscall_stats);trace__symbols__exit (trace);evlist__free_syscall_tp_fields (evlist); -evlist__delete (evlist); +evlist__put (evlist);cgroup__put (trace->cgroup); trace->evlist =NULL ; trace->live = false;
@@ -4672,21 +4672,21 @@ static int trace__run(struct trace *trace, int argc, const char **argv) out_error:fprintf (trace->output,"%s\n" , errbuf); - goto out_delete_evlist; + goto out_put_evlist; out_error_apply_filters:fprintf (trace->output,"Failed to set filter \"%s\" on event %s: %m\n" , evsel->filter,evsel__name (evsel)); - goto out_delete_evlist; + goto out_put_evlist; } out_error_mem:fprintf (trace->output,"Not enough memory to run!\n" ); - goto out_delete_evlist; + goto out_put_evlist; out_errno:fprintf (trace->output,"%m\n" ); - goto out_delete_evlist; + goto out_put_evlist; }static int trace__replay (struct trace *trace)
@@ -5364,7 +5364,7 @@ static void trace__exit(struct trace *trace)zfree (&trace->syscalls.table); }zfree (&trace->perfconfig_events); -evlist__delete (trace->evlist); +evlist__put (trace->evlist); trace->evlist =NULL ;ordered_events__free (&trace->oe.data);#ifdef HAVE_LIBBPF_SUPPORT
tools/perf/tests/backward-ring-buffer.c +9 -9
@@ -111,7 +111,7 @@ static int test__backward_ring_buffer(struct test_suite *test __maybe_unused, in err =evlist__create_maps (evlist, &opts.target);if (err <0 ) {pr_debug ("Not enough memory to create thread/cpu maps\n" ); - goto out_delete_evlist; + goto out_put_evlist; }parse_events_error__init (&parse_error);
@@ -124,7 +124,7 @@ static int test__backward_ring_buffer(struct test_suite *test __maybe_unused, inif (err) {pr_debug ("Failed to parse tracepoint event, try use root\n" ); ret =TEST_SKIP ; - goto out_delete_evlist; + goto out_put_evlist; }evlist__config (evlist, &opts,NULL );
@@ -133,19 +133,19 @@ static int test__backward_ring_buffer(struct test_suite *test __maybe_unused, inif (err <0 ) {pr_debug ("perf_evlist__open: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } ret =TEST_FAIL ; err =do_test (evlist, opts.mmap_pages, &sample_count, &comm_count);if (err !=TEST_OK ) - goto out_delete_evlist; + goto out_put_evlist;if ((sample_count !=NR_ITERS ) || (comm_count !=NR_ITERS )) {pr_err ("Unexpected counter: sample_count=%d, comm_count=%d\n" , sample_count, comm_count); - goto out_delete_evlist; + goto out_put_evlist; }evlist__close (evlist);
@@ -154,16 +154,16 @@ static int test__backward_ring_buffer(struct test_suite *test __maybe_unused, inif (err <0 ) {pr_debug ("perf_evlist__open: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } err =do_test (evlist,1 , &sample_count, &comm_count);if (err !=TEST_OK ) - goto out_delete_evlist; + goto out_put_evlist; ret =TEST_OK ; -out_delete_evlist: -evlist__delete (evlist); +out_put_evlist: +evlist__put (evlist);return ret; }
tools/perf/tests/code-reading.c +2 -2
@@ -807,7 +807,7 @@ static int do_test_code_reading(bool try_kcore) }perf_evlist__set_maps (&evlist->core,NULL ,NULL ); -evlist__delete (evlist); +evlist__put (evlist); evlist =NULL ;continue ; }
@@ -844,7 +844,7 @@ static int do_test_code_reading(bool try_kcore) out_put:thread__put (thread); out_err: -evlist__delete (evlist); +evlist__put (evlist);perf_cpu_map__put (cpus);perf_thread_map__put (threads);machine__delete (machine);
tools/perf/tests/event-times.c +2 -2
@@ -186,7 +186,7 @@ static int test_times(int (attach)(struct evlist *), err =attach (evlist);if (err ==TEST_SKIP ) {pr_debug (" SKIP : not enough rights\n" ); -evlist__delete (evlist); +evlist__put (evlist);return err; }
@@ -205,7 +205,7 @@ static int test_times(int (attach)(struct evlist *), count.ena, count.run); out_err: -evlist__delete (evlist); +evlist__put (evlist);return !err ?TEST_OK :TEST_FAIL ; }
tools/perf/tests/event_update.c +1 -1
@@ -117,7 +117,7 @@ static int test__event_update(struct test_suite *test __maybe_unused, int subtesTEST_ASSERT_VAL ("failed to synthesize attr update cpus" , !perf_event__synthesize_event_update_cpus (&tmp.tool, evsel, process_event_cpus)); -evlist__delete (evlist); +evlist__put (evlist);return 0 ; }
tools/perf/tests/evsel-roundtrip-name.c +4 -4
@@ -33,7 +33,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)if (err) {pr_debug ("Failure to parse cache event '%s' possibly as PMUs don't support it" , name); -evlist__delete (evlist); +evlist__put (evlist);continue ; }evlist__for_each_entry (evlist, evsel) {
@@ -42,7 +42,7 @@ static int perf_evsel__roundtrip_cache_name_test(void) ret =TEST_FAIL ; } } -evlist__delete (evlist); +evlist__put (evlist); } } }
@@ -66,7 +66,7 @@ static int perf_evsel__name_array_test(const char *const names[], int nr_names)if (err) {pr_debug ("failed to parse event '%s', err %d\n" , names[i], err); -evlist__delete (evlist); +evlist__put (evlist); ret =TEST_FAIL ;continue ; }
@@ -76,7 +76,7 @@ static int perf_evsel__name_array_test(const char *const names[], int nr_names) ret =TEST_FAIL ; } } -evlist__delete (evlist); +evlist__put (evlist); }return ret; }
tools/perf/tests/expand-cgroup.c +4 -4
@@ -106,7 +106,7 @@ static int expand_default_events(void)TEST_ASSERT_VAL ("failed to get evlist" , evlist); ret =test_expand_events (evlist); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
@@ -133,7 +133,7 @@ static int expand_group_events(void) ret =test_expand_events (evlist); out:parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
@@ -164,7 +164,7 @@ static int expand_libpfm_events(void) ret =test_expand_events (evlist); out: -evlist__delete (evlist); +evlist__put (evlist);return ret; }
@@ -188,7 +188,7 @@ static int expand_metric_events(void) ret =test_expand_events (evlist); out: -evlist__delete (evlist); +evlist__put (evlist);return ret; }
tools/perf/tests/hists_cumulate.c +1 -1
@@ -744,7 +744,7 @@ static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subt out:/* tear down everything */ -evlist__delete (evlist); +evlist__put (evlist);machines__exit (&machines);put_fake_samples ();
tools/perf/tests/hists_filter.c +1 -1
@@ -332,7 +332,7 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes out:/* tear down everything */ -evlist__delete (evlist); +evlist__put (evlist);reset_output_field ();machines__exit (&machines);put_fake_samples ();
tools/perf/tests/hists_link.c +1 -1
@@ -352,7 +352,7 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest out:/* tear down everything */ -evlist__delete (evlist); +evlist__put (evlist);reset_output_field ();machines__exit (&machines);put_fake_samples ();
tools/perf/tests/hists_output.c +1 -1
@@ -631,7 +631,7 @@ static int test__hists_output(struct test_suite *test __maybe_unused, int subtes out:/* tear down everything */ -evlist__delete (evlist); +evlist__put (evlist);machines__exit (&machines);put_fake_samples ();
tools/perf/tests/hwmon_pmu.c +1 -1
@@ -214,7 +214,7 @@ static int do_test(size_t i, bool with_pmu, bool with_alias) out:parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
tools/perf/tests/keep-tracking.c +1 -1
@@ -153,7 +153,7 @@ static int test__keep_tracking(struct test_suite *test __maybe_unused, int subte out_err:if (evlist) {evlist__disable (evlist); -evlist__delete (evlist); +evlist__put (evlist); }perf_cpu_map__put (cpus);perf_thread_map__put (threads);
tools/perf/tests/mmap-basic.c +9 -9
@@ -94,7 +94,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest/* Permissions failure, flag the failure as a skip. */ err =TEST_SKIP ; } - goto out_delete_evlist; + goto out_put_evlist; } evsels[i]->core.attr.wakeup_events =1 ;
@@ -106,7 +106,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtestpr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } nr_events[i] =0 ;
@@ -116,7 +116,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtestif (evlist__mmap (evlist,128 ) <0 ) {pr_debug ("failed to mmap events: %d (%s)\n" , errno,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; }for (i =0 ; i < nsyscalls; ++i)
@@ -134,7 +134,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtestif (event->header.type !=PERF_RECORD_SAMPLE ) {pr_debug ("unexpected %s event\n" ,perf_event__name (event->header.type)); - goto out_delete_evlist; + goto out_put_evlist; }perf_sample__init (&sample,/*all=*/ false);
@@ -142,7 +142,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtestif (err) {pr_err ("Can't parse sample, err = %d\n" , err);perf_sample__exit (&sample); - goto out_delete_evlist; + goto out_put_evlist; } err =-1 ;
@@ -151,7 +151,7 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtestif (evsel ==NULL ) {pr_debug ("event with id %" PRIu64" doesn't map to an evsel\n" , sample.id); - goto out_delete_evlist; + goto out_put_evlist; } nr_events[evsel->core.idx]++;perf_mmap__consume (&md->core);
@@ -166,12 +166,12 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest expected_nr_events[evsel->core.idx], evsel__name(evsel), nr_events[evsel->core.idx]); err =-1 ; - goto out_delete_evlist; + goto out_put_evlist; } } -out_delete_evlist: -evlist__delete (evlist); +out_put_evlist: +evlist__put (evlist); out_free_cpus:perf_cpu_map__put (cpus); out_free_threads:
tools/perf/tests/openat-syscall-tp-fields.c +9 -9
@@ -51,7 +51,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unusedif (IS_ERR (evsel)) {pr_debug ("%s: evsel__newtp\n" , __func__); ret =PTR_ERR (evsel) == -EACCES ?TEST_SKIP :TEST_FAIL ; - goto out_delete_evlist; + goto out_put_evlist; }evlist__add (evlist, evsel);
@@ -59,7 +59,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused err =evlist__create_maps (evlist, &opts.target);if (err <0 ) {pr_debug ("%s: evlist__create_maps\n" , __func__); - goto out_delete_evlist; + goto out_put_evlist; }evsel__config (evsel, &opts,NULL );
@@ -70,14 +70,14 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unusedif (err <0 ) {pr_debug ("perf_evlist__open: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } err =evlist__mmap (evlist,UINT_MAX );if (err <0 ) {pr_debug ("evlist__mmap: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; }evlist__enable (evlist);
@@ -115,7 +115,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unusedif (err) {pr_debug ("Can't parse sample, err = %d\n" , err);perf_sample__exit (&sample); - goto out_delete_evlist; + goto out_put_evlist; } tp_flags =evsel__intval (evsel, &sample,"flags" );
@@ -123,7 +123,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unusedif (flags != tp_flags) {pr_debug ("%s: Expected flags=%#x, got %#x\n" , __func__, flags, tp_flags); - goto out_delete_evlist; + goto out_put_evlist; } goto out_ok;
@@ -136,13 +136,13 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unusedif (++nr_polls >5 ) {pr_debug ("%s: no events!\n" , __func__); - goto out_delete_evlist; + goto out_put_evlist; } } out_ok: ret =TEST_OK ; -out_delete_evlist: -evlist__delete (evlist); +out_put_evlist: +evlist__put (evlist); out:return ret; }
tools/perf/tests/parse-events.c +2 -2
@@ -2568,7 +2568,7 @@ static int test_event(const struct evlist_test *e) ret = e->check (evlist); }parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
@@ -2594,7 +2594,7 @@ static int test_event_fake_pmu(const char *str) }parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
tools/perf/tests/parse-metric.c +2 -2
@@ -84,7 +84,7 @@ static int __compute_metric(const char *name, struct value *vals, cpus =perf_cpu_map__new ("0" );if (!cpus) { -evlist__delete (evlist); +evlist__put (evlist);return -ENOMEM ; }
@@ -113,7 +113,7 @@ static int __compute_metric(const char *name, struct value *vals,/* ... cleanup. */ evlist__free_stats (evlist);perf_cpu_map__put (cpus); -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/tests/parse-no-sample-id-all.c +1 -1
@@ -49,7 +49,7 @@ static int process_events(union perf_event **events, size_t count)for (i =0 ; i < count && !err; i++) err =process_event (&evlist, events[i]); -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/tests/perf-record.c +9 -9
@@ -105,7 +105,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest err =evlist__create_maps (evlist, &opts.target);if (err <0 ) {pr_debug ("Not enough memory to create thread/cpu maps\n" ); - goto out_delete_evlist; + goto out_put_evlist; }/*
@@ -117,7 +117,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest err =evlist__prepare_workload (evlist, &opts.target, argv, false,NULL );if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); - goto out_delete_evlist; + goto out_put_evlist; }/*
@@ -134,7 +134,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtestpr_debug ("sched__get_first_possible_cpu: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf)));evlist__cancel_workload (evlist); - goto out_delete_evlist; + goto out_put_evlist; } cpu = err;
@@ -146,7 +146,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtestpr_debug ("sched_setaffinity: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf)));evlist__cancel_workload (evlist); - goto out_delete_evlist; + goto out_put_evlist; }/*
@@ -158,7 +158,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtestpr_debug ("perf_evlist__open: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf)));evlist__cancel_workload (evlist); - goto out_delete_evlist; + goto out_put_evlist; }/*
@@ -171,7 +171,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtestpr_debug ("evlist__mmap: %s\n" ,str_error_r (errno, sbuf,sizeof (sbuf)));evlist__cancel_workload (evlist); - goto out_delete_evlist; + goto out_put_evlist; }/*
@@ -209,7 +209,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtestif (verbose >0 )perf_event__fprintf (event,NULL , stderr);pr_debug ("Couldn't parse sample\n" ); - goto out_delete_evlist; + goto out_put_evlist; }if (verbose >0 ) {
@@ -350,9 +350,9 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtestpr_debug ("PERF_RECORD_MMAP for %s missing!\n" ,"[vdso]" ); ++errs; } -out_delete_evlist: +out_put_evlist:CPU_FREE (cpu_mask); -evlist__delete (evlist); +evlist__put (evlist); out:perf_sample__exit (&sample);if (err == -EACCES )
tools/perf/tests/perf-time-to-tsc.c +1 -1
@@ -201,7 +201,7 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su err =TEST_OK ; out_err: -evlist__delete (evlist); +evlist__put (evlist);perf_cpu_map__put (cpus);perf_thread_map__put (threads);return err;
tools/perf/tests/pfm.c +2 -2
@@ -80,7 +80,7 @@ static int test__pfm_events(struct test_suite *test __maybe_unused,evlist__nr_groups (evlist), 0); -evlist__delete (evlist); +evlist__put (evlist); }return 0 ; }
@@ -165,7 +165,7 @@ static int test__pfm_group(struct test_suite *test __maybe_unused,evlist__nr_groups (evlist), table[i].nr_groups); -evlist__delete (evlist); +evlist__put (evlist); }return 0 ; }
tools/perf/tests/pmu-events.c +3 -3
@@ -797,7 +797,7 @@ static int check_parse_id(const char *id, struct parse_events_error *error) /*warn_if_reordered=*/true, /*fake_tp=*/false);free (dup); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
@@ -844,7 +844,7 @@ static int test__parsing_callback(const struct pmu_metric *pm, cpus =perf_cpu_map__new ("0" );if (!cpus) { -evlist__delete (evlist); +evlist__put (evlist);return -ENOMEM ; }
@@ -899,7 +899,7 @@ static int test__parsing_callback(const struct pmu_metric *pm,/* ... cleanup. */ evlist__free_stats (evlist);perf_cpu_map__put (cpus); -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/tests/pmu.c +2 -2
@@ -287,7 +287,7 @@ static int test__pmu_usr_chgs(struct test_suite *test __maybe_unused, int subtes ret =TEST_OK ; err_out:parse_events_terms__exit (&terms); -evlist__delete (evlist); +evlist__put (evlist);test_pmu_put (dir, pmu);return ret; }
@@ -339,7 +339,7 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest ret =TEST_OK ; err_out:parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);test_pmu_put (dir, pmu);return ret; }
tools/perf/tests/sw-clock.c +7 -7
@@ -59,7 +59,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) evsel =evsel__new (&attr);if (evsel ==NULL ) {pr_debug ("evsel__new\n" ); - goto out_delete_evlist; + goto out_put_evlist; }evlist__add (evlist, evsel);
@@ -68,7 +68,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)if (!cpus || !threads) { err = -ENOMEM ;pr_debug ("Not enough memory to create thread/cpu maps\n" ); - goto out_delete_evlist; + goto out_put_evlist; }perf_evlist__set_maps (&evlist->core, cpus, threads);
@@ -80,14 +80,14 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)pr_debug ("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64" in this test.\n" ,str_error_r (errno, sbuf,sizeof (sbuf)), knob, (u64 )attr.sample_freq); - goto out_delete_evlist; + goto out_put_evlist; } err =evlist__mmap (evlist,128 );if (err <0 ) {pr_debug ("failed to mmap event: %d (%s)\n" , errno,str_error_r (errno, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; }evlist__enable (evlist);
@@ -113,7 +113,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)if (err <0 ) {pr_debug ("Error during parse sample\n" );perf_sample__exit (&sample); - goto out_delete_evlist; + goto out_put_evlist; } total_periods += sample.period;
@@ -131,10 +131,10 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id) err =-1 ; } -out_delete_evlist: +out_put_evlist:perf_cpu_map__put (cpus);perf_thread_map__put (threads); -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/tests/switch-tracking.c +1 -1
@@ -579,7 +579,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub out:if (evlist) {evlist__disable (evlist); -evlist__delete (evlist); +evlist__put (evlist); }perf_cpu_map__put (cpus);perf_thread_map__put (threads);
tools/perf/tests/task-exit.c +7 -7
@@ -74,7 +74,7 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _if (!cpus || !threads) { err = -ENOMEM ;pr_debug ("Not enough memory to create thread/cpu maps\n" ); - goto out_delete_evlist; + goto out_put_evlist; }perf_evlist__set_maps (&evlist->core, cpus, threads);
@@ -82,7 +82,7 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _ err =evlist__prepare_workload (evlist, &target, argv, false, workload_exec_failed_signal);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); - goto out_delete_evlist; + goto out_put_evlist; } evsel =evlist__first (evlist);
@@ -101,14 +101,14 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _if (err <0 ) {pr_debug ("Couldn't open the evlist: %s\n" ,str_error_r (-err, sbuf,sizeof (sbuf))); - goto out_delete_evlist; + goto out_put_evlist; }if (evlist__mmap (evlist,128 ) <0 ) {pr_debug ("failed to mmap events: %d (%s)\n" , errno,str_error_r (errno, sbuf,sizeof (sbuf))); err =-1 ; - goto out_delete_evlist; + goto out_put_evlist; }evlist__start_workload (evlist);
@@ -133,7 +133,7 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _if (retry_count++ >1000 ) {pr_debug ("Failed after retrying 1000 times\n" ); err =-1 ; - goto out_delete_evlist; + goto out_put_evlist; } goto retry;
@@ -144,10 +144,10 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _ err =-1 ; } -out_delete_evlist: +out_put_evlist:perf_cpu_map__put (cpus);perf_thread_map__put (threads); -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/tests/tool_pmu.c +1 -1
@@ -67,7 +67,7 @@ static int do_test(enum tool_pmu_event ev, bool with_pmu) out:parse_events_error__exit (&err); -evlist__delete (evlist); +evlist__put (evlist);return ret; }
tools/perf/tests/topology.c +1 -1
@@ -57,7 +57,7 @@ static int session_write_header(char *path) !perf_session__write_header (session, session->evlist, perf_data__fd(&data), true)); -evlist__delete (session->evlist); +evlist__put (session->evlist);perf_session__delete (session);return 0 ;
tools/perf/util/cgroup.c +2 -2
@@ -520,8 +520,8 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str, bool open_cgro cgrp_event_expanded = true; out_err: -evlist__delete (orig_list); -evlist__delete (tmp_list); +evlist__put (orig_list); +evlist__put (tmp_list);metricgroup__rblist_exit (&orig_metric_events);release_cgroup_list ();
tools/perf/util/data-convert-bt.c +1 -1
@@ -1363,7 +1363,7 @@ static void cleanup_events(struct perf_session *session)zfree (&evsel->priv); } -evlist__delete (evlist); +evlist__put (evlist); session->evlist =NULL ; }
tools/perf/util/evlist.c +15 -5
@@ -75,7 +75,7 @@ int sigqueue(pid_t pid, int sig, const union sigval value);#define FD (e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))#define SID (e, x, y) xyarray__entry(e->core.sample_id, x, y) -void evlist__init (struct evlist *evlist,struct perf_cpu_map *cpus, +static void evlist__init (struct evlist *evlist,struct perf_cpu_map *cpus,struct perf_thread_map *threads) {perf_evlist__init (&evlist->core);
@@ -88,6 +88,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus, evlist->nr_br_cntr =-1 ;metricgroup__rblist_init (&evlist->metric_events);INIT_LIST_HEAD (&evlist->deferred_samples); +refcount_set (&evlist->refcnt,1 ); }struct evlist *evlist__new (void )
@@ -139,7 +140,7 @@ struct evlist *evlist__new_default(const struct target *target, bool sample_callreturn evlist; out_err: -evlist__delete (evlist); +evlist__put (evlist);return NULL ; }
@@ -148,13 +149,19 @@ struct evlist *evlist__new_dummy(void)struct evlist *evlist =evlist__new ();if (evlist &&evlist__add_dummy (evlist)) { -evlist__delete (evlist); +evlist__put (evlist); evlist =NULL ; }return evlist; } +struct evlist *evlist__get (struct evlist *evlist) +{ +refcount_inc (&evlist->refcnt); +return evlist; +} +/** * evlist__set_id_pos - set the positions of event ids. * @evlist: selected event list
@@ -193,7 +200,7 @@ static void evlist__purge(struct evlist *evlist) evlist->core.nr_entries =0 ; } -void evlist__exit (struct evlist *evlist) +static void evlist__exit (struct evlist *evlist) {metricgroup__rblist_exit (&evlist->metric_events);event_enable_timer__exit (&evlist->eet);
@@ -202,11 +209,14 @@ void evlist__exit(struct evlist *evlist)perf_evlist__exit (&evlist->core); } -void evlist__delete (struct evlist *evlist) +void evlist__put (struct evlist *evlist) {if (evlist ==NULL )return ; +if (!refcount_dec_and_test (&evlist->refcnt)) +return ; +evlist__free_stats (evlist);evlist__munmap (evlist);evlist__close (evlist);
tools/perf/util/evlist.h +3 -4
@@ -61,6 +61,7 @@ struct event_enable_timer;struct evlist {struct perf_evlist core; +refcount_t refcnt;bool enabled;bool no_affinity;int id_pos;
@@ -109,10 +110,8 @@ struct evsel_str_handler {struct evlist *evlist__new (void );struct evlist *evlist__new_default (const struct target *target,bool sample_callchains);struct evlist *evlist__new_dummy (void ); -void evlist__init (struct evlist *evlist,struct perf_cpu_map *cpus, -struct perf_thread_map *threads); -void evlist__exit (struct evlist *evlist); -void evlist__delete (struct evlist *evlist); +struct evlist *evlist__get (struct evlist *evlist); +void evlist__put (struct evlist *evlist);void evlist__add (struct evlist *evlist,struct evsel *entry);void evlist__remove (struct evlist *evlist,struct evsel *evsel);
tools/perf/util/expr.c +1 -1
@@ -450,7 +450,7 @@ double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids, const ret =parse_event (tmp, id) ?0 :1 ; } out: -evlist__delete (tmp); +evlist__put (tmp);return ret; }
tools/perf/util/header.c +6 -6
@@ -4909,12 +4909,12 @@ int perf_session__read_header(struct perf_session *session) evsel =evsel__new (&f_attr.attr);if (evsel ==NULL ) - goto out_delete_evlist; + goto out_put_evlist; evsel->needs_swap = header->needs_swap;/* * Do it before so that if perf_evsel__alloc_id fails, this -* entry gets purged too at evlist__delete(). +* entry gets purged too at evlist__put(). */ evlist__add (session->evlist, evsel);
@@ -4925,7 +4925,7 @@ int perf_session__read_header(struct perf_session *session)* hattr->ids threads. */ if (perf_evsel__alloc_id (&evsel->core,1 , nr_ids)) - goto out_delete_evlist; + goto out_put_evlist;lseek (fd, f_attr.ids.offset,SEEK_SET );
@@ -4944,7 +4944,7 @@ int perf_session__read_header(struct perf_session *session) perf_file_section__process);if (evlist__prepare_tracepoint_events (session->evlist, session->tevent.pevent)) - goto out_delete_evlist; + goto out_put_evlist;#else perf_header__process_sections (header, fd,NULL , perf_file_section__process);#endif
@@ -4953,8 +4953,8 @@ int perf_session__read_header(struct perf_session *session) out_errno:return -errno; -out_delete_evlist: -evlist__delete (session->evlist); +out_put_evlist: +evlist__put (session->evlist); session->evlist =NULL ;return -ENOMEM ; }
tools/perf/util/metricgroup.c +3 -3
@@ -214,7 +214,7 @@ static void metric__free(struct metric *m)zfree (&m->metric_refs);expr__ctx_free (m->pctx);zfree (&m->modifier); -evlist__delete (m->evlist); +evlist__put (m->evlist);free (m); }
@@ -1335,7 +1335,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, parsed_evlist =NULL ; err_out:parse_events_error__exit (&parse_error); -evlist__delete (parsed_evlist); +evlist__put (parsed_evlist);strbuf_release (&events);return ret; }
@@ -1546,7 +1546,7 @@ static int parse_groups(struct evlist *perf_evlist,if (combined_evlist) {evlist__splice_list_tail (perf_evlist, &combined_evlist->core.entries); -evlist__delete (combined_evlist); +evlist__put (combined_evlist); }list_for_each_entry (m, &metric_list, nd) {
tools/perf/util/parse-events.c +2 -2
@@ -2316,7 +2316,7 @@ int __parse_events(struct evlist *evlist, const char *str, const char *pmu_filte/* * There are 2 users - builtin-record and builtin-test objects. -* Both call evlist__delete in case of error, so we dont +* Both call evlist__put in case of error, so we dont * need to bother. */ return ret;
@@ -2519,7 +2519,7 @@ int parse_events_option_new_evlist(const struct option *opt, const char *str, in } ret =parse_events_option (opt, str, unset);if (ret) { -evlist__delete (*args->evlistp); +evlist__put (*args->evlistp); *args->evlistp =NULL ; }
tools/perf/util/perf_api_probe.c +1 -1
@@ -57,7 +57,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha err =0 ; out_delete: -evlist__delete (evlist); +evlist__put (evlist);return err; }
tools/perf/util/python.c +81 -131
410 lines not on this page · raw message
tools/perf/util/record.c +1 -1
@@ -264,7 +264,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str) ret = true; out_delete: -evlist__delete (temp_evlist); +evlist__put (temp_evlist);return ret; }
tools/perf/util/session.c +1 -1
@@ -264,7 +264,7 @@ void perf_session__delete(struct perf_session *session)machines__exit (&session->machines);if (session->data) {if (perf_data__is_read (session->data)) -evlist__delete (session->evlist); +evlist__put (session->evlist);perf_data__close (session->data); }#ifdef HAVE_LIBTRACEEVENT
tools/perf/util/sideband_evlist.c +8 -8
@@ -102,7 +102,7 @@ int evlist__start_sb_thread(struct evlist *evlist, struct target *target)return 0 ;if (evlist__create_maps (evlist, target)) - goto out_delete_evlist; + goto out_put_evlist;if (evlist->core.nr_entries >1 ) {bool can_sample_identifier =perf_can_sample_identifier ();
@@ -116,25 +116,25 @@ int evlist__start_sb_thread(struct evlist *evlist, struct target *target)evlist__for_each_entry (evlist, counter) {if (evsel__open (counter, evlist->core.user_requested_cpus, evlist->core.threads) <0 ) - goto out_delete_evlist; + goto out_put_evlist; }if (evlist__mmap (evlist,UINT_MAX )) - goto out_delete_evlist; + goto out_put_evlist;evlist__for_each_entry (evlist, counter) {if (evsel__enable (counter)) - goto out_delete_evlist; + goto out_put_evlist; } evlist->thread.done =0 ;if (pthread_create (&evlist->thread.th,NULL , perf_evlist__poll_thread, evlist)) - goto out_delete_evlist; + goto out_put_evlist;return 0 ; -out_delete_evlist: -evlist__delete (evlist); +out_put_evlist: +evlist__put (evlist); evlist =NULL ;return -1 ; }
@@ -145,5 +145,5 @@ void evlist__stop_sb_thread(struct evlist *evlist)return ; evlist->thread.done =1 ;pthread_join (evlist->thread.th,NULL ); -evlist__delete (evlist); +evlist__put (evlist); }
Signature · 1 line
2.54.0.545.g6539524ca2-goog