tracing/ftrace: factorize the tracing files creation
Subsystems (3)
PATCH 1/1 tracing/ftrace: factorize the tracing files creation
Impact: cleanup
Most of the tracing files creation follow the same pattern:
ret = debugfs_create_file(...)
if (!ret)
pr_warning("Couldn't create ... entry\n")
Unify it!
--- kernel/trace/ftrace.c | 47 +++-------- kernel/trace/ring_buffer.c | 7 +- kernel/trace/trace.c | 159 ++++++++++++++---------------------- kernel/trace/trace.h | 6 ++ kernel/trace/trace_event_profile.c | 3 +- kernel/trace/trace_printk.c | 6 +- kernel/trace/trace_stack.c | 13 +-- kernel/trace/trace_sysprof.c | 6 +- 8 files changed, 90 insertions(+), 157 deletions(-)
kernel/trace/ftrace.c +12 -35
@@ -764,7 +764,6 @@ static struct tracer_stat function_stats __initdata = {static void ftrace_profile_debugfs (struct dentry *d_tracer) {struct ftrace_profile_stat *stat; -struct dentry *entry;char *name;int ret;int cpu;
@@ -798,11 +797,8 @@ static void ftrace_profile_debugfs(struct dentry *d_tracer) } } - entry =debugfs_create_file ("function_profile_enabled" ,0644 , - d_tracer,NULL , &ftrace_profile_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'function_profile_enabled' entry\n" ); +trace_create_file ("function_profile_enabled" ,0644 , + d_tracer,NULL , &ftrace_profile_fops); }#else /* CONFIG_FUNCTION_PROFILER */
@@ -2698,38 +2694,23 @@ static const struct file_operations ftrace_graph_fops = {static __init int ftrace_init_dyn_debugfs (struct dentry *d_tracer) { -struct dentry *entry; - entry =debugfs_create_file ("available_filter_functions" ,0444 , - d_tracer,NULL , &ftrace_avail_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'available_filter_functions' entry\n" ); +trace_create_file ("available_filter_functions" ,0444 , + d_tracer,NULL , &ftrace_avail_fops); - entry =debugfs_create_file ("failures" ,0444 , - d_tracer,NULL , &ftrace_failures_fops); -if (!entry) -pr_warning ("Could not create debugfs 'failures' entry\n" ); +trace_create_file ("failures" ,0444 , + d_tracer,NULL , &ftrace_failures_fops); - entry =debugfs_create_file ("set_ftrace_filter" ,0644 , d_tracer, -NULL , &ftrace_filter_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_ftrace_filter' entry\n" ); +trace_create_file ("set_ftrace_filter" ,0644 , d_tracer, +NULL , &ftrace_filter_fops); - entry =debugfs_create_file ("set_ftrace_notrace" ,0644 , d_tracer, +trace_create_file ("set_ftrace_notrace" ,0644 , d_tracer,NULL , &ftrace_notrace_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_ftrace_notrace' entry\n" );#ifdef CONFIG_FUNCTION_GRAPH_TRACER - entry =debugfs_create_file ("set_graph_function" ,0444 , d_tracer, +trace_create_file ("set_graph_function" ,0444 , d_tracer,NULL , &ftrace_graph_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_graph_function' entry\n" );#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ return 0 ;
@@ -2987,7 +2968,6 @@ static const struct file_operations ftrace_pid_fops = {static __init int ftrace_init_debugfs (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry ();if (!d_tracer)
@@ -2995,11 +2975,8 @@ static __init int ftrace_init_debugfs(void)ftrace_init_dyn_debugfs (d_tracer); - entry =debugfs_create_file ("set_ftrace_pid" ,0644 , d_tracer, -NULL , &ftrace_pid_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_ftrace_pid' entry\n" ); +trace_create_file ("set_ftrace_pid" ,0644 , d_tracer, +NULL , &ftrace_pid_fops);ftrace_profile_debugfs (d_tracer);
kernel/trace/ring_buffer.c +2 -5
@@ -2849,14 +2849,11 @@ static const struct file_operations rb_simple_fops = {static __init int rb_init_debugfs (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry (); - entry =debugfs_create_file ("tracing_on" ,0644 , d_tracer, - &ring_buffer_flags, &rb_simple_fops); -if (!entry) -pr_warning ("Could not create debugfs 'tracing_on' entry\n" ); +trace_create_file ("tracing_on" ,0644 , d_tracer, + &ring_buffer_flags, &rb_simple_fops);return 0 ; }
kernel/trace/trace.c +62 -97
237 lines not on this page · raw message
kernel/trace/trace.h +6 -0
@@ -470,6 +470,12 @@ void trace_wake_up(void);void tracing_reset (struct trace_array *tr,int cpu);void tracing_reset_online_cpus (struct trace_array *tr);int tracing_open_generic (struct inode *inode,struct file *filp); +struct dentry *trace_create_file (const char *name, +mode_t mode, +struct dentry *parent, +void *data, +const struct file_operations *fops); +struct dentry *tracing_init_dentry (void );void init_tracer_sysprof_debugfs (struct dentry *d_tracer);
kernel/trace/trace_event_profile.c +2 -1
@@ -6,7 +6,7 @@*/ #include "trace.h" - +#if 0 int ftrace_profile_enable (int event_id) {struct ftrace_event_call *event;
@@ -29,3 +29,4 @@ void ftrace_profile_disable(int event_id) } } +#endif
kernel/trace/trace_printk.c +1 -5
@@ -245,17 +245,13 @@ static const struct file_operations ftrace_formats_fops = {static __init int init_trace_printk_function_export (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry ();if (!d_tracer)return 0 ; - entry =debugfs_create_file ("printk_formats" ,0444 , d_tracer, +trace_create_file ("printk_formats" ,0444 , d_tracer,NULL , &ftrace_formats_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'printk_formats' entry\n" );return 0 ; }
kernel/trace/trace_stack.c +4 -9
@@ -352,19 +352,14 @@ __setup("stacktrace", enable_stacktrace);static __init int stack_trace_init (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry (); - entry =debugfs_create_file ("stack_max_size" ,0644 , d_tracer, - &max_stack_size, &stack_max_size_fops); -if (!entry) -pr_warning ("Could not create debugfs 'stack_max_size' entry\n" ); +trace_create_file ("stack_max_size" ,0644 , d_tracer, + &max_stack_size, &stack_max_size_fops); - entry =debugfs_create_file ("stack_trace" ,0444 , d_tracer, -NULL , &stack_trace_fops); -if (!entry) -pr_warning ("Could not create debugfs 'stack_trace' entry\n" ); +trace_create_file ("stack_trace" ,0444 , d_tracer, +NULL , &stack_trace_fops);if (stack_tracer_enabled)register_ftrace_function (&trace_ops);
kernel/trace/trace_sysprof.c +1 -5
@@ -321,11 +321,7 @@ static const struct file_operations sysprof_sample_fops = {void init_tracer_sysprof_debugfs (struct dentry *d_tracer) { -struct dentry *entry; - entry =debugfs_create_file ("sysprof_sample_period" ,0644 , +trace_create_file ("sysprof_sample_period" ,0644 , d_tracer,NULL , &sysprof_sample_fops); -if (entry) -return ; -pr_warning ("Could not create debugfs 'sysprof_sample_period' entry\n" ); }
Signature · 1 line
1.6.1
Steven Rostedt
maintainerQuoted 10 lines · Frederic Weisbecker
Impact: cleanup
Most of the tracing files creation follow the same pattern:
ret =
debugfs_create_file(...)
if (!ret)
pr_warning("Couldn't create ... entry\n")Unify it!
I could have sworn I did this before. I found this patch with the timestamp dated Feb 8, 2008. This is even before we came up with the name "ftrace" and I was still calling it "mcount".
Oh well, it somehow never got out :-(
I'll Ack yours ;-)
Old patch:
From: Steven Rostedt <[email protected]>
Subject: clean up trace debugfs error messages
The debugfs creation had a bunch of cut and paste errors in the prints. This patch creates a single function to create the debugfs file and print out the error if it fails.
--- kernel/trace/trace.c | 53 +++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 31 deletions(-)
kernel/trace/trace.c +22 -31
@@ -1394,63 +1394,54 @@ struct dentry *tracing_init_dentry(void)return d_tracer; } +static __init void +tracing_debugfs_create_file (const char *name,mode_t mode, +struct dentry *parent,void *data, +const struct file_operations *fops) +{ +struct dentry *entry; + + entry =debugfs_create_file (name, mode, parent, data, fops); +if (!entry) +pr_warning ("Could not create debugfs '%s' entry\n" , name); +} +static __init void tracer_init_debugfs (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry (); - entry =debugfs_create_file ("tracing_enabled" ,0644 , d_tracer, +tracing_debugfs_create_file ("tracing_enabled" ,0644 , d_tracer, &global_trace, &tracing_ctrl_fops); -if (!entry) -pr_warning ("Could not create debugfs 'tracing_enabled' entry\n" ); - entry =debugfs_create_file ("iter_ctrl" ,0644 , d_tracer, + +tracing_debugfs_create_file ("iter_ctrl" ,0644 , d_tracer,NULL , &tracing_iter_fops); -if (!entry) -pr_warning ("Could not create debugfs 'iter_ctrl' entry\n" ); - entry =debugfs_create_file ("latency_trace" ,0444 , d_tracer, +tracing_debugfs_create_file ("latency_trace" ,0444 , d_tracer, &global_trace, &tracing_lt_fops); -if (!entry) -pr_warning ("Could not create debugfs 'latency_trace' entry\n" ); - entry =debugfs_create_file ("trace" ,0444 , d_tracer, +tracing_debugfs_create_file ("trace" ,0444 , d_tracer, &global_trace, &tracing_fops); -if (!entry) -pr_warning ("Could not create debugfs 'trace' entry\n" ); - entry =debugfs_create_file ("available_tracers" ,0444 , d_tracer, +tracing_debugfs_create_file ("available_tracers" ,0444 , d_tracer, &global_trace, &show_traces_fops); -if (!entry) -pr_warning ("Could not create debugfs 'trace' entry\n" ); - entry =debugfs_create_file ("current_tracer" ,0444 , d_tracer, +tracing_debugfs_create_file ("current_tracer" ,0444 , d_tracer, &global_trace, &set_tracer_fops); -if (!entry) -pr_warning ("Could not create debugfs 'trace' entry\n" ); - entry =debugfs_create_file ("tracing_max_latency" ,0644 , d_tracer, +tracing_debugfs_create_file ("tracing_max_latency" ,0644 , d_tracer, &tracing_max_latency, &tracing_max_lat_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'tracing_max_latency' entry\n" ); - entry =debugfs_create_file ("tracing_thresh" ,0644 , d_tracer, +tracing_debugfs_create_file ("tracing_thresh" ,0644 , d_tracer, &tracing_thresh, &tracing_max_lat_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'tracing_threash' entry\n" );#ifdef CONFIG_DYNAMIC_FTRACE - entry =debugfs_create_file ("dyn_ftrace_total_info" ,0444 , d_tracer, +tracing_debugfs_create_file ("dyn_ftrace_total_info" ,0444 , d_tracer, &ftrace_update_tot_cnt, &tracing_read_long_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'dyn_ftrace_total_info' entry\n" );#endif }
Steven Rostedt
maintainerQuoted 28 lines · Steven Rostedt
Quoted 10 lines · Frederic Weisbecker
Impact: cleanup
Most of the tracing files creation follow the same pattern:
ret =
debugfs_create_file(...)
if (!ret)
pr_warning("Couldn't create ... entry\n")Unify it!
I could have sworn I did this before. I found this patch with the timestamp dated Feb 8, 2008. This is even before we came up with the name "ftrace" and I was still calling it "mcount".
Oh well, it somehow never got out :-(
I'll Ack yours ;-)
Old patch:
From: Steven Rostedt <[email protected]>
Subject: clean up trace debugfs error messages
Quoted 6 lines
The debugfs creation had a bunch of cut and paste errors in the prints. This patch creates a single function to create the debugfs file and print out the error if it fails.
Signed-off-by Steven Rostedt <[email protected]>
I always wondered why Ingo never pulled it in. I can not find any record of me emailing it. I've not only searched Google, but it is not in any of my "sent" folders either. I must have been suffering a senior moment, and thought I emailed it when I never did :-/
-- Steve
Quoted 37 lines · Steven Rostedt
Quoted 33 lines · Steven Rostedt
Quoted 10 lines · Frederic Weisbecker
Impact: cleanup
Most of the tracing files creation follow the same pattern:
ret =
debugfs_create_file(...)
if (!ret)
pr_warning("Couldn't create ... entry\n")Unify it!
I could have sworn I did this before. I found this patch with the timestamp dated Feb 8, 2008. This is even before we came up with the name "ftrace" and I was still calling it "mcount".
Oh well, it somehow never got out :-(
I'll Ack yours ;-)
Old patch:
From: Steven Rostedt <[email protected]>
Subject: clean up trace debugfs error messagesThe debugfs creation had a bunch of cut and paste errors in the prints. This patch creates a single function to create the debugfs file and print out the error if it fails.
Quoted 9 lines
Quoted 1 line
Signed-off-by Steven Rostedt <[email protected]>I always wondered why Ingo never pulled it in. I can not find any record of me emailing it. I've not only searched Google, but it is not in any of my "sent" folders either. I must have been suffering a senior moment, and thought I emailed it when I never did :-/
-- Steve
Be care, that's not the first time! Remember this old copy_from_user_inatomic() ?
:-)
Quoted 4 lines · Frederic Weisbecker
Impact: cleanup
Most of the tracing files creation follow the same pattern:
Quoted 8 lines
ret =
debugfs_create_file(...)
if (!ret)
pr_warning("Couldn't create ... entry\n")Unify it!
Reported-by Ingo Molnar <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>
Thanks, applied.
Note, I only applied it to tracing/ftrace, which does not have the profiler code. That part of the patch has been rejected.
-- Steve
Commit-ID: 5452af664f6fba26b80eb2c8c4ceae2999d5cf56 Gitweb: http://git.kernel.org/tip/5452af664f6fba26b80eb2c8c4ceae2999d5cf56 Author: Frederic Weisbecker <[email protected]> AuthorDate: Fri, 27 Mar 2009 00:25:38 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 7 Apr 2009 14:43:07 +0200
tracing/ftrace: factorize the tracing files creation
Impact: cleanup
Most of the tracing files creation follow the same pattern:
ret = debugfs_create_file(...)
if (!ret)
pr_warning("Couldn't create ... entry\n")
Unify it!
LKML-Reference: <[email protected]>
--- kernel/trace/ftrace.c | 39 ++------- kernel/trace/ring_buffer.c | 7 +- kernel/trace/trace.c | 159 ++++++++++++++---------------------- kernel/trace/trace.h | 6 ++ kernel/trace/trace_event_profile.c | 1 - kernel/trace/trace_printk.c | 6 +- kernel/trace/trace_stack.c | 13 +-- kernel/trace/trace_sysprof.c | 6 +- 8 files changed, 86 insertions(+), 151 deletions(-)
kernel/trace/ftrace.c +10 -29
@@ -2698,38 +2698,23 @@ static const struct file_operations ftrace_graph_fops = {static __init int ftrace_init_dyn_debugfs (struct dentry *d_tracer) { -struct dentry *entry; - entry =debugfs_create_file ("available_filter_functions" ,0444 , - d_tracer,NULL , &ftrace_avail_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'available_filter_functions' entry\n" ); +trace_create_file ("available_filter_functions" ,0444 , + d_tracer,NULL , &ftrace_avail_fops); - entry =debugfs_create_file ("failures" ,0444 , - d_tracer,NULL , &ftrace_failures_fops); -if (!entry) -pr_warning ("Could not create debugfs 'failures' entry\n" ); +trace_create_file ("failures" ,0444 , + d_tracer,NULL , &ftrace_failures_fops); - entry =debugfs_create_file ("set_ftrace_filter" ,0644 , d_tracer, -NULL , &ftrace_filter_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_ftrace_filter' entry\n" ); +trace_create_file ("set_ftrace_filter" ,0644 , d_tracer, +NULL , &ftrace_filter_fops); - entry =debugfs_create_file ("set_ftrace_notrace" ,0644 , d_tracer, +trace_create_file ("set_ftrace_notrace" ,0644 , d_tracer,NULL , &ftrace_notrace_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_ftrace_notrace' entry\n" );#ifdef CONFIG_FUNCTION_GRAPH_TRACER - entry =debugfs_create_file ("set_graph_function" ,0444 , d_tracer, +trace_create_file ("set_graph_function" ,0444 , d_tracer,NULL , &ftrace_graph_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_graph_function' entry\n" );#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ return 0 ;
@@ -2987,7 +2972,6 @@ static const struct file_operations ftrace_pid_fops = {static __init int ftrace_init_debugfs (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry ();if (!d_tracer)
@@ -2995,11 +2979,8 @@ static __init int ftrace_init_debugfs(void)ftrace_init_dyn_debugfs (d_tracer); - entry =debugfs_create_file ("set_ftrace_pid" ,0644 , d_tracer, -NULL , &ftrace_pid_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'set_ftrace_pid' entry\n" ); +trace_create_file ("set_ftrace_pid" ,0644 , d_tracer, +NULL , &ftrace_pid_fops);ftrace_profile_debugfs (d_tracer);
kernel/trace/ring_buffer.c +2 -5
@@ -2845,14 +2845,11 @@ static const struct file_operations rb_simple_fops = {static __init int rb_init_debugfs (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry (); - entry =debugfs_create_file ("tracing_on" ,0644 , d_tracer, - &ring_buffer_flags, &rb_simple_fops); -if (!entry) -pr_warning ("Could not create debugfs 'tracing_on' entry\n" ); +trace_create_file ("tracing_on" ,0644 , d_tracer, + &ring_buffer_flags, &rb_simple_fops);return 0 ; }
kernel/trace/trace.c +62 -97
237 lines not on this page · raw message
kernel/trace/trace.h +6 -0
@@ -470,6 +470,12 @@ void trace_wake_up(void);void tracing_reset (struct trace_array *tr,int cpu);void tracing_reset_online_cpus (struct trace_array *tr);int tracing_open_generic (struct inode *inode,struct file *filp); +struct dentry *trace_create_file (const char *name, +mode_t mode, +struct dentry *parent, +void *data, +const struct file_operations *fops); +struct dentry *tracing_init_dentry (void );void init_tracer_sysprof_debugfs (struct dentry *d_tracer);
kernel/trace/trace_event_profile.c +0 -1
@@ -28,4 +28,3 @@ void ftrace_profile_disable(int event_id)return event->profile_disable (event); } } -
kernel/trace/trace_printk.c +1 -5
@@ -245,17 +245,13 @@ static const struct file_operations ftrace_formats_fops = {static __init int init_trace_printk_function_export (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry ();if (!d_tracer)return 0 ; - entry =debugfs_create_file ("printk_formats" ,0444 , d_tracer, +trace_create_file ("printk_formats" ,0444 , d_tracer,NULL , &ftrace_formats_fops); -if (!entry) -pr_warning ("Could not create debugfs " -"'printk_formats' entry\n" );return 0 ; }
kernel/trace/trace_stack.c +4 -9
@@ -352,19 +352,14 @@ __setup("stacktrace", enable_stacktrace);static __init int stack_trace_init (void ) {struct dentry *d_tracer; -struct dentry *entry; d_tracer =tracing_init_dentry (); - entry =debugfs_create_file ("stack_max_size" ,0644 , d_tracer, - &max_stack_size, &stack_max_size_fops); -if (!entry) -pr_warning ("Could not create debugfs 'stack_max_size' entry\n" ); +trace_create_file ("stack_max_size" ,0644 , d_tracer, + &max_stack_size, &stack_max_size_fops); - entry =debugfs_create_file ("stack_trace" ,0444 , d_tracer, -NULL , &stack_trace_fops); -if (!entry) -pr_warning ("Could not create debugfs 'stack_trace' entry\n" ); +trace_create_file ("stack_trace" ,0444 , d_tracer, +NULL , &stack_trace_fops);if (stack_tracer_enabled)register_ftrace_function (&trace_ops);
kernel/trace/trace_sysprof.c +1 -5
@@ -321,11 +321,7 @@ static const struct file_operations sysprof_sample_fops = {void init_tracer_sysprof_debugfs (struct dentry *d_tracer) { -struct dentry *entry; - entry =debugfs_create_file ("sysprof_sample_period" ,0644 , +trace_create_file ("sysprof_sample_period" ,0644 , d_tracer,NULL , &sysprof_sample_fops); -if (entry) -return ; -pr_warning ("Could not create debugfs 'sysprof_sample_period' entry\n" ); }