Skip to content

Commit fa6f0cc

Browse files
Villemoesrostedt
authored andcommitted
tracing: Replace seq_printf by simpler equivalents
Using seq_printf to print a simple string or a single character is a lot more expensive than it needs to be, since seq_puts and seq_putc exist. These patches do seq_printf(m, s) -> seq_puts(m, s) seq_printf(m, "%s", s) -> seq_puts(m, s) seq_printf(m, "%c", c) -> seq_putc(m, c) Subsequent patches will simplify further. Link: http://lkml.kernel.org/r/1415479332-25944-2-git-send-email-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 8520ded commit fa6f0cc

9 files changed

Lines changed: 71 additions & 71 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,13 @@ static int function_stat_cmp(void *p1, void *p2)
571571
static int function_stat_headers(struct seq_file *m)
572572
{
573573
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
574-
seq_printf(m, " Function "
575-
"Hit Time Avg s^2\n"
576-
" -------- "
577-
"--- ---- --- ---\n");
574+
seq_puts(m, " Function "
575+
"Hit Time Avg s^2\n"
576+
" -------- "
577+
"--- ---- --- ---\n");
578578
#else
579-
seq_printf(m, " Function Hit\n"
580-
" -------- ---\n");
579+
seq_puts(m, " Function Hit\n"
580+
" -------- ---\n");
581581
#endif
582582
return 0;
583583
}
@@ -604,7 +604,7 @@ static int function_stat_show(struct seq_file *m, void *v)
604604
seq_printf(m, " %-30.30s %10lu", str, rec->counter);
605605

606606
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
607-
seq_printf(m, " ");
607+
seq_puts(m, " ");
608608
avg = rec->time;
609609
do_div(avg, rec->counter);
610610

@@ -3006,9 +3006,9 @@ static int t_show(struct seq_file *m, void *v)
30063006

30073007
if (iter->flags & FTRACE_ITER_PRINTALL) {
30083008
if (iter->flags & FTRACE_ITER_NOTRACE)
3009-
seq_printf(m, "#### no functions disabled ####\n");
3009+
seq_puts(m, "#### no functions disabled ####\n");
30103010
else
3011-
seq_printf(m, "#### all functions enabled ####\n");
3011+
seq_puts(m, "#### all functions enabled ####\n");
30123012
return 0;
30133013
}
30143014

@@ -3030,13 +3030,13 @@ static int t_show(struct seq_file *m, void *v)
30303030
seq_printf(m, "\ttramp: %pS",
30313031
(void *)ops->trampoline);
30323032
else
3033-
seq_printf(m, "\ttramp: ERROR!");
3033+
seq_puts(m, "\ttramp: ERROR!");
30343034

30353035
}
30363036
add_trampoline_func(m, ops, rec);
30373037
}
30383038

3039-
seq_printf(m, "\n");
3039+
seq_putc(m, '\n');
30403040

30413041
return 0;
30423042
}
@@ -4233,9 +4233,9 @@ static int g_show(struct seq_file *m, void *v)
42334233
struct ftrace_graph_data *fgd = m->private;
42344234

42354235
if (fgd->table == ftrace_graph_funcs)
4236-
seq_printf(m, "#### all functions enabled ####\n");
4236+
seq_puts(m, "#### all functions enabled ####\n");
42374237
else
4238-
seq_printf(m, "#### no functions disabled ####\n");
4238+
seq_puts(m, "#### no functions disabled ####\n");
42394239
return 0;
42404240
}
42414241

@@ -5155,12 +5155,12 @@ static int fpid_show(struct seq_file *m, void *v)
51555155
const struct ftrace_pid *fpid = list_entry(v, struct ftrace_pid, list);
51565156

51575157
if (v == (void *)1) {
5158-
seq_printf(m, "no pid\n");
5158+
seq_puts(m, "no pid\n");
51595159
return 0;
51605160
}
51615161

51625162
if (fpid->pid == ftrace_swapper_pid)
5163-
seq_printf(m, "swapper tasks\n");
5163+
seq_puts(m, "swapper tasks\n");
51645164
else
51655165
seq_printf(m, "%u\n", pid_vnr(fpid->pid));
51665166

‎kernel/trace/trace.c‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,44 +2860,44 @@ static void test_ftrace_alive(struct seq_file *m)
28602860
{
28612861
if (!ftrace_is_dead())
28622862
return;
2863-
seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2864-
seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n");
2863+
seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2864+
seq_puts(m, "# MAY BE MISSING FUNCTION EVENTS\n");
28652865
}
28662866

28672867
#ifdef CONFIG_TRACER_MAX_TRACE
28682868
static void show_snapshot_main_help(struct seq_file *m)
28692869
{
2870-
seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
2871-
seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2872-
seq_printf(m, "# Takes a snapshot of the main buffer.\n");
2873-
seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
2874-
seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
2875-
seq_printf(m, "# is not a '0' or '1')\n");
2870+
seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
2871+
seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2872+
seq_puts(m, "# Takes a snapshot of the main buffer.\n");
2873+
seq_puts(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
2874+
seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
2875+
seq_puts(m, "# is not a '0' or '1')\n");
28762876
}
28772877

28782878
static void show_snapshot_percpu_help(struct seq_file *m)
28792879
{
2880-
seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
2880+
seq_puts(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
28812881
#ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
2882-
seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2883-
seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n");
2882+
seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
2883+
seq_puts(m, "# Takes a snapshot of the main buffer for this cpu.\n");
28842884
#else
2885-
seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
2886-
seq_printf(m, "# Must use main snapshot file to allocate.\n");
2885+
seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
2886+
seq_puts(m, "# Must use main snapshot file to allocate.\n");
28872887
#endif
2888-
seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
2889-
seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
2890-
seq_printf(m, "# is not a '0' or '1')\n");
2888+
seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
2889+
seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
2890+
seq_puts(m, "# is not a '0' or '1')\n");
28912891
}
28922892

28932893
static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
28942894
{
28952895
if (iter->tr->allocated_snapshot)
2896-
seq_printf(m, "#\n# * Snapshot is allocated *\n#\n");
2896+
seq_puts(m, "#\n# * Snapshot is allocated *\n#\n");
28972897
else
2898-
seq_printf(m, "#\n# * Snapshot is freed *\n#\n");
2898+
seq_puts(m, "#\n# * Snapshot is freed *\n#\n");
28992899

2900-
seq_printf(m, "# Snapshot commands:\n");
2900+
seq_puts(m, "# Snapshot commands:\n");
29012901
if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
29022902
show_snapshot_main_help(m);
29032903
else
@@ -3251,7 +3251,7 @@ static int t_show(struct seq_file *m, void *v)
32513251
if (!t)
32523252
return 0;
32533253

3254-
seq_printf(m, "%s", t->name);
3254+
seq_puts(m, t->name);
32553255
if (t->next)
32563256
seq_putc(m, ' ');
32573257
else
@@ -5753,10 +5753,10 @@ ftrace_snapshot_print(struct seq_file *m, unsigned long ip,
57535753

57545754
seq_printf(m, "%ps:", (void *)ip);
57555755

5756-
seq_printf(m, "snapshot");
5756+
seq_puts(m, "snapshot");
57575757

57585758
if (count == -1)
5759-
seq_printf(m, ":unlimited\n");
5759+
seq_puts(m, ":unlimited\n");
57605760
else
57615761
seq_printf(m, ":count=%ld\n", count);
57625762

‎kernel/trace/trace_branch.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ extern unsigned long __stop_annotated_branch_profile[];
233233

234234
static int annotated_branch_stat_headers(struct seq_file *m)
235235
{
236-
seq_printf(m, " correct incorrect %% ");
237-
seq_printf(m, " Function "
238-
" File Line\n"
239-
" ------- --------- - "
240-
" -------- "
241-
" ---- ----\n");
236+
seq_puts(m, " correct incorrect % ");
237+
seq_puts(m, " Function "
238+
" File Line\n"
239+
" ------- --------- - "
240+
" -------- "
241+
" ---- ----\n");
242242
return 0;
243243
}
244244

@@ -274,7 +274,7 @@ static int branch_stat_show(struct seq_file *m, void *v)
274274

275275
seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
276276
if (percent < 0)
277-
seq_printf(m, " X ");
277+
seq_puts(m, " X ");
278278
else
279279
seq_printf(m, "%3ld ", percent);
280280
seq_printf(m, "%-30.30s %-20.20s %d\n", p->func, f, p->line);
@@ -362,12 +362,12 @@ extern unsigned long __stop_branch_profile[];
362362

363363
static int all_branch_stat_headers(struct seq_file *m)
364364
{
365-
seq_printf(m, " miss hit %% ");
366-
seq_printf(m, " Function "
367-
" File Line\n"
368-
" ------- --------- - "
369-
" -------- "
370-
" ---- ----\n");
365+
seq_puts(m, " miss hit % ");
366+
seq_puts(m, " Function "
367+
" File Line\n"
368+
" ------- --------- - "
369+
" -------- "
370+
" ---- ----\n");
371371
return 0;
372372
}
373373

‎kernel/trace/trace_events.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static int f_show(struct seq_file *m, void *v)
918918
case FORMAT_HEADER:
919919
seq_printf(m, "name: %s\n", ftrace_event_name(call));
920920
seq_printf(m, "ID: %d\n", call->event.type);
921-
seq_printf(m, "format:\n");
921+
seq_puts(m, "format:\n");
922922
return 0;
923923

924924
case FORMAT_FIELD_SEPERATOR:
@@ -1988,7 +1988,7 @@ event_enable_print(struct seq_file *m, unsigned long ip,
19881988
ftrace_event_name(data->file->event_call));
19891989

19901990
if (data->count == -1)
1991-
seq_printf(m, ":unlimited\n");
1991+
seq_puts(m, ":unlimited\n");
19921992
else
19931993
seq_printf(m, ":count=%ld\n", data->count);
19941994

‎kernel/trace/trace_events_trigger.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ event_trigger_print(const char *name, struct seq_file *m,
373373
{
374374
long count = (long)data;
375375

376-
seq_printf(m, "%s", name);
376+
seq_puts(m, name);
377377

378378
if (count == -1)
379379
seq_puts(m, ":unlimited");

‎kernel/trace/trace_functions.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ ftrace_probe_print(const char *name, struct seq_file *m,
361361
seq_printf(m, "%ps:%s", (void *)ip, name);
362362

363363
if (count == -1)
364-
seq_printf(m, ":unlimited\n");
364+
seq_puts(m, ":unlimited\n");
365365
else
366366
seq_printf(m, ":count=%ld\n", count);
367367

‎kernel/trace/trace_functions_graph.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,32 +1407,32 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
14071407
print_lat_header(s, flags);
14081408

14091409
/* 1st line */
1410-
seq_printf(s, "#");
1410+
seq_puts(s, "#");
14111411
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
1412-
seq_printf(s, " TIME ");
1412+
seq_puts(s, " TIME ");
14131413
if (flags & TRACE_GRAPH_PRINT_CPU)
1414-
seq_printf(s, " CPU");
1414+
seq_puts(s, " CPU");
14151415
if (flags & TRACE_GRAPH_PRINT_PROC)
1416-
seq_printf(s, " TASK/PID ");
1416+
seq_puts(s, " TASK/PID ");
14171417
if (lat)
1418-
seq_printf(s, "||||");
1418+
seq_puts(s, "||||");
14191419
if (flags & TRACE_GRAPH_PRINT_DURATION)
1420-
seq_printf(s, " DURATION ");
1421-
seq_printf(s, " FUNCTION CALLS\n");
1420+
seq_puts(s, " DURATION ");
1421+
seq_puts(s, " FUNCTION CALLS\n");
14221422

14231423
/* 2nd line */
1424-
seq_printf(s, "#");
1424+
seq_puts(s, "#");
14251425
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
1426-
seq_printf(s, " | ");
1426+
seq_puts(s, " | ");
14271427
if (flags & TRACE_GRAPH_PRINT_CPU)
1428-
seq_printf(s, " | ");
1428+
seq_puts(s, " | ");
14291429
if (flags & TRACE_GRAPH_PRINT_PROC)
1430-
seq_printf(s, " | | ");
1430+
seq_puts(s, " | | ");
14311431
if (lat)
1432-
seq_printf(s, "||||");
1432+
seq_puts(s, "||||");
14331433
if (flags & TRACE_GRAPH_PRINT_DURATION)
1434-
seq_printf(s, " | | ");
1435-
seq_printf(s, " | | | |\n");
1434+
seq_puts(s, " | | ");
1435+
seq_puts(s, " | | | |\n");
14361436
}
14371437

14381438
static void print_graph_headers(struct seq_file *s)

‎kernel/trace/trace_kprobe.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
826826
struct trace_kprobe *tk = v;
827827
int i;
828828

829-
seq_printf(m, "%c", trace_kprobe_is_return(tk) ? 'r' : 'p');
829+
seq_putc(m, trace_kprobe_is_return(tk) ? 'r' : 'p');
830830
seq_printf(m, ":%s/%s", tk->tp.call.class->system,
831831
ftrace_event_name(&tk->tp.call));
832832

@@ -840,7 +840,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
840840

841841
for (i = 0; i < tk->tp.nr_args; i++)
842842
seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
843-
seq_printf(m, "\n");
843+
seq_putc(m, '\n');
844844

845845
return 0;
846846
}

‎kernel/trace/trace_uprobe.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
606606
for (i = 0; i < tu->tp.nr_args; i++)
607607
seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
608608

609-
seq_printf(m, "\n");
609+
seq_putc(m, '\n');
610610
return 0;
611611
}
612612

0 commit comments

Comments
 (0)