From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
To: acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com,
irogers@google.com, namhyung@kernel.org,
segher@kernel.crashing.org, christophe.leroy@csgroup.eu
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, akanksha@linux.ibm.com,
maddy@linux.ibm.com, atrajeev@linux.vnet.ibm.com,
kjain@linux.ibm.com, disgoel@linux.vnet.ibm.com
Subject: [PATCH V6 17/18] tools/perf: Update data_type_cmp and sort__typeoff_sort function to include var_name in comparison
Date: Sun, 7 Jul 2024 20:14:18 +0530 [thread overview]
Message-ID: <20240707144419.92510-18-atrajeev@linux.vnet.ibm.com> (raw)
In-Reply-To: <20240707144419.92510-1-atrajeev@linux.vnet.ibm.com>
Currently data_type_cmp() only compares size and type name.
But in cases where the type name of two data type entries
is same, but var_name is different, the comparison can't distinguish
two different types.
Consider there is a "long unsigned int" with var_name as "X" and there
is global variable "long unsigned int". Currently since
data_type_cmp uses only type_name for comparison ( "long unsigned int"),
it won't distinguish these as separate entries. Update the
functions "data_type_cmp" as well as "sort__typeoff_sort" to
compare variable names after type name if it exists.
Also updated "hist_entry__typeoff_snprintf" to print var_name if
it is set. With the changes,
11.42% long unsigned int long unsigned int +0 (current_stack_pointer)
4.68% struct paca_struct struct paca_struct +2312 (__current)
4.57% struct paca_struct struct paca_struct +2354 (irq_soft_mask)
2.69% struct paca_struct struct paca_struct +2808 (canary)
2.68% struct paca_struct struct paca_struct +8 (paca_index)
2.24% struct paca_struct struct paca_struct +48 (data_offset)
1.43% long unsigned int long unsigned int +0 (no field)
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
tools/perf/util/annotate-data.c | 24 ++++++++++++++++++++++--
tools/perf/util/sort.c | 23 +++++++++++++++++++++--
2 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
index 8d05f3dbddf6..759c6a22e719 100644
--- a/tools/perf/util/annotate-data.c
+++ b/tools/perf/util/annotate-data.c
@@ -167,7 +167,7 @@ static void exit_type_state(struct type_state *state)
}
/*
- * Compare type name and size to maintain them in a tree.
+ * Compare type name, var_name and size to maintain them in a tree.
* I'm not sure if DWARF would have information of a single type in many
* different places (compilation units). If not, it could compare the
* offset of the type entry in the .debug_info section.
@@ -176,12 +176,32 @@ static int data_type_cmp(const void *_key, const struct rb_node *node)
{
const struct annotated_data_type *key = _key;
struct annotated_data_type *type;
+ int64_t ret = 0;
type = rb_entry(node, struct annotated_data_type, node);
if (key->self.size != type->self.size)
return key->self.size - type->self.size;
- return strcmp(key->self.type_name, type->self.type_name);
+
+ ret = strcmp(key->self.type_name, type->self.type_name);
+ if (ret) {
+ return ret;
+ }
+
+ /*
+ * Compare var_name if it exists for key and type.
+ * If both nodes doesn't have var_name, but one of
+ * them has, return non-zero. This is to indicate nodes
+ * are not the same if one has var_name, but other doesn't.
+ */
+ if (key->self.var_name && type->self.var_name) {
+ ret = strcmp(key->self.var_name, type->self.var_name);
+ if (ret)
+ return ret;
+ } else if (key->self.var_name || type->self.var_name)
+ return 1;
+
+ return ret;
}
static bool data_type_less(struct rb_node *node_a, const struct rb_node *node_b)
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index cd39ea972193..c6d885060ee7 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -2267,9 +2267,25 @@ sort__typeoff_sort(struct hist_entry *left, struct hist_entry *right)
right_type = right->mem_type;
}
+ /*
+ * Compare type_name first. Next, ompare var_name if it exists
+ * for left and right hist_entry. If both entries doesn't have
+ * var_name, but one of them has, return non-zero. This is to
+ * indicate entries are not the same if one has var_name, but the
+ * other doesn't.
+ * If type_name and var_name is same, use mem_type_off field.
+ */
ret = strcmp(left_type->self.type_name, right_type->self.type_name);
if (ret)
return ret;
+
+ if (left_type->self.var_name && right_type->self.var_name) {
+ ret = strcmp(left_type->self.var_name, right_type->self.var_name);
+ if (ret)
+ return ret;
+ } else if (right_type->self.var_name || left_type->self.var_name)
+ return 1;
+
return left->mem_type_off - right->mem_type_off;
}
@@ -2305,9 +2321,12 @@ static int hist_entry__typeoff_snprintf(struct hist_entry *he, char *bf,
char buf[4096];
buf[0] = '\0';
- if (list_empty(&he_type->self.children))
+ if (list_empty(&he_type->self.children)) {
snprintf(buf, sizeof(buf), "no field");
- else
+ if (he_type->self.var_name)
+ strcpy(buf, he_type->self.var_name);
+
+ } else
fill_member_name(buf, sizeof(buf), &he_type->self,
he->mem_type_off, true);
buf[4095] = '\0';
--
2.43.0
next prev parent reply other threads:[~2024-07-07 14:45 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-07 14:44 [PATCH V6 00/18] Add data type profiling support for powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 01/18] tools/perf: Move the data structures related to register type to header file Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 02/18] tools/perf: Add "update_insn_state" callback function to handle arch specific instruction tracking Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 03/18] tools/perf: Update TYPE_STATE_MAX_REGS to include max of regs in powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 04/18] tools/perf: Add disasm_line__parse to parse raw instruction for powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 05/18] tools/perf: Add support to capture and parse raw instruction in powerpc using dso__data_read_offset utility Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 06/18] tools/perf: Update parameters for reg extract functions to use raw instruction on powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 07/18] tools/perf: Add parse function for memory instructions in powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 08/18] tools/perf: Add support to identify memory instructions of opcode 31 " Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 09/18] tools/perf: Add some of the arithmetic instructions to support instruction tracking " Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 10/18] tools/perf: Add more instructions for instruction tracking Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 11/18] tools/perf: Update instruction tracking for powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 12/18] tools/perf: Make capstone_init non-static so that it can be used during symbol disassemble Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 13/18] tools/perf: Use capstone_init and remove open_capstone_handle from disasm.c Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 14/18] tools/perf: Add support to use libcapstone in powerpc Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 15/18] tools/perf: Add support to find global register variables using find_data_type_global_reg Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 16/18] tools/perf: Add support for global_die to capture name of variable in case of register defined variable Athira Rajeev
2024-07-07 14:44 ` Athira Rajeev [this message]
2024-07-12 21:25 ` [PATCH V6 17/18] tools/perf: Update data_type_cmp and sort__typeoff_sort function to include var_name in comparison Namhyung Kim
2024-07-13 6:22 ` Athira Rajeev
2024-07-13 14:55 ` Namhyung Kim
2024-07-13 17:21 ` Athira Rajeev
2024-07-07 14:44 ` [PATCH V6 18/18] tools/perf: Set instruction name to be used with insn-stat when using raw instruction Athira Rajeev
2024-07-12 21:27 ` Namhyung Kim
2024-07-13 6:01 ` Athira Rajeev
2024-07-12 3:44 ` [PATCH V6 00/18] Add data type profiling support for powerpc Athira Rajeev
2024-07-12 3:48 ` Namhyung Kim
2024-07-12 16:33 ` kajoljain
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=20240707144419.92510-18-atrajeev@linux.vnet.ibm.com \
--to=atrajeev@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akanksha@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=disgoel@linux.vnet.ibm.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kjain@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=namhyung@kernel.org \
--cc=segher@kernel.crashing.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).