[PATCH 1/5] perf hists: Introduce perf_hpp for hist period printing

2012-09-02 Thread Namhyung Kim
From: Namhyung Kim 

Current hist print functions are messy because it has to consider many
of command line options and the code doing that is scattered around to
places. So when someone wants to add an option to manipulate the hist
output it'd very easy to miss to update all of them in sync. And things
getting worse as more options/features are added continuously.

So I'd like to refactor them using hpp formats and move common code to
ui/hist.c in order to make it easy to maintain and to add new features.

Signed-off-by: Namhyung Kim 
---
 tools/perf/Makefile|   2 +
 tools/perf/builtin-diff.c  |   1 +
 tools/perf/ui/hist.c   | 316 +
 tools/perf/ui/setup.c  |   8 +-
 tools/perf/ui/stdio/hist.c | 238 ++
 tools/perf/util/hist.h |  37 ++
 6 files changed, 402 insertions(+), 200 deletions(-)
 create mode 100644 tools/perf/ui/hist.c

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 722ddee61f9f..23e5c6ab4276 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -403,7 +403,9 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o
 LIB_OBJS += $(OUTPUT)util/target.o
 LIB_OBJS += $(OUTPUT)util/rblist.o
 LIB_OBJS += $(OUTPUT)util/intlist.o
+
 LIB_OBJS += $(OUTPUT)ui/helpline.o
+LIB_OBJS += $(OUTPUT)ui/hist.o
 LIB_OBJS += $(OUTPUT)ui/stdio/hist.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index d29d350fb2b7..3fc53f8b098e 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -235,6 +235,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix __used)
if (symbol__init() < 0)
return -1;
 
+   perf_hpp__init(true, show_displacement);
setup_sorting(diff_usage, options);
setup_pager();
 
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
new file mode 100644
index ..c9a566cfd9c2
--- /dev/null
+++ b/tools/perf/ui/hist.c
@@ -0,0 +1,316 @@
+#include 
+
+#include "../util/hist.h"
+#include "../util/util.h"
+#include "../util/sort.h"
+
+
+/* hist period print (hpp) functions */
+static int hpp__header_overhead(struct perf_hpp *hpp)
+{
+   if (hpp->ptr)
+   return scnprintf(hpp->buf, hpp->size, "Baseline");
+   else
+   return scnprintf(hpp->buf, hpp->size, "Overhead");
+}
+
+static int hpp__width_overhead(struct perf_hpp *hpp __used)
+{
+   return 8;
+}
+
+static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "  %5.2f%%", 
percent);
+}
+
+static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period / hpp->total_period;
+   return scnprintf(hpp->buf, hpp->size, "  %5.2f%%", percent);
+}
+
+static int hpp__header_overhead_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp->buf, hpp->size, " sys  ");
+}
+
+static int hpp__width_overhead_sys(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_sys / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_sys / hpp->total_period;
+   return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__header_overhead_us(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp->buf, hpp->size, " user ");
+}
+
+static int hpp__width_overhead_us(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_us / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_us / hpp->total_period;
+   return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp->buf, hpp->size, "guest sys");
+}
+
+static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __used)
+{
+   return 9;
+}
+
+static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_guest_sys / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "  %5.2f%% ", 
percent);
+}
+
+static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_guest_sys / 

[PATCH 1/5] perf hists: Introduce perf_hpp for hist period printing

2012-09-02 Thread Namhyung Kim
From: Namhyung Kim namhyung@lge.com

Current hist print functions are messy because it has to consider many
of command line options and the code doing that is scattered around to
places. So when someone wants to add an option to manipulate the hist
output it'd very easy to miss to update all of them in sync. And things
getting worse as more options/features are added continuously.

So I'd like to refactor them using hpp formats and move common code to
ui/hist.c in order to make it easy to maintain and to add new features.

Signed-off-by: Namhyung Kim namhy...@kernel.org
---
 tools/perf/Makefile|   2 +
 tools/perf/builtin-diff.c  |   1 +
 tools/perf/ui/hist.c   | 316 +
 tools/perf/ui/setup.c  |   8 +-
 tools/perf/ui/stdio/hist.c | 238 ++
 tools/perf/util/hist.h |  37 ++
 6 files changed, 402 insertions(+), 200 deletions(-)
 create mode 100644 tools/perf/ui/hist.c

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 722ddee61f9f..23e5c6ab4276 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -403,7 +403,9 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o
 LIB_OBJS += $(OUTPUT)util/target.o
 LIB_OBJS += $(OUTPUT)util/rblist.o
 LIB_OBJS += $(OUTPUT)util/intlist.o
+
 LIB_OBJS += $(OUTPUT)ui/helpline.o
+LIB_OBJS += $(OUTPUT)ui/hist.o
 LIB_OBJS += $(OUTPUT)ui/stdio/hist.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index d29d350fb2b7..3fc53f8b098e 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -235,6 +235,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix __used)
if (symbol__init()  0)
return -1;
 
+   perf_hpp__init(true, show_displacement);
setup_sorting(diff_usage, options);
setup_pager();
 
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
new file mode 100644
index ..c9a566cfd9c2
--- /dev/null
+++ b/tools/perf/ui/hist.c
@@ -0,0 +1,316 @@
+#include math.h
+
+#include ../util/hist.h
+#include ../util/util.h
+#include ../util/sort.h
+
+
+/* hist period print (hpp) functions */
+static int hpp__header_overhead(struct perf_hpp *hpp)
+{
+   if (hpp-ptr)
+   return scnprintf(hpp-buf, hpp-size, Baseline);
+   else
+   return scnprintf(hpp-buf, hpp-size, Overhead);
+}
+
+static int hpp__width_overhead(struct perf_hpp *hpp __used)
+{
+   return 8;
+}
+
+static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size,   %5.2f%%, 
percent);
+}
+
+static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period / hpp-total_period;
+   return scnprintf(hpp-buf, hpp-size,   %5.2f%%, percent);
+}
+
+static int hpp__header_overhead_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp-buf, hpp-size,  sys  );
+}
+
+static int hpp__width_overhead_sys(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_sys / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_sys / hpp-total_period;
+   return scnprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__header_overhead_us(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp-buf, hpp-size,  user );
+}
+
+static int hpp__width_overhead_us(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_us / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_us / hpp-total_period;
+   return scnprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp-buf, hpp-size, guest sys);
+}
+
+static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __used)
+{
+   return 9;
+}
+
+static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_guest_sys / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size,   %5.2f%% , 
percent);
+}
+
+static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_guest_sys / hpp-total_period;
+   return 

[PATCH 1/5] perf hists: Introduce perf_hpp for hist period printing

2012-08-21 Thread Namhyung Kim
From: Namhyung Kim 

Current hist print functions are messy because it has to consider many
of command line options and the code doing that is scattered around to
places. So when someone wants to add an option to manipulate the hist
output it'd very easy to miss to update all of them in sync. And things
getting worse as more options/features are added continuously.

So I'd like to refactor them using hpp formats and move common code to
ui/hist.c in order to make it easy to maintain and to add new features.

Signed-off-by: Namhyung Kim 
---
 tools/perf/Makefile|   2 +
 tools/perf/builtin-diff.c  |   1 +
 tools/perf/ui/hist.c   | 316 +
 tools/perf/ui/setup.c  |   8 +-
 tools/perf/ui/stdio/hist.c | 238 ++
 tools/perf/util/hist.h |  37 ++
 6 files changed, 402 insertions(+), 200 deletions(-)
 create mode 100644 tools/perf/ui/hist.c

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 6bd888d04b6e..e834b848c9b1 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -403,7 +403,9 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o
 LIB_OBJS += $(OUTPUT)util/target.o
 LIB_OBJS += $(OUTPUT)util/rblist.o
 LIB_OBJS += $(OUTPUT)util/intlist.o
+
 LIB_OBJS += $(OUTPUT)ui/helpline.o
+LIB_OBJS += $(OUTPUT)ui/hist.o
 LIB_OBJS += $(OUTPUT)ui/stdio/hist.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index d29d350fb2b7..3fc53f8b098e 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -235,6 +235,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix __used)
if (symbol__init() < 0)
return -1;
 
+   perf_hpp__init(true, show_displacement);
setup_sorting(diff_usage, options);
setup_pager();
 
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
new file mode 100644
index ..c9a566cfd9c2
--- /dev/null
+++ b/tools/perf/ui/hist.c
@@ -0,0 +1,316 @@
+#include 
+
+#include "../util/hist.h"
+#include "../util/util.h"
+#include "../util/sort.h"
+
+
+/* hist period print (hpp) functions */
+static int hpp__header_overhead(struct perf_hpp *hpp)
+{
+   if (hpp->ptr)
+   return scnprintf(hpp->buf, hpp->size, "Baseline");
+   else
+   return scnprintf(hpp->buf, hpp->size, "Overhead");
+}
+
+static int hpp__width_overhead(struct perf_hpp *hpp __used)
+{
+   return 8;
+}
+
+static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "  %5.2f%%", 
percent);
+}
+
+static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period / hpp->total_period;
+   return scnprintf(hpp->buf, hpp->size, "  %5.2f%%", percent);
+}
+
+static int hpp__header_overhead_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp->buf, hpp->size, " sys  ");
+}
+
+static int hpp__width_overhead_sys(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_sys / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_sys / hpp->total_period;
+   return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__header_overhead_us(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp->buf, hpp->size, " user ");
+}
+
+static int hpp__width_overhead_us(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_us / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_us / hpp->total_period;
+   return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent);
+}
+
+static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp->buf, hpp->size, "guest sys");
+}
+
+static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __used)
+{
+   return 9;
+}
+
+static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_guest_sys / hpp->total_period;
+   return percent_color_snprintf(hpp->buf, hpp->size, "  %5.2f%% ", 
percent);
+}
+
+static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he->period_guest_sys / 

[PATCH 1/5] perf hists: Introduce perf_hpp for hist period printing

2012-08-21 Thread Namhyung Kim
From: Namhyung Kim namhyung@lge.com

Current hist print functions are messy because it has to consider many
of command line options and the code doing that is scattered around to
places. So when someone wants to add an option to manipulate the hist
output it'd very easy to miss to update all of them in sync. And things
getting worse as more options/features are added continuously.

So I'd like to refactor them using hpp formats and move common code to
ui/hist.c in order to make it easy to maintain and to add new features.

Signed-off-by: Namhyung Kim namhy...@kernel.org
---
 tools/perf/Makefile|   2 +
 tools/perf/builtin-diff.c  |   1 +
 tools/perf/ui/hist.c   | 316 +
 tools/perf/ui/setup.c  |   8 +-
 tools/perf/ui/stdio/hist.c | 238 ++
 tools/perf/util/hist.h |  37 ++
 6 files changed, 402 insertions(+), 200 deletions(-)
 create mode 100644 tools/perf/ui/hist.c

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 6bd888d04b6e..e834b848c9b1 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -403,7 +403,9 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o
 LIB_OBJS += $(OUTPUT)util/target.o
 LIB_OBJS += $(OUTPUT)util/rblist.o
 LIB_OBJS += $(OUTPUT)util/intlist.o
+
 LIB_OBJS += $(OUTPUT)ui/helpline.o
+LIB_OBJS += $(OUTPUT)ui/hist.o
 LIB_OBJS += $(OUTPUT)ui/stdio/hist.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index d29d350fb2b7..3fc53f8b098e 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -235,6 +235,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix __used)
if (symbol__init()  0)
return -1;
 
+   perf_hpp__init(true, show_displacement);
setup_sorting(diff_usage, options);
setup_pager();
 
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
new file mode 100644
index ..c9a566cfd9c2
--- /dev/null
+++ b/tools/perf/ui/hist.c
@@ -0,0 +1,316 @@
+#include math.h
+
+#include ../util/hist.h
+#include ../util/util.h
+#include ../util/sort.h
+
+
+/* hist period print (hpp) functions */
+static int hpp__header_overhead(struct perf_hpp *hpp)
+{
+   if (hpp-ptr)
+   return scnprintf(hpp-buf, hpp-size, Baseline);
+   else
+   return scnprintf(hpp-buf, hpp-size, Overhead);
+}
+
+static int hpp__width_overhead(struct perf_hpp *hpp __used)
+{
+   return 8;
+}
+
+static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size,   %5.2f%%, 
percent);
+}
+
+static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period / hpp-total_period;
+   return scnprintf(hpp-buf, hpp-size,   %5.2f%%, percent);
+}
+
+static int hpp__header_overhead_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp-buf, hpp-size,  sys  );
+}
+
+static int hpp__width_overhead_sys(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_sys / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_sys / hpp-total_period;
+   return scnprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__header_overhead_us(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp-buf, hpp-size,  user );
+}
+
+static int hpp__width_overhead_us(struct perf_hpp *hpp __used)
+{
+   return 6;
+}
+
+static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_us / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_us / hpp-total_period;
+   return scnprintf(hpp-buf, hpp-size, %5.2f%%, percent);
+}
+
+static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp)
+{
+   return scnprintf(hpp-buf, hpp-size, guest sys);
+}
+
+static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __used)
+{
+   return 9;
+}
+
+static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_guest_sys / hpp-total_period;
+   return percent_color_snprintf(hpp-buf, hpp-size,   %5.2f%% , 
percent);
+}
+
+static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
+struct hist_entry *he)
+{
+   double percent = 100.0 * he-period_guest_sys / hpp-total_period;
+   return