Skip to contentSkip to conversation

Put common histogram functions for perf in their own file

PATCH In review John Kacur 2 participants 6 messages Sep 28, 2009 – Sep 30, 2009 perf events

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/1 Put common histogram functions for perf in their own file

Quoted 1 line

From d187ab3a62526ffbdff91911f4b2da813ccf037f Mon Sep 17 00:00:00 2001

From: John Kacur <[email protected]>
Date: Mon, 28 Sep 2009 14:53:08 +0200
Subject: [PATCH] Move histogram related functions into their own files (hist.c and hist.h)
and make use of them in builtin-annotate.c and builtin-report.c

---
 tools/perf/Makefile           |    2 +
 tools/perf/builtin-annotate.c |  152 +-------------------------------------
 tools/perf/builtin-report.c   |   65 ++--------------
 tools/perf/util/hist.c        |  164 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/hist.h        |   47 ++++++++++++
 5 files changed, 224 insertions(+), 206 deletions(-)
 create mode 100644 tools/perf/util/hist.c
 create mode 100644 tools/perf/util/hist.h
tools/perf/Makefile +2 -0
index 0a9e5ae..3a99a9f 100644
@@ -340,6 +340,7 @@ LIB_H += util/module.h
 LIB_H += util/color.h
 LIB_H += util/values.h
 LIB_H += util/sort.h
+LIB_H += util/hist.h
 
 LIB_OBJS += util/abspath.o
 LIB_OBJS += util/alias.o
@@ -376,6 +377,7 @@ LIB_OBJS += util/trace-event-read.o
 LIB_OBJS += util/trace-event-info.o
 LIB_OBJS += util/svghelper.o
 LIB_OBJS += util/sort.o
+LIB_OBJS += util/hist.o
 
 BUILTIN_OBJS += builtin-annotate.o
 BUILTIN_OBJS += builtin-help.o
tools/perf/builtin-annotate.c +2 -150

176 lines not on this page · raw message

tools/perf/builtin-report.c +9 -56

136 lines not on this page · raw message

tools/perf/util/hist.c new file +164 -0

164 lines not on this page · raw message

tools/perf/util/hist.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.6.0.6
author
#1 lore raw

Ingo, please do not use the previous version of this patch - I forgot to remove the commented out code.

This version of the patch is the one I would like applied.

Thank You.

Quoted 1 line

From 55b04a16258b7d9db77d9f8666c14e0438211177 Mon Sep 17 00:00:00 2001

From: John Kacur <[email protected]>
Date: Mon, 28 Sep 2009 14:53:08 +0200
Subject: [PATCH] Move histogram related functions into their own files (hist.c and hist.h)
and make use of them in builtin-annotate.c and builtin-report.c

---
 tools/perf/Makefile           |    2 +
 tools/perf/builtin-annotate.c |  152 +-------------------------------------
 tools/perf/builtin-report.c   |  164 +----------------------------------------
 tools/perf/util/hist.c        |  164 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/hist.h        |   47 ++++++++++++
 5 files changed, 216 insertions(+), 313 deletions(-)
 create mode 100644 tools/perf/util/hist.c
 create mode 100644 tools/perf/util/hist.h
tools/perf/Makefile +2 -0
index 0a9e5ae..3a99a9f 100644
@@ -340,6 +340,7 @@ LIB_H += util/module.h
 LIB_H += util/color.h
 LIB_H += util/values.h
 LIB_H += util/sort.h
+LIB_H += util/hist.h
 
 LIB_OBJS += util/abspath.o
 LIB_OBJS += util/alias.o
@@ -376,6 +377,7 @@ LIB_OBJS += util/trace-event-read.o
 LIB_OBJS += util/trace-event-info.o
 LIB_OBJS += util/svghelper.o
 LIB_OBJS += util/sort.o
+LIB_OBJS += util/hist.o
 
 BUILTIN_OBJS += builtin-annotate.o
 BUILTIN_OBJS += builtin-help.o
tools/perf/builtin-annotate.c +2 -150

176 lines not on this page · raw message

tools/perf/builtin-report.c +1 -163

202 lines not on this page · raw message

tools/perf/util/hist.c new file +164 -0

164 lines not on this page · raw message

tools/perf/util/hist.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#2 lore raw

[tip:perf/core] perf tools: Put common histogram functions in their own file

Commit-ID:  3d1d07ecd2009f65cb2091563fa21f9600c36774
Gitweb:     http://git.kernel.org/tip/3d1d07ecd2009f65cb2091563fa21f9600c36774
Author:     John Kacur <[email protected]>
AuthorDate: Mon, 28 Sep 2009 15:32:55 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 30 Sep 2009 13:57:56 +0200

perf tools: Put common histogram functions in their own file

Move histogram related functions into their own files (hist.c and hist.h) and make use of them in builtin-annotate.c and builtin-report.c.

LKML-Reference: <[email protected]>

---
 tools/perf/Makefile           |    2 +
 tools/perf/builtin-annotate.c |  152 +-------------------------------------
 tools/perf/builtin-report.c   |  164 +----------------------------------------
 tools/perf/util/hist.c        |  164 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/hist.h        |   47 ++++++++++++
 5 files changed, 216 insertions(+), 313 deletions(-)
tools/perf/Makefile +2 -0
index 0a9e5ae..3a99a9f 100644
@@ -340,6 +340,7 @@ LIB_H += util/module.h
 LIB_H += util/color.h
 LIB_H += util/values.h
 LIB_H += util/sort.h
+LIB_H += util/hist.h
 
 LIB_OBJS += util/abspath.o
 LIB_OBJS += util/alias.o
@@ -376,6 +377,7 @@ LIB_OBJS += util/trace-event-read.o
 LIB_OBJS += util/trace-event-info.o
 LIB_OBJS += util/svghelper.o
 LIB_OBJS += util/sort.o
+LIB_OBJS += util/hist.o
 
 BUILTIN_OBJS += builtin-annotate.o
 BUILTIN_OBJS += builtin-help.o
tools/perf/builtin-annotate.c +2 -150

176 lines not on this page · raw message

tools/perf/builtin-report.c +1 -163

202 lines not on this page · raw message

tools/perf/util/hist.c new file +164 -0

164 lines not on this page · raw message

tools/perf/util/hist.h new file +47 -0

47 lines not on this page · raw message

#3 lore raw
In reply to John Kacur
Quoted 5 lines · John Kacur

From d187ab3a62526ffbdff91911f4b2da813ccf037f Mon Sep 17 00:00:00 2001
From: John Kacur <[email protected]>
Date: Mon, 28 Sep 2009 14:53:08 +0200
Subject: [PATCH] Move histogram related functions into their own files (hist.c and hist.h)
and make use of them in builtin-annotate.c and builtin-report.c

I guess a part of the title should be in the changelog, and the title should be a compressed version :)

tools/perf/builtin-annotate.c more: · line 716

Quoted 10 lines

static int
process_sample_event(event_t *event, unsigned long offset, unsigned long head) {

tools/perf/builtin-annotate.c +1 -1
@@ -861,7 +713,7 @@ more:
 		dsos__fprintf(stdout);
 
 	collapse__resort();
-	output__resort();
+	output__resort(total);

Now I wonder if we actually ever need to sort the entries in perf annotate. The only thing we need is to count the hits per ip.

Quoted 25 lines
tools/perf/builtin-annotate.c +0 -0
 	find_annotations();
 
tools/perf/builtin-report.c +1 -2
index 7b43504..ff6de9e 100644
@@ -28,6 +28,7 @@
 
 #include "util/thread.h"
 #include "util/sort.h"
+#include "util/hist.h"
 
 static char		const *input_name = "perf.data";
 
@@ -55,8 +56,6 @@ static int		exclude_other = 1;
 
 static char		callchain_default_opt[] = "fractal,0.5";
 
-static int		callchain;
-
 static char		__cwd[PATH_MAX];
 static char		*cwd = __cwd;
 static int		cwdlen;

tools/perf/builtin-report.c static struct thread *last_match; · line 73

Quoted 8 lines
tools/perf/builtin-report.c +0 -5
@@ -66,50 +65,8 @@ static struct thread	*last_match;
 
 static struct perf_header *header;
 
-static
-struct callchain_param	callchain_param = {
-	.mode	= CHAIN_GRAPH_REL,
-	.min_percent = 0.5
-};

At least for now, this part is only used by report. May be better keep it in report?

Concerning the whole, that looks nice. Especially annotate doesn't even seem to need any sort.

So we could eventually keep the hist sorting only in report. But that said, it's nice to make all these sorting and histogram features in a separate file for general purpose. We can bet that will be reused soon or later. If not this is still good to split it, to clear a bit builtin-report.c

But the callchain bits should perhaps stay in report. If that needs to be used elsewhere, it would need a kind of cleanup before.

author
#4 lore raw
Quoted 11 lines · Frederic Weisbecker
Quoted 5 lines · John Kacur

From d187ab3a62526ffbdff91911f4b2da813ccf037f Mon Sep 17 00:00:00 2001
From: John Kacur <[email protected]>
Date: Mon, 28 Sep 2009 14:53:08 +0200
Subject: [PATCH] Move histogram related functions into their own files (hist.c and hist.h)
and make use of them in builtin-annotate.c and builtin-report.c

I guess a part of the title should be in the changelog, and the title should be a compressed version :)

Okay - I added the title of the mail to the changelog

Quoted 10 lines
Quoted 10 lines

static int
process_sample_event(event_t *event, unsigned long offset, unsigned long head) {

(quoted diff) +0 -0
@@ -861,7 +713,7 @@ more:
 		dsos__fprintf(stdout);
 
Quoted 9 lines

Review more: · line 716

Quoted 3 lines
(quoted diff) +1 -1
 	collapse__resort();
-	output__resort();
+	output__resort(total);

Now I wonder if we actually ever need to sort the entries in perf annotate. The only thing we need is to count the hits per ip.

perf annotate still will not sort the entries with these changes. because callchain will be equal to zero.

Calling output__resort(total) will be harmless because the calculation will be thrown away in output__insert_entry() here:
if (callchain)

		callchain_param.sort(&he->sorted_chain, &he->callchain,
				      min_callchain_hits, &callchain_param);
Quoted 44 lines
Quoted 27 lines
(quoted diff) +0 -0
 	find_annotations();
 
tools/perf/builtin-report.c +1 -2
index 7b43504..ff6de9e 100644
@@ -28,6 +28,7 @@
 
 #include "util/thread.h"
 #include "util/sort.h"
+#include "util/hist.h"
 
 static char		const *input_name = "perf.data";
 
@@ -55,8 +56,6 @@ static int		exclude_other = 1;
 
 static char		callchain_default_opt[] = "fractal,0.5";
 
-static int		callchain;
-
 static char		__cwd[PATH_MAX];
 static char		*cwd = __cwd;
 static int		cwdlen;

tools/perf/builtin-report.c static struct thread *last_match; · line 73

Quoted 8 lines
tools/perf/builtin-report.c +0 -5
@@ -66,50 +65,8 @@ static struct thread	*last_match;
 
 static struct perf_header *header;
 
-static
-struct callchain_param	callchain_param = {
-	.mode	= CHAIN_GRAPH_REL,
-	.min_percent = 0.5
-};

At least for now, this part is only used by report. May be better keep it in report?

Concerning the whole, that looks nice. Especially annotate doesn't even seem to need any sort.

Quoted 9 lines

So we could eventually keep the hist sorting only in report. But that said, it's nice to make all these sorting and histogram features in a separate file for general purpose. We can bet that will be reused soon or later. If not this is still good to split it, to clear a bit builtin-report.c

But the callchain bits should perhaps stay in report. If that needs to be used elsewhere, it would need a kind of cleanup before.

Okay, I agree with you, so I am respinning the patch with callchain and callchain_param put back in builtin-report.c.

Quoted 1 line

From 7c6a2035c32d17db0e566a36c7e345ec2182f722 Mon Sep 17 00:00:00 2001

From: John Kacur <[email protected]>
Date: Mon, 28 Sep 2009 14:53:08 +0200
Subject: [PATCH] Put common histogram functions for perf in their own file

Move histogram related functions into their own files (hist.c and hist.h) and make use of them in builtin-annotate.c and builtin-report.c

---
 tools/perf/Makefile           |    2 +
 tools/perf/builtin-annotate.c |  152 +--------------------------------------
 tools/perf/builtin-report.c   |  160 +----------------------------------------
 tools/perf/builtin.h          |    3 +
 tools/perf/util/hist.c        |  158 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/hist.h        |   45 ++++++++++++
 6 files changed, 212 insertions(+), 308 deletions(-)
 create mode 100644 tools/perf/util/hist.c
 create mode 100644 tools/perf/util/hist.h
tools/perf/Makefile +2 -0
index 0a9e5ae..3a99a9f 100644
@@ -340,6 +340,7 @@ LIB_H += util/module.h
 LIB_H += util/color.h
 LIB_H += util/values.h
 LIB_H += util/sort.h
+LIB_H += util/hist.h
 
 LIB_OBJS += util/abspath.o
 LIB_OBJS += util/alias.o
@@ -376,6 +377,7 @@ LIB_OBJS += util/trace-event-read.o
 LIB_OBJS += util/trace-event-info.o
 LIB_OBJS += util/svghelper.o
 LIB_OBJS += util/sort.o
+LIB_OBJS += util/hist.o
 
 BUILTIN_OBJS += builtin-annotate.o
 BUILTIN_OBJS += builtin-help.o
tools/perf/builtin-annotate.c +2 -150

176 lines not on this page · raw message

tools/perf/builtin-report.c +2 -158

202 lines not on this page · raw message

tools/perf/builtin.h +3 -0
index e11d8d2..5d46892 100644
@@ -4,6 +4,9 @@
 #include "util/util.h"
 #include "util/strbuf.h"
 
+extern int callchain;
+extern struct callchain_param	callchain_param;
+
 extern const char perf_version_string[];
 extern const char perf_usage_string[];
 extern const char perf_more_info_string[];
tools/perf/util/hist.c new file +158 -0

158 lines not on this page · raw message

tools/perf/util/hist.h new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#5 lore raw
Quoted 2 lines · John Kacur

perf annotate still will not sort the entries with these changes. because callchain will be equal to zero.

The sorting does not only applies to callchains but also on histogram entries.

Quoted 5 lines

Calling output__resort(total) will be harmless because the calculation will be thrown away in output__insert_entry() here:
if (callchain)

		callchain_param.sort(&he->sorted_chain, &he->callchain,
				      min_callchain_hits, &callchain_param);

Hmm, but the histogram entries will still be sorted, I might be wrong but it doesn't seem to be needed.

That said it's not something introduced by your patch, it was already there, but I guess it would be a nice separate cleanup patch.

Quoted 9 lines

From 7c6a2035c32d17db0e566a36c7e345ec2182f722 Mon Sep 17 00:00:00 2001
From: John Kacur <[email protected]>
Date: Mon, 28 Sep 2009 14:53:08 +0200
Subject: [PATCH] Put common histogram functions for perf in their own file

Move histogram related functions into their own files (hist.c and hist.h) and make use of them in builtin-annotate.c and builtin-report.c

Thanks!