X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fcommon%2Feal_common_trace_ctf.c;h=33e419aac7fb5d691325ea5f68ed6fb33115ed1f;hb=e863fe3a13da89787fdf3b5c590101a3c0f10af6;hp=9dc91df0fb078555e23f4657b9ff8d4e9facb9b7;hpb=2114521cff9151381e235e43205e3133c593bc84;p=dpdk.git diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c index 9dc91df0fb..33e419aac7 100644 --- a/lib/librte_eal/common/eal_common_trace_ctf.c +++ b/lib/librte_eal/common/eal_common_trace_ctf.c @@ -37,11 +37,12 @@ meta_copy(char **meta, int *offset, char *str, int rc) if (rc < 0) return rc; - ptr = realloc(ptr, count + rc); + ptr = realloc(ptr, count + rc + 1); if (ptr == NULL) goto free_str; memcpy(RTE_PTR_ADD(ptr, count), str, rc); + ptr[count + rc] = '\0'; count += rc; free(str); @@ -220,139 +221,21 @@ meta_stream_emit(char **meta, int *offset) return meta_copy(meta, offset, str, rc); } -static void -string_fixed_replace(char *input, const char *search, const char *replace) -{ - char *found; - size_t len; - - found = strstr(input, search); - if (found == NULL) - return; - - if (strlen(found) != strlen(search)) - return; - - len = strlen(replace); - memcpy(found, replace, len); - found[len] = '\0'; -} - -static void -ctf_fixup_align(char *str) -{ - string_fixed_replace(str, "align", "_align"); -} - -static void -ctf_fixup_arrow_deref(char *str) -{ - const char *replace = "_"; - const char *search = "->"; - char *found; - size_t len; - - found = strstr(str, search); - if (found == NULL) - return; - - do { - memcpy(found, replace, strlen(replace)); - len = strlen(found + 2); - memcpy(found + 1, found + 2, len); - found[len + 1] = '\0'; - found = strstr(str, search); - } while (found != NULL); -} - -static void -ctf_fixup_dot_deref(char *str) -{ - const char *replace = "_"; - const char *search = "."; - char *found; - size_t len; - - found = strstr(str, search); - if (found == NULL) - return; - - len = strlen(replace); - do { - memcpy(found, replace, len); - found = strstr(str, search); - } while (found != NULL); -} - -static void -ctf_fixup_event(char *str) -{ - string_fixed_replace(str, "event", "_event"); -} - -static int -ctf_fixup_keyword(char *str) -{ - char dup_str[TRACE_CTF_FIELD_SIZE]; - char input[TRACE_CTF_FIELD_SIZE]; - const char *delim = ";"; - char *from; - int len; - - if (str == NULL) - return 0; - - len = strlen(str); - if (len >= TRACE_CTF_FIELD_SIZE) { - trace_err("ctf_field reached its maximum limit"); - return -EMSGSIZE; - } - - /* Create duplicate string */ - strcpy(dup_str, str); - - len = 0; - from = strtok(dup_str, delim); - while (from != NULL) { - strcpy(input, from); - ctf_fixup_align(input); - ctf_fixup_dot_deref(input); - ctf_fixup_arrow_deref(input); - ctf_fixup_event(input); - - strcpy(&input[strlen(input)], delim); - if ((len + strlen(input)) >= TRACE_CTF_FIELD_SIZE) { - trace_err("ctf_field reached its maximum limit"); - return -EMSGSIZE; - } - - strcpy(str + len, input); - len += strlen(input); - from = strtok(NULL, delim); - } - - return 0; -} - static int meta_event_emit(char **meta, int *offset, struct trace_point *tp) { char *str = NULL; int rc; - /* Fixup ctf field string in case it using reserved ctf keywords */ - rc = ctf_fixup_keyword(tp->ctf_field); - if (rc) - return rc; - rc = metadata_printf(&str, "event {\n" " id = %d;\n" " name = \"%s\";\n" " fields := struct {\n" - " %s\n" + "%s" " };\n" - "};\n\n", trace_id_get(tp->handle), tp->name, tp->ctf_field); + "};\n\n", trace_id_get(tp->handle), tp->name, + tp->ctf_field != NULL ? tp->ctf_field : ""); return meta_copy(meta, offset, str, rc); } @@ -491,3 +374,43 @@ rte_trace_metadata_dump(FILE *f) rc = fprintf(f, "%s", ctf_meta); return rc < 0 ? rc : 0; } + +char *trace_metadata_fixup_field(const char *field) +{ + const char *ctf_reserved_words[] = { + "align", + "event", + }; + unsigned int i; + char *out; + char *p; + + /* reserved keywords */ + for (i = 0; i < RTE_DIM(ctf_reserved_words); i++) { + if (strcmp(field, ctf_reserved_words[i]) != 0) + continue; + if (asprintf(&out, "_%s", ctf_reserved_words[i]) == -1) + out = NULL; + return out; + } + + /* nothing to replace, return early */ + if (strstr(field, ".") == NULL && strstr(field, "->") == NULL) + return NULL; + + out = strdup(field); + if (out == NULL) + return NULL; + p = out; + while ((p = strstr(p, ".")) != NULL) { + p[0] = '_'; + p++; + } + p = out; + while ((p = strstr(p, "->")) != NULL) { + p[0] = '_'; + p++; + memmove(p, p + 1, strlen(p)); + } + return out; +}