Skip to contentSkip to conversation

perf tools: Fix "Command" sort_entry's cmp and collapse function

PATCH In review Jiri Olsa 3 participants 3 messages May 15, 2015 – May 18, 2015 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 perf tools: Fix "Command" sort_entry's cmp and collapse function

Currently the se_cmp and se_collapse use pointer comparison, which is ok for for testing equality of strings. It's not ok as comparing function for rbtree insertion, because it gives different results based on current pointer values.

We saw test 32 (hists cumulation test) failing based on different environment setup. Having all sort functions straightened fix the test for us.

---
 tools/perf/util/sort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/sort.c +2 -2
index 4593f36ecc4c..09d4696fd9a1 100644
@@ -89,14 +89,14 @@ static int64_t
 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
 {
 	/* Compare the addr that should be unique among comm */
-	return comm__str(right->comm) - comm__str(left->comm);
+	return strcmp(comm__str(right->comm), comm__str(left->comm));
 }
 
 static int64_t
 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
 {
 	/* Compare the addr that should be unique among comm */
-	return comm__str(right->comm) - comm__str(left->comm);
+	return strcmp(comm__str(right->comm), comm__str(left->comm));
 }
 
 static int64_t
Signature · 1 line
1.9.3
maintainer
#1 lore raw

Hi Jiri,

CC-ing Frederic as he wrote the comm change.

Quoted 8 lines · Jiri Olsa

Currently the se_cmp and se_collapse use pointer comparison, which is ok for for testing equality of strings. It's not ok as comparing function for rbtree insertion, because it gives different results based on current pointer values.

We saw test 32 (hists cumulation test) failing based on different environment setup. Having all sort functions straightened fix the test for us.

Can you elaborate it?

AFAIK comm string is shared among threads so pointer comparison and 'strcmp == 0' should have same result..

Thanks,
Namhyung

Quoted 37 lines
---
 tools/perf/util/sort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/sort.c +2 -2
index 4593f36ecc4c..09d4696fd9a1 100644
@@ -89,14 +89,14 @@ static int64_t
 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
 {
 	/* Compare the addr that should be unique among comm */
-	return comm__str(right->comm) - comm__str(left->comm);
+	return strcmp(comm__str(right->comm), comm__str(left->comm));
 }
 
 static int64_t
 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
 {
 	/* Compare the addr that should be unique among comm */
-	return comm__str(right->comm) - comm__str(left->comm);
+	return strcmp(comm__str(right->comm), comm__str(left->comm));
 }
 
 static int64_t
Signature · 7 lines
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#2 lore raw
Quoted 10 lines · Namhyung Kim

Hi Jiri,

CC-ing Frederic as he wrote the comm change.

Quoted 5 lines · Jiri Olsa

Currently the se_cmp and se_collapse use pointer comparison, which is ok for for testing equality of strings. It's not ok as comparing function for rbtree insertion, because it gives different results based on current pointer values.

Quoted 8 lines
Quoted 3 lines

We saw test 32 (hists cumulation test) failing based on different environment setup. Having all sort functions straightened fix the test for us.

Can you elaborate it?

AFAIK comm string is shared among threads so pointer comparison and 'strcmp == 0' should have same result..

well pointers (A, B) substraction will get either negative (A < B) or possitive number (A > B). Now if your environment happens to have those pointers switched you'll get different result for same strings.

Following python script forced the 'perf test 32' to switch those pointers and screwed the Command sorting.. it's not very reliable on upstream for some reason.. but very reproducible on RHEL7

---
#!/bin/python

import os

env={}

env['PATH'] = "/tmp:"*500

os.execve("./perf", ["perf", "test", "32", "-v"], env)
---

jirka