summaryrefslogtreecommitdiff
path: root/tools/perf/python
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-09-28 23:58:37 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-09-29 20:53:09 +0200
commit4b34e3ad4cbb91ff5d6f99bb9c7dd85694c15bec (patch)
tree936dd688f33fb65cadc8bd25c859172915c37f78 /tools/perf/python
parent66d7274859b983a018ea672ef4790ce9b5c715d9 (diff)
perf python event_analyzing_sample: Default to in-memory SQLite database
When -d/--db is not specified, event_analyzing_sample.py created a temporary file in /tmp via tempfile.mkstemp() and deleted it in trace_end(). As noted during review, creating the database in a shared /tmp directory does not reserve SQLite's auxiliary sidecar filenames (-journal or -wal), and a temporary on-disk file is unnecessary when the caller did not ask to persist the database. Default to sqlite3.connect(":memory:") when db_path is not provided, removing the temporary file creation and cleanup logic, and test both the default in-memory mode and explicit -d file mode in test_event_analyzing_sample_python.sh. Fixes: eeb70645a8097437 ("perf python: Port event_analyzing_sample to perf module") Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/python')
-rwxr-xr-xtools/perf/python/event_analyzing_sample.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/tools/perf/python/event_analyzing_sample.py b/tools/perf/python/event_analyzing_sample.py
index 15b47cff9fa3..b4efee88d94b 100755
--- a/tools/perf/python/event_analyzing_sample.py
+++ b/tools/perf/python/event_analyzing_sample.py
@@ -17,10 +17,8 @@ from __future__ import annotations
import argparse
import math
-import os
import sqlite3
import struct
-import tempfile
from typing import Any
import perf
@@ -117,16 +115,11 @@ session: Any = None
class _DB:
con: sqlite3.Connection | None = None
- temp_path: str | None = None
def trace_begin(db_path: str | None = None) -> None:
"""Initialize database tables."""
print("In trace_begin:\n")
- if not db_path:
- fd, db_path = tempfile.mkstemp(prefix="perf_events_", suffix=".db")
- os.close(fd)
- _DB.temp_path = db_path
- con = sqlite3.connect(db_path)
+ con = sqlite3.connect(db_path or ":memory:")
try:
# Drop any pre-existing tables so repeated runs do not accumulate duplicate events.
con.execute("drop table if exists gen_events;")
@@ -297,28 +290,20 @@ def show_pebs_ll() -> None:
def trace_end() -> None:
"""Called at the end of trace processing."""
print("In trace_end:\n")
- try:
- if _DB.con:
- try:
- _DB.con.commit()
- show_general_events()
- show_pebs_ll()
- finally:
- _DB.con.close()
- _DB.con = None
- finally:
- if _DB.temp_path and os.path.exists(_DB.temp_path):
- try:
- os.remove(_DB.temp_path)
- except OSError:
- pass
- _DB.temp_path = None
+ if _DB.con:
+ try:
+ _DB.con.commit()
+ show_general_events()
+ show_pebs_ll()
+ finally:
+ _DB.con.close()
+ _DB.con = None
if __name__ == "__main__":
ap = argparse.ArgumentParser(description="Analyze events with SQLite")
ap.add_argument("-i", "--input", default="perf.data", help="Input file name")
ap.add_argument("-d", "--db", "--database", dest="database", default=None,
- help="Database file name (defaults to a temporary file cleaned up on exit)")
+ help="Database file name (defaults to an in-memory database)")
args = ap.parse_args()
try: