Skip to content

Commit

Permalink
perf annotate: Add the cmp_null function and make use of it
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
John Kacur authored and Ingo Molnar committed Sep 24, 2009
1 parent 725b136 commit cbfeb26
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ struct sort_entry {
size_t (*print)(FILE *fp, struct hist_entry *);
};

static int64_t cmp_null(void *l, void *r)
{
if (!l && !r)
return 0;
else if (!l)
return -1;
else
return 1;
}

/* --sort pid */

static int64_t
Expand Down Expand Up @@ -116,14 +126,8 @@ sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
char *comm_l = left->thread->comm;
char *comm_r = right->thread->comm;

if (!comm_l || !comm_r) {
if (!comm_l && !comm_r)
return 0;
else if (!comm_l)
return -1;
else
return 1;
}
if (!comm_l || !comm_r)
return cmp_null(comm_l, comm_r);

return strcmp(comm_l, comm_r);
}
Expand All @@ -149,14 +153,8 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
struct dso *dso_l = left->dso;
struct dso *dso_r = right->dso;

if (!dso_l || !dso_r) {
if (!dso_l && !dso_r)
return 0;
else if (!dso_l)
return -1;
else
return 1;
}
if (!dso_l || !dso_r)
return cmp_null(dso_l, dso_r);

return strcmp(dso_l->name, dso_r->name);
}
Expand Down

0 comments on commit cbfeb26

Please sign in to comment.