diff options
author | John Kacur <jkacur@redhat.com> | 2009-09-24 12:01:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-09-24 15:27:50 -0400 |
commit | cbfeb267cb0ff632dbc8ff02685012bee2e87434 (patch) | |
tree | 24662435a423aa20aa4ac5468140b547f8afdd92 /tools/perf | |
parent | 725b13685c61168f71825b3fb67d96d2d7aa3b0f (diff) |
perf annotate: Add the cmp_null function and make use of it
This function exists in builtin-report.c but not in
builtin-annotate.c Functions that use cmp_null are shorter and
clearer.
Synchronizing functions between these two files will also make it
easier to potential share code in the future.
Signed-off-by: John Kacur <jkacur@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <alpine.LFD.2.00.0909241754031.11383@localhost.localdomain>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-annotate.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 1ec741615814..a33087328bd4 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -82,6 +82,16 @@ struct sort_entry { | |||
82 | size_t (*print)(FILE *fp, struct hist_entry *); | 82 | size_t (*print)(FILE *fp, struct hist_entry *); |
83 | }; | 83 | }; |
84 | 84 | ||
85 | static int64_t cmp_null(void *l, void *r) | ||
86 | { | ||
87 | if (!l && !r) | ||
88 | return 0; | ||
89 | else if (!l) | ||
90 | return -1; | ||
91 | else | ||
92 | return 1; | ||
93 | } | ||
94 | |||
85 | /* --sort pid */ | 95 | /* --sort pid */ |
86 | 96 | ||
87 | static int64_t | 97 | static int64_t |
@@ -116,14 +126,8 @@ sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) | |||
116 | char *comm_l = left->thread->comm; | 126 | char *comm_l = left->thread->comm; |
117 | char *comm_r = right->thread->comm; | 127 | char *comm_r = right->thread->comm; |
118 | 128 | ||
119 | if (!comm_l || !comm_r) { | 129 | if (!comm_l || !comm_r) |
120 | if (!comm_l && !comm_r) | 130 | return cmp_null(comm_l, comm_r); |
121 | return 0; | ||
122 | else if (!comm_l) | ||
123 | return -1; | ||
124 | else | ||
125 | return 1; | ||
126 | } | ||
127 | 131 | ||
128 | return strcmp(comm_l, comm_r); | 132 | return strcmp(comm_l, comm_r); |
129 | } | 133 | } |
@@ -149,14 +153,8 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | |||
149 | struct dso *dso_l = left->dso; | 153 | struct dso *dso_l = left->dso; |
150 | struct dso *dso_r = right->dso; | 154 | struct dso *dso_r = right->dso; |
151 | 155 | ||
152 | if (!dso_l || !dso_r) { | 156 | if (!dso_l || !dso_r) |
153 | if (!dso_l && !dso_r) | 157 | return cmp_null(dso_l, dso_r); |
154 | return 0; | ||
155 | else if (!dso_l) | ||
156 | return -1; | ||
157 | else | ||
158 | return 1; | ||
159 | } | ||
160 | 158 | ||
161 | return strcmp(dso_l->name, dso_r->name); | 159 | return strcmp(dso_l->name, dso_r->name); |
162 | } | 160 | } |