Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 182285
b: refs/heads/master
c: 50307a4
h: refs/heads/master
i:
  182283: 2a43ffd
v: v3
  • Loading branch information
Lai Jiangshan authored and Steven Rostedt committed Jan 6, 2010
1 parent 1b4262d commit e2bbe3d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 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: 509e760cd91c831983097ae174cb6c0b8c6c8e6b
refs/heads/master: 50307a45f8515f6244e3b08e6b19824b9fbfe293
68 changes: 67 additions & 1 deletion trunk/kernel/trace/trace_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,67 @@ int syscall_enter_format(struct ftrace_event_call *call, struct trace_seq *s)
return trace_seq_putc(s, '\n');
}

static
int __set_enter_print_fmt(struct syscall_metadata *entry, char *buf, int len)
{
int i;
int pos = 0;

/* When len=0, we just calculate the needed length */
#define LEN_OR_ZERO (len ? len - pos : 0)

pos += snprintf(buf + pos, LEN_OR_ZERO, "\"");
for (i = 0; i < entry->nb_args; i++) {
pos += snprintf(buf + pos, LEN_OR_ZERO, "%s: 0x%%0%zulx%s",
entry->args[i], sizeof(unsigned long),
i == entry->nb_args - 1 ? "" : ", ");
}
pos += snprintf(buf + pos, LEN_OR_ZERO, "\"");

for (i = 0; i < entry->nb_args; i++) {
pos += snprintf(buf + pos, LEN_OR_ZERO,
", ((unsigned long)(REC->%s))", entry->args[i]);
}

#undef LEN_OR_ZERO

/* return the length of print_fmt */
return pos;
}

static int set_syscall_print_fmt(struct ftrace_event_call *call)
{
char *print_fmt;
int len;
struct syscall_metadata *entry = call->data;

if (entry->enter_event != call) {
call->print_fmt = "\"0x%lx\", REC->ret";
return 0;
}

/* First: called with 0 length to calculate the needed length */
len = __set_enter_print_fmt(entry, NULL, 0);

print_fmt = kmalloc(len + 1, GFP_KERNEL);
if (!print_fmt)
return -ENOMEM;

/* Second: actually write the @print_fmt */
__set_enter_print_fmt(entry, print_fmt, len + 1);
call->print_fmt = print_fmt;

return 0;
}

static void free_syscall_print_fmt(struct ftrace_event_call *call)
{
struct syscall_metadata *entry = call->data;

if (entry->enter_event == call)
kfree(call->print_fmt);
}

int syscall_exit_format(struct ftrace_event_call *call, struct trace_seq *s)
{
int ret;
Expand Down Expand Up @@ -386,9 +447,14 @@ int init_syscall_trace(struct ftrace_event_call *call)
{
int id;

if (set_syscall_print_fmt(call) < 0)
return -ENOMEM;

id = register_ftrace_event(call->event);
if (!id)
if (!id) {
free_syscall_print_fmt(call);
return -ENODEV;
}
call->id = id;
INIT_LIST_HEAD(&call->fields);
return 0;
Expand Down

0 comments on commit e2bbe3d

Please sign in to comment.