Commit 0c9e6f63 authored by Lai Jiangshan's avatar Lai Jiangshan Committed by Frederic Weisbecker
Browse files

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.

Signed-off-by: default avatarLai Jiangshan <laijs@cn.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <4A6EEE5E.2000001@cn.fujitsu.com>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
parent 1f9963cb
Loading
Loading
Loading
Loading
+4 −26
Original line number Original line Diff line number Diff line
@@ -183,43 +183,19 @@ static void graph_trace_reset(struct trace_array *tr)
	unregister_ftrace_graph();
	unregister_ftrace_graph();
}
}


static inline int log10_cpu(int nb)
static int max_bytes_for_cpu;
{
	if (nb / 100)
		return 3;
	if (nb / 10)
		return 2;
	return 1;
}


static enum print_line_t
static enum print_line_t
print_graph_cpu(struct trace_seq *s, int cpu)
print_graph_cpu(struct trace_seq *s, int cpu)
{
{
	int i;
	int ret;
	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
	 * Start with a space character - to make it stand out
	 * to the right a bit when trace output is pasted into
	 * to the right a bit when trace output is pasted into
	 * email:
	 * email:
	 */
	 */
	ret = trace_seq_printf(s, " ");
	ret = trace_seq_printf(s, " %*d) ", max_bytes_for_cpu, cpu);

	/*
	 * 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);
	if (!ret)
	if (!ret)
		return TRACE_TYPE_PARTIAL_LINE;
		return TRACE_TYPE_PARTIAL_LINE;


@@ -919,6 +895,8 @@ static struct tracer graph_trace __read_mostly = {


static __init int init_graph_trace(void)
static __init int init_graph_trace(void)
{
{
	max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1);

	return register_tracer(&graph_trace);
	return register_tracer(&graph_trace);
}
}