Add trace:domain,trace:procname,trace:pid support
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 22 Nov 2011 16:58:14 +0000 (17:58 +0100)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 22 Nov 2011 16:58:14 +0000 (17:58 +0100)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/bt-dummy/bt-dummy.c
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/babeltrace-internal.h
include/babeltrace/ctf-ir/metadata.h
include/babeltrace/format.h

index bac8a85f700a2f7b14dc5fbe4265d24e47aeadca..2c1c44404eea61ad8c1b7e0427708b26a0630e6a 100644 (file)
@@ -99,7 +99,7 @@ static void usage(FILE *fp)
        fprintf(fp, "                                 Available field names:\n");
        fprintf(fp, "                                     (payload OR args OR arg)\n");
        fprintf(fp, "                                     all, scope, header, (context OR ctx)\n");
-       fprintf(fp, "                                     trace\n");
+       fprintf(fp, "                                     trace, trace:domain, trace:procname, trace:vpid\n");
        fprintf(fp, "                                        (payload active by default)\n");
        list_formats(fp);
        fprintf(fp, "\n");
@@ -128,6 +128,12 @@ static int get_names_args(poptContext *pc)
                        opt_payload_field_names = 1;
                else if (!strcmp(str, "trace"))
                        opt_trace_name = 1;
+               else if (!strcmp(str, "trace:domain"))
+                       opt_trace_domain = 1;
+               else if (!strcmp(str, "trace:procname"))
+                       opt_trace_procname = 1;
+               else if (!strcmp(str, "trace:vpid"))
+                       opt_trace_vpid = 1;
                else {
                        fprintf(stdout, "[error] unknown field name type %s\n", str);
                        return -EINVAL;
@@ -254,7 +260,8 @@ static int traverse_dir(const char *fpath, const struct stat *sb,
        } else {
                close(fd);
                close(dirfd);
-               td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow,
+               td_read = fmt_read->open_trace(opt_input_path,
+                               fpath, O_RDONLY, ctf_move_pos_slow,
                                NULL);
                if (!td_read) {
                        fprintf(stdout, "Error opening trace \"%s\" "
@@ -333,7 +340,7 @@ int main(int argc, char **argv)
                return 0;
        }
 
-       td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL, NULL);
+       td_write = fmt_write->open_trace(NULL, opt_output_path, O_RDWR, NULL, NULL);
        if (!td_write) {
                fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n",
                        opt_output_path ? : "<none>");
index d7f75fb1a9c2f8d83fbb2866d3f21b640ab0002e..821ee17df51ee6663044f9b52a5b73faa5fc7726 100644 (file)
@@ -39,7 +39,8 @@ int bt_dummy_write_event(struct stream_pos *ppos,
 }
 
 static
-struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
+struct trace_descriptor *bt_dummy_open_trace(const char *collection_path,
+               const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                        int whence), FILE *metadata_fp)
 {
index 9ad23012d9512cc2fe4c79e8cc999a8a1850ada1..9b5f98be1a23bd6d90104f836e9ea20977dbb291 100644 (file)
@@ -39,7 +39,10 @@ int opt_all_field_names,
        opt_header_field_names,
        opt_context_field_names,
        opt_payload_field_names,
-       opt_trace_name;
+       opt_trace_name,
+       opt_trace_domain,
+       opt_trace_procname,
+       opt_trace_vpid;
 
 enum field_item {
        ITEM_SCOPE,
@@ -48,7 +51,8 @@ enum field_item {
        ITEM_PAYLOAD,
 };
 
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+struct trace_descriptor *ctf_text_open_trace(const char *collection_path,
+               const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                        int whence), FILE *metadata_fp);
 void ctf_text_close_trace(struct trace_descriptor *descriptor);
@@ -154,6 +158,7 @@ int ctf_text_write_event(struct stream_pos *ppos,
        struct ctf_stream_event *event;
        uint64_t id;
        int ret;
+       int dom_print = 0;
 
        id = stream->event_id;
 
@@ -189,16 +194,58 @@ int ctf_text_write_event(struct stream_pos *ppos,
        }
        if ((opt_trace_name || opt_all_field_names) && stream_class->trace->path[0] != '\0') {
                set_field_names_print(pos, ITEM_HEADER);
-               if (pos->print_names)
-                       fprintf(pos->fp, "trace = ");
+               if (pos->print_names) {
+                       if (opt_trace_name || opt_all_field_names)
+                               fprintf(pos->fp, "trace = ");
+               }
 
                fprintf(pos->fp, "%s", stream_class->trace->path);
-
                if (pos->print_names)
                        fprintf(pos->fp, ", ");
                else
                        fprintf(pos->fp, " ");
        }
+       if ((opt_trace_domain) && stream_class->trace->domain[0] != '\0') {
+               set_field_names_print(pos, ITEM_HEADER);
+               if (pos->print_names) {
+                       fprintf(pos->fp, "trace:domain = ");
+               }
+               if (opt_trace_domain)
+                       fprintf(pos->fp, "%s", stream_class->trace->domain);
+               if (pos->print_names)
+                       fprintf(pos->fp, ", ");
+               dom_print = 1;
+       }
+       if ((opt_trace_procname) && stream_class->trace->procname[0] != '\0') {
+               set_field_names_print(pos, ITEM_HEADER);
+               if (pos->print_names) {
+                       fprintf(pos->fp, "trace:procname = ");
+               } else if (dom_print) {
+                       fprintf(pos->fp, ":");
+               }
+
+               if (opt_trace_procname)
+                       fprintf(pos->fp, "%s", stream_class->trace->procname);
+               if (pos->print_names)
+                       fprintf(pos->fp, ", ");
+               dom_print = 1;
+       }
+       if ((opt_trace_vpid) && stream_class->trace->vpid[0] != '\0') {
+               set_field_names_print(pos, ITEM_HEADER);
+               if (pos->print_names) {
+                       fprintf(pos->fp, "trace:vpid = ");
+               } else if (dom_print) {
+                       fprintf(pos->fp, ":");
+               }
+
+               if (opt_trace_vpid)
+                       fprintf(pos->fp, "%s", stream_class->trace->vpid);
+               if (pos->print_names)
+                       fprintf(pos->fp, ", ");
+               dom_print = 1;
+       }
+       if (dom_print && !pos->print_names)
+               fprintf(pos->fp, " ");
        set_field_names_print(pos, ITEM_HEADER);
        if (pos->print_names)
                fprintf(pos->fp, "name = ");
@@ -299,7 +346,8 @@ error:
 }
 
 
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+struct trace_descriptor *ctf_text_open_trace(const char *collection_path,
+               const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                        int whence), FILE *metadata_fp)
 {
index 8b9441fdd701ea078bd2839b1009af05e5e1b117..33287524f51d7b7aeb0b533f012cd60423b1469d 100644 (file)
@@ -55,7 +55,7 @@
 extern int yydebug;
 
 static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags,
+struct trace_descriptor *ctf_open_trace(const char *collection_path, const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                        int whence), FILE *metadata_fp);
 static
@@ -1140,8 +1140,93 @@ error:
        return ret;
 }
 
+static void
+init_domain_name(struct ctf_trace *td)
+{
+       char *start, *end;
+
+       start = td->path + strlen(td->collection_path);
+       start++;        /* skip / */
+       end = strchr(start, '/');
+       if (!end)
+               return;
+       memcpy(td->domain, start, end - start);
+       td->domain[end - start] = '\0';
+}
+
+static void
+init_proc_name(struct ctf_trace *td)
+{
+       char buf[PATH_MAX];
+       char *start, *end;
+
+       if (td->domain[0] == '\0')
+               return;
+       memcpy(buf, td->path, PATH_MAX);
+       start = buf + strlen(td->collection_path);
+       start++;        /* skip / */
+       start = strchr(start, '/');     /* get begin of domain content */
+       if (!start)
+               return;
+       start++;        /* skip / */
+       /* find last -, skips time */
+       end = strrchr(start, '-');
+       if (!end)
+               return;
+       *end = '\0';
+       /* find previous -, skips date */
+       end = strrchr(start, '-');
+       if (!end)
+               return;
+       *end = '\0';
+       /* find previous -, skips pid */
+       end = strrchr(start, '-');
+       if (!end)
+               return;
+       *end = '\0';
+
+       memcpy(td->procname, start, end - start);
+       td->procname[end - start] = '\0';
+}
+
+static void
+init_vpid(struct ctf_trace *td)
+{
+       char buf[PATH_MAX];
+       char *start, *end;
+
+       if (td->domain[0] == '\0')
+               return;
+       memcpy(buf, td->path, PATH_MAX);
+       start = buf + strlen(td->collection_path);
+       start++;        /* skip / */
+       start = strchr(start, '/');     /* get begin of domain content */
+       if (!start)
+               return;
+       start++;        /* skip / */
+       /* find last -, skips time */
+       end = strrchr(start, '-');
+       if (!end)
+               return;
+       *end = '\0';
+       /* find previous -, skips date */
+       end = strrchr(start, '-');
+       if (!end)
+               return;
+       *end = '\0';
+       /* find previous -, skips pid */
+       start = strrchr(start, '-');
+       if (!start)
+               return;
+       start++;        /* skip - */
+
+       memcpy(td->vpid, start, end - start);
+       td->vpid[end - start] = '\0';
+}
+
 static
-int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
+int ctf_open_trace_read(struct ctf_trace *td, const char *collection_path,
+               const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                        int whence), FILE *metadata_fp)
 {
@@ -1167,8 +1252,13 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
                ret = -errno;
                goto error_dirfd;
        }
+       strncpy(td->collection_path, collection_path, PATH_MAX);
+       td->collection_path[PATH_MAX - 1] = '\0';
        strncpy(td->path, path, PATH_MAX);
        td->path[PATH_MAX - 1] = '\0';
+       init_domain_name(td);
+       init_proc_name(td);
+       init_vpid(td);
 
        /*
         * Keep the metadata file separate.
@@ -1224,7 +1314,7 @@ error:
 }
 
 static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags,
+struct trace_descriptor *ctf_open_trace(const char *collection_path, const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                        int whence), FILE *metadata_fp)
 {
@@ -1239,7 +1329,7 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags,
                        fprintf(stdout, "[error] Path missing for input CTF trace.\n");
                        goto error;
                }
-               ret = ctf_open_trace_read(td, path, flags, move_pos_slow, metadata_fp);
+               ret = ctf_open_trace_read(td, collection_path, path, flags, move_pos_slow, metadata_fp);
                if (ret)
                        goto error;
                break;
index a329cc939192012bdb5c0979aa51fb6fe6fed9ca..58af9c90e3605485d924610ab0a4001aff2e52e5 100644 (file)
@@ -34,6 +34,9 @@ extern int opt_all_field_names,
        opt_header_field_names,
        opt_context_field_names,
        opt_payload_field_names,
-       opt_trace_name;
+       opt_trace_name,
+       opt_trace_domain,
+       opt_trace_procname,
+       opt_trace_vpid;
 
 #endif
index b9157567ff4bbfca880e5ba2ce8dcdd6169ef1d8..3f03504ea1850bda7fc67e305270b8180703b91e 100644 (file)
@@ -102,7 +102,11 @@ struct ctf_trace {
 
        /* Heap of streams, ordered to always get the lowest timestam */
        struct ptr_heap *stream_heap;
+       char collection_path[PATH_MAX];
        char path[PATH_MAX];
+       char domain[PATH_MAX];
+       char procname[PATH_MAX];
+       char vpid[PATH_MAX];
 };
 
 #define CTF_STREAM_SET_FIELD(ctf_stream, field)                                \
index 5cf795a76418f5f281b826a5f33b455e001dec93..46120fafe66de55e8e8e344038f42429c2f4c196 100644 (file)
@@ -43,7 +43,8 @@ struct mmap_stream_list {
 struct format {
        GQuark name;
 
-       struct trace_descriptor *(*open_trace)(const char *path, int flags,
+       struct trace_descriptor *(*open_trace)(const char *collection_path,
+                       const char *path, int flags,
                        void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
                                int whence), FILE *metadata_fp);
        struct trace_descriptor *(*open_mmap_trace)(
This page took 0.042789 seconds and 4 git commands to generate.