From: Mathieu Desnoyers Date: Tue, 22 Nov 2011 16:58:14 +0000 (+0100) Subject: Add trace:domain,trace:procname,trace:pid support X-Git-Tag: v0.8~10 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=8c250d8758df3a8a4a5c6aafb63fe198bb21fe22 Add trace:domain,trace:procname,trace:pid support Signed-off-by: Mathieu Desnoyers --- diff --git a/converter/babeltrace.c b/converter/babeltrace.c index bac8a85f..2c1c4440 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -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 ? : ""); diff --git a/formats/bt-dummy/bt-dummy.c b/formats/bt-dummy/bt-dummy.c index d7f75fb1..821ee17d 100644 --- a/formats/bt-dummy/bt-dummy.c +++ b/formats/bt-dummy/bt-dummy.c @@ -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) { diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 9ad23012..9b5f98be 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -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) { diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 8b9441fd..33287524 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -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; diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index a329cc93..58af9c90 100644 --- a/include/babeltrace/babeltrace-internal.h +++ b/include/babeltrace/babeltrace-internal.h @@ -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 diff --git a/include/babeltrace/ctf-ir/metadata.h b/include/babeltrace/ctf-ir/metadata.h index b9157567..3f03504e 100644 --- a/include/babeltrace/ctf-ir/metadata.h +++ b/include/babeltrace/ctf-ir/metadata.h @@ -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) \ diff --git a/include/babeltrace/format.h b/include/babeltrace/format.h index 5cf795a7..46120faf 100644 --- a/include/babeltrace/format.h +++ b/include/babeltrace/format.h @@ -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)(