From: Andi Kleen <ak@linux.intel.com>
To: linux-perf-users@vger.kernel.org
Cc: adrian.hunter@intel.com, namhyung@kernel.org, acme@kernel.org,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH v1 08/10] perf: resolve inlines for perf_brstack_srcline/perf_ip_srcline
Date: Thu, 5 Sep 2024 08:08:02 -0700 [thread overview]
Message-ID: <20240905151058.2127122-9-ak@linux.intel.com> (raw)
In-Reply-To: <20240905151058.2127122-1-ak@linux.intel.com>
Extend perf_brstack/ip_srcline to also return the inline stack to the
python script. I made it unconditional for now.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
.../scripts/python/Perf-Trace-Util/Context.c | 43 ++++++++++++++++---
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 1c1d8d08b10e..a1c3c35bc6e6 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -194,7 +194,12 @@ static PyObject *do_resolve_ip(struct scripting_context *c, PyObject *ipp)
bool kernel;
u64 ip = PyLong_AsUnsignedLongLong(ipp);
unsigned line = 0, disc = 0;
+ struct inline_node *inode = calloc(sizeof(struct inline_node), 1);
+ if (!inode)
+ goto err2;
+
+ INIT_LIST_HEAD(&inode->val);
kernel = machine__kernel_ip(c->machine, ip);
if (kernel)
cpumode = PERF_RECORD_MISC_KERNEL;
@@ -213,15 +218,41 @@ static PyObject *do_resolve_ip(struct scripting_context *c, PyObject *ipp)
goto err;
if (dso__data(dso)->status == DSO_DATA_STATUS_ERROR)
goto err;
- srcfile = get_srcline_split(dso, map__rip_2objdump(al.map, al.addr), &line, &disc);
- if (srcfile)
- result = Py_BuildValue("(sII)", srcfile, line, disc);
- free(srcfile);
+ srcfile = get_srcline_split(dso, map__rip_2objdump(al.map, al.addr), &line,
+ &disc, inode);
+ if (srcfile && srcfile != SRCLINE_UNKNOWN) {
+ if (!list_empty(&inode->val)) {
+ PyObject *inlines;
+ struct inline_list *ilist;
+ int num;
+ num = 0;
+ list_for_each_entry (ilist, &inode->val, list)
+ num++;
+ inlines = PyTuple_New(num);
+ if (!inlines)
+ goto out;
+ num = 0;
+ list_for_each_entry (ilist, &inode->val, list) {
+ PyTuple_SetItem(inlines, num,
+ Py_BuildValue("(ssII)",
+ ilist->srcline, ilist->symbol->name,
+ ilist->line, ilist->disc));
+ num++;
+ }
+ result = Py_BuildValue("(sIIO)", srcfile, line, disc, inlines);
+ Py_DECREF(inlines);
+ out:
+ } else {
+ result = Py_BuildValue("(sII)", srcfile, line, disc);
+ }
+ }
+ zfree_srcline(&srcfile);
err:
addr_location__exit(&al);
err2:
if (!result)
return Py_BuildValue("");
+ inline_node__delete(inode);
return result;
}
@@ -268,9 +299,9 @@ static PyMethodDef ContextMethods[] = {
{ "perf_sample_srccode", perf_sample_srccode,
METH_VARARGS, "Get source file name, line number and line."},
{ "perf_brstack_srcline", perf_brstack_srcline,
- METH_VARARGS, "Get source file name, line number, discriminator for from/to of a brstack entry." },
+ METH_VARARGS, "Get source file name, line number, discriminator, inline stack for from/to of a brstack entry." },
{ "perf_resolve_ip", perf_resolve_ip,
- METH_VARARGS, "Get source file name, line number, discriminator for numerical IP." },
+ METH_VARARGS, "Get source file name, line number, discriminator, inline stack for numerical IP." },
{ NULL, NULL, 0, NULL}
};
--
2.45.2
next prev parent reply other threads:[~2024-09-05 15:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 15:07 [RESEND] More dwarf support in python interface Andi Kleen
2024-09-05 15:07 ` [PATCH v1 01/10] perf: Avoid buffer overflow in python register interface Andi Kleen
2024-09-05 15:07 ` [PATCH v1 02/10] perf: Support discriminator in addr2line Andi Kleen
2024-09-05 15:07 ` [PATCH v1 03/10] perf: Plumb passing machine to scripts Andi Kleen
2024-09-05 15:07 ` [PATCH v1 04/10] perf: Add perf_brstack_srcline to resolve brstack entries Andi Kleen
2024-09-05 15:07 ` [PATCH v1 05/10] perf: Add perf_resolve_ip python interface Andi Kleen
2024-09-05 15:08 ` [PATCH v1 06/10] perf: Add plumbling for line/disc for inlines Andi Kleen
2024-09-05 15:08 ` [PATCH v1 07/10] perf: Support returning inlines in get_srcline_split Andi Kleen
2024-09-05 15:08 ` Andi Kleen [this message]
2024-09-05 15:08 ` [PATCH v1 09/10] perf: Add build id and filename to perf_brstack/ip_srcline Andi Kleen
2024-09-05 15:08 ` [PATCH v1 10/10] perf: Update documentation for new python callbacks Andi Kleen
2024-09-05 15:25 ` [RESEND] More dwarf support in python interface Arnaldo Carvalho de Melo
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=20240905151058.2127122-9-ak@linux.intel.com \
--to=ak@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.