Linux Perf Users
 help / color / mirror / Atom feed
From: Jens Remus <jremus@linux.ibm.com>
To: Ian Rogers <irogers@google.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Cc: Jens Remus <jremus@linux.ibm.com>,
	Jan Polensky <japo@linux.ibm.com>,
	Sumanth Korikkar <sumanthk@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] perf python: Export inlined symbol flag in DB export scripts
Date: Fri,  4 Dec 2026 17:24:29 +0100	[thread overview]
Message-ID: <20261204162426.4171717-9-jremus@linux.ibm.com> (raw)
In-Reply-To: <20261204162426.4171717-7-jremus@linux.ibm.com>

Add an inlined column to the symbols table of the SQLite and PostgreSQL
exports, populated from perf.callchain_node.inlined.  An inlined frame
and a regular frame can share their name and DSO, so the flag is part
of the key that identifies a symbol.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
 tools/perf/python/export-to-postgresql.py | 32 +++++++++++++----------
 tools/perf/python/export-to-sqlite.py     | 18 +++++++------
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/tools/perf/python/export-to-postgresql.py b/tools/perf/python/export-to-postgresql.py
index 9cac64dee361..4f303d239440 100755
--- a/tools/perf/python/export-to-postgresql.py
+++ b/tools/perf/python/export-to-postgresql.py
@@ -205,7 +205,7 @@ class PostgresExporter:
             'branch_types': {},
             'call_paths': {}
         }
-        self.symbol_rows: Dict[int, tuple[int, int, int, int, str]] = {}
+        self.symbol_rows: Dict[int, tuple[int, int, int, int, bool, str]] = {}
 
         self.next_id = {
             'machine': 1,
@@ -372,6 +372,7 @@ class PostgresExporter:
                     sym_start       bigint,
                     sym_end         bigint,
                     binding         integer,
+                    inlined         boolean,
                     name            varchar(2048))
         """)
         self.do_query("""
@@ -514,7 +515,7 @@ class PostgresExporter:
         self.write_thread(0, 0, 0, -1, -1)
         self.write_comm(0, "unknown", 0, 0, 0)
         self.write_dso(0, 0, "unknown", "unknown", "")
-        self.write_symbol(0, 0, 0, 0, 0, "unknown")
+        self.write_symbol(0, 0, 0, 0, 0, False, "unknown")
         self.write_call_path(0, 0, 0, 0)
         # Sentinel id = 0 rows in sample_table.bin and call_table.bin satisfy
         # PostgreSQL FOREIGN KEY constraints (call_id/return_id -> samples.id
@@ -638,13 +639,15 @@ class PostgresExporter:
         self.files['dso'].write(value)
 
     def write_symbol(self, symbol_id: int, dso_id: int, sym_start: int,
-                      sym_end: int, binding: int, symbol_name: str) -> None:
+                      sym_end: int, binding: int, inlined: bool,
+                      symbol_name: str) -> None:
         """Write symbol to binary file."""
         name_bytes = toserverstr(symbol_name)
         n = len(name_bytes)
-        fmt = "!hiqiqiQiQiii" + str(n) + "s"
-        value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8,
-                            sym_start, 8, sym_end, 4, binding, n, name_bytes)
+        fmt = "!hiqiqiQiQiiiBi" + str(n) + "s"
+        value = struct.pack(fmt, 7, 8, symbol_id, 8, dso_id, 8,
+                            sym_start, 8, sym_end, 4, binding, 1, inlined,
+                            n, name_bytes)
         self.files['symbol'].write(value)
 
     def write_call_path(self, cp_id: int, parent_id: int, symbol_id: int,
@@ -771,18 +774,18 @@ class PostgresExporter:
         return dso_id
 
     def get_symbol_id(self, dso_id: int, name: str, start: int,
-                      end: int) -> int:
+                      end: int, inlined: bool = False) -> int:
         """Get or create symbol ID."""
-        key = (dso_id, name)
+        key = (dso_id, name, inlined)
         if key in self.caches['symbols']:
             symbol_id, cached_start, cached_end = self.caches['symbols'][key]
             if cached_start == 0 and cached_end == 0 and (start != 0 or end != 0):
                 self.caches['symbols'][key] = (symbol_id, start, end)
-                self.symbol_rows[symbol_id] = (dso_id, start, end, 0, name)
+                self.symbol_rows[symbol_id] = (dso_id, start, end, 0, inlined, name)
             return symbol_id
         symbol_id = self.next_id['symbol']
         self.caches['symbols'][key] = (symbol_id, start, end)
-        self.symbol_rows[symbol_id] = (dso_id, start, end, 0, name)
+        self.symbol_rows[symbol_id] = (dso_id, start, end, 0, inlined, name)
         self.next_id['symbol'] += 1
         return symbol_id
 
@@ -887,7 +890,7 @@ class PostgresExporter:
             dso_name = node.dso or "Unknown_dso"
             symbol_name = node.symbol or "Unknown_symbol"
             dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
-            symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0)
+            symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0, node.inlined)
             parent_id = call_path_id
             call_path_id = self.get_call_path_id(parent_id, symbol_id, node.ip)
         return call_path_id, parent_id
@@ -963,7 +966,8 @@ class PostgresExporter:
                                    or "Unknown_symbol")
 
                 node_dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
-                node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0)
+                node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0,
+                                                    getattr(node, 'inlined', False))
 
                 parent_id = self.get_call_path_id(parent_id, node_symbol_id, node.ip)
             call_path_id = parent_id
@@ -997,8 +1001,8 @@ class PostgresExporter:
     def finalize(self) -> None:
         """Copy files to database and add keys/views."""
         print("Copying to database...")
-        for symbol_id, (dso_id, sym_start, sym_end, binding, name) in self.symbol_rows.items():
-            self.write_symbol(symbol_id, dso_id, sym_start, sym_end, binding, name)
+        for symbol_id, (dso_id, sym_start, sym_end, binding, inlined, name) in self.symbol_rows.items():
+            self.write_symbol(symbol_id, dso_id, sym_start, sym_end, binding, inlined, name)
         for name, f in self.files.items():
             self.close_output_file(f)
 
diff --git a/tools/perf/python/export-to-sqlite.py b/tools/perf/python/export-to-sqlite.py
index 0a8087e51037..e582bb6004fd 100755
--- a/tools/perf/python/export-to-sqlite.py
+++ b/tools/perf/python/export-to-sqlite.py
@@ -168,6 +168,7 @@ class DatabaseExporter:
                     sym_start BIGINT,
                     sym_end BIGINT,
                     binding INTEGER,
+                    inlined BOOLEAN,
                     name    VARCHAR(2048))
         """)
         self.con.execute("""
@@ -460,7 +461,7 @@ class DatabaseExporter:
         self.con.execute("INSERT OR IGNORE INTO comms VALUES (0, 'unknown', 0, 0, 0)")
         self.con.execute("INSERT OR IGNORE INTO dsos VALUES (0, 0, 'unknown', 'unknown', '')")
         self.con.execute("INSERT OR IGNORE INTO call_paths VALUES (0, 0, 0, 0)")
-        self.con.execute("INSERT OR IGNORE INTO symbols VALUES (0, 0, 0, 0, 0, 'unknown')")
+        self.con.execute("INSERT OR IGNORE INTO symbols VALUES (0, 0, 0, 0, 0, 0, 'unknown')")
         for b_type, b_name in BRANCH_TYPES:
             self.con.execute("INSERT OR IGNORE INTO branch_types VALUES (?, ?)", (b_type, b_name))
             self.caches['branch_types'][b_type] = b_name
@@ -470,7 +471,7 @@ class DatabaseExporter:
         self.caches['threads'][(0, 0, 0)] = 0
         self.caches['comms'][('unknown', 0)] = 0
         self.caches['dsos'][(0, 'unknown', 'unknown', '')] = 0
-        self.caches['symbols'][(0, 'unknown')] = (0, 0, 0)
+        self.caches['symbols'][(0, 'unknown', False)] = (0, 0, 0)
         # Initialize comm_threads mapping
         self.comm_threads_cache: set[tuple[int, int]] = set()
         self.next_comm_thread_id = 1
@@ -570,9 +571,9 @@ class DatabaseExporter:
         return dso_id
 
     def get_symbol_id(self, dso_id: int, name: str, start: int,
-                      end: int) -> int:
+                      end: int, inlined: bool = False) -> int:
         """Get or create symbol ID."""
-        key = (dso_id, name)
+        key = (dso_id, name, inlined)
         if key in self.caches['symbols']:
             symbol_id, cached_start, cached_end = self.caches['symbols'][key]
             if cached_start == 0 and cached_end == 0 and (start != 0 or end != 0):
@@ -581,8 +582,8 @@ class DatabaseExporter:
                 self.caches['symbols'][key] = (symbol_id, start, end)
             return symbol_id
         symbol_id = self.next_id['symbol']
-        self._exec("INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?)",
-                   (symbol_id, dso_id, start, end, 0, name))
+        self._exec("INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?, ?)",
+                   (symbol_id, dso_id, start, end, 0, inlined, name))
         self.caches['symbols'][key] = (symbol_id, start, end)
         self.next_id['symbol'] += 1
         return symbol_id
@@ -643,7 +644,8 @@ class DatabaseExporter:
                 symbol_name = node.symbol or "Unknown_symbol"
 
                 node_dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
-                node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0)
+                node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0,
+                                                    node.inlined)
 
                 parent_id = self.get_call_path_id(parent_id, node_symbol_id, node.ip)
             call_path_id = parent_id
@@ -760,7 +762,7 @@ class DatabaseExporter:
             dso_name = node.dso or "Unknown_dso"
             symbol_name = node.symbol or "Unknown_symbol"
             dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
-            symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0)
+            symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0, node.inlined)
             parent_id = call_path_id
             call_path_id = self.get_call_path_id(parent_id, symbol_id, node.ip)
         return call_path_id, parent_id
-- 
2.53.0


  parent reply	other threads:[~2026-12-04 16:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:24 [PATCH 0/5] perf python: Honor more perf script options Jens Remus
2026-12-04 16:24 ` [PATCH 1/5] perf python: Support inlined frames in callchains Jens Remus
2026-12-04 16:46   ` sashiko-bot
2026-12-04 16:24 ` Jens Remus [this message]
2026-12-04 16:59   ` [PATCH 2/5] perf python: Export inlined symbol flag in DB export scripts sashiko-bot
2026-12-04 16:24 ` [PATCH 3/5] perf python: Honor perf script --show-kernel-path Jens Remus
2026-12-04 17:13   ` sashiko-bot
2026-12-04 16:24 ` [PATCH 4/5] perf python: Honor perf script --demangle and --demangle-kernel Jens Remus
2026-12-04 16:24 ` [PATCH 5/5] perf python: Honor perf script --max-stack Jens Remus
2026-12-04 17:35   ` sashiko-bot
2026-12-04 17:35 ` [PATCH 0/5] perf python: Honor more perf script options sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204162426.4171717-9-jremus@linux.ibm.com \
    --to=jremus@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=irogers@google.com \
    --cc=japo@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sumanthk@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox