tracing: simplify print_graph_cpu()
PATCH 1/1 tracing: simplify print_graph_cpu()
print_graph_cpu() is little over-designed.
And "log10_all" may be wrong when there are holes in cpu_online_mask:
the max online cpu id > cpumask_weight(cpu_online_mask)
---
kernel/trace/trace_functions_graph.c +4 -26
@@ -183,43 +183,19 @@ static void graph_trace_reset(struct trace_array *tr)unregister_ftrace_graph (); } -static inline int log10_cpu (int nb) -{ -if (nb /100 ) -return 3 ; -if (nb /10 ) -return 2 ; -return 1 ; -} +static int max_bytes_for_cpu;static enum print_line_t print_graph_cpu (struct trace_seq *s,int cpu) { -int i;int ret; -int log10_this =log10_cpu (cpu); -int log10_all =log10_cpu (cpumask_weight (cpu_online_mask)); -/* * Start with a space character - to make it stand out * to the right a bit when trace output is pasted into * email: */ - ret =trace_seq_printf (s," " ); - -/* -* Tricky - we space the CPU field according to the max -* number of online CPUs. On a 2-cpu system it would take -* a maximum of 1 digit - on a 128 cpu system it would -* take up to 3 digits: -*/ -for (i =0 ; i < log10_all - log10_this; i++) { - ret =trace_seq_printf (s," " ); -if (!ret) -return TRACE_TYPE_PARTIAL_LINE ; - } - ret =trace_seq_printf (s,"%d) " , cpu); + ret =trace_seq_printf (s," %*d) " , max_bytes_for_cpu, cpu);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;
@@ -919,6 +895,8 @@ static struct tracer graph_trace __read_mostly = {static __init int init_graph_trace (void ) { + max_bytes_for_cpu =snprintf (NULL ,0 ,"%d" , nr_cpu_ids -1 ); +return register_tracer (&graph_trace); }
Frederic Weisbecker
AppliedQuoted 59 lines · Lai Jiangshan
print_graph_cpu()is little over-designed.And "
log10_all" may be wrong when there are holes incpu_online_mask:
the max online cpu id >cpumask_weight(cpu_online_mask)Signed-off-by Lai Jiangshan <[email protected]>---
kernel/trace/trace_functions_graph.c +2
-26@@ -183,43 +183,19 @@ static void graph_trace_reset(struct trace_array *tr)unregister_ftrace_graph (); } -static inline int log10_cpu (int nb) -{ -if (nb /100 ) -return 3 ; -if (nb /10 ) -return 2 ; -return 1 ; -} +static int max_bytes_for_cpu;static enum print_line_t print_graph_cpu (struct trace_seq *s,int cpu) { -int i;int ret; -int log10_this =log10_cpu (cpu); -int log10_all =log10_cpu (cpumask_weight (cpu_online_mask)); -/* * Start with a space character - to make it stand out * to the right a bit when trace output is pasted into * email: */ - ret =trace_seq_printf (s," " ); - -/* -* Tricky - we space the CPU field according to the max -* number of online CPUs. On a 2-cpu system it would take -* a maximum of 1 digit - on a 128 cpu system it would -* take up to 3 digits: -*/ -for (i =0 ; i < log10_all - log10_this; i++) { - ret =trace_seq_printf (s," " ); -if (!ret) -return TRACE_TYPE_PARTIAL_LINE ; - } - ret =trace_seq_printf (s,"%d) " , cpu); + ret =trace_seq_printf (s," %*d) " , max_bytes_for_cpu, cpu);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;
kernel/trace/trace_functions_graph.c static struct tracer graph_trace __read_mostly = { · line 898
Quoted 4 lines
kernel/trace/trace_functions_graph.c +1
-0@@ -919,6 +895,8 @@ static struct tracer graph_trace __read_mostly = {static __init int init_graph_trace (void ) { + max_bytes_for_cpu =snprintf (NULL ,0 ,"%d" , nr_cpu_ids -1 );
Nice trick :-)
Queued for .32, thanks!
Quoted 8 lines
kernel/trace/trace_functions_graph.c +1
-0+return register_tracer (&graph_trace); }
[tip:tracing/core] tracing: Simplify print_graph_cpu()
In reply to Lai JiangshanCommit-ID: 40699ef64a3203a79d0873da678d0423aa10ae3a Gitweb: http://git.kernel.org/tip/40699ef64a3203a79d0873da678d0423aa10ae3a Author: Lai Jiangshan <[email protected]> AuthorDate: Tue, 28 Jul 2009 20:26:06 +0800 Committer: Frederic Weisbecker <[email protected]> CommitDate: Wed, 29 Jul 2009 01:04:32 +0200
tracing: Simplify print_graph_cpu()
print_graph_cpu() is little over-designed.
And "log10_all" may be wrong when there are holes in cpu_online_mask:
the max online cpu id > cpumask_weight(cpu_online_mask)
So change it by using a static column length for the cpu matching nr_cpu_ids number of decimal characters.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_functions_graph.c | 30 ++++-------------------------- 1 files changed, 4 insertions(+), 26 deletions(-)
kernel/trace/trace_functions_graph.c +4 -26
@@ -183,43 +183,19 @@ static void graph_trace_reset(struct trace_array *tr)unregister_ftrace_graph (); } -static inline int log10_cpu (int nb) -{ -if (nb /100 ) -return 3 ; -if (nb /10 ) -return 2 ; -return 1 ; -} +static int max_bytes_for_cpu;static enum print_line_t print_graph_cpu (struct trace_seq *s,int cpu) { -int i;int ret; -int log10_this =log10_cpu (cpu); -int log10_all =log10_cpu (cpumask_weight (cpu_online_mask)); -/* * Start with a space character - to make it stand out * to the right a bit when trace output is pasted into * email: */ - ret =trace_seq_printf (s," " ); - -/* -* Tricky - we space the CPU field according to the max -* number of online CPUs. On a 2-cpu system it would take -* a maximum of 1 digit - on a 128 cpu system it would -* take up to 3 digits: -*/ -for (i =0 ; i < log10_all - log10_this; i++) { - ret =trace_seq_printf (s," " ); -if (!ret) -return TRACE_TYPE_PARTIAL_LINE ; - } - ret =trace_seq_printf (s,"%d) " , cpu); + ret =trace_seq_printf (s," %*d) " , max_bytes_for_cpu, cpu);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;
@@ -919,6 +895,8 @@ static struct tracer graph_trace __read_mostly = {static __init int init_graph_trace (void ) { + max_bytes_for_cpu =snprintf (NULL ,0 ,"%d" , nr_cpu_ids -1 ); +return register_tracer (&graph_trace); }
[tip:tracing/core] tracing: Simplify print_graph_cpu()
In reply to Lai JiangshanCommit-ID: 0c9e6f639aed490202bbc79214f4495cf4bfde58 Gitweb: http://git.kernel.org/tip/0c9e6f639aed490202bbc79214f4495cf4bfde58 Author: Lai Jiangshan <[email protected]> AuthorDate: Tue, 28 Jul 2009 20:26:06 +0800 Committer: Frederic Weisbecker <[email protected]> CommitDate: Thu, 6 Aug 2009 07:28:04 +0200
tracing: Simplify print_graph_cpu()
print_graph_cpu() is little over-designed.
And "log10_all" may be wrong when there are holes in cpu_online_mask:
the max online cpu id > cpumask_weight(cpu_online_mask)
So change it by using a static column length for the cpu matching nr_cpu_ids number of decimal characters.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_functions_graph.c | 30 ++++-------------------------- 1 files changed, 4 insertions(+), 26 deletions(-)
kernel/trace/trace_functions_graph.c +4 -26
@@ -183,43 +183,19 @@ static void graph_trace_reset(struct trace_array *tr)unregister_ftrace_graph (); } -static inline int log10_cpu (int nb) -{ -if (nb /100 ) -return 3 ; -if (nb /10 ) -return 2 ; -return 1 ; -} +static int max_bytes_for_cpu;static enum print_line_t print_graph_cpu (struct trace_seq *s,int cpu) { -int i;int ret; -int log10_this =log10_cpu (cpu); -int log10_all =log10_cpu (cpumask_weight (cpu_online_mask)); -/* * Start with a space character - to make it stand out * to the right a bit when trace output is pasted into * email: */ - ret =trace_seq_printf (s," " ); - -/* -* Tricky - we space the CPU field according to the max -* number of online CPUs. On a 2-cpu system it would take -* a maximum of 1 digit - on a 128 cpu system it would -* take up to 3 digits: -*/ -for (i =0 ; i < log10_all - log10_this; i++) { - ret =trace_seq_printf (s," " ); -if (!ret) -return TRACE_TYPE_PARTIAL_LINE ; - } - ret =trace_seq_printf (s,"%d) " , cpu); + ret =trace_seq_printf (s," %*d) " , max_bytes_for_cpu, cpu);if (!ret)return TRACE_TYPE_PARTIAL_LINE ;
@@ -919,6 +895,8 @@ static struct tracer graph_trace __read_mostly = {static __init int init_graph_trace (void ) { + max_bytes_for_cpu =snprintf (NULL ,0 ,"%d" , nr_cpu_ids -1 ); +return register_tracer (&graph_trace); }