Optimization: lttng UI uses sprintf instead of strcpy
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 4 Mar 2016 16:31:00 +0000 (11:31 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 4 Mar 2016 17:02:03 +0000 (12:02 -0500)
The LTTng client currently uses sprintf with format strings
that don't contain a format specifier.

Users have reported concerns for the scalability and performance
of the LTTng UI because of this overkill use of sprintf instead
of strcpy which, presumably, could be inlined by the compiler.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/list.c

index efa1abfd0751e4c9f7858114cbf7009a94ae0a2d..bcada31cd38625b47322d665c9ebbf7ff27a2b8f 100644 (file)
@@ -214,6 +214,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event)
        int count;
        size_t i;
        const char * const exclusion_fmt = " [exclusions: ";
+       const size_t exclusion_fmt_len = strlen(exclusion_fmt);
 
        exclusion_count = lttng_event_get_exclusion_name_count(event);
        if (exclusion_count < 0) {
@@ -234,15 +235,12 @@ static char *get_exclusion_names_msg(struct lttng_event *event)
         */
        exclusion_msg = malloc(exclusion_count +
                        exclusion_count * LTTNG_SYMBOL_NAME_LEN +
-                       strlen(exclusion_fmt) + 1);
+                       exclusion_fmt_len + 1);
        if (!exclusion_msg) {
                goto end;
        }
 
-       at = exclusion_msg;
-       count = sprintf(at, exclusion_fmt);
-       at += count;
-
+       at = strcpy(exclusion_msg, exclusion_fmt) + exclusion_fmt_len;
        for (i = 0; i < exclusion_count; ++i) {
                const char *name;
 
@@ -266,7 +264,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event)
        }
 
        /* This also puts a final '\0' at the end of exclusion_msg */
-       sprintf(at, "]");
+       strcpy(at, "]");
 
 end:
        return exclusion_msg;
This page took 0.028583 seconds and 5 git commands to generate.