diff options
| author | Namhyung Kim <namhyung.kim@lge.com> | 2013-07-03 03:09:02 -0400 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2014-01-02 16:17:38 -0500 |
| commit | 5bf652aaf46ca6ae477ea0d162e68d577cf244aa (patch) | |
| tree | ab1210b0008678995f0d6bf5b8da1bf0dccd0c14 /kernel/trace/trace_probe.c | |
| parent | 2dc1018372c3b1db1410c7087de7866d4cad8cc3 (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/trace/trace_probe.c')
| -rw-r--r-- | kernel/trace/trace_probe.c | 62 |
1 files changed, 62 insertions, 0 deletions
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 | |||
| 841 | static 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 | |||
| 885 | int 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 | } | ||
