trace2: cleanup whitespace in perf format
authorJeff Hostetler <jeffhost@microsoft.com>
Fri, 9 Aug 2019 15:00:57 +0000 (08:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Aug 2019 17:48:02 +0000 (10:48 -0700)
Make use of new sq_append_quote_argv_pretty() to normalize
how we handle leading whitespace in perf format messages.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0211-trace2-perf.sh
trace2/tr2_tgt_perf.c
index 2c3ad6e8c186d7c563d9e10db228dcb21d19a99a..6ee8ee3b6729f05f2d553086738f1fb797d833b7 100755 (executable)
@@ -130,11 +130,11 @@ test_expect_success 'perf stream, child processes' '
                d0|main|version|||||$V
                d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0
                d0|main|cmd_name|||||trace2 (trace2)
                d0|main|version|||||$V
                d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0
                d0|main|cmd_name|||||trace2 (trace2)
-               d0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0
+               d0|main|child_start||_T_ABS_|||[ch0] class:? argv:[test-tool trace2 004child test-tool trace2 001return 0]
                d1|main|version|||||$V
                d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0
                d1|main|cmd_name|||||trace2 (trace2/trace2)
                d1|main|version|||||$V
                d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0
                d1|main|cmd_name|||||trace2 (trace2/trace2)
-               d1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0
+               d1|main|child_start||_T_ABS_|||[ch0] class:? argv:[test-tool trace2 001return 0]
                d2|main|version|||||$V
                d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0
                d2|main|cmd_name|||||trace2 (trace2/trace2/trace2)
                d2|main|version|||||$V
                d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0
                d2|main|cmd_name|||||trace2 (trace2/trace2/trace2)
index 8e52395de2d1ba37d966891331b81355ae032c58..fd979db4ad80040ae34dfe1c53816040364e1eb3 100644 (file)
@@ -184,7 +184,7 @@ static void fn_start_fl(const char *file, int line,
        const char *event_name = "start";
        struct strbuf buf_payload = STRBUF_INIT;
 
        const char *event_name = "start";
        struct strbuf buf_payload = STRBUF_INIT;
 
-       sq_quote_argv_pretty(&buf_payload, argv);
+       sq_append_quote_argv_pretty(&buf_payload, argv);
 
        perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
                         NULL, NULL, &buf_payload);
 
        perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
                         NULL, NULL, &buf_payload);
@@ -299,8 +299,9 @@ static void fn_alias_fl(const char *file, int line, const char *alias,
        const char *event_name = "alias";
        struct strbuf buf_payload = STRBUF_INIT;
 
        const char *event_name = "alias";
        struct strbuf buf_payload = STRBUF_INIT;
 
-       strbuf_addf(&buf_payload, "alias:%s argv:", alias);
-       sq_quote_argv_pretty(&buf_payload, argv);
+       strbuf_addf(&buf_payload, "alias:%s argv:[", alias);
+       sq_append_quote_argv_pretty(&buf_payload, argv);
+       strbuf_addch(&buf_payload, ']');
 
        perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
                         &buf_payload);
 
        perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
                         &buf_payload);
@@ -329,10 +330,14 @@ static void fn_child_start_fl(const char *file, int line,
                sq_quote_buf_pretty(&buf_payload, cmd->dir);
        }
 
                sq_quote_buf_pretty(&buf_payload, cmd->dir);
        }
 
-       strbuf_addstr(&buf_payload, " argv:");
-       if (cmd->git_cmd)
-               strbuf_addstr(&buf_payload, " git");
-       sq_quote_argv_pretty(&buf_payload, cmd->argv);
+       strbuf_addstr(&buf_payload, " argv:[");
+       if (cmd->git_cmd) {
+               strbuf_addstr(&buf_payload, "git");
+               if (cmd->argv[0])
+                       strbuf_addch(&buf_payload, ' ');
+       }
+       sq_append_quote_argv_pretty(&buf_payload, cmd->argv);
+       strbuf_addch(&buf_payload, ']');
 
        perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
                         NULL, NULL, &buf_payload);
 
        perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
                         NULL, NULL, &buf_payload);
@@ -383,10 +388,14 @@ static void fn_exec_fl(const char *file, int line, uint64_t us_elapsed_absolute,
        struct strbuf buf_payload = STRBUF_INIT;
 
        strbuf_addf(&buf_payload, "id:%d ", exec_id);
        struct strbuf buf_payload = STRBUF_INIT;
 
        strbuf_addf(&buf_payload, "id:%d ", exec_id);
-       strbuf_addstr(&buf_payload, "argv:");
-       if (exe)
-               strbuf_addf(&buf_payload, " %s", exe);
-       sq_quote_argv_pretty(&buf_payload, argv);
+       strbuf_addstr(&buf_payload, "argv:[");
+       if (exe) {
+               strbuf_addstr(&buf_payload, exe);
+               if (argv[0])
+                       strbuf_addch(&buf_payload, ' ');
+       }
+       sq_append_quote_argv_pretty(&buf_payload, argv);
+       strbuf_addch(&buf_payload, ']');
 
        perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
                         NULL, NULL, &buf_payload);
 
        perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,
                         NULL, NULL, &buf_payload);