Skip to contentSkip to conversation

trace_kprobe: init print_fmt

PATCH In review Lai Jiangshan 2 participants 2 messages Dec 9, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 8/10 trace_kprobe: init print_fmt

Init print_fmt for trace_kprobe.
It will be used for replacing ->show_format().

---

kernel/trace/trace_kprobe.c +56 -1
index 3ef66d4..a12d39b 100644
@@ -1212,6 +1212,55 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
 					 ", REC->" FIELD_STRING_RETIP);
 }
 
+static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
+{
+	int i;
+	int pos = 0;
+
+	const char *fmt, *arg;
+
+	if (!probe_is_return(tp)) {
+		fmt = "(%lx)";
+		arg = "REC->" FIELD_STRING_IP;
+	} else {
+		fmt = "(%lx <- %lx)";
+		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
+	}
+
+	pos += snprintf(buf + pos, len > pos ? len - pos : 0, "\"%s", fmt);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, len > pos ? len - pos : 0,
+				" %s=%%lx", tp->args[i].name);
+	}
+
+	pos += snprintf(buf + pos, len > pos ? len - pos : 0, "\", %s", arg);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, len > pos ? len - pos : 0,
+				", REC->%s", tp->args[i].name);
+	}
+
+	/* return the length of print_fmt */
+	return pos;
+}
+
+static int set_print_fmt(struct trace_probe *tp)
+{
+	int len;
+	char *print_fmt;
+
+	len = __set_print_fmt(tp, NULL, 0);
+	print_fmt = kmalloc(len + 1, GFP_KERNEL);
+	if (!print_fmt)
+		return -ENOMEM;
+
+	__set_print_fmt(tp, print_fmt, len + 1);
+	tp->call.print_fmt = print_fmt;
+
+	return 0;
+}
+
 #ifdef CONFIG_EVENT_PROFILE
 
 /* Kprobe profile handler */
@@ -1418,10 +1467,14 @@ static int register_probe_event(struct trace_probe *tp)
 		call->show_format = kprobe_event_show_format;
 		call->define_fields = kprobe_event_define_fields;
 	}
+	if (set_print_fmt(tp) < 0)
+		return -ENOMEM;
 	call->event = &tp->event;
 	call->id = register_ftrace_event(&tp->event);
-	if (!call->id)
+	if (!call->id) {
+		kfree(call->print_fmt);
 		return -ENODEV;
+	}
 	call->enabled = 0;
 	call->regfunc = probe_event_enable;
 	call->unregfunc = probe_event_disable;
@@ -1435,6 +1488,7 @@ static int register_probe_event(struct trace_probe *tp)
 	ret = trace_add_event_call(call);
 	if (ret) {
 		pr_info("Failed to register kprobe event: %s\n", call->name);
+		kfree(call->print_fmt);
 		unregister_ftrace_event(&tp->event);
 	}
 	return ret;
@@ -1444,6 +1498,7 @@ static void unregister_probe_event(struct trace_probe *tp)
 {
 	/* tp->event is unregistered in trace_remove_event_call() */
 	trace_remove_event_call(&tp->call);
+	kfree(tp->call.print_fmt);
 }
 
 /* Make a debugfs interface for controling probe points */
Acked-by on v1 8/10
#1 lore raw
Quoted 4 lines · Lai Jiangshan

Init print_fmt for trace_kprobe.
It will be used for replacing ->show_format().

Looks good to me.

Quoted 99 lines

---

kernel/trace/trace_kprobe.c +56 -2
index 3ef66d4..a12d39b 100644
@@ -1212,6 +1212,55 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
  					 ", REC->" FIELD_STRING_RETIP);
  }
 
+static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
+{
+	int i;
+	int pos = 0;
+
+	const char *fmt, *arg;
+
+	if (!probe_is_return(tp)) {
+		fmt = "(%lx)";
+		arg = "REC->" FIELD_STRING_IP;
+	} else {
+		fmt = "(%lx<- %lx)";
+		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
+	}
+
+	pos += snprintf(buf + pos, len>  pos ? len - pos : 0, "\"%s", fmt);
+
+	for (i = 0; i<  tp->nr_args; i++) {
+		pos += snprintf(buf + pos, len>  pos ? len - pos : 0,
+				" %s=%%lx", tp->args[i].name);
+	}
+
+	pos += snprintf(buf + pos, len>  pos ? len - pos : 0, "\", %s", arg);
+
+	for (i = 0; i<  tp->nr_args; i++) {
+		pos += snprintf(buf + pos, len>  pos ? len - pos : 0,
+				", REC->%s", tp->args[i].name);
+	}
+
+	/* return the length of print_fmt */
+	return pos;
+}
+
+static int set_print_fmt(struct trace_probe *tp)
+{
+	int len;
+	char *print_fmt;
+
+	len = __set_print_fmt(tp, NULL, 0);
+	print_fmt = kmalloc(len + 1, GFP_KERNEL);
+	if (!print_fmt)
+		return -ENOMEM;
+
+	__set_print_fmt(tp, print_fmt, len + 1);
+	tp->call.print_fmt = print_fmt;
+
+	return 0;
+}
+
  #ifdef CONFIG_EVENT_PROFILE
 
  /* Kprobe profile handler */
@@ -1418,10 +1467,14 @@ static int register_probe_event(struct trace_probe *tp)
  		call->show_format = kprobe_event_show_format;
  		call->define_fields = kprobe_event_define_fields;
  	}
+	if (set_print_fmt(tp)<  0)
+		return -ENOMEM;
  	call->event =&tp->event;
  	call->id = register_ftrace_event(&tp->event);
-	if (!call->id)
+	if (!call->id) {
+		kfree(call->print_fmt);
  		return -ENODEV;
+	}
  	call->enabled = 0;
  	call->regfunc = probe_event_enable;
  	call->unregfunc = probe_event_disable;
@@ -1435,6 +1488,7 @@ static int register_probe_event(struct trace_probe *tp)
  	ret = trace_add_event_call(call);
  	if (ret) {
  		pr_info("Failed to register kprobe event: %s\n", call->name);
+		kfree(call->print_fmt);
  		unregister_ftrace_event(&tp->event);
  	}
  	return ret;
@@ -1444,6 +1498,7 @@ static void unregister_probe_event(struct trace_probe *tp)
  {
  	/* tp->event is unregistered in trace_remove_event_call() */
  	trace_remove_event_call(&tp->call);
+	kfree(tp->call.print_fmt);
  }
 
  /* Make a debugfs interface for controling probe points */
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 7 lines
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]