From: "Steven Rostedt (Red Hat)" <rost...@goodmis.org>

Instead of cropping off the '"' and '\n"' from a printk format every
time it is referenced, do it when it's added. This makes it easier to
reference a printk_map and should speed things up a little.

Signed-off-by: Steven Rostedt <rost...@goodmis.org>
Cc: Andrew Morton <a...@linux-foundation.org>
Cc: Frederic Weisbecker <fweis...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namhy...@kernel.org>
Link: http://lkml.kernel.org/r/20131101215500.495619...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <a...@redhat.com>
---
 tools/lib/traceevent/event-parse.c | 29 ++++++++++++++---------------
 tools/lib/traceevent/event-parse.h |  2 +-
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c 
b/tools/lib/traceevent/event-parse.c
index deedff9d06af..856b79105abc 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -604,10 +604,11 @@ find_printk(struct pevent *pevent, unsigned long long 
addr)
  * This registers a string by the address it was stored in the kernel.
  * The @fmt passed in is duplicated.
  */
-int pevent_register_print_string(struct pevent *pevent, char *fmt,
+int pevent_register_print_string(struct pevent *pevent, const char *fmt,
                                 unsigned long long addr)
 {
        struct printk_list *item = malloc(sizeof(*item));
+       char *p;
 
        if (!item)
                return -1;
@@ -615,10 +616,21 @@ int pevent_register_print_string(struct pevent *pevent, 
char *fmt,
        item->next = pevent->printklist;
        item->addr = addr;
 
+       /* Strip off quotes and '\n' from the end */
+       if (fmt[0] == '"')
+               fmt++;
        item->printk = strdup(fmt);
        if (!item->printk)
                goto out_free;
 
+       p = item->printk + strlen(item->printk) - 1;
+       if (*p == '"')
+               *p = 0;
+
+       p -= 2;
+       if (strcmp(p, "\\n") == 0)
+               *p = 0;
+
        pevent->printklist = item;
        pevent->printk_count++;
 
@@ -3887,7 +3899,6 @@ get_bprint_format(void *data, int size __maybe_unused,
        struct format_field *field;
        struct printk_map *printk;
        char *format;
-       char *p;
 
        field = pevent->bprint_fmt_field;
 
@@ -3909,20 +3920,8 @@ get_bprint_format(void *data, int size __maybe_unused,
                return format;
        }
 
-       p = printk->printk;
-       /* Remove any quotes. */
-       if (*p == '"')
-               p++;
-       if (asprintf(&format, "%s : %s", "%pf", p) < 0)
+       if (asprintf(&format, "%s : %s", "%pf", printk->printk) < 0)
                return NULL;
-       /* remove ending quotes and new line since we will add one too */
-       p = format + strlen(format) - 1;
-       if (*p == '"')
-               *p = 0;
-
-       p -= 2;
-       if (strcmp(p, "\\n") == 0)
-               *p = 0;
 
        return format;
 }
diff --git a/tools/lib/traceevent/event-parse.h 
b/tools/lib/traceevent/event-parse.h
index 7503edf5ac6a..9ab6367f2fe9 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -533,7 +533,7 @@ int pevent_register_comm(struct pevent *pevent, const char 
*comm, int pid);
 void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
 int pevent_register_function(struct pevent *pevent, char *name,
                             unsigned long long addr, char *mod);
-int pevent_register_print_string(struct pevent *pevent, char *fmt,
+int pevent_register_print_string(struct pevent *pevent, const char *fmt,
                                 unsigned long long addr);
 int pevent_pid_is_registered(struct pevent *pevent, int pid);
 
-- 
1.8.1.4

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

Reply via email to