Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 146154
b: refs/heads/master
c: 8f31bfe
h: refs/heads/master
v: v3
  • Loading branch information
Li Zefan authored and Ingo Molnar committed May 8, 2009
1 parent a96d458 commit e83cde5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 81 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 74f4fd21664148b8c454cc07bfe74e4dd51cf07b
refs/heads/master: 8f31bfe538ebafac187d2d4465a92e1d9ee6d8c2
126 changes: 46 additions & 80 deletions trunk/kernel/trace/trace_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,44 @@ static void ftrace_event_enable_disable(struct ftrace_event_call *call,
}
}

static int ftrace_set_clr_event(char *buf, int set)
/*
* __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
*/
static int __ftrace_set_clr_event(const char *match, const char *sub,
const char *event, int set)
{
struct ftrace_event_call *call;
int ret;

mutex_lock(&event_mutex);
list_for_each_entry(call, &ftrace_events, list) {

if (!call->name || !call->regfunc)
continue;

if (match &&
strcmp(match, call->name) != 0 &&
strcmp(match, call->system) != 0)
continue;

if (sub && strcmp(sub, call->system) != 0)
continue;

if (event && strcmp(event, call->name) != 0)
continue;

ftrace_event_enable_disable(call, set);

ret = 0;
}
mutex_unlock(&event_mutex);

return ret;
}

static int ftrace_set_clr_event(char *buf, int set)
{
char *event = NULL, *sub = NULL, *match;
int ret = -EINVAL;

/*
* The buf format can be <subsystem>:<event-name>
Expand All @@ -141,30 +174,7 @@ static int ftrace_set_clr_event(char *buf, int set)
event = NULL;
}

mutex_lock(&event_mutex);
list_for_each_entry(call, &ftrace_events, list) {

if (!call->name || !call->regfunc)
continue;

if (match &&
strcmp(match, call->name) != 0 &&
strcmp(match, call->system) != 0)
continue;

if (sub && strcmp(sub, call->system) != 0)
continue;

if (event && strcmp(event, call->name) != 0)
continue;

ftrace_event_enable_disable(call, set);

ret = 0;
}
mutex_unlock(&event_mutex);

return ret;
return __ftrace_set_clr_event(match, sub, event, set);
}

/* 128 should be much more than enough */
Expand Down Expand Up @@ -408,18 +418,14 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
struct ftrace_event_call *call;
char buf[2];
int set = -1;
int all = 0;
int ret;

if (system[0] == '*')
all = 1;

mutex_lock(&event_mutex);
list_for_each_entry(call, &ftrace_events, list) {
if (!call->name || !call->regfunc)
continue;

if (!all && strcmp(call->system, system) != 0)
if (system && strcmp(call->system, system) != 0)
continue;

/*
Expand Down Expand Up @@ -480,7 +486,6 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
{
const char *system = filp->private_data;
unsigned long val;
char *command;
char buf[64];
ssize_t ret;

Expand All @@ -500,30 +505,16 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
if (ret < 0)
return ret;

switch (val) {
case 0:
case 1:
break;

default:
if (val != 0 && val != 1)
return -EINVAL;
}

/* +3 for the ":*\0" */
command = kmalloc(strlen(system)+3, GFP_KERNEL);
if (!command)
return -ENOMEM;
sprintf(command, "%s:*", system);

ret = ftrace_set_clr_event(command, val);
ret = __ftrace_set_clr_event(NULL, system, NULL, val);
if (ret)
goto out_free;
goto out;

ret = cnt;

out_free:
kfree(command);

out:
*ppos += cnt;

return ret;
Expand Down Expand Up @@ -1181,7 +1172,7 @@ static __init int event_trace_init(void)
&ftrace_show_header_fops);

trace_create_file("enable", 0644, d_events,
"*", &ftrace_system_enable_fops);
NULL, &ftrace_system_enable_fops);

for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
/* The linker may leave blanks */
Expand Down Expand Up @@ -1259,7 +1250,6 @@ static __init void event_trace_self_tests(void)
{
struct ftrace_event_call *call;
struct event_subsystem *system;
char *sysname;
int ret;

pr_info("Running tests on trace events:\n");
Expand Down Expand Up @@ -1305,14 +1295,7 @@ static __init void event_trace_self_tests(void)

pr_info("Testing event system %s: ", system->name);

/* ftrace_set_clr_event can modify the name passed in. */
sysname = kstrdup(system->name, GFP_KERNEL);
if (WARN_ON(!sysname)) {
pr_warning("Can't allocate memory, giving up!\n");
return;
}
ret = ftrace_set_clr_event(sysname, 1);
kfree(sysname);
ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
if (WARN_ON_ONCE(ret)) {
pr_warning("error enabling system %s\n",
system->name);
Expand All @@ -1321,14 +1304,7 @@ static __init void event_trace_self_tests(void)

event_test_stuff();

sysname = kstrdup(system->name, GFP_KERNEL);
if (WARN_ON(!sysname)) {
pr_warning("Can't allocate memory, giving up!\n");
return;
}
ret = ftrace_set_clr_event(sysname, 0);
kfree(sysname);

ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
if (WARN_ON_ONCE(ret))
pr_warning("error disabling system %s\n",
system->name);
Expand All @@ -1341,26 +1317,16 @@ static __init void event_trace_self_tests(void)
pr_info("Running tests on all trace events:\n");
pr_info("Testing all events: ");

sysname = kmalloc(4, GFP_KERNEL);
if (WARN_ON(!sysname)) {
pr_warning("Can't allocate memory, giving up!\n");
return;
}
memcpy(sysname, "*:*", 4);
ret = ftrace_set_clr_event(sysname, 1);
ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
if (WARN_ON_ONCE(ret)) {
kfree(sysname);
pr_warning("error enabling all events\n");
return;
}

event_test_stuff();

/* reset sysname */
memcpy(sysname, "*:*", 4);
ret = ftrace_set_clr_event(sysname, 0);
kfree(sysname);

ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
if (WARN_ON_ONCE(ret)) {
pr_warning("error disabling all events\n");
return;
Expand Down

0 comments on commit e83cde5

Please sign in to comment.