Fix erroneous use of "-n" for additional fields, add "-f"
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 27 Jan 2012 20:32:28 +0000 (15:32 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 27 Jan 2012 20:32:28 +0000 (15:32 -0500)
The -n option is for enabling "field name" printing.
Add a new "-f" option for enabling optional fields.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/ctf-text/ctf-text.c
include/babeltrace/babeltrace-internal.h

index a30e330f2766c31ea78f30b4afb29bb53785ce0c..03b9d2f2ff379c57c332a720e75fb4d59f026c1a 100644 (file)
@@ -62,6 +62,7 @@ enum {
        OPT_VERBOSE,
        OPT_DEBUG,
        OPT_NAMES,
+       OPT_FIELDS,
        OPT_NO_DELTA,
 };
 
@@ -74,6 +75,7 @@ static struct poptOption long_options[] = {
        { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL },
        { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL },
        { "names", 'n', POPT_ARG_STRING, NULL, OPT_NAMES, NULL, NULL },
+       { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
        { "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
        { NULL, 0, 0, NULL, 0, NULL, NULL },
 };
@@ -102,13 +104,13 @@ static void usage(FILE *fp)
        fprintf(fp, "  -d, --debug                    Debug mode\n");
        fprintf(fp, "                                 (or set BABELTRACE_DEBUG environment variable)\n");
        fprintf(fp, "      --no-delta                 Do not print time delta between consecutive events\n");
-       fprintf(fp, "  -n, --names name1<,name2,...>  Print field names.\n");
-       fprintf(fp, "                                 Available field names:\n");
+       fprintf(fp, "  -n, --names name1<,name2,...>  Print field names:\n");
        fprintf(fp, "                                     (payload OR args OR arg)\n");
        fprintf(fp, "                                     all, scope, header, (context OR ctx)\n");
-       fprintf(fp, "                                     trace, trace:domain, trace:procname, trace:vpid,\n");
-       fprintf(fp, "                                     loglevel.\n");
        fprintf(fp, "                                        (payload active by default)\n");
+       fprintf(fp, "  -f, --fields name1<,name2,...> Print additional fields:\n");
+       fprintf(fp, "                                     all, trace, trace:domain, trace:procname,\n");
+       fprintf(fp, "                                     trace:vpid, loglevel.\n");
        list_formats(fp);
        fprintf(fp, "\n");
 }
@@ -134,18 +136,39 @@ static int get_names_args(poptContext *pc)
                        opt_header_field_names = 1;
                else if (!strcmp(str, "payload") || !strcmp(str, "args") || !strcmp(str, "arg"))
                        opt_payload_field_names = 1;
+               else {
+                       fprintf(stderr, "[error] unknown field name type %s\n", str);
+                       return -EINVAL;
+               }
+       } while ((str = strtok_r(NULL, ",", &strctx)));
+       return 0;
+}
+
+static int get_fields_args(poptContext *pc)
+{
+       char *str, *strlist, *strctx;
+
+       opt_payload_field_names = 0;
+       strlist = (char *) poptGetOptArg(*pc);
+       if (!strlist) {
+               return -EINVAL;
+       }
+       str = strtok_r(strlist, ",", &strctx);
+       do {
+               if (!strcmp(str, "all"))
+                       opt_all_fields = 1;
                else if (!strcmp(str, "trace"))
-                       opt_trace_name = 1;
+                       opt_trace_field = 1;
                else if (!strcmp(str, "trace:domain"))
-                       opt_trace_domain = 1;
+                       opt_trace_domain_field = 1;
                else if (!strcmp(str, "trace:procname"))
-                       opt_trace_procname = 1;
+                       opt_trace_procname_field = 1;
                else if (!strcmp(str, "trace:vpid"))
-                       opt_trace_vpid = 1;
+                       opt_trace_vpid_field = 1;
                else if (!strcmp(str, "loglevel"))
-                       opt_loglevel = 1;
+                       opt_loglevel_field = 1;
                else {
-                       fprintf(stderr, "[error] unknown field name type %s\n", str);
+                       fprintf(stderr, "[error] unknown field type %s\n", str);
                        return -EINVAL;
                }
        } while ((str = strtok_r(NULL, ",", &strctx)));
@@ -191,11 +214,17 @@ static int parse_options(int argc, char **argv)
                                goto end;
                        }
                        break;
+               case OPT_FIELDS:
+                       if (get_fields_args(&pc)) {
+                               ret = -EINVAL;
+                               goto end;
+                       }
+                       break;
                case OPT_DEBUG:
                        babeltrace_debug = 1;
                        break;
                case OPT_NO_DELTA:
-                       opt_delta = 0;
+                       opt_delta_field = 0;
                        break;
                default:
                        ret = -EINVAL;
index cac080e951da48da8efa6cfa5b4cdca1cec84f04..a837f914b436a01f1fce65fab994e4f55e98cc2e 100644 (file)
@@ -41,12 +41,13 @@ int opt_all_field_names,
        opt_header_field_names,
        opt_context_field_names,
        opt_payload_field_names,
-       opt_trace_name,
-       opt_trace_domain,
-       opt_trace_procname,
-       opt_trace_vpid,
-       opt_loglevel,
-       opt_delta = 1;
+       opt_all_fields,
+       opt_trace_field,
+       opt_trace_domain_field,
+       opt_trace_procname_field,
+       opt_trace_vpid_field,
+       opt_loglevel_field,
+       opt_delta_field = 1;
 
 enum field_item {
        ITEM_SCOPE,
@@ -201,7 +202,7 @@ int ctf_text_write_event(struct stream_pos *ppos,
                else
                        fprintf(pos->fp, " ");
        }
-       if (opt_delta && stream->has_timestamp) {
+       if ((opt_delta_field || opt_all_fields) && stream->has_timestamp) {
                uint64_t delta, delta_sec, delta_nsec;
 
                set_field_names_print(pos, ITEM_HEADER);
@@ -228,66 +229,58 @@ int ctf_text_write_event(struct stream_pos *ppos,
                pos->last_timestamp = stream->timestamp;
        }
 
-       if ((opt_trace_name || opt_all_field_names) && stream_class->trace->path[0] != '\0') {
+       if ((opt_trace_field || opt_all_fields) && stream_class->trace->path[0] != '\0') {
                set_field_names_print(pos, ITEM_HEADER);
                if (pos->print_names) {
-                       if (opt_trace_name || opt_all_field_names)
-                               fprintf(pos->fp, "trace = ");
+                       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') {
+       if ((opt_trace_domain_field && !opt_all_fields) && 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);
+               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') {
+       if ((opt_trace_procname_field && !opt_all_fields) && 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);
+               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') {
+       if ((opt_trace_vpid_field && !opt_all_fields) && 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);
+               fprintf(pos->fp, "%s", stream_class->trace->vpid);
                if (pos->print_names)
                        fprintf(pos->fp, ", ");
                dom_print = 1;
        }
-       if ((opt_loglevel || opt_all_field_names) && event_class->loglevel_identifier != 0) {
+       if ((opt_loglevel_field || opt_all_fields) && event_class->loglevel_identifier != 0) {
                set_field_names_print(pos, ITEM_HEADER);
                if (pos->print_names) {
                        fprintf(pos->fp, "loglevel = ");
                } else if (dom_print) {
                        fprintf(pos->fp, ":");
                }
-
                fprintf(pos->fp, "%s (%lld)",
                        g_quark_to_string(event_class->loglevel_identifier),
                        (long long) event_class->loglevel_value);
index 39dc097e73f3e824bd4c6ad59cc5e0ea3d84e324..ebeb048e6f4951c45f5ce6673e40467fdbc80e58 100644 (file)
@@ -31,11 +31,12 @@ extern int opt_all_field_names,
        opt_header_field_names,
        opt_context_field_names,
        opt_payload_field_names,
-       opt_trace_name,
-       opt_trace_domain,
-       opt_trace_procname,
-       opt_trace_vpid,
-       opt_loglevel,
-       opt_delta;
+       opt_all_fields,
+       opt_trace_field,
+       opt_trace_domain_field,
+       opt_trace_procname_field,
+       opt_trace_vpid_field,
+       opt_loglevel_field,
+       opt_delta_field;
 
 #endif
This page took 0.040453 seconds and 4 git commands to generate.