Skip to contentSkip to conversation

Add-the-cmp_null-function-to-builtin-annotate.c

PATCH In review John Kacur 1 participant 3 messages Sep 24, 2009 perf events

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/3 Add-the-cmp_null-function-to-builtin-annotate.c

Quoted 1 line

From 93d856e28036610f54efc41efba89cd887f2af90 Mon Sep 17 00:00:00 2001

From: John Kacur <[email protected]>
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.

---
 tools/perf/builtin-annotate.c |   30 ++++++++++++++----------------
 1 files changed, 14 insertions(+), 16 deletions(-)
tools/perf/builtin-annotate.c +14 -16
index 1ec7416..a330873 100644
@@ -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);
 }
Signature · 1 line
1.6.0.6
#2 lore raw

[tip:perf/core] perf annotate: Add the cmp_null function and make use of it

In reply to John Kacur
Commit-ID:  cbfeb267cb0ff632dbc8ff02685012bee2e87434
Gitweb:     http://git.kernel.org/tip/cbfeb267cb0ff632dbc8ff02685012bee2e87434
Author:     John Kacur <[email protected]>
AuthorDate: Thu, 24 Sep 2009 18:01:51 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 24 Sep 2009 21:27:50 +0200

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.

Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-annotate.c |   30 ++++++++++++++----------------
 1 files changed, 14 insertions(+), 16 deletions(-)
tools/perf/builtin-annotate.c +14 -16
index 1ec7416..a330873 100644
@@ -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);
 }