Skip to content

Commit 7bcfaf5

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Add trace_options kernel command line parameter
Add trace_options to the kernel command line parameter to be able to set options at early boot. For example, to enable stack dumps of events, add the following: trace_options=stacktrace This along with the trace_event option, you can get not only traces of the events but also the stack dumps with them. Requested-by: Frederic Weisbecker <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 0d5c6e1 commit 7bcfaf5

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

Documentation/kernel-parameters.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,22 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
28592859
to facilitate early boot debugging.
28602860
See also Documentation/trace/events.txt
28612861

2862+
trace_options=[option-list]
2863+
[FTRACE] Enable or disable tracer options at boot.
2864+
The option-list is a comma delimited list of options
2865+
that can be enabled or disabled just as if you were
2866+
to echo the option name into
2867+
2868+
/sys/kernel/debug/tracing/trace_options
2869+
2870+
For example, to enable stacktrace option (to dump the
2871+
stack trace of each event), add to the command line:
2872+
2873+
trace_options=stacktrace
2874+
2875+
See also Documentation/trace/ftrace.txt "trace options"
2876+
section.
2877+
28622878
transparent_hugepage=
28632879
[KNL]
28642880
Format: [always|madvise|never]

kernel/trace/trace.c

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ static int __init set_ftrace_dump_on_oops(char *str)
155155
}
156156
__setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
157157

158+
159+
static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
160+
static char *trace_boot_options __initdata;
161+
162+
static int __init set_trace_boot_options(char *str)
163+
{
164+
strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
165+
trace_boot_options = trace_boot_options_buf;
166+
return 0;
167+
}
168+
__setup("trace_options=", set_trace_boot_options);
169+
158170
unsigned long long ns2usecs(cycle_t nsec)
159171
{
160172
nsec += 500;
@@ -2838,24 +2850,14 @@ static void set_tracer_flags(unsigned int mask, int enabled)
28382850
trace_printk_start_stop_comm(enabled);
28392851
}
28402852

2841-
static ssize_t
2842-
tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2843-
size_t cnt, loff_t *ppos)
2853+
static int trace_set_options(char *option)
28442854
{
2845-
char buf[64];
28462855
char *cmp;
28472856
int neg = 0;
2848-
int ret;
2857+
int ret = 0;
28492858
int i;
28502859

2851-
if (cnt >= sizeof(buf))
2852-
return -EINVAL;
2853-
2854-
if (copy_from_user(&buf, ubuf, cnt))
2855-
return -EFAULT;
2856-
2857-
buf[cnt] = 0;
2858-
cmp = strstrip(buf);
2860+
cmp = strstrip(option);
28592861

28602862
if (strncmp(cmp, "no", 2) == 0) {
28612863
neg = 1;
@@ -2874,10 +2876,25 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
28742876
mutex_lock(&trace_types_lock);
28752877
ret = set_tracer_option(current_trace, cmp, neg);
28762878
mutex_unlock(&trace_types_lock);
2877-
if (ret)
2878-
return ret;
28792879
}
28802880

2881+
return ret;
2882+
}
2883+
2884+
static ssize_t
2885+
tracing_trace_options_write(struct file *filp, const char __user *ubuf,
2886+
size_t cnt, loff_t *ppos)
2887+
{
2888+
char buf[64];
2889+
2890+
if (cnt >= sizeof(buf))
2891+
return -EINVAL;
2892+
2893+
if (copy_from_user(&buf, ubuf, cnt))
2894+
return -EFAULT;
2895+
2896+
trace_set_options(buf);
2897+
28812898
*ppos += cnt;
28822899

28832900
return cnt;
@@ -5133,6 +5150,13 @@ __init static int tracer_alloc_buffers(void)
51335150

51345151
register_die_notifier(&trace_die_notifier);
51355152

5153+
while (trace_boot_options) {
5154+
char *option;
5155+
5156+
option = strsep(&trace_boot_options, ",");
5157+
trace_set_options(option);
5158+
}
5159+
51365160
return 0;
51375161

51385162
out_free_cpumask:

0 commit comments

Comments
 (0)