From: John Kacur <jkacur@redhat.com>
To: mingo@elte.hu, Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH 1/3]Add-the-cmp_null-function-to-builtin-annotate.c
Date: Thu, 24 Sep 2009 18:01:51 +0200 (CEST) [thread overview]
Message-ID: <alpine.LFD.2.00.0909241754031.11383@localhost.localdomain> (raw)
>From 93d856e28036610f54efc41efba89cd887f2af90 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Mon, 21 Sep 2009 13:10:45 +0200
Subject: [PATCH] Add the cmp_null function to builtin-annotate.c and make use of it.
Add the cmp_null function to builtin-annotate.c 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>
---
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 1ec7416..a330873 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -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
@@ -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);
}
@@ -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);
}
--
1.6.0.6
next reply other threads:[~2009-09-24 16:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-24 16:01 John Kacur [this message]
2009-09-24 16:33 ` John Kacur
2009-09-24 19:36 ` [tip:perf/core] perf annotate: Add the cmp_null function and make use of it tip-bot for John Kacur
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=alpine.LFD.2.00.0909241754031.11383@localhost.localdomain \
--to=jkacur@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®