aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-07-03 03:09:02 -0400
committerSteven Rostedt <rostedt@goodmis.org>2014-01-02 16:17:38 -0500
commit5bf652aaf46ca6ae477ea0d162e68d577cf244aa (patch)
treeab1210b0008678995f0d6bf5b8da1bf0dccd0c14 /kernel
parent2dc1018372c3b1db1410c7087de7866d4cad8cc3 (diff)
tracing/probes: Integrate duplicate set_print_fmt()
The set_print_fmt() functions are implemented almost same for [ku]probes. Move it to a common place and get rid of the duplication. Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Acked-by: Oleg Nesterov <oleg@redhat.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: zhangwei(Jovi) <jovi.zhangwei@huawei.com> Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/trace_kprobe.c63
-rw-r--r--kernel/trace/trace_probe.c62
-rw-r--r--kernel/trace/trace_probe.h2
-rw-r--r--kernel/trace/trace_uprobe.c55
4 files changed, 66 insertions, 116 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index fb1a02735d6a..c9ffdafb9ada 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -964,67 +964,6 @@ static int kretprobe_event_define_fields(struct ftrace_event_call *event_call)
964 return 0; 964 return 0;
965} 965}
966 966
967static int __set_print_fmt(struct trace_kprobe *tk, char *buf, int len)
968{
969 int i;
970 int pos = 0;
971
972 const char *fmt, *arg;
973
974 if (!trace_kprobe_is_return(tk)) {
975 fmt = "(%lx)";
976 arg = "REC->" FIELD_STRING_IP;
977 } else {
978 fmt = "(%lx <- %lx)";
979 arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
980 }
981
982 /* When len=0, we just calculate the needed length */
983#define LEN_OR_ZERO (len ? len - pos : 0)
984
985 pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
986
987 for (i = 0; i < tk->tp.nr_args; i++) {
988 pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
989 tk->tp.args[i].name, tk->tp.args[i].type->fmt);
990 }
991
992 pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
993
994 for (i = 0; i < tk->tp.nr_args; i++) {
995 if (strcmp(tk->tp.args[i].type->name, "string") == 0)
996 pos += snprintf(buf + pos, LEN_OR_ZERO,
997 ", __get_str(%s)",
998 tk->tp.args[i].name);
999 else
1000 pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
1001 tk->tp.args[i].name);
1002 }
1003
1004#undef LEN_OR_ZERO
1005
1006 /* return the length of print_fmt */
1007 return pos;
1008}
1009
1010static int set_print_fmt(struct trace_kprobe *tk)
1011{
1012 int len;
1013 char *print_fmt;
1014
1015 /* First: called with 0 length to calculate the needed length */
1016 len = __set_print_fmt(tk, NULL, 0);
1017 print_fmt = kmalloc(len + 1, GFP_KERNEL);
1018 if (!print_fmt)
1019 return -ENOMEM;
1020
1021 /* Second: actually write the @print_fmt */
1022 __set_print_fmt(tk, print_fmt, len + 1);
1023 tk->tp.call.print_fmt = print_fmt;
1024
1025 return 0;
1026}
1027
1028#ifdef CONFIG_PERF_EVENTS 967#ifdef CONFIG_PERF_EVENTS
1029 968
1030/* Kprobe profile handler */ 969/* Kprobe profile handler */
@@ -1175,7 +1114,7 @@ static int register_kprobe_event(struct trace_kprobe *tk)
1175 call->event.funcs = &kprobe_funcs; 1114 call->event.funcs = &kprobe_funcs;
1176 call->class->define_fields = kprobe_event_define_fields; 1115 call->class->define_fields = kprobe_event_define_fields;
1177 } 1116 }
1178 if (set_print_fmt(tk) < 0) 1117 if (set_print_fmt(&tk->tp, trace_kprobe_is_return(tk)) < 0)
1179 return -ENOMEM; 1118 return -ENOMEM;
1180 ret = register_ftrace_event(&call->event); 1119 ret = register_ftrace_event(&call->event);
1181 if (!ret) { 1120 if (!ret) {
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 430505b08a6f..d8347b01ce89 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -837,3 +837,65 @@ out:
837 837
838 return ret; 838 return ret;
839} 839}
840
841static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
842 bool is_return)
843{
844 int i;
845 int pos = 0;
846
847 const char *fmt, *arg;
848
849 if (!is_return) {
850 fmt = "(%lx)";
851 arg = "REC->" FIELD_STRING_IP;
852 } else {
853 fmt = "(%lx <- %lx)";
854 arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
855 }
856
857 /* When len=0, we just calculate the needed length */
858#define LEN_OR_ZERO (len ? len - pos : 0)
859
860 pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
861
862 for (i = 0; i < tp->nr_args; i++) {
863 pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
864 tp->args[i].name, tp->args[i].type->fmt);
865 }
866
867 pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
868
869 for (i = 0; i < tp->nr_args; i++) {
870 if (strcmp(tp->args[i].type->name, "string") == 0)
871 pos += snprintf(buf + pos, LEN_OR_ZERO,
872 ", __get_str(%s)",
873 tp->args[i].name);
874 else
875 pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
876 tp->args[i].name);
877 }
878
879#undef LEN_OR_ZERO
880
881 /* return the length of print_fmt */
882 return pos;
883}
884
885int set_print_fmt(struct trace_probe *tp, bool is_return)
886{
887 int len;
888 char *print_fmt;
889
890 /* First: called with 0 length to calculate the needed length */
891 len = __set_print_fmt(tp, NULL, 0, is_return);
892 print_fmt = kmalloc(len + 1, GFP_KERNEL);
893 if (!print_fmt)
894 return -ENOMEM;
895
896 /* Second: actually write the @print_fmt */
897 __set_print_fmt(tp, print_fmt, len + 1, is_return);
898 tp->call.print_fmt = print_fmt;
899
900 return 0;
901}
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index d384fbd4025c..2c979cb66367 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -226,3 +226,5 @@ store_trace_args(int ent_size, struct trace_probe *tp, struct pt_regs *regs,
226 data + tp->args[i].offset); 226 data + tp->args[i].offset);
227 } 227 }
228} 228}
229
230extern int set_print_fmt(struct trace_probe *tp, bool is_return);
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index afda3726f288..b233d9cb1216 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -682,59 +682,6 @@ static int uprobe_event_define_fields(struct ftrace_event_call *event_call)
682 return 0; 682 return 0;
683} 683}
684 684
685#define LEN_OR_ZERO (len ? len - pos : 0)
686static int __set_print_fmt(struct trace_uprobe *tu, char *buf, int len)
687{
688 const char *fmt, *arg;
689 int i;
690 int pos = 0;
691
692 if (is_ret_probe(tu)) {
693 fmt = "(%lx <- %lx)";
694 arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
695 } else {
696 fmt = "(%lx)";
697 arg = "REC->" FIELD_STRING_IP;
698 }
699
700 /* When len=0, we just calculate the needed length */
701
702 pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
703
704 for (i = 0; i < tu->tp.nr_args; i++) {
705 pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
706 tu->tp.args[i].name, tu->tp.args[i].type->fmt);
707 }
708
709 pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
710
711 for (i = 0; i < tu->tp.nr_args; i++) {
712 pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
713 tu->tp.args[i].name);
714 }
715
716 return pos; /* return the length of print_fmt */
717}
718#undef LEN_OR_ZERO
719
720static int set_print_fmt(struct trace_uprobe *tu)
721{
722 char *print_fmt;
723 int len;
724
725 /* First: called with 0 length to calculate the needed length */
726 len = __set_print_fmt(tu, NULL, 0);
727 print_fmt = kmalloc(len + 1, GFP_KERNEL);
728 if (!print_fmt)
729 return -ENOMEM;
730
731 /* Second: actually write the @print_fmt */
732 __set_print_fmt(tu, print_fmt, len + 1);
733 tu->tp.call.print_fmt = print_fmt;
734
735 return 0;
736}
737
738#ifdef CONFIG_PERF_EVENTS 685#ifdef CONFIG_PERF_EVENTS
739static bool 686static bool
740__uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm) 687__uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
@@ -966,7 +913,7 @@ static int register_uprobe_event(struct trace_uprobe *tu)
966 call->event.funcs = &uprobe_funcs; 913 call->event.funcs = &uprobe_funcs;
967 call->class->define_fields = uprobe_event_define_fields; 914 call->class->define_fields = uprobe_event_define_fields;
968 915
969 if (set_print_fmt(tu) < 0) 916 if (set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0)
970 return -ENOMEM; 917 return -ENOMEM;
971 918
972 ret = register_ftrace_event(&call->event); 919 ret = register_ftrace_event(&call->event);