{"thread":{"id":"50834","subject":"[PATCH 0/4] trace2: load trace2 settings from system config","startedAt":"2019-03-28T13:31:00Z","lastAt":"2019-05-07T01:18:20Z","messageCount":68,"participants":["Jeff Hostetler via GitGitGadget","Ævar Arnfjörð Bjarmason","Jeff Hostetler","Josh Steadmon","Jonathan Nieder","Junio C Hamano","Johannes Schindelin","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"372614","messageId":"pull.169.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":null,"subject":"[PATCH 0/4] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-28T13:30:52Z","receivedAt":"2019-03-28T13:31:00Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"Teach git to load default Trace2 settings from the system config (usually\n\"/etc/gitconfig\"). The existing GIT_TR2_* environment variables can be used\nto override the new system defaults. It also includes a little startup\nrefactoring.\n\nNote: I found interactive testing of this feature to be awkward on some\nplatforms because of the use of prefix- or runtime-prefix-relative locations\nfor the system configuration. It was easy to accidentally use an officially\ninstalled version of git to set a system config variable in the official\nsystem config directory; and then when testing with the test version of git,\nthat value would not be seen because it was looking for the system config\nfile in a different directory.\n\nJeff Hostetler (4):\n  trace2: refactor setting process starting time\n  trace2: add absolute elapsed time to start event\n  trace2: find exec-dir before trace2 initialization\n  trace2: use system config for default trace2 settings\n\n Documentation/technical/api-trace2.txt |  54 +++++++++--\n Makefile                               |   1 +\n common-main.c                          |   6 +-\n compat/mingw.c                         |   2 +\n t/t0210-trace2-normal.sh               |  41 +++++++-\n t/t0211-trace2-perf.sh                 |  53 ++++++++---\n t/t0212-trace2-event.sh                |  52 +++++++++-\n trace2.c                               |  19 +++-\n trace2.h                               |  24 ++++-\n trace2/tr2_cfg.c                       |   7 +-\n trace2/tr2_dst.c                       |  24 ++---\n trace2/tr2_dst.h                       |   3 +-\n trace2/tr2_sysenv.c                    | 125 +++++++++++++++++++++++++\n trace2/tr2_sysenv.h                    |  36 +++++++\n trace2/tr2_tgt.h                       |   1 +\n trace2/tr2_tgt_event.c                 |  24 ++---\n trace2/tr2_tgt_normal.c                |  13 +--\n trace2/tr2_tgt_perf.c                  |  17 ++--\n trace2/tr2_tls.c                       |  38 +++++---\n trace2/tr2_tls.h                       |   8 +-\n 20 files changed, 455 insertions(+), 93 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\n\nbase-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/169\n-- \ngitgitgadget\n"},{"id":"372615","messageId":"7f1a34732271f9fbdbec0f4cd0a5990466ebd071.1553779851.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.git.gitgitgadget@gmail.com","subject":"[PATCH 1/4] trace2: refactor setting process starting time","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-28T13:30:57Z","receivedAt":"2019-03-28T13:31:03Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreate trace2_initialize_clock() and call from main() to capture\nprocess start time in isolation and before other sub-systems are\nready.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++--\n common-main.c                          |  2 ++\n compat/mingw.c                         |  2 ++\n trace2.c                               |  7 ++++-\n trace2.h                               | 17 ++++++++++++\n trace2/tr2_tls.c                       | 38 ++++++++++++++++----------\n trace2/tr2_tls.h                       |  8 +++++-\n 7 files changed, 67 insertions(+), 19 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 2de565fa3d..f37fccf1da 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -160,17 +160,23 @@ purposes.\n \n These are concerned with the lifetime of the overall git process.\n \n+`void trace2_initialize_clock()`::\n+\n+\tInitialize the Trace2 start clock and nothing else.  This should\n+\tbe called at the very top of main() to capture the process start\n+\ttime and reduce startup order dependencies.\n+\n `void trace2_initialize()`::\n \n \tDetermines if any Trace2 Targets should be enabled and\n-\tinitializes the Trace2 facility.  This includes starting the\n-\telapsed time clocks and thread local storage (TLS).\n+\tinitializes the Trace2 facility.  This includes setting up the\n+\tTrace2 thread local storage (TLS).\n +\n This function emits a \"version\" message containing the version of git\n and the Trace2 protocol.\n +\n This function should be called from `main()` as early as possible in\n-the life of the process.\n+the life of the process after essential process initialization.\n \n `int trace2_is_enabled()`::\n \ndiff --git a/common-main.c b/common-main.c\nindex d484aec209..6137af0e63 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -27,6 +27,8 @@ int main(int argc, const char **argv)\n {\n \tint result;\n \n+\ttrace2_initialize_clock();\n+\n \t/*\n \t * Always open file descriptors 0/1/2 to avoid clobbering files\n \t * in die().  It also avoids messing up when the pipes are dup'ed\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 6b04514cdc..a2f74aca6a 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -2569,6 +2569,8 @@ void mingw_startup(void)\n \twchar_t **wenv, **wargv;\n \t_startupinfo si;\n \n+\ttrace2_initialize_clock();\n+\n \tmaybe_redirect_std_handles();\n \n \t/* get wide char arguments and environment */\ndiff --git a/trace2.c b/trace2.c\nindex ccccd4ef09..6dd51e6aa5 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)\n \traise(signo);\n }\n \n+void trace2_initialize_clock(void)\n+{\n+\ttr2tls_start_process_clock();\n+}\n+\n void trace2_initialize_fl(const char *file, int line)\n {\n \tstruct tr2_tgt *tgt_j;\n@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name)\n \tus_now = getnanotime() / 1000;\n \tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n \n-\ttr2tls_create_self(thread_name);\n+\ttr2tls_create_self(thread_name, us_now);\n \n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_thread_start_fl)\ndiff --git a/trace2.h b/trace2.h\nindex ae5020d0e6..8f89e70c44 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -19,6 +19,23 @@ struct json_writer;\n  * [] trace2_printf*    -- legacy trace[1] messages.\n  */\n \n+/*\n+ * Initialize the TRACE2 clock and do nothing else, in particular\n+ * no mallocs, no system inspection, and no environment inspection.\n+ *\n+ * This should be called at the very top of main() to capture the\n+ * process start time.  This is intended to reduce chicken-n-egg\n+ * bootstrap pressure.\n+ *\n+ * It is safe to call this more than once.  This allows capturing\n+ * absolute startup costs on Windows which uses a little trickery\n+ * to do setup work before common-main.c:main() is called.\n+ *\n+ * The main trace2_initialize_fl() may be called a little later\n+ * after more infrastructure is established.\n+ */\n+void trace2_initialize_clock(void);\n+\n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n  * targets are enabled in the environment.  Emits a 'version' event.\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 8e65b0361d..31fb529f93 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -10,16 +10,30 @@\n #define TR2_REGION_NESTING_INITIAL_SIZE (100)\n \n static struct tr2tls_thread_ctx *tr2tls_thread_main;\n-static uint64_t tr2tls_us_start_main;\n+static uint64_t tr2tls_us_start_process;\n \n static pthread_mutex_t tr2tls_mutex;\n static pthread_key_t tr2tls_key;\n \n static int tr2_next_thread_id; /* modify under lock */\n \n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n+void tr2tls_start_process_clock(void)\n+{\n+\tif (tr2tls_us_start_process)\n+\t\treturn;\n+\n+\t/*\n+\t * Keep the absolute start time of the process (i.e. the main\n+\t * process) in a fixed variable since other threads need to\n+\t * access it.  This allows them to do that without a lock on\n+\t * main thread's array data (because of reallocs).\n+\t */\n+\ttr2tls_us_start_process = getnanotime() / 1000;\n+}\n+\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start)\n {\n-\tuint64_t us_now = getnanotime() / 1000;\n \tstruct tr2tls_thread_ctx *ctx = xcalloc(1, sizeof(*ctx));\n \n \t/*\n@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n \t */\n \tctx->alloc = TR2_REGION_NESTING_INITIAL_SIZE;\n \tctx->array_us_start = (uint64_t *)xcalloc(ctx->alloc, sizeof(uint64_t));\n-\tctx->array_us_start[ctx->nr_open_regions++] = us_now;\n+\tctx->array_us_start[ctx->nr_open_regions++] = us_thread_start;\n \n \tctx->thread_id = tr2tls_locked_increment(&tr2_next_thread_id);\n \n@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)\n \t * here and silently continue.\n \t */\n \tif (!ctx)\n-\t\tctx = tr2tls_create_self(\"unknown\");\n+\t\tctx = tr2tls_create_self(\"unknown\", getnanotime() / 1000);\n \n \treturn ctx;\n }\n@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)\n \tif (!tr2tls_thread_main)\n \t\treturn 0;\n \n-\treturn us - tr2tls_us_start_main;\n+\treturn us - tr2tls_us_start_process;\n }\n \n void tr2tls_init(void)\n {\n+\ttr2tls_start_process_clock();\n+\n \tpthread_key_create(&tr2tls_key, NULL);\n \tinit_recursive_mutex(&tr2tls_mutex);\n \n-\ttr2tls_thread_main = tr2tls_create_self(\"main\");\n-\t/*\n-\t * Keep a copy of the absolute start time of the main thread\n-\t * in a fixed variable since other threads need to access it.\n-\t * This also eliminates the need to lock accesses to the main\n-\t * thread's array (because of reallocs).\n-\t */\n-\ttr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];\n+\ttr2tls_thread_main = tr2tls_create_self(\"main\",\n+\t\t\t\t\t\ttr2tls_us_start_process);\n }\n \n void tr2tls_release(void)\ndiff --git a/trace2/tr2_tls.h b/trace2/tr2_tls.h\nindex bb80e3f8e7..b1e327a928 100644\n--- a/trace2/tr2_tls.h\n+++ b/trace2/tr2_tls.h\n@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {\n  * In this and all following functions the term \"self\" refers to the\n  * current thread.\n  */\n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start);\n \n /*\n  * Get our TLS data.\n@@ -94,4 +95,9 @@ void tr2tls_release(void);\n  */\n int tr2tls_locked_increment(int *p);\n \n+/*\n+ * Capture the process start time and do nothing else.\n+ */\n+void tr2tls_start_process_clock(void);\n+\n #endif /* TR2_TLS_H */\n-- \ngitgitgadget\n\n"},{"id":"372616","messageId":"c15f783c26ea426688b488c2522dd9c9072cc1bf.1553779851.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.git.gitgitgadget@gmail.com","subject":"[PATCH 2/4] trace2: add absolute elapsed time to start event","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-28T13:31:00Z","receivedAt":"2019-03-28T13:31:05Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nAdd elapsed process time to \"start\" event to measure\nthe performance of early process startup.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 11 ++++++-----\n t/t0211-trace2-perf.sh                 | 12 ++++++------\n trace2.c                               |  8 +++++++-\n trace2/tr2_tgt.h                       |  1 +\n trace2/tr2_tgt_event.c                 |  5 ++++-\n trace2/tr2_tgt_normal.c                |  3 ++-\n trace2/tr2_tgt_perf.c                  |  7 ++++---\n 7 files changed, 30 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex f37fccf1da..baaa1153bb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n-12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |           |           |            | git version\n+12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |  0.001173 |           |            | git version\n 12:28:42.621111 git.c:432                         | d0 | main                     | cmd_name     |     |           |           |            | version (version)\n 12:28:42.621225 git.c:662                         | d0 | main                     | exit         |     |  0.001227 |           |            | code:0\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.event\n {\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n {\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n {\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n {\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the \"start\" and\n {\n \t\"event\":\"start\",\n \t...\n+\t\"t_abs\":0.001227, # elapsed time in seconds\n \t\"argv\":[\"git\",\"version\"]\n }\n ------------\n@@ -1118,7 +1119,7 @@ $ git status\n \n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.160.g5676107ecd.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1163,7 +1164,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.162.gb4ccea44db.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1219,7 +1220,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.156.gf9916ae094.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n d0 | main                     | region_enter | r1  |  0.001791 |           | index      | label:do_read_index .git/index\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex 953e2f7847..c9694b29f7 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:0\n \t\td0|main|atexit||_T_ABS_|||code:0\n@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 1\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 1\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:1\n \t\td0|main|atexit||_T_ABS_|||code:1\n@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|error|||||hello world\n \t\td0|main|error|||||this is a test\n@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0\n \t\td1|main|version|||||$V\n-\t\td1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0\n+\t\td1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0\n \t\td1|main|cmd_name|||||trace2 (trace2/trace2)\n \t\td1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0\n \t\td2|main|version|||||$V\n-\t\td2|main|start|||||_EXE_ trace2 001return 0\n+\t\td2|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td2|main|cmd_name|||||trace2 (trace2/trace2/trace2)\n \t\td2|main|exit||_T_ABS_|||code:0\n \t\td2|main|atexit||_T_ABS_|||code:0\ndiff --git a/trace2.c b/trace2.c\nindex 6dd51e6aa5..1c180062dd 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv)\n {\n \tstruct tr2_tgt *tgt_j;\n \tint j;\n+\tuint64_t us_now;\n+\tuint64_t us_elapsed_absolute;\n \n \tif (!trace2_enabled)\n \t\treturn;\n \n+\tus_now = getnanotime() / 1000;\n+\tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n+\n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_start_fl)\n-\t\t\ttgt_j->pfn_start_fl(file, line, argv);\n+\t\t\ttgt_j->pfn_start_fl(file, line, us_elapsed_absolute,\n+\t\t\t\t\t    argv);\n }\n \n int trace2_cmd_exit_fl(const char *file, int line, int code)\ndiff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h\nindex 297bb8ffbe..7b90469212 100644\n--- a/trace2/tr2_tgt.h\n+++ b/trace2/tr2_tgt.h\n@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);\n typedef void(tr2_tgt_evt_version_fl_t)(const char *file, int line);\n \n typedef void(tr2_tgt_evt_start_fl_t)(const char *file, int line,\n+\t\t\t\t     uint64_t us_elapsed_absolute,\n \t\t\t\t     const char **argv);\n typedef void(tr2_tgt_evt_exit_fl_t)(const char *file, int line,\n \t\t\t\t    uint64_t us_elapsed_absolute, int code);\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 107cb5317d..89a4d3ae9a 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)\n \tjw_release(&jw);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct json_writer jw = JSON_WRITER_INIT;\n+\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \n \tjw_object_begin(&jw, 0);\n \tevent_fmt_prepare(event_name, file, line, NULL, &jw);\n+\tjw_object_double(&jw, \"t_abs\", 6, t_abs);\n \tjw_object_inline_begin_array(&jw, \"argv\");\n \tjw_array_argv(&jw, argv);\n \tjw_end(&jw);\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 547183d5b6..57f3e18f5b 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex f0746fcf86..9c3b4d8a0f 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \n \tsq_quote_argv_pretty(&buf_payload, argv);\n \n-\tperf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,\n-\t\t\t &buf_payload);\n+\tperf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,\n+\t\t\t NULL, NULL, &buf_payload);\n \tstrbuf_release(&buf_payload);\n }\n \n-- \ngitgitgadget\n\n"},{"id":"372617","messageId":"d4023acde7172089615ea5abd4e91ef90c1791a7.1553779851.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.git.gitgitgadget@gmail.com","subject":"[PATCH 3/4] trace2: find exec-dir before trace2 initialization","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-28T13:31:02Z","receivedAt":"2019-03-28T13:31:06Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Git to resolve the executable directory before initializing\nTrace2.  This allows the system configuration directory to be\ndiscovered earlier (because it is sometimes relative to the prefix\nor runtime-prefix).\n\nThis will be used by the next commit to allow trace2 settings to\nbe loaded from the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 6137af0e63..299ca62a72 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -37,12 +37,12 @@ int main(int argc, const char **argv)\n \tsanitize_stdfds();\n \trestore_sigpipe_to_default();\n \n+\tgit_resolve_executable_dir(argv[0]);\n+\n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n \ttrace2_collect_process_info();\n \n-\tgit_resolve_executable_dir(argv[0]);\n-\n \tgit_setup_gettext();\n \n \tinitialize_the_repository();\n-- \ngitgitgadget\n\n"},{"id":"372618","messageId":"7e0d4e20fbb3abbc787bc216d2c4bd8c18860aed.1553779851.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.git.gitgitgadget@gmail.com","subject":"[PATCH 4/4] trace2: use system config for default trace2 settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-28T13:31:04Z","receivedAt":"2019-03-28T13:31:10Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach git to read the system config (usually \"/etc/gitconfig\") for\ndefault Trace2 settings.  This allows system-wide Trace2 settings to\nbe installed and inherited to make it easier to manage a collection of\nsystems.\n\nThe original GIT_TR2* environment variables are loaded afterwards and\ncan be used to override the system settings.\n\nOnly the system config file is used.  Trace2 config values are ignored\nin local, global, and other config files.  Likewise, the \"-c\" command\nline arguments are ignored for Trace2 values.  These limits are for\nperformance reasons.\n\n(1) For users not using Trace2, there should be minimal overhead to\ndetect that Trace2 is not enabled.  In particular, Trace2 should not\nallocate lots of otherwise unused data strucutres.\n\n(2) For accurate performance measurements, Trace2 should be initialized\nas early in the git process as possible, and before most of the normal\ngit process initialization (which involves discovering the .git directory\nand reading a hierarchy of config files).\n\nAdded the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing\npurposes to specify the pathname of a fake \"system\" config or disable\nuse of the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt |  31 ++++++\n Makefile                               |   1 +\n t/t0210-trace2-normal.sh               |  41 +++++++-\n t/t0211-trace2-perf.sh                 |  41 +++++++-\n t/t0212-trace2-event.sh                |  52 +++++++++-\n trace2.c                               |   4 +\n trace2.h                               |   7 +-\n trace2/tr2_cfg.c                       |   7 +-\n trace2/tr2_dst.c                       |  24 ++---\n trace2/tr2_dst.h                       |   3 +-\n trace2/tr2_sysenv.c                    | 125 +++++++++++++++++++++++++\n trace2/tr2_sysenv.h                    |  36 +++++++\n trace2/tr2_tgt_event.c                 |  19 ++--\n trace2/tr2_tgt_normal.c                |  10 +-\n trace2/tr2_tgt_perf.c                  |  10 +-\n 15 files changed, 356 insertions(+), 55 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex baaa1153bb..13ca595c69 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -117,6 +117,37 @@ values are recognized.\n Socket type can be either `stream` or `dgram`.  If the socket type is\n omitted, Git will try both.\n \n+== Trace2 Settings in System Config\n+\n+Trace2 also reads configuration information from the system config.\n+This is intended to help adminstrators to gather system-wide Git\n+performance data.\n+\n+Trace2 only reads the system configuration, it does not read global,\n+local, worktree, or `-c` config settings.\n+\n+Trace2 will try to load the following system configuration settings\n+and then read the corresponding environment variables at startup.\n+\n+....\n+---------------------------------------------------\n+trace2.normalTarget          GIT_TR2\n+trace2.normalBrief           GIT_TR2_BRIEF\n+\n+trace2.perfTarget            GIT_TR2_PERF\n+trace2.perfBrief             GIT_TR2_PERF_BRIEF\n+\n+trace2.eventTarget           GIT_TR2_EVENT\n+trace2.eventBrief            GIT_TR2_EVENT_BRIEF\n+trace2.eventNesting          GIT_TR2_EVENT_NESTING\n+\n+trace2.configParams          GIT_TR2_CONFIG_PARAMS\n+\n+trace2.destinationDebug      GIT_TR2_DST_DEBUG\n+---------------------------------------------------\n+....\n+\n+\n == Trace2 API\n \n All public Trace2 functions and macros are defined in `trace2.h` and\ndiff --git a/Makefile b/Makefile\nindex 3e03290d8f..9ddfa3dfe7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o\n LIB_OBJS += trace2/tr2_cmd_name.o\n LIB_OBJS += trace2/tr2_dst.o\n LIB_OBJS += trace2/tr2_sid.o\n+LIB_OBJS += trace2/tr2_sysenv.o\n LIB_OBJS += trace2/tr2_tbuf.o\n LIB_OBJS += trace2/tr2_tgt_event.o\n LIB_OBJS += trace2/tr2_tgt_normal.o\ndiff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh\nindex 03a0aedb1d..5d4c04ed30 100755\n--- a/t/t0210-trace2-normal.sh\n+++ b/t/t0210-trace2-normal.sh\n@@ -1,5 +1,14 @@\n #!/bin/sh\n \n+# Disable loading of Trace2 settings from the system config\n+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n+\n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_BRIEF\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility (normal target)'\n . ./test-lib.sh\n \n@@ -15,11 +24,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -132,4 +136,31 @@ test_expect_success 'normal stream, error event' '\n \ttest_cmp expect actual\n '\n \n+# Now test using system config by using a mocked up config file\n+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n+# GIT_TR2* environment variables.\n+\n+unset GIT_TR2_BRIEF\n+\n+MOCK=./mock_system_config\n+\n+test_expect_success 'setup mocked /etc/gitconfig' '\n+\tgit config --file $MOCK trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\tgit config --file $MOCK trace2.normalBrief 1\n+'\n+\n+test_expect_success 'using mock, normal stream, return code 0' '\n+\ttest_when_finished \"rm trace.normal actual expect\" &&\n+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex c9694b29f7..abe35b2186 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -1,5 +1,14 @@\n #!/bin/sh\n \n+# Disable loading of Trace2 settings from the system config\n+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n+\n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_PERF_BRIEF\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility (perf target)'\n . ./test-lib.sh\n \n@@ -15,11 +24,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_PERF_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -150,4 +154,31 @@ test_expect_success 'perf stream, child processes' '\n \ttest_cmp expect actual\n '\n \n+# Now test using system config by using a mocked up config file\n+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n+# GIT_TR2* environment variables.\n+\n+unset GIT_TR2_PERF_BRIEF\n+\n+MOCK=./mock_system_config\n+\n+test_expect_success 'setup mocked /etc/gitconfig' '\n+\tgit config --file $MOCK trace2.perfTarget \"$(pwd)/trace.perf\" &&\n+\tgit config --file $MOCK trace2.perfBrief 1\n+'\n+\n+test_expect_success 'using mock, perf stream, return code 0' '\n+\ttest_when_finished \"rm trace.perf actual expect\" &&\n+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n+\tcat >expect <<-EOF &&\n+\t\td0|main|version|||||$V\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n+\t\td0|main|cmd_name|||||trace2 (trace2)\n+\t\td0|main|exit||_T_ABS_|||code:0\n+\t\td0|main|atexit||_T_ABS_|||code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh\nindex 028b6c5671..c535496261 100755\n--- a/t/t0212-trace2-event.sh\n+++ b/t/t0212-trace2-event.sh\n@@ -1,5 +1,14 @@\n #!/bin/sh\n \n+# Disable loading of Trace2 settings from the system config\n+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n+\n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_BARE\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility'\n . ./test-lib.sh\n \n@@ -17,11 +26,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BARE\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -233,4 +237,42 @@ test_expect_success JSON_PP 'basic trace2_data' '\n \ttest_cmp expect actual\n '\n \n+# Now test using system config by using a mocked up config file\n+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n+# GIT_TR2* environment variables.\n+\n+MOCK=./mock_system_config\n+\n+test_expect_success 'setup mocked /etc/gitconfig' '\n+\tgit config --file $MOCK trace2.eventTarget \"$(pwd)/trace.event\"\n+'\n+\n+test_expect_success JSON_PP 'using mock, event stream, error event' '\n+\ttest_when_finished \"rm trace.event actual expect\" &&\n+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 003error \"hello world\" \"this is a test\" &&\n+\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n+\tsed -e \"s/^|//\" >expect <<-EOF &&\n+\t|VAR1 = {\n+\t|  \"_SID0_\":{\n+\t|    \"argv\":[\n+\t|      \"_EXE_\",\n+\t|      \"trace2\",\n+\t|      \"003error\",\n+\t|      \"hello world\",\n+\t|      \"this is a test\"\n+\t|    ],\n+\t|    \"errors\":[\n+\t|      \"%s\",\n+\t|      \"%s\"\n+\t|    ],\n+\t|    \"exit_code\":0,\n+\t|    \"hierarchy\":\"trace2\",\n+\t|    \"name\":\"trace2\",\n+\t|    \"version\":\"$V\"\n+\t|  }\n+\t|};\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/trace2.c b/trace2.c\nindex 1c180062dd..490b3f071e 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -10,6 +10,7 @@\n #include \"trace2/tr2_cmd_name.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)\n \ttr2_sid_release();\n \ttr2_cmd_name_release();\n \ttr2_cfg_free_patterns();\n+\ttr2_sysenv_release();\n \n \ttrace2_enabled = 0;\n }\n@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)\n \tif (trace2_enabled)\n \t\treturn;\n \n+\ttr2_sysenv_load();\n+\n \tif (!tr2_tgt_want_builtins())\n \t\treturn;\n \ttrace2_enabled = 1;\ndiff --git a/trace2.h b/trace2.h\nindex 8f89e70c44..cda8349058 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n \n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n- * targets are enabled in the environment.  Emits a 'version' event.\n+ * targets are enabled in the system config or the environment.\n+ * Emits a 'version' event.\n  *\n  * Cleanup/Termination is handled automatically by a registered\n  * atexit() routine.\n@@ -125,8 +126,8 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n  * Emit one or more 'def_param' events for \"interesting\" configuration\n  * settings.\n  *\n- * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n- * list of patterns considered important.  For example:\n+ * Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns\n+ * configured important.  For example:\n  *\n  *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n  *\ndiff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\nindex b329921ac5..caa7f06948 100644\n--- a/trace2/tr2_cfg.c\n+++ b/trace2/tr2_cfg.c\n@@ -1,8 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n-#include \"tr2_cfg.h\"\n-\n-#define TR2_ENVVAR_CFG_PARAM \"GIT_TR2_CONFIG_PARAMS\"\n+#include \"trace2/tr2_cfg.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n static struct strbuf **tr2_cfg_patterns;\n static int tr2_cfg_count_patterns;\n@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)\n \t\treturn tr2_cfg_count_patterns;\n \ttr2_cfg_loaded = 1;\n \n-\tenvvar = getenv(TR2_ENVVAR_CFG_PARAM);\n+\tenvvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM);\n \tif (!envvar || !*envvar)\n \t\treturn tr2_cfg_count_patterns;\n \ndiff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c\nindex fd490a43ad..575cd69aa9 100644\n--- a/trace2/tr2_dst.c\n+++ b/trace2/tr2_dst.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n /*\n  * If a Trace2 target cannot be opened for writing, we should issue a\n@@ -7,17 +8,13 @@\n  * or socket and beyond the user's control -- especially since every\n  * git command (and sub-command) will print the message.  So we silently\n  * eat these warnings and just discard the trace data.\n- *\n- * Enable the following environment variable to see these warnings.\n  */\n-#define TR2_ENVVAR_DST_DEBUG \"GIT_TR2_DST_DEBUG\"\n-\n static int tr2_dst_want_warning(void)\n {\n \tstatic int tr2env_dst_debug = -1;\n \n \tif (tr2env_dst_debug == -1) {\n-\t\tconst char *env_value = getenv(TR2_ENVVAR_DST_DEBUG);\n+\t\tconst char *env_value = tr2_sysenv_get(TR2_SYSENV_DST_DEBUG);\n \t\tif (!env_value || !*env_value)\n \t\t\ttr2env_dst_debug = 0;\n \t\telse\n@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)\n \tif (fd == -1) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: could not open '%s' for '%s' tracing: %s\",\n-\t\t\t\ttgt_value, dst->env_var_name, strerror(errno));\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\t\tstrerror(errno));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \tif (!path || !*path) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n-\t\t\t\ttgt_value, dst->env_var_name);\n+\t\t\t\ttgt_value, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \t    strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX path '%s' for '%s' tracing\",\n-\t\t\t\tpath, dst->env_var_name);\n+\t\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n error:\n \tif (tr2_dst_want_warning())\n \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n-\t\t\tpath, dst->env_var_name, strerror(e));\n+\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var), strerror(e));\n \n \ttr2_dst_trace_disable(dst);\n \treturn 0;\n@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_addf(&buf, \"trace2: unknown value for '%s': '%s'\",\n-\t\t    dst->env_var_name, tgt_value);\n+\t\t    tr2_sysenv_display_name(dst->sysenv_var), tgt_value);\n \twarning(\"%s\", buf.buf);\n \n \tstrbuf_release(&buf);\n@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst)\n \n \tdst->initialized = 1;\n \n-\ttgt_value = getenv(dst->env_var_name);\n+\ttgt_value = tr2_sysenv_get(dst->sysenv_var);\n \n \tif (!tgt_value || !strcmp(tgt_value, \"\") || !strcmp(tgt_value, \"0\") ||\n \t    !strcasecmp(tgt_value, \"false\")) {\n@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)\n \t\treturn;\n \n \tif (tr2_dst_want_warning())\n-\t\twarning(\"unable to write trace to '%s': %s\", dst->env_var_name,\n+\t\twarning(\"unable to write trace to '%s': %s\",\n+\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n \t\t\tstrerror(errno));\n \ttr2_dst_trace_disable(dst);\n }\ndiff --git a/trace2/tr2_dst.h b/trace2/tr2_dst.h\nindex 9a64f05b02..3adf3bac13 100644\n--- a/trace2/tr2_dst.h\n+++ b/trace2/tr2_dst.h\n@@ -2,9 +2,10 @@\n #define TR2_DST_H\n \n struct strbuf;\n+#include \"trace2/tr2_sysenv.h\"\n \n struct tr2_dst {\n-\tconst char *const env_var_name;\n+\tenum tr2_sysenv_variable sysenv_var;\n \tint fd;\n \tunsigned int initialized : 1;\n \tunsigned int need_close : 1;\ndiff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\nnew file mode 100644\nindex 0000000000..656613e371\n--- /dev/null\n+++ b/trace2/tr2_sysenv.c\n@@ -0,0 +1,125 @@\n+#include \"cache.h\"\n+#include \"config.h\"\n+#include \"dir.h\"\n+#include \"tr2_sysenv.h\"\n+\n+/*\n+ * Each entry represents a trace2 setting.\n+ * See Documentation/technical/api-trace2.txt\n+ */\n+struct tr2_sysenv_entry {\n+\tconst char *env_var_name;\n+\tconst char *git_config_name;\n+\n+\tchar *value;\n+\tunsigned int getenv_called : 1;\n+};\n+\n+/*\n+ * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n+ * These strings are constant and must match the published names as\n+ * described in the documentation.\n+ *\n+ * We do not define entries for the GIT_TR2_PARENT_* environment\n+ * variables because they are transient and used to pass information\n+ * from parent to child git processes, rather than settings.\n+ */\n+/* clang-format off */\n+static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n+\t{ \"GIT_TR2_CONFIG_PARAMS\",   \"trace2.configparams\"     },\n+\n+\t{ \"GIT_TR2_DST_DEBUG\",       \"trace2.destinationdebug\" },\n+\n+\t{ \"GIT_TR2\",                 \"trace2.normaltarget\"     },\n+\t{ \"GIT_TR2_BRIEF\",           \"trace2.normalbrief\"      },\n+\n+\t{ \"GIT_TR2_EVENT\",           \"trace2.eventtarget\"      },\n+\t{ \"GIT_TR2_EVENT_BRIEF\",     \"trace2.eventbrief\"       },\n+\t{ \"GIT_TR2_EVENT_NESTING\",   \"trace2.eventnesting\"     },\n+\n+\t{ \"GIT_TR2_PERF\",            \"trace2.perftarget\"       },\n+\t{ \"GIT_TR2_PERF_BRIEF\",      \"trace2.perfbrief\"        },\n+};\n+/* clang-format on */\n+\n+static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n+{\n+\tint k;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n+\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n+\t\t\tfree(tr2_sysenv_settings[k].value);\n+\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n+ * unless we were built with a runtime-prefix).  These are intended to\n+ * define the default values for Trace2 as requested by the administrator.\n+ */\n+void tr2_sysenv_load(void)\n+{\n+\tconst char *system_config_pathname;\n+\tconst char *test_pathname;\n+\n+\tsystem_config_pathname = git_etc_gitconfig();\n+\n+\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n+\tif (test_pathname) {\n+\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n+\t\t\treturn; /* disable use of system config */\n+\n+\t\t/* mock it with given test file */\n+\t\tsystem_config_pathname = test_pathname;\n+\t}\n+\n+\tif (file_exists(system_config_pathname))\n+\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n+\t\t\t\t     NULL);\n+}\n+\n+/*\n+ * Return the value for the requested setting.  Start with the /etc/gitconfig\n+ * value and allow the corresponding environment variable to override it.\n+ */\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\tif (!tr2_sysenv_settings[var].getenv_called) {\n+\t\tconst char *v = getenv(tr2_sysenv_settings[var].env_var_name);\n+\t\tif (v && *v) {\n+\t\t\tfree(tr2_sysenv_settings[var].value);\n+\t\t\ttr2_sysenv_settings[var].value = xstrdup(v);\n+\t\t}\n+\t\ttr2_sysenv_settings[var].getenv_called = 1;\n+\t}\n+\n+\treturn tr2_sysenv_settings[var].value;\n+}\n+\n+/*\n+ * Return a friendly name for this setting that is suitable for printing\n+ * in an error messages.\n+ */\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\treturn tr2_sysenv_settings[var].env_var_name;\n+}\n+\n+void tr2_sysenv_release(void)\n+{\n+\tint k;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++)\n+\t\tfree(tr2_sysenv_settings[k].value);\n+}\ndiff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h\nnew file mode 100644\nindex 0000000000..369b20bd87\n--- /dev/null\n+++ b/trace2/tr2_sysenv.h\n@@ -0,0 +1,36 @@\n+#ifndef TR2_SYSENV_H\n+#define TR2_SYSENV_H\n+\n+/*\n+ * The Trace2 settings that can be loaded from /etc/gitconfig\n+ * and/or user environment variables.\n+ *\n+ * Note that this set does not contain any of the transient\n+ * environment variables used to pass information from parent\n+ * to child git processes, such \"GIT_TR2_PARENT_SID\".\n+ */\n+enum tr2_sysenv_variable {\n+\tTR2_SYSENV_CFG_PARAM = 0,\n+\n+\tTR2_SYSENV_DST_DEBUG,\n+\n+\tTR2_SYSENV_NORMAL,\n+\tTR2_SYSENV_NORMAL_BRIEF,\n+\n+\tTR2_SYSENV_EVENT,\n+\tTR2_SYSENV_EVENT_BRIEF,\n+\tTR2_SYSENV_EVENT_NESTING,\n+\n+\tTR2_SYSENV_PERF,\n+\tTR2_SYSENV_PERF_BRIEF,\n+\n+\tTR2_SYSENV_MUST_BE_LAST\n+};\n+\n+void tr2_sysenv_load(void);\n+\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable);\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);\n+void tr2_sysenv_release(void);\n+\n+#endif /* TR2_SYSENV_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 89a4d3ae9a..bb6e323953 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -6,10 +6,11 @@\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };\n \n /*\n  * The version number of the JSON data generated by the EVENT target\n@@ -28,17 +29,15 @@ static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n  * are primarily intended for the performance target during debugging.\n  *\n  * Some of the outer-most messages, however, may be of interest to the\n- * event target.  Set this environment variable to a larger integer for\n- * more detail in the event target.\n+ * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase\n+ * region details in the event target.\n  */\n-#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n static int tr2env_event_nesting_wanted = 2;\n \n /*\n- * Set this environment variable to true to omit the <time>, <file>, and\n+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and\n  * <line> fields from most events.\n  */\n-#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n static int tr2env_event_brief;\n \n static int fn_init(void)\n@@ -46,17 +45,17 @@ static int fn_init(void)\n \tint want = tr2_dst_trace_want(&tr2dst_event);\n \tint want_nesting;\n \tint want_brief;\n-\tchar *nesting;\n-\tchar *brief;\n+\tconst char *nesting;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n+\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n \tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n \t\ttr2env_event_nesting_wanted = want_nesting;\n \n-\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n \tif (brief && ((want_brief = atoi(brief)) > 0))\n \t\ttr2env_event_brief = want_brief;\n \ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 57f3e18f5b..3364223805 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -4,19 +4,19 @@\n #include \"quote.h\"\n #include \"version.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_normal = { \"GIT_TR2\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin normal target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n static int tr2env_normal_brief;\n \n #define TR2FMT_NORMAL_FL_WIDTH (50)\n@@ -25,12 +25,12 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_normal);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n \t\ttr2env_normal_brief = want_brief;\ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex 9c3b4d8a0f..1ad781c32e 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -6,19 +6,19 @@\n #include \"json-writer.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_perf = { \"GIT_TR2_PERF\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use TR2_SYSENV_PERF_BRIEF to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin performance target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n static int tr2env_perf_brief;\n \n #define TR2FMT_PERF_FL_WIDTH (50)\n@@ -36,14 +36,14 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_perf);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n \tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n \n-\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n \t\ttr2env_perf_brief = want_brief;\n-- \ngitgitgadget\n"},{"id":"372621","messageId":"87wokj9ic1.fsf@evledraar.gmail.com","threadId":"50834","inReplyTo":"7e0d4e20fbb3abbc787bc216d2c4bd8c18860aed.1553779851.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 4/4] trace2: use system config for default trace2 settings","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-03-28T14:36:30Z","receivedAt":"2019-03-28T14:36:38Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Mar 28 2019, Jeff Hostetler via GitGitGadget wrote:\n\nThanks for working on this!\n\nHaven't given this any deep testing. Just some observations:\n\n> From: Jeff Hostetler <jeffhost@microsoft.com>\n>\n> Teach git to read the system config (usually \"/etc/gitconfig\") for\n> default Trace2 settings.  This allows system-wide Trace2 settings to\n> be installed and inherited to make it easier to manage a collection of\n> systems.\n>\n> The original GIT_TR2* environment variables are loaded afterwards and\n> can be used to override the system settings.\n>\n> Only the system config file is used.  Trace2 config values are ignored\n> in local, global, and other config files.  Likewise, the \"-c\" command\n> line arguments are ignored for Trace2 values.  These limits are for\n> performance reasons.\n>\n> (1) For users not using Trace2, there should be minimal overhead to\n> detect that Trace2 is not enabled.  In particular, Trace2 should not\n> allocate lots of otherwise unused data strucutres.\n>\n> (2) For accurate performance measurements, Trace2 should be initialized\n> as early in the git process as possible, and before most of the normal\n> git process initialization (which involves discovering the .git directory\n> and reading a hierarchy of config files).\n>\n> Added the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing\n> purposes to specify the pathname of a fake \"system\" config or disable\n> use of the system config.\n>\n> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n> ---\n>  Documentation/technical/api-trace2.txt |  31 ++++++\n>  Makefile                               |   1 +\n>  t/t0210-trace2-normal.sh               |  41 +++++++-\n>  t/t0211-trace2-perf.sh                 |  41 +++++++-\n>  t/t0212-trace2-event.sh                |  52 +++++++++-\n>  trace2.c                               |   4 +\n>  trace2.h                               |   7 +-\n>  trace2/tr2_cfg.c                       |   7 +-\n>  trace2/tr2_dst.c                       |  24 ++---\n>  trace2/tr2_dst.h                       |   3 +-\n>  trace2/tr2_sysenv.c                    | 125 +++++++++++++++++++++++++\n>  trace2/tr2_sysenv.h                    |  36 +++++++\n>  trace2/tr2_tgt_event.c                 |  19 ++--\n>  trace2/tr2_tgt_normal.c                |  10 +-\n>  trace2/tr2_tgt_perf.c                  |  10 +-\n>  15 files changed, 356 insertions(+), 55 deletions(-)\n>  create mode 100644 trace2/tr2_sysenv.c\n>  create mode 100644 trace2/tr2_sysenv.h\n>\n> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\n> index baaa1153bb..13ca595c69 100644\n> --- a/Documentation/technical/api-trace2.txt\n> +++ b/Documentation/technical/api-trace2.txt\n> @@ -117,6 +117,37 @@ values are recognized.\n>  Socket type can be either `stream` or `dgram`.  If the socket type is\n>  omitted, Git will try both.\n>\n> +== Trace2 Settings in System Config\n> +\n> +Trace2 also reads configuration information from the system config.\n> +This is intended to help adminstrators to gather system-wide Git\n> +performance data.\n> +\n> +Trace2 only reads the system configuration, it does not read global,\n> +local, worktree, or `-c` config settings.\n> +\n> +Trace2 will try to load the following system configuration settings\n> +and then read the corresponding environment variables at startup.\n> +\n> +....\n> +---------------------------------------------------\n> +trace2.normalTarget          GIT_TR2\n> +trace2.normalBrief           GIT_TR2_BRIEF\n> +\n> +trace2.perfTarget            GIT_TR2_PERF\n> +trace2.perfBrief             GIT_TR2_PERF_BRIEF\n> +\n> +trace2.eventTarget           GIT_TR2_EVENT\n> +trace2.eventBrief            GIT_TR2_EVENT_BRIEF\n> +trace2.eventNesting          GIT_TR2_EVENT_NESTING\n> +\n> +trace2.configParams          GIT_TR2_CONFIG_PARAMS\n> +\n> +trace2.destinationDebug      GIT_TR2_DST_DEBUG\n> +---------------------------------------------------\n> +....\n> +\n> +\n>  == Trace2 API\n>\n>  All public Trace2 functions and macros are defined in `trace2.h` and\n> diff --git a/Makefile b/Makefile\n> index 3e03290d8f..9ddfa3dfe7 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o\n>  LIB_OBJS += trace2/tr2_cmd_name.o\n>  LIB_OBJS += trace2/tr2_dst.o\n>  LIB_OBJS += trace2/tr2_sid.o\n> +LIB_OBJS += trace2/tr2_sysenv.o\n>  LIB_OBJS += trace2/tr2_tbuf.o\n>  LIB_OBJS += trace2/tr2_tgt_event.o\n>  LIB_OBJS += trace2/tr2_tgt_normal.o\n> diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh\n> index 03a0aedb1d..5d4c04ed30 100755\n> --- a/t/t0210-trace2-normal.sh\n> +++ b/t/t0210-trace2-normal.sh\n> @@ -1,5 +1,14 @@\n>  #!/bin/sh\n>\n> +# Disable loading of Trace2 settings from the system config\n> +# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n> +GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n> +\n> +# Turn off any inherited trace2 settings for this test.\n> +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n> +unset GIT_TR2_BRIEF\n> +unset GIT_TR2_CONFIG_PARAMS\n> +\n>  test_description='test trace2 facility (normal target)'\n>  . ./test-lib.sh\n>\n> @@ -15,11 +24,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n>  # Warning: So you may see extra lines in artifact files when\n>  # Warning: interactively debugging.\n>\n> -# Turn off any inherited trace2 settings for this test.\n> -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n> -unset GIT_TR2_BRIEF\n> -unset GIT_TR2_CONFIG_PARAMS\n> -\n>  V=$(git version | sed -e 's/^git version //') && export V\n>\n>  # There are multiple trace2 targets: normal, perf, and event.\n> @@ -132,4 +136,31 @@ test_expect_success 'normal stream, error event' '\n>  \ttest_cmp expect actual\n>  '\n>\n> +# Now test using system config by using a mocked up config file\n> +# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n> +# GIT_TR2* environment variables.\n> +\n> +unset GIT_TR2_BRIEF\n> +\n> +MOCK=./mock_system_config\n> +\n> +test_expect_success 'setup mocked /etc/gitconfig' '\n> +\tgit config --file $MOCK trace2.normalTarget \"$(pwd)/trace.normal\" &&\n> +\tgit config --file $MOCK trace2.normalBrief 1\n> +'\n> +\n> +test_expect_success 'using mock, normal stream, return code 0' '\n> +\ttest_when_finished \"rm trace.normal actual expect\" &&\n> +\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n> +\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n> +\tcat >expect <<-EOF &&\n> +\t\tversion $V\n> +\t\tstart _EXE_ trace2 001return 0\n> +\t\tcmd_name trace2 (trace2)\n> +\t\texit elapsed:_TIME_ code:0\n> +\t\tatexit elapsed:_TIME_ code:0\n> +\tEOF\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_done\n> diff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\n> index c9694b29f7..abe35b2186 100755\n> --- a/t/t0211-trace2-perf.sh\n> +++ b/t/t0211-trace2-perf.sh\n> @@ -1,5 +1,14 @@\n>  #!/bin/sh\n>\n> +# Disable loading of Trace2 settings from the system config\n> +# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n> +GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n> +\n> +# Turn off any inherited trace2 settings for this test.\n> +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n> +unset GIT_TR2_PERF_BRIEF\n> +unset GIT_TR2_CONFIG_PARAMS\n> +\n>  test_description='test trace2 facility (perf target)'\n>  . ./test-lib.sh\n>\n> @@ -15,11 +24,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n>  # Warning: So you may see extra lines in artifact files when\n>  # Warning: interactively debugging.\n>\n> -# Turn off any inherited trace2 settings for this test.\n> -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n> -unset GIT_TR2_PERF_BRIEF\n> -unset GIT_TR2_CONFIG_PARAMS\n> -\n>  V=$(git version | sed -e 's/^git version //') && export V\n>\n>  # There are multiple trace2 targets: normal, perf, and event.\n> @@ -150,4 +154,31 @@ test_expect_success 'perf stream, child processes' '\n>  \ttest_cmp expect actual\n>  '\n>\n> +# Now test using system config by using a mocked up config file\n> +# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n> +# GIT_TR2* environment variables.\n> +\n> +unset GIT_TR2_PERF_BRIEF\n> +\n> +MOCK=./mock_system_config\n> +\n> +test_expect_success 'setup mocked /etc/gitconfig' '\n> +\tgit config --file $MOCK trace2.perfTarget \"$(pwd)/trace.perf\" &&\n> +\tgit config --file $MOCK trace2.perfBrief 1\n> +'\n> +\n> +test_expect_success 'using mock, perf stream, return code 0' '\n> +\ttest_when_finished \"rm trace.perf actual expect\" &&\n> +\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n> +\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n> +\tcat >expect <<-EOF &&\n> +\t\td0|main|version|||||$V\n> +\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n> +\t\td0|main|cmd_name|||||trace2 (trace2)\n> +\t\td0|main|exit||_T_ABS_|||code:0\n> +\t\td0|main|atexit||_T_ABS_|||code:0\n> +\tEOF\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_done\n> diff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh\n> index 028b6c5671..c535496261 100755\n> --- a/t/t0212-trace2-event.sh\n> +++ b/t/t0212-trace2-event.sh\n> @@ -1,5 +1,14 @@\n>  #!/bin/sh\n>\n> +# Disable loading of Trace2 settings from the system config\n> +# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n> +GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n> +\n> +# Turn off any inherited trace2 settings for this test.\n> +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n> +unset GIT_TR2_BARE\n> +unset GIT_TR2_CONFIG_PARAMS\n> +\n>  test_description='test trace2 facility'\n>  . ./test-lib.sh\n>\n> @@ -17,11 +26,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n>  # Warning: So you may see extra lines in artifact files when\n>  # Warning: interactively debugging.\n>\n> -# Turn off any inherited trace2 settings for this test.\n> -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n> -unset GIT_TR2_BARE\n> -unset GIT_TR2_CONFIG_PARAMS\n> -\n>  V=$(git version | sed -e 's/^git version //') && export V\n>\n>  # There are multiple trace2 targets: normal, perf, and event.\n> @@ -233,4 +237,42 @@ test_expect_success JSON_PP 'basic trace2_data' '\n>  \ttest_cmp expect actual\n>  '\n>\n> +# Now test using system config by using a mocked up config file\n> +# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n> +# GIT_TR2* environment variables.\n> +\n> +MOCK=./mock_system_config\n> +\n> +test_expect_success 'setup mocked /etc/gitconfig' '\n> +\tgit config --file $MOCK trace2.eventTarget \"$(pwd)/trace.event\"\n> +'\n> +\n> +test_expect_success JSON_PP 'using mock, event stream, error event' '\n> +\ttest_when_finished \"rm trace.event actual expect\" &&\n> +\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 003error \"hello world\" \"this is a test\" &&\n> +\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n> +\tsed -e \"s/^|//\" >expect <<-EOF &&\n> +\t|VAR1 = {\n> +\t|  \"_SID0_\":{\n> +\t|    \"argv\":[\n> +\t|      \"_EXE_\",\n> +\t|      \"trace2\",\n> +\t|      \"003error\",\n> +\t|      \"hello world\",\n> +\t|      \"this is a test\"\n> +\t|    ],\n> +\t|    \"errors\":[\n> +\t|      \"%s\",\n> +\t|      \"%s\"\n> +\t|    ],\n> +\t|    \"exit_code\":0,\n> +\t|    \"hierarchy\":\"trace2\",\n> +\t|    \"name\":\"trace2\",\n> +\t|    \"version\":\"$V\"\n> +\t|  }\n> +\t|};\n> +\tEOF\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_done\n> diff --git a/trace2.c b/trace2.c\n> index 1c180062dd..490b3f071e 100644\n> --- a/trace2.c\n> +++ b/trace2.c\n> @@ -10,6 +10,7 @@\n>  #include \"trace2/tr2_cmd_name.h\"\n>  #include \"trace2/tr2_dst.h\"\n>  #include \"trace2/tr2_sid.h\"\n> +#include \"trace2/tr2_sysenv.h\"\n>  #include \"trace2/tr2_tgt.h\"\n>  #include \"trace2/tr2_tls.h\"\n>\n> @@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)\n>  \ttr2_sid_release();\n>  \ttr2_cmd_name_release();\n>  \ttr2_cfg_free_patterns();\n> +\ttr2_sysenv_release();\n>\n>  \ttrace2_enabled = 0;\n>  }\n> @@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)\n>  \tif (trace2_enabled)\n>  \t\treturn;\n>\n> +\ttr2_sysenv_load();\n> +\n>  \tif (!tr2_tgt_want_builtins())\n>  \t\treturn;\n>  \ttrace2_enabled = 1;\n> diff --git a/trace2.h b/trace2.h\n> index 8f89e70c44..cda8349058 100644\n> --- a/trace2.h\n> +++ b/trace2.h\n> @@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n>\n>  /*\n>   * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n> - * targets are enabled in the environment.  Emits a 'version' event.\n> + * targets are enabled in the system config or the environment.\n> + * Emits a 'version' event.\n>   *\n>   * Cleanup/Termination is handled automatically by a registered\n>   * atexit() routine.\n> @@ -125,8 +126,8 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n>   * Emit one or more 'def_param' events for \"interesting\" configuration\n>   * settings.\n>   *\n> - * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n> - * list of patterns considered important.  For example:\n> + * Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns\n> + * configured important.  For example:\n>   *\n>   *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n>   *\n> diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\n> index b329921ac5..caa7f06948 100644\n> --- a/trace2/tr2_cfg.c\n> +++ b/trace2/tr2_cfg.c\n> @@ -1,8 +1,7 @@\n>  #include \"cache.h\"\n>  #include \"config.h\"\n> -#include \"tr2_cfg.h\"\n> -\n> -#define TR2_ENVVAR_CFG_PARAM \"GIT_TR2_CONFIG_PARAMS\"\n> +#include \"trace2/tr2_cfg.h\"\n> +#include \"trace2/tr2_sysenv.h\"\n>\n>  static struct strbuf **tr2_cfg_patterns;\n>  static int tr2_cfg_count_patterns;\n> @@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)\n>  \t\treturn tr2_cfg_count_patterns;\n>  \ttr2_cfg_loaded = 1;\n>\n> -\tenvvar = getenv(TR2_ENVVAR_CFG_PARAM);\n> +\tenvvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM);\n>  \tif (!envvar || !*envvar)\n>  \t\treturn tr2_cfg_count_patterns;\n>\n> diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c\n> index fd490a43ad..575cd69aa9 100644\n> --- a/trace2/tr2_dst.c\n> +++ b/trace2/tr2_dst.c\n> @@ -1,5 +1,6 @@\n>  #include \"cache.h\"\n>  #include \"trace2/tr2_dst.h\"\n> +#include \"trace2/tr2_sysenv.h\"\n>\n>  /*\n>   * If a Trace2 target cannot be opened for writing, we should issue a\n> @@ -7,17 +8,13 @@\n>   * or socket and beyond the user's control -- especially since every\n>   * git command (and sub-command) will print the message.  So we silently\n>   * eat these warnings and just discard the trace data.\n> - *\n> - * Enable the following environment variable to see these warnings.\n>   */\n> -#define TR2_ENVVAR_DST_DEBUG \"GIT_TR2_DST_DEBUG\"\n> -\n>  static int tr2_dst_want_warning(void)\n>  {\n>  \tstatic int tr2env_dst_debug = -1;\n>\n>  \tif (tr2env_dst_debug == -1) {\n> -\t\tconst char *env_value = getenv(TR2_ENVVAR_DST_DEBUG);\n> +\t\tconst char *env_value = tr2_sysenv_get(TR2_SYSENV_DST_DEBUG);\n>  \t\tif (!env_value || !*env_value)\n>  \t\t\ttr2env_dst_debug = 0;\n>  \t\telse\n> @@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)\n>  \tif (fd == -1) {\n>  \t\tif (tr2_dst_want_warning())\n>  \t\t\twarning(\"trace2: could not open '%s' for '%s' tracing: %s\",\n> -\t\t\t\ttgt_value, dst->env_var_name, strerror(errno));\n> +\t\t\t\ttgt_value,\n> +\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n> +\t\t\t\tstrerror(errno));\n>\n>  \t\ttr2_dst_trace_disable(dst);\n>  \t\treturn 0;\n> @@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n>  \tif (!path || !*path) {\n>  \t\tif (tr2_dst_want_warning())\n>  \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n> -\t\t\t\ttgt_value, dst->env_var_name);\n> +\t\t\t\ttgt_value, tr2_sysenv_display_name(dst->sysenv_var));\n>\n>  \t\ttr2_dst_trace_disable(dst);\n>  \t\treturn 0;\n> @@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n>  \t    strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {\n>  \t\tif (tr2_dst_want_warning())\n>  \t\t\twarning(\"trace2: invalid AF_UNIX path '%s' for '%s' tracing\",\n> -\t\t\t\tpath, dst->env_var_name);\n> +\t\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var));\n>\n>  \t\ttr2_dst_trace_disable(dst);\n>  \t\treturn 0;\n> @@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n>  error:\n>  \tif (tr2_dst_want_warning())\n>  \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n> -\t\t\tpath, dst->env_var_name, strerror(e));\n> +\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var), strerror(e));\n>\n>  \ttr2_dst_trace_disable(dst);\n>  \treturn 0;\n> @@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,\n>  \tstruct strbuf buf = STRBUF_INIT;\n>\n>  \tstrbuf_addf(&buf, \"trace2: unknown value for '%s': '%s'\",\n> -\t\t    dst->env_var_name, tgt_value);\n> +\t\t    tr2_sysenv_display_name(dst->sysenv_var), tgt_value);\n>  \twarning(\"%s\", buf.buf);\n>\n>  \tstrbuf_release(&buf);\n> @@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst)\n>\n>  \tdst->initialized = 1;\n>\n> -\ttgt_value = getenv(dst->env_var_name);\n> +\ttgt_value = tr2_sysenv_get(dst->sysenv_var);\n>\n>  \tif (!tgt_value || !strcmp(tgt_value, \"\") || !strcmp(tgt_value, \"0\") ||\n>  \t    !strcasecmp(tgt_value, \"false\")) {\n> @@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)\n>  \t\treturn;\n>\n>  \tif (tr2_dst_want_warning())\n> -\t\twarning(\"unable to write trace to '%s': %s\", dst->env_var_name,\n> +\t\twarning(\"unable to write trace to '%s': %s\",\n> +\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n>  \t\t\tstrerror(errno));\n>  \ttr2_dst_trace_disable(dst);\n>  }\n> diff --git a/trace2/tr2_dst.h b/trace2/tr2_dst.h\n> index 9a64f05b02..3adf3bac13 100644\n> --- a/trace2/tr2_dst.h\n> +++ b/trace2/tr2_dst.h\n> @@ -2,9 +2,10 @@\n>  #define TR2_DST_H\n>\n>  struct strbuf;\n> +#include \"trace2/tr2_sysenv.h\"\n>\n>  struct tr2_dst {\n> -\tconst char *const env_var_name;\n> +\tenum tr2_sysenv_variable sysenv_var;\n>  \tint fd;\n>  \tunsigned int initialized : 1;\n>  \tunsigned int need_close : 1;\n> diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\n> new file mode 100644\n> index 0000000000..656613e371\n> --- /dev/null\n> +++ b/trace2/tr2_sysenv.c\n> @@ -0,0 +1,125 @@\n> +#include \"cache.h\"\n> +#include \"config.h\"\n> +#include \"dir.h\"\n> +#include \"tr2_sysenv.h\"\n> +\n> +/*\n> + * Each entry represents a trace2 setting.\n> + * See Documentation/technical/api-trace2.txt\n> + */\n> +struct tr2_sysenv_entry {\n> +\tconst char *env_var_name;\n> +\tconst char *git_config_name;\n> +\n> +\tchar *value;\n> +\tunsigned int getenv_called : 1;\n> +};\n> +\n> +/*\n> + * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n> + * These strings are constant and must match the published names as\n> + * described in the documentation.\n> + *\n> + * We do not define entries for the GIT_TR2_PARENT_* environment\n> + * variables because they are transient and used to pass information\n> + * from parent to child git processes, rather than settings.\n> + */\n> +/* clang-format off */\n> +static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n> +\t{ \"GIT_TR2_CONFIG_PARAMS\",   \"trace2.configparams\"     },\n> +\n> +\t{ \"GIT_TR2_DST_DEBUG\",       \"trace2.destinationdebug\" },\n> +\n> +\t{ \"GIT_TR2\",                 \"trace2.normaltarget\"     },\n> +\t{ \"GIT_TR2_BRIEF\",           \"trace2.normalbrief\"      },\n> +\n> +\t{ \"GIT_TR2_EVENT\",           \"trace2.eventtarget\"      },\n> +\t{ \"GIT_TR2_EVENT_BRIEF\",     \"trace2.eventbrief\"       },\n> +\t{ \"GIT_TR2_EVENT_NESTING\",   \"trace2.eventnesting\"     },\n> +\n> +\t{ \"GIT_TR2_PERF\",            \"trace2.perftarget\"       },\n> +\t{ \"GIT_TR2_PERF_BRIEF\",      \"trace2.perfbrief\"        },\n> +};\n> +/* clang-format on */\n> +\n> +static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n> +{\n> +\tint k;\n> +\n\nI added:\n\n\tif (!starts_with(key, \"trace2.\"))\n\t\treturn 0;\n\nHere, and everything works as expected. I think that's a good\nidea. Makes this O(n) over N config keys instead of O(n*x) where x = num\nentries in tr2_sysenv_settings.\n\n> +\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n> +\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n> +\t\t\tfree(tr2_sysenv_settings[k].value);\n> +\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n> +\t\t\treturn 0;\n> +\t\t}\n> +\t}\n> +\n> +\treturn 0;\n> +}\n> +\n> +/*\n> + * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n> + * unless we were built with a runtime-prefix).  These are intended to\n> + * define the default values for Trace2 as requested by the administrator.\n> + */\n> +void tr2_sysenv_load(void)\n> +{\n> +\tconst char *system_config_pathname;\n> +\tconst char *test_pathname;\n> +\n> +\tsystem_config_pathname = git_etc_gitconfig();\n> +\n> +\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n> +\tif (test_pathname) {\n> +\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n> +\t\t\treturn; /* disable use of system config */\n> +\n> +\t\t/* mock it with given test file */\n> +\t\tsystem_config_pathname = test_pathname;\n> +\t}\n> +\n> +\tif (file_exists(system_config_pathname))\n> +\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n> +\t\t\t\t     NULL);\n\nMaybe this isn't worth it, but this \"file_exists\" thing is something we\ncould abstract in the config machinery (or maybe passing via\n\"config_options\" makes more sense):\n\n    diff --git a/config.c b/config.c\n    index 0f0cdd8c0f..ea625a508f 100644\n    --- a/config.c\n    +++ b/config.c\n    @@ -1549,12 +1549,15 @@ static int git_config_from_stdin(config_fn_t fn, void *data)\n\n     int git_config_from_file_with_options(config_fn_t fn, const char *filename,\n     \t\t\t\t      void *data,\n    -\t\t\t\t      const struct config_options *opts)\n    +\t\t\t\t      const struct config_options *opts,\n    +\t\t\t\t      int or_warn)\n     {\n     \tint ret = -1;\n     \tFILE *f;\n\n    -\tf = fopen_or_warn(filename, \"r\");\n    +\tf = or_warn\n    +\t\t? fopen_or_warn(filename, \"r\")\n    +\t\t: fopen(filename, \"r\");\n     \tif (f) {\n     \t\tret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename,\n     \t\t\t\t\t  filename, f, data, opts);\n    @@ -1565,7 +1568,7 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,\n\n     int git_config_from_file(config_fn_t fn, const char *filename, void *data)\n     {\n    -\treturn git_config_from_file_with_options(fn, filename, data, NULL);\n    +\treturn git_config_from_file_with_options(fn, filename, data, NULL, 1);\n     }\n\n     int git_config_from_mem(config_fn_t fn,\n    @@ -2787,7 +2790,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,\n     \t\t */\n     \t\tif (git_config_from_file_with_options(store_aux,\n     \t\t\t\t\t\t      config_filename,\n    -\t\t\t\t\t\t      &store, &opts)) {\n    +\t\t\t\t\t\t      &store, &opts, 1)) {\n     \t\t\terror(_(\"invalid config file %s\"), config_filename);\n     \t\t\tret = CONFIG_INVALID_FILE;\n     \t\t\tgoto out_free;\n    diff --git a/config.h b/config.h\n    index ee5d3fa7b4..52e93e6cdc 100644\n    --- a/config.h\n    +++ b/config.h\n    @@ -72,7 +72,8 @@ extern int git_default_config(const char *, const char *, void *);\n     extern int git_config_from_file(config_fn_t fn, const char *, void *);\n     extern int git_config_from_file_with_options(config_fn_t fn, const char *,\n     \t\t\t\t\t     void *,\n    -\t\t\t\t\t     const struct config_options *);\n    +\t\t\t\t\t     const struct config_options *,\n    +\t\t\t\t\t     int);\n     extern int git_config_from_mem(config_fn_t fn,\n     \t\t\t       const enum config_origin_type,\n     \t\t\t       const char *name,\n    diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\n    index 656613e371..25a9c19d20 100644\n    --- a/trace2/tr2_sysenv.c\n    +++ b/trace2/tr2_sysenv.c\n    @@ -78,9 +81,9 @@ void tr2_sysenv_load(void)\n     \t\tsystem_config_pathname = test_pathname;\n     \t}\n\n    -\tif (file_exists(system_config_pathname))\n    -\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n    -\t\t\t\t     NULL);\n    +\tgit_config_from_file_with_options(tr2_sysenv_cb,\n    +\t\t\t\t\t  system_config_pathname, NULL, NULL,\n    +\t\t\t\t\t  0);\n     }\n\n     /*\n\n\n> +}\n> +\n> +/*\n> + * Return the value for the requested setting.  Start with the /etc/gitconfig\n> + * value and allow the corresponding environment variable to override it.\n> + */\n> +const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n> +{\n> +\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n> +\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n> +\n> +\tif (!tr2_sysenv_settings[var].getenv_called) {\n> +\t\tconst char *v = getenv(tr2_sysenv_settings[var].env_var_name);\n> +\t\tif (v && *v) {\n> +\t\t\tfree(tr2_sysenv_settings[var].value);\n> +\t\t\ttr2_sysenv_settings[var].value = xstrdup(v);\n> +\t\t}\n> +\t\ttr2_sysenv_settings[var].getenv_called = 1;\n> +\t}\n> +\n> +\treturn tr2_sysenv_settings[var].value;\n> +}\n> +\n> +/*\n> + * Return a friendly name for this setting that is suitable for printing\n> + * in an error messages.\n> + */\n> +const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var)\n> +{\n> +\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n> +\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n> +\n> +\treturn tr2_sysenv_settings[var].env_var_name;\n> +}\n> +\n> +void tr2_sysenv_release(void)\n> +{\n> +\tint k;\n> +\n> +\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++)\n> +\t\tfree(tr2_sysenv_settings[k].value);\n> +}\n> diff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h\n> new file mode 100644\n> index 0000000000..369b20bd87\n> --- /dev/null\n> +++ b/trace2/tr2_sysenv.h\n> @@ -0,0 +1,36 @@\n> +#ifndef TR2_SYSENV_H\n> +#define TR2_SYSENV_H\n> +\n> +/*\n> + * The Trace2 settings that can be loaded from /etc/gitconfig\n> + * and/or user environment variables.\n> + *\n> + * Note that this set does not contain any of the transient\n> + * environment variables used to pass information from parent\n> + * to child git processes, such \"GIT_TR2_PARENT_SID\".\n> + */\n> +enum tr2_sysenv_variable {\n> +\tTR2_SYSENV_CFG_PARAM = 0,\n> +\n> +\tTR2_SYSENV_DST_DEBUG,\n> +\n> +\tTR2_SYSENV_NORMAL,\n> +\tTR2_SYSENV_NORMAL_BRIEF,\n> +\n> +\tTR2_SYSENV_EVENT,\n> +\tTR2_SYSENV_EVENT_BRIEF,\n> +\tTR2_SYSENV_EVENT_NESTING,\n> +\n> +\tTR2_SYSENV_PERF,\n> +\tTR2_SYSENV_PERF_BRIEF,\n> +\n> +\tTR2_SYSENV_MUST_BE_LAST\n> +};\n> +\n> +void tr2_sysenv_load(void);\n> +\n> +const char *tr2_sysenv_get(enum tr2_sysenv_variable);\n> +const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);\n> +void tr2_sysenv_release(void);\n> +\n> +#endif /* TR2_SYSENV_H */\n> diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\n> index 89a4d3ae9a..bb6e323953 100644\n> --- a/trace2/tr2_tgt_event.c\n> +++ b/trace2/tr2_tgt_event.c\n> @@ -6,10 +6,11 @@\n>  #include \"trace2/tr2_dst.h\"\n>  #include \"trace2/tr2_tbuf.h\"\n>  #include \"trace2/tr2_sid.h\"\n> +#include \"trace2/tr2_sysenv.h\"\n>  #include \"trace2/tr2_tgt.h\"\n>  #include \"trace2/tr2_tls.h\"\n>\n> -static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n> +static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };\n>\n>  /*\n>   * The version number of the JSON data generated by the EVENT target\n> @@ -28,17 +29,15 @@ static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n>   * are primarily intended for the performance target during debugging.\n>   *\n>   * Some of the outer-most messages, however, may be of interest to the\n> - * event target.  Set this environment variable to a larger integer for\n> - * more detail in the event target.\n> + * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase\n> + * region details in the event target.\n>   */\n> -#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n>  static int tr2env_event_nesting_wanted = 2;\n>\n>  /*\n> - * Set this environment variable to true to omit the <time>, <file>, and\n> + * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and\n>   * <line> fields from most events.\n>   */\n> -#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n>  static int tr2env_event_brief;\n>\n>  static int fn_init(void)\n> @@ -46,17 +45,17 @@ static int fn_init(void)\n>  \tint want = tr2_dst_trace_want(&tr2dst_event);\n>  \tint want_nesting;\n>  \tint want_brief;\n> -\tchar *nesting;\n> -\tchar *brief;\n> +\tconst char *nesting;\n> +\tconst char *brief;\n>\n>  \tif (!want)\n>  \t\treturn want;\n>\n> -\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n> +\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n>  \tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n>  \t\ttr2env_event_nesting_wanted = want_nesting;\n>\n> -\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n> +\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n>  \tif (brief && ((want_brief = atoi(brief)) > 0))\n>  \t\ttr2env_event_brief = want_brief;\n\nA lot of this pre-dates this patch, but I wonder if the whole of trace2\ncouldn't make more use of config.c's bool parsing for things like\nthese. Maybe by having a \"cfg_type\" enum & parsed_value void* in\ntr2_sysenv_entry?\n\n> diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\n> index 57f3e18f5b..3364223805 100644\n> --- a/trace2/tr2_tgt_normal.c\n> +++ b/trace2/tr2_tgt_normal.c\n> @@ -4,19 +4,19 @@\n>  #include \"quote.h\"\n>  #include \"version.h\"\n>  #include \"trace2/tr2_dst.h\"\n> +#include \"trace2/tr2_sysenv.h\"\n>  #include \"trace2/tr2_tbuf.h\"\n>  #include \"trace2/tr2_tgt.h\"\n>  #include \"trace2/tr2_tls.h\"\n>\n> -static struct tr2_dst tr2dst_normal = { \"GIT_TR2\", 0, 0, 0 };\n> +static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 };\n>\n>  /*\n> - * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n> + * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the \"<time> <file>:<line>\"\n>   * fields from each line written to the builtin normal target.\n>   *\n>   * Unit tests may want to use this to help with testing.\n>   */\n> -#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n>  static int tr2env_normal_brief;\n>\n>  #define TR2FMT_NORMAL_FL_WIDTH (50)\n> @@ -25,12 +25,12 @@ static int fn_init(void)\n>  {\n>  \tint want = tr2_dst_trace_want(&tr2dst_normal);\n>  \tint want_brief;\n> -\tchar *brief;\n> +\tconst char *brief;\n>\n>  \tif (!want)\n>  \t\treturn want;\n>\n> -\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n> +\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n>  \tif (brief && *brief &&\n>  \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n>  \t\ttr2env_normal_brief = want_brief;\n\n\n> diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\n> index 9c3b4d8a0f..1ad781c32e 100644\n> --- a/trace2/tr2_tgt_perf.c\n> +++ b/trace2/tr2_tgt_perf.c\n> @@ -6,19 +6,19 @@\n>  #include \"json-writer.h\"\n>  #include \"trace2/tr2_dst.h\"\n>  #include \"trace2/tr2_sid.h\"\n> +#include \"trace2/tr2_sysenv.h\"\n>  #include \"trace2/tr2_tbuf.h\"\n>  #include \"trace2/tr2_tgt.h\"\n>  #include \"trace2/tr2_tls.h\"\n>\n> -static struct tr2_dst tr2dst_perf = { \"GIT_TR2_PERF\", 0, 0, 0 };\n> +static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 };\n>\n>  /*\n> - * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n> + * Use TR2_SYSENV_PERF_BRIEF to omit the \"<time> <file>:<line>\"\n>   * fields from each line written to the builtin performance target.\n>   *\n>   * Unit tests may want to use this to help with testing.\n>   */\n> -#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n>  static int tr2env_perf_brief;\n>\n>  #define TR2FMT_PERF_FL_WIDTH (50)\n> @@ -36,14 +36,14 @@ static int fn_init(void)\n>  {\n>  \tint want = tr2_dst_trace_want(&tr2dst_perf);\n>  \tint want_brief;\n> -\tchar *brief;\n> +\tconst char *brief;\n>\n>  \tif (!want)\n>  \t\treturn want;\n>\n>  \tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n>\n> -\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n> +\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n>  \tif (brief && *brief &&\n>  \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n>  \t\ttr2env_perf_brief = want_brief;\n"},{"id":"372642","messageId":"f09d1d23-865f-fc35-250b-141a4d049029@jeffhostetler.com","threadId":"50834","inReplyTo":"87wokj9ic1.fsf@evledraar.gmail.com","subject":"Re: [PATCH 4/4] trace2: use system config for default trace2 settings","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-03-28T18:50:08Z","receivedAt":"2019-03-28T18:50:12Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 3/28/2019 10:36 AM, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Thu, Mar 28 2019, Jeff Hostetler via GitGitGadget wrote:\n> \n> Thanks for working on this!\n> \n> Haven't given this any deep testing. Just some observations:\n> \n>> From: Jeff Hostetler <jeffhost@microsoft.com>\n>>\n>> Teach git to read the system config (usually \"/etc/gitconfig\") for\n>> default Trace2 settings.  This allows system-wide Trace2 settings to\n>> be installed and inherited to make it easier to manage a collection of\n>> systems.\n[...]\n\n>> diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\n>> new file mode 100644\n>> index 0000000000..656613e371\n>> --- /dev/null\n[...]\n\n>> +/* clang-format off */\n>> +static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n>> +\t{ \"GIT_TR2_CONFIG_PARAMS\",   \"trace2.configparams\"     },\n>> +\n>> +\t{ \"GIT_TR2_DST_DEBUG\",       \"trace2.destinationdebug\" },\n>> +\n>> +\t{ \"GIT_TR2\",                 \"trace2.normaltarget\"     },\n>> +\t{ \"GIT_TR2_BRIEF\",           \"trace2.normalbrief\"      },\n>> +\n>> +\t{ \"GIT_TR2_EVENT\",           \"trace2.eventtarget\"      },\n>> +\t{ \"GIT_TR2_EVENT_BRIEF\",     \"trace2.eventbrief\"       },\n>> +\t{ \"GIT_TR2_EVENT_NESTING\",   \"trace2.eventnesting\"     },\n>> +\n>> +\t{ \"GIT_TR2_PERF\",            \"trace2.perftarget\"       },\n>> +\t{ \"GIT_TR2_PERF_BRIEF\",      \"trace2.perfbrief\"        },\n>> +};\n>> +/* clang-format on */\n>> +\n>> +static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n>> +{\n>> +\tint k;\n>> +\n> \n> I added:\n> \n> \tif (!starts_with(key, \"trace2.\"))\n> \t\treturn 0;\n> \n> Here, and everything works as expected. I think that's a good\n> idea. Makes this O(n) over N config keys instead of O(n*x) where x = num\n> entries in tr2_sysenv_settings.\n\nGood idea.  Thanks!\n\n> \n>> +\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n>> +\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n>> +\t\t\tfree(tr2_sysenv_settings[k].value);\n>> +\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n>> +\t\t\treturn 0;\n>> +\t\t}\n>> +\t}\n>> +\n>> +\treturn 0;\n>> +}\n>> +\n>> +/*\n>> + * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n>> + * unless we were built with a runtime-prefix).  These are intended to\n>> + * define the default values for Trace2 as requested by the administrator.\n>> + */\n>> +void tr2_sysenv_load(void)\n>> +{\n>> +\tconst char *system_config_pathname;\n>> +\tconst char *test_pathname;\n>> +\n>> +\tsystem_config_pathname = git_etc_gitconfig();\n>> +\n>> +\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n>> +\tif (test_pathname) {\n>> +\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n>> +\t\t\treturn; /* disable use of system config */\n>> +\n>> +\t\t/* mock it with given test file */\n>> +\t\tsystem_config_pathname = test_pathname;\n>> +\t}\n>> +\n>> +\tif (file_exists(system_config_pathname))\n>> +\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n>> +\t\t\t\t     NULL);\n> \n> Maybe this isn't worth it, but this \"file_exists\" thing is something we\n> could abstract in the config machinery (or maybe passing via\n> \"config_options\" makes more sense):\n[...]\n\nThis is a good idea, but I think I'll save this for a future effort\nrather than add it to the current patch series.  It just seems outside\nof my scope right now and adds to the footprint of this series.\n\n[...]\n>>\n>> -\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n>> +\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n>>   \tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n>>   \t\ttr2env_event_nesting_wanted = want_nesting;\n>>\n>> -\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n>> +\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n>>   \tif (brief && ((want_brief = atoi(brief)) > 0))\n>>   \t\ttr2env_event_brief = want_brief;\n> \n> A lot of this pre-dates this patch, but I wonder if the whole of trace2\n> couldn't make more use of config.c's bool parsing for things like\n> these. Maybe by having a \"cfg_type\" enum & parsed_value void* in\n> tr2_sysenv_entry?\n\nI converted the \"brief\" instances in the normal and perf targets to\nuse git_parse_maybe_bool() already, but I missed this one.\n\nThe nesting one above is actually an integer value rather than a bool.\nI'll rename the variables in the re-roll to clarify that.\n\n\n[...]\n>> -\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n>> +\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n>>   \tif (brief && *brief &&\n>>   \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n>>   \t\ttr2env_normal_brief = want_brief;\n[...]\n>> -\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n>> +\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n>>   \tif (brief && *brief &&\n>>   \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n>>   \t\ttr2env_perf_brief = want_brief;\n\n\nThanks for the review.\nI'll push up another version shortly.\n\nJeff\n"},{"id":"372648","messageId":"20190328212814.GB60888@google.com","threadId":"50834","inReplyTo":"7e0d4e20fbb3abbc787bc216d2c4bd8c18860aed.1553779851.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 4/4] trace2: use system config for default trace2 settings","fromName":"Josh Steadmon","fromEmail":"steadmon@google.com","sentAt":"2019-03-28T21:28:14Z","receivedAt":"2019-03-28T21:28:26Z","isPatch":true,"sender":{"key":"steadmon@google.com","avatar":"https://avatars.githubusercontent.com/u/2654920?v=4"},"body":"One quick comment:\n\nOn 2019.03.28 06:31, Jeff Hostetler via GitGitGadget wrote:\n[...]\n> diff --git a/trace2.h b/trace2.h\n> index 8f89e70c44..cda8349058 100644\n> --- a/trace2.h\n> +++ b/trace2.h\n> @@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n>  \n>  /*\n>   * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n> - * targets are enabled in the environment.  Emits a 'version' event.\n> + * targets are enabled in the system config or the environment.\n> + * Emits a 'version' event.\n>   *\n>   * Cleanup/Termination is handled automatically by a registered\n>   * atexit() routine.\n> @@ -125,8 +126,8 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n>   * Emit one or more 'def_param' events for \"interesting\" configuration\n>   * settings.\n>   *\n> - * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n> - * list of patterns considered important.  For example:\n> + * Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns\n> + * configured important.  For example:\n>   *\n>   *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n>   *\n\nLooks like the example needs to be updated with the new var name as\nwell.\n"},{"id":"372716","messageId":"pull.169.v2.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.git.gitgitgadget@gmail.com","subject":"[PATCH v2 0/7] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:24Z","receivedAt":"2019-03-29T17:04:28Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"Here is version 2. It addresses most the V1 comments WRT the system config\nchanges.\n\nIt also addresses the format and uniqueness of the SID as discussed in [1].\nThe SID now containes: the UTC date/time, part of SHA1 of the hostname, and\nthe PID and is formatted to make it safe for filenames.\n\nIt also contains (a somewhat unrelated platform-specific) commit to report\ntotal process memory usage at exit. This is helpful when looking for\nproblematic commands that might have scaling problems.\n\n[1] \nhttps://public-inbox.org/git/51e88650-8667-df1f-13ef-4537f2e70346@jeffhostetler.com/T/#m6b4e6f2b0374d5ba88de8d0350ce6bf51b28d7da\n\n\n----------------------------------------------------------------------------\n\nTeach git to load default Trace2 settings from the system config (usually\n\"/etc/gitconfig\"). The existing GIT_TR2_* environment variables can be used\nto override the new system defaults. It also includes a little startup\nrefactoring.\n\nNote: I found interactive testing of this feature to be awkward on some\nplatforms because of the use of prefix- or runtime-prefix-relative locations\nfor the system configuration. It was easy to accidentally use an officially\ninstalled version of git to set a system config variable in the official\nsystem config directory; and then when testing with the test version of git,\nthat value would not be seen because it was looking for the system config\nfile in a different directory.\n\nJeff Hostetler (7):\n  trace2: refactor setting process starting time\n  trace2: add absolute elapsed time to start event\n  trace2: find exec-dir before trace2 initialization\n  trace2: use system config for default trace2 settings\n  trace2: report peak memory usage of the process\n  trace2: clarify UTC datetime formatting\n  trace2: make SIDs more unique\n\n Documentation/technical/api-trace2.txt   |  66 +++++++++---\n Makefile                                 |   1 +\n common-main.c                            |   8 +-\n compat/mingw.c                           |   2 +\n compat/win32/trace2_win32_process_info.c |  50 ++++++++-\n t/t0210-trace2-normal.sh                 |  41 +++++++-\n t/t0211-trace2-perf.sh                   |  53 ++++++++--\n t/t0212-trace2-event.sh                  |  52 ++++++++-\n trace2.c                                 |  21 +++-\n trace2.h                                 |  43 ++++++--\n trace2/tr2_cfg.c                         |   7 +-\n trace2/tr2_dst.c                         |  24 ++---\n trace2/tr2_dst.h                         |   3 +-\n trace2/tr2_sid.c                         |  39 ++++++-\n trace2/tr2_sysenv.c                      | 128 +++++++++++++++++++++++\n trace2/tr2_sysenv.h                      |  36 +++++++\n trace2/tr2_tbuf.c                        |  20 +++-\n trace2/tr2_tbuf.h                        |   5 +-\n trace2/tr2_tgt.h                         |   1 +\n trace2/tr2_tgt_event.c                   |  53 +++++-----\n trace2/tr2_tgt_normal.c                  |  19 ++--\n trace2/tr2_tgt_perf.c                    |  23 ++--\n trace2/tr2_tls.c                         |  38 ++++---\n trace2/tr2_tls.h                         |   8 +-\n 24 files changed, 604 insertions(+), 137 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\n\nbase-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/169\n\nRange-diff vs v1:\n\n 1:  7f1a347322 = 1:  7f1a347322 trace2: refactor setting process starting time\n 2:  c15f783c26 = 2:  c15f783c26 trace2: add absolute elapsed time to start event\n 3:  d4023acde7 = 3:  d4023acde7 trace2: find exec-dir before trace2 initialization\n 4:  7e0d4e20fb ! 4:  d048f3ffb8 trace2: use system config for default trace2 settings\n     @@ -332,11 +332,16 @@\n        *\n      - * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n      - * list of patterns considered important.  For example:\n     -+ * Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns\n     -+ * configured important.  For example:\n     -  *\n     -  *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n     +- *\n     +- *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n     ++ * Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated\n     ++ * list of patterns configured important.  For example:\n     ++ *     git config --system trace2.configParams 'core.*,remote.*.url'\n     ++ * or:\n     ++ *     GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url\"\n        *\n     +  * Note: this routine does a read-only iteration on the config data\n     +  * (using read_early_config()), so it must not be called until enough\n      \n       diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\n       --- a/trace2/tr2_cfg.c\n     @@ -527,6 +532,9 @@\n      +{\n      +\tint k;\n      +\n     ++\tif (!starts_with(key, \"trace2.\"))\n     ++\t\treturn 0;\n     ++\n      +\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n      +\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n      +\t\t\tfree(tr2_sysenv_settings[k].value);\n     @@ -673,7 +681,8 @@\n      + * region details in the event target.\n        */\n      -#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n     - static int tr2env_event_nesting_wanted = 2;\n     +-static int tr2env_event_nesting_wanted = 2;\n     ++static int tr2env_event_max_nesting_levels = 2;\n       \n       /*\n      - * Set this environment variable to true to omit the <time>, <file>, and\n     @@ -681,12 +690,14 @@\n        * <line> fields from most events.\n        */\n      -#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n     - static int tr2env_event_brief;\n     +-static int tr2env_event_brief;\n     ++static int tr2env_event_be_brief;\n       \n       static int fn_init(void)\n     -@@\n     + {\n       \tint want = tr2_dst_trace_want(&tr2dst_event);\n     - \tint want_nesting;\n     +-\tint want_nesting;\n     ++\tint max_nesting;\n       \tint want_brief;\n      -\tchar *nesting;\n      -\tchar *brief;\n     @@ -697,15 +708,74 @@\n       \t\treturn want;\n       \n      -\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n     +-\tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n     +-\t\ttr2env_event_nesting_wanted = want_nesting;\n      +\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n     - \tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n     - \t\ttr2env_event_nesting_wanted = want_nesting;\n     ++\tif (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))\n     ++\t\ttr2env_event_max_nesting_levels = max_nesting;\n       \n      -\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n     +-\tif (brief && ((want_brief = atoi(brief)) > 0))\n     +-\t\ttr2env_event_brief = want_brief;\n      +\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n     - \tif (brief && ((want_brief = atoi(brief)) > 0))\n     - \t\ttr2env_event_brief = want_brief;\n     ++\tif (brief && *brief &&\n     ++\t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n     ++\t\ttr2env_event_be_brief = want_brief;\n       \n     + \treturn want;\n     + }\n     +@@\n     + \t/*\n     + \t * In brief mode, only emit <time> on these 2 event types.\n     + \t */\n     +-\tif (!tr2env_event_brief || !strcmp(event_name, \"version\") ||\n     ++\tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n     + \t    !strcmp(event_name, \"atexit\")) {\n     + \t\ttr2_tbuf_utc_time(&tb_now);\n     + \t\tjw_object_string(jw, \"time\", tb_now.buf);\n     + \t}\n     + \n     +-\tif (!tr2env_event_brief && file && *file) {\n     ++\tif (!tr2env_event_be_brief && file && *file) {\n     + \t\tjw_object_string(jw, \"file\", file);\n     + \t\tjw_object_intmax(jw, \"line\", line);\n     + \t}\n     +@@\n     + {\n     + \tconst char *event_name = \"region_enter\";\n     + \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n     +-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n     ++\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n     + \t\tstruct json_writer jw = JSON_WRITER_INIT;\n     + \n     + \t\tjw_object_begin(&jw, 0);\n     +@@\n     + {\n     + \tconst char *event_name = \"region_leave\";\n     + \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n     +-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n     ++\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n     + \t\tstruct json_writer jw = JSON_WRITER_INIT;\n     + \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n     + \n     +@@\n     + {\n     + \tconst char *event_name = \"data\";\n     + \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n     +-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n     ++\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n     + \t\tstruct json_writer jw = JSON_WRITER_INIT;\n     + \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n     + \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n     +@@\n     + {\n     + \tconst char *event_name = \"data_json\";\n     + \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n     +-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n     ++\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n     + \t\tstruct json_writer jw = JSON_WRITER_INIT;\n     + \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n     + \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n      \n       diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\n       --- a/trace2/tr2_tgt_normal.c\n     @@ -730,9 +800,11 @@\n        * Unit tests may want to use this to help with testing.\n        */\n      -#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n     - static int tr2env_normal_brief;\n     +-static int tr2env_normal_brief;\n     ++static int tr2env_normal_be_brief;\n       \n       #define TR2FMT_NORMAL_FL_WIDTH (50)\n     + \n      @@\n       {\n       \tint want = tr2_dst_trace_want(&tr2dst_normal);\n     @@ -747,7 +819,20 @@\n      +\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n       \tif (brief && *brief &&\n       \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n     - \t\ttr2env_normal_brief = want_brief;\n     +-\t\ttr2env_normal_brief = want_brief;\n     ++\t\ttr2env_normal_be_brief = want_brief;\n     + \n     + \treturn want;\n     + }\n     +@@\n     + {\n     + \tstrbuf_setlen(buf, 0);\n     + \n     +-\tif (!tr2env_normal_brief) {\n     ++\tif (!tr2env_normal_be_brief) {\n     + \t\tstruct tr2_tbuf tb_now;\n     + \n     + \t\ttr2_tbuf_local_time(&tb_now);\n      \n       diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\n       --- a/trace2/tr2_tgt_perf.c\n     @@ -772,9 +857,11 @@\n        * Unit tests may want to use this to help with testing.\n        */\n      -#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n     - static int tr2env_perf_brief;\n     +-static int tr2env_perf_brief;\n     ++static int tr2env_perf_be_brief;\n       \n       #define TR2FMT_PERF_FL_WIDTH (50)\n     + #define TR2FMT_PERF_MAX_EVENT_NAME (12)\n      @@\n       {\n       \tint want = tr2_dst_trace_want(&tr2dst_perf);\n     @@ -791,4 +878,17 @@\n      +\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n       \tif (brief && *brief &&\n       \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n     - \t\ttr2env_perf_brief = want_brief;\n     +-\t\ttr2env_perf_brief = want_brief;\n     ++\t\ttr2env_perf_be_brief = want_brief;\n     + \n     + \treturn want;\n     + }\n     +@@\n     + \n     + \tstrbuf_setlen(buf, 0);\n     + \n     +-\tif (!tr2env_perf_brief) {\n     ++\tif (!tr2env_perf_be_brief) {\n     + \t\tstruct tr2_tbuf tb_now;\n     + \n     + \t\ttr2_tbuf_local_time(&tb_now);\n -:  ---------- > 5:  86d8fe28cf trace2: report peak memory usage of the process\n -:  ---------- > 6:  ae11cc4186 trace2: clarify UTC datetime formatting\n -:  ---------- > 7:  4352952677 trace2: make SIDs more unique\n\n-- \ngitgitgadget\n"},{"id":"372717","messageId":"c15f783c26ea426688b488c2522dd9c9072cc1bf.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 2/7] trace2: add absolute elapsed time to start event","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:26Z","receivedAt":"2019-03-29T17:04:32Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nAdd elapsed process time to \"start\" event to measure\nthe performance of early process startup.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 11 ++++++-----\n t/t0211-trace2-perf.sh                 | 12 ++++++------\n trace2.c                               |  8 +++++++-\n trace2/tr2_tgt.h                       |  1 +\n trace2/tr2_tgt_event.c                 |  5 ++++-\n trace2/tr2_tgt_normal.c                |  3 ++-\n trace2/tr2_tgt_perf.c                  |  7 ++++---\n 7 files changed, 30 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex f37fccf1da..baaa1153bb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n-12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |           |           |            | git version\n+12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |  0.001173 |           |            | git version\n 12:28:42.621111 git.c:432                         | d0 | main                     | cmd_name     |     |           |           |            | version (version)\n 12:28:42.621225 git.c:662                         | d0 | main                     | exit         |     |  0.001227 |           |            | code:0\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.event\n {\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n {\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n {\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n {\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the \"start\" and\n {\n \t\"event\":\"start\",\n \t...\n+\t\"t_abs\":0.001227, # elapsed time in seconds\n \t\"argv\":[\"git\",\"version\"]\n }\n ------------\n@@ -1118,7 +1119,7 @@ $ git status\n \n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.160.g5676107ecd.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1163,7 +1164,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.162.gb4ccea44db.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1219,7 +1220,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.156.gf9916ae094.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n d0 | main                     | region_enter | r1  |  0.001791 |           | index      | label:do_read_index .git/index\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex 953e2f7847..c9694b29f7 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:0\n \t\td0|main|atexit||_T_ABS_|||code:0\n@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 1\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 1\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:1\n \t\td0|main|atexit||_T_ABS_|||code:1\n@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|error|||||hello world\n \t\td0|main|error|||||this is a test\n@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0\n \t\td1|main|version|||||$V\n-\t\td1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0\n+\t\td1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0\n \t\td1|main|cmd_name|||||trace2 (trace2/trace2)\n \t\td1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0\n \t\td2|main|version|||||$V\n-\t\td2|main|start|||||_EXE_ trace2 001return 0\n+\t\td2|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td2|main|cmd_name|||||trace2 (trace2/trace2/trace2)\n \t\td2|main|exit||_T_ABS_|||code:0\n \t\td2|main|atexit||_T_ABS_|||code:0\ndiff --git a/trace2.c b/trace2.c\nindex 6dd51e6aa5..1c180062dd 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv)\n {\n \tstruct tr2_tgt *tgt_j;\n \tint j;\n+\tuint64_t us_now;\n+\tuint64_t us_elapsed_absolute;\n \n \tif (!trace2_enabled)\n \t\treturn;\n \n+\tus_now = getnanotime() / 1000;\n+\tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n+\n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_start_fl)\n-\t\t\ttgt_j->pfn_start_fl(file, line, argv);\n+\t\t\ttgt_j->pfn_start_fl(file, line, us_elapsed_absolute,\n+\t\t\t\t\t    argv);\n }\n \n int trace2_cmd_exit_fl(const char *file, int line, int code)\ndiff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h\nindex 297bb8ffbe..7b90469212 100644\n--- a/trace2/tr2_tgt.h\n+++ b/trace2/tr2_tgt.h\n@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);\n typedef void(tr2_tgt_evt_version_fl_t)(const char *file, int line);\n \n typedef void(tr2_tgt_evt_start_fl_t)(const char *file, int line,\n+\t\t\t\t     uint64_t us_elapsed_absolute,\n \t\t\t\t     const char **argv);\n typedef void(tr2_tgt_evt_exit_fl_t)(const char *file, int line,\n \t\t\t\t    uint64_t us_elapsed_absolute, int code);\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 107cb5317d..89a4d3ae9a 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)\n \tjw_release(&jw);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct json_writer jw = JSON_WRITER_INIT;\n+\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \n \tjw_object_begin(&jw, 0);\n \tevent_fmt_prepare(event_name, file, line, NULL, &jw);\n+\tjw_object_double(&jw, \"t_abs\", 6, t_abs);\n \tjw_object_inline_begin_array(&jw, \"argv\");\n \tjw_array_argv(&jw, argv);\n \tjw_end(&jw);\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 547183d5b6..57f3e18f5b 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex f0746fcf86..9c3b4d8a0f 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \n \tsq_quote_argv_pretty(&buf_payload, argv);\n \n-\tperf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,\n-\t\t\t &buf_payload);\n+\tperf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,\n+\t\t\t NULL, NULL, &buf_payload);\n \tstrbuf_release(&buf_payload);\n }\n \n-- \ngitgitgadget\n\n"},{"id":"372718","messageId":"d4023acde7172089615ea5abd4e91ef90c1791a7.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 3/7] trace2: find exec-dir before trace2 initialization","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:27Z","receivedAt":"2019-03-29T17:04:32Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Git to resolve the executable directory before initializing\nTrace2.  This allows the system configuration directory to be\ndiscovered earlier (because it is sometimes relative to the prefix\nor runtime-prefix).\n\nThis will be used by the next commit to allow trace2 settings to\nbe loaded from the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 6137af0e63..299ca62a72 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -37,12 +37,12 @@ int main(int argc, const char **argv)\n \tsanitize_stdfds();\n \trestore_sigpipe_to_default();\n \n+\tgit_resolve_executable_dir(argv[0]);\n+\n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n \ttrace2_collect_process_info();\n \n-\tgit_resolve_executable_dir(argv[0]);\n-\n \tgit_setup_gettext();\n \n \tinitialize_the_repository();\n-- \ngitgitgadget\n\n"},{"id":"372719","messageId":"86d8fe28cf2f51a494163f9cec3e3b0541288435.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 5/7] trace2: report peak memory usage of the process","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:29Z","receivedAt":"2019-03-29T17:04:34Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Windows version of git to report peak memory usage\nduring exit() processing.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c                            |  2 +-\n compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++--\n trace2.c                                 |  2 +\n trace2.h                                 | 14 +++++--\n 4 files changed, 60 insertions(+), 8 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 299ca62a72..582a7b1886 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -41,7 +41,7 @@ int main(int argc, const char **argv)\n \n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n-\ttrace2_collect_process_info();\n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);\n \n \tgit_setup_gettext();\n \ndiff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c\nindex 52bd62034b..2a514caed9 100644\n--- a/compat/win32/trace2_win32_process_info.c\n+++ b/compat/win32/trace2_win32_process_info.c\n@@ -1,5 +1,6 @@\n #include \"../../cache.h\"\n #include \"../../json-writer.h\"\n+#include \"lazyload.h\"\n #include <Psapi.h>\n #include <tlHelp32.h>\n \n@@ -137,11 +138,54 @@ static void get_is_being_debugged(void)\n \t\t\t\t   \"windows/debugger_present\", 1);\n }\n \n-void trace2_collect_process_info(void)\n+/*\n+ * Emit JSON data with the peak memory usage of the current process.\n+ */\n+static void get_peak_memory_info(void)\n+{\n+\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo,\n+\t\t\t  HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);\n+\n+\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n+\t\tPROCESS_MEMORY_COUNTERS pmc;\n+\n+\t\tif (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,\n+\t\t\t\t\t sizeof(pmc))) {\n+\t\t\tstruct json_writer jw = JSON_WRITER_INIT;\n+\n+\t\t\tjw_object_begin(&jw, 0);\n+\n+#define KV(kv) #kv, (intmax_t)pmc.kv\n+\n+\t\t\tjw_object_intmax(&jw, KV(PageFaultCount));\n+\t\t\tjw_object_intmax(&jw, KV(PeakWorkingSetSize));\n+\t\t\tjw_object_intmax(&jw, KV(PeakPagefileUsage));\n+\n+\t\t\tjw_end(&jw);\n+\n+\t\t\ttrace2_data_json(\"process\", the_repository,\n+\t\t\t\t\t \"windows/memory\", &jw);\n+\t\t\tjw_release(&jw);\n+\t\t}\n+\t}\n+}\n+\n+void trace2_collect_process_info(enum trace2_process_info_reason reason)\n {\n \tif (!trace2_is_enabled())\n \t\treturn;\n \n-\tget_is_being_debugged();\n-\tget_ancestry();\n+\tswitch (reason) {\n+\tcase TRACE2_PROCESS_INFO_STARTUP:\n+\t\tget_is_being_debugged();\n+\t\tget_ancestry();\n+\t\treturn;\n+\n+\tcase TRACE2_PROCESS_INFO_EXIT:\n+\t\tget_peak_memory_info();\n+\t\treturn;\n+\n+\tdefault:\n+\t\tBUG(\"trace2_collect_process_info: unknown reason '%d'\", reason);\n+\t}\n }\ndiff --git a/trace2.c b/trace2.c\nindex 490b3f071e..6baa65cdf9 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)\n \tif (!trace2_enabled)\n \t\treturn code;\n \n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);\n+\n \ttr2main_exit_code = code;\n \n \tus_now = getnanotime() / 1000;\ndiff --git a/trace2.h b/trace2.h\nindex 894bfca7e0..888531eb08 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);\n  * Optional platform-specific code to dump information about the\n  * current and any parent process(es).  This is intended to allow\n  * post-processors to know who spawned this git instance and anything\n- * else the platform may be able to tell us about the current process.\n+ * else that the platform may be able to tell us about the current process.\n  */\n+\n+enum trace2_process_info_reason {\n+\tTRACE2_PROCESS_INFO_STARTUP,\n+\tTRACE2_PROCESS_INFO_EXIT,\n+};\n+\n #if defined(GIT_WINDOWS_NATIVE)\n-void trace2_collect_process_info(void);\n+void trace2_collect_process_info(enum trace2_process_info_reason reason);\n #else\n-#define trace2_collect_process_info() \\\n-\tdo {                          \\\n+#define trace2_collect_process_info(reason) \\\n+\tdo {                                \\\n \t} while (0)\n #endif\n \n-- \ngitgitgadget\n\n"},{"id":"372720","messageId":"ae11cc4186e6299ee5d7bd5cc1d85f1a9db2bb35.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 6/7] trace2: clarify UTC datetime formatting","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:30Z","receivedAt":"2019-03-29T17:04:36Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate tr2_tbuf_utc_datetime to generate extended UTC format.\nUpdate tr2_tgt_event target to use extended format in 'time' columns.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++------\n trace2/tr2_tbuf.c                      |  4 ++--\n trace2/tr2_tbuf.h                      |  4 ++--\n trace2/tr2_tgt_event.c                 |  2 +-\n 4 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 13ca595c69..db968e31f7 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -573,7 +573,7 @@ The following key/value pairs are common to all events:\n \t\"event\":\"version\",\n \t\"sid\":\"1547659722619736-11614\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16 17:28:42.620713\",\n+\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n \t\"file\":\"common-main.c\",\n \t\"line\":38,\n \t...\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex 0844910423..eb1b240d8a 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb)\n \t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n }\n \n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n {\n \tstruct timeval tv;\n \tstruct tm tm;\n@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n \tgmtime_r(&secs, &tm);\n \n \txsnprintf(tb->buf, sizeof(tb->buf),\n-\t\t  \"%4d-%02d-%02d %02d:%02d:%02d.%06ld\", tm.tm_year + 1900,\n+\t\t  \"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ\", tm.tm_year + 1900,\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 9cdefa3957..2a1d173ff2 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -16,8 +16,8 @@ struct tr2_tbuf {\n void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n \n /*\n- * Fill buffer with formatted UTC time string.\n+ * Fill buffer with formatted UTC datatime string.\n  */\n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 48d9193b2c..2c97cf54be 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t */\n \tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n-\t\ttr2_tbuf_utc_time(&tb_now);\n+\t\ttr2_tbuf_utc_datetime_extended(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"372721","messageId":"d048f3ffb801adc7f1b4e48248ca31ebade1b37d.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 4/7] trace2: use system config for default trace2 settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:28Z","receivedAt":"2019-03-29T17:04:37Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach git to read the system config (usually \"/etc/gitconfig\") for\ndefault Trace2 settings.  This allows system-wide Trace2 settings to\nbe installed and inherited to make it easier to manage a collection of\nsystems.\n\nThe original GIT_TR2* environment variables are loaded afterwards and\ncan be used to override the system settings.\n\nOnly the system config file is used.  Trace2 config values are ignored\nin local, global, and other config files.  Likewise, the \"-c\" command\nline arguments are ignored for Trace2 values.  These limits are for\nperformance reasons.\n\n(1) For users not using Trace2, there should be minimal overhead to\ndetect that Trace2 is not enabled.  In particular, Trace2 should not\nallocate lots of otherwise unused data strucutres.\n\n(2) For accurate performance measurements, Trace2 should be initialized\nas early in the git process as possible, and before most of the normal\ngit process initialization (which involves discovering the .git directory\nand reading a hierarchy of config files).\n\nAdded the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing\npurposes to specify the pathname of a fake \"system\" config or disable\nuse of the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt |  31 ++++++\n Makefile                               |   1 +\n t/t0210-trace2-normal.sh               |  41 +++++++-\n t/t0211-trace2-perf.sh                 |  41 +++++++-\n t/t0212-trace2-event.sh                |  52 +++++++++-\n trace2.c                               |   4 +\n trace2.h                               |  12 ++-\n trace2/tr2_cfg.c                       |   7 +-\n trace2/tr2_dst.c                       |  24 ++---\n trace2/tr2_dst.h                       |   3 +-\n trace2/tr2_sysenv.c                    | 128 +++++++++++++++++++++++++\n trace2/tr2_sysenv.h                    |  36 +++++++\n trace2/tr2_tgt_event.c                 |  46 ++++-----\n trace2/tr2_tgt_normal.c                |  16 ++--\n trace2/tr2_tgt_perf.c                  |  16 ++--\n 15 files changed, 382 insertions(+), 76 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex baaa1153bb..13ca595c69 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -117,6 +117,37 @@ values are recognized.\n Socket type can be either `stream` or `dgram`.  If the socket type is\n omitted, Git will try both.\n \n+== Trace2 Settings in System Config\n+\n+Trace2 also reads configuration information from the system config.\n+This is intended to help adminstrators to gather system-wide Git\n+performance data.\n+\n+Trace2 only reads the system configuration, it does not read global,\n+local, worktree, or `-c` config settings.\n+\n+Trace2 will try to load the following system configuration settings\n+and then read the corresponding environment variables at startup.\n+\n+....\n+---------------------------------------------------\n+trace2.normalTarget          GIT_TR2\n+trace2.normalBrief           GIT_TR2_BRIEF\n+\n+trace2.perfTarget            GIT_TR2_PERF\n+trace2.perfBrief             GIT_TR2_PERF_BRIEF\n+\n+trace2.eventTarget           GIT_TR2_EVENT\n+trace2.eventBrief            GIT_TR2_EVENT_BRIEF\n+trace2.eventNesting          GIT_TR2_EVENT_NESTING\n+\n+trace2.configParams          GIT_TR2_CONFIG_PARAMS\n+\n+trace2.destinationDebug      GIT_TR2_DST_DEBUG\n+---------------------------------------------------\n+....\n+\n+\n == Trace2 API\n \n All public Trace2 functions and macros are defined in `trace2.h` and\ndiff --git a/Makefile b/Makefile\nindex 3e03290d8f..9ddfa3dfe7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o\n LIB_OBJS += trace2/tr2_cmd_name.o\n LIB_OBJS += trace2/tr2_dst.o\n LIB_OBJS += trace2/tr2_sid.o\n+LIB_OBJS += trace2/tr2_sysenv.o\n LIB_OBJS += trace2/tr2_tbuf.o\n LIB_OBJS += trace2/tr2_tgt_event.o\n LIB_OBJS += trace2/tr2_tgt_normal.o\ndiff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh\nindex 03a0aedb1d..5d4c04ed30 100755\n--- a/t/t0210-trace2-normal.sh\n+++ b/t/t0210-trace2-normal.sh\n@@ -1,5 +1,14 @@\n #!/bin/sh\n \n+# Disable loading of Trace2 settings from the system config\n+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n+\n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_BRIEF\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility (normal target)'\n . ./test-lib.sh\n \n@@ -15,11 +24,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -132,4 +136,31 @@ test_expect_success 'normal stream, error event' '\n \ttest_cmp expect actual\n '\n \n+# Now test using system config by using a mocked up config file\n+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n+# GIT_TR2* environment variables.\n+\n+unset GIT_TR2_BRIEF\n+\n+MOCK=./mock_system_config\n+\n+test_expect_success 'setup mocked /etc/gitconfig' '\n+\tgit config --file $MOCK trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\tgit config --file $MOCK trace2.normalBrief 1\n+'\n+\n+test_expect_success 'using mock, normal stream, return code 0' '\n+\ttest_when_finished \"rm trace.normal actual expect\" &&\n+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex c9694b29f7..abe35b2186 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -1,5 +1,14 @@\n #!/bin/sh\n \n+# Disable loading of Trace2 settings from the system config\n+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n+\n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_PERF_BRIEF\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility (perf target)'\n . ./test-lib.sh\n \n@@ -15,11 +24,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_PERF_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -150,4 +154,31 @@ test_expect_success 'perf stream, child processes' '\n \ttest_cmp expect actual\n '\n \n+# Now test using system config by using a mocked up config file\n+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n+# GIT_TR2* environment variables.\n+\n+unset GIT_TR2_PERF_BRIEF\n+\n+MOCK=./mock_system_config\n+\n+test_expect_success 'setup mocked /etc/gitconfig' '\n+\tgit config --file $MOCK trace2.perfTarget \"$(pwd)/trace.perf\" &&\n+\tgit config --file $MOCK trace2.perfBrief 1\n+'\n+\n+test_expect_success 'using mock, perf stream, return code 0' '\n+\ttest_when_finished \"rm trace.perf actual expect\" &&\n+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n+\tcat >expect <<-EOF &&\n+\t\td0|main|version|||||$V\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n+\t\td0|main|cmd_name|||||trace2 (trace2)\n+\t\td0|main|exit||_T_ABS_|||code:0\n+\t\td0|main|atexit||_T_ABS_|||code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh\nindex 028b6c5671..c535496261 100755\n--- a/t/t0212-trace2-event.sh\n+++ b/t/t0212-trace2-event.sh\n@@ -1,5 +1,14 @@\n #!/bin/sh\n \n+# Disable loading of Trace2 settings from the system config\n+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n+\n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_BARE\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility'\n . ./test-lib.sh\n \n@@ -17,11 +26,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BARE\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -233,4 +237,42 @@ test_expect_success JSON_PP 'basic trace2_data' '\n \ttest_cmp expect actual\n '\n \n+# Now test using system config by using a mocked up config file\n+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n+# GIT_TR2* environment variables.\n+\n+MOCK=./mock_system_config\n+\n+test_expect_success 'setup mocked /etc/gitconfig' '\n+\tgit config --file $MOCK trace2.eventTarget \"$(pwd)/trace.event\"\n+'\n+\n+test_expect_success JSON_PP 'using mock, event stream, error event' '\n+\ttest_when_finished \"rm trace.event actual expect\" &&\n+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 003error \"hello world\" \"this is a test\" &&\n+\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n+\tsed -e \"s/^|//\" >expect <<-EOF &&\n+\t|VAR1 = {\n+\t|  \"_SID0_\":{\n+\t|    \"argv\":[\n+\t|      \"_EXE_\",\n+\t|      \"trace2\",\n+\t|      \"003error\",\n+\t|      \"hello world\",\n+\t|      \"this is a test\"\n+\t|    ],\n+\t|    \"errors\":[\n+\t|      \"%s\",\n+\t|      \"%s\"\n+\t|    ],\n+\t|    \"exit_code\":0,\n+\t|    \"hierarchy\":\"trace2\",\n+\t|    \"name\":\"trace2\",\n+\t|    \"version\":\"$V\"\n+\t|  }\n+\t|};\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/trace2.c b/trace2.c\nindex 1c180062dd..490b3f071e 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -10,6 +10,7 @@\n #include \"trace2/tr2_cmd_name.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)\n \ttr2_sid_release();\n \ttr2_cmd_name_release();\n \ttr2_cfg_free_patterns();\n+\ttr2_sysenv_release();\n \n \ttrace2_enabled = 0;\n }\n@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)\n \tif (trace2_enabled)\n \t\treturn;\n \n+\ttr2_sysenv_load();\n+\n \tif (!tr2_tgt_want_builtins())\n \t\treturn;\n \ttrace2_enabled = 1;\ndiff --git a/trace2.h b/trace2.h\nindex 8f89e70c44..894bfca7e0 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n \n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n- * targets are enabled in the environment.  Emits a 'version' event.\n+ * targets are enabled in the system config or the environment.\n+ * Emits a 'version' event.\n  *\n  * Cleanup/Termination is handled automatically by a registered\n  * atexit() routine.\n@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n  * Emit one or more 'def_param' events for \"interesting\" configuration\n  * settings.\n  *\n- * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n- * list of patterns considered important.  For example:\n- *\n- *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n+ * Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated\n+ * list of patterns configured important.  For example:\n+ *     git config --system trace2.configParams 'core.*,remote.*.url'\n+ * or:\n+ *     GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url\"\n  *\n  * Note: this routine does a read-only iteration on the config data\n  * (using read_early_config()), so it must not be called until enough\ndiff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\nindex b329921ac5..caa7f06948 100644\n--- a/trace2/tr2_cfg.c\n+++ b/trace2/tr2_cfg.c\n@@ -1,8 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n-#include \"tr2_cfg.h\"\n-\n-#define TR2_ENVVAR_CFG_PARAM \"GIT_TR2_CONFIG_PARAMS\"\n+#include \"trace2/tr2_cfg.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n static struct strbuf **tr2_cfg_patterns;\n static int tr2_cfg_count_patterns;\n@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)\n \t\treturn tr2_cfg_count_patterns;\n \ttr2_cfg_loaded = 1;\n \n-\tenvvar = getenv(TR2_ENVVAR_CFG_PARAM);\n+\tenvvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM);\n \tif (!envvar || !*envvar)\n \t\treturn tr2_cfg_count_patterns;\n \ndiff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c\nindex fd490a43ad..575cd69aa9 100644\n--- a/trace2/tr2_dst.c\n+++ b/trace2/tr2_dst.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n /*\n  * If a Trace2 target cannot be opened for writing, we should issue a\n@@ -7,17 +8,13 @@\n  * or socket and beyond the user's control -- especially since every\n  * git command (and sub-command) will print the message.  So we silently\n  * eat these warnings and just discard the trace data.\n- *\n- * Enable the following environment variable to see these warnings.\n  */\n-#define TR2_ENVVAR_DST_DEBUG \"GIT_TR2_DST_DEBUG\"\n-\n static int tr2_dst_want_warning(void)\n {\n \tstatic int tr2env_dst_debug = -1;\n \n \tif (tr2env_dst_debug == -1) {\n-\t\tconst char *env_value = getenv(TR2_ENVVAR_DST_DEBUG);\n+\t\tconst char *env_value = tr2_sysenv_get(TR2_SYSENV_DST_DEBUG);\n \t\tif (!env_value || !*env_value)\n \t\t\ttr2env_dst_debug = 0;\n \t\telse\n@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)\n \tif (fd == -1) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: could not open '%s' for '%s' tracing: %s\",\n-\t\t\t\ttgt_value, dst->env_var_name, strerror(errno));\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\t\tstrerror(errno));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \tif (!path || !*path) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n-\t\t\t\ttgt_value, dst->env_var_name);\n+\t\t\t\ttgt_value, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \t    strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX path '%s' for '%s' tracing\",\n-\t\t\t\tpath, dst->env_var_name);\n+\t\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n error:\n \tif (tr2_dst_want_warning())\n \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n-\t\t\tpath, dst->env_var_name, strerror(e));\n+\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var), strerror(e));\n \n \ttr2_dst_trace_disable(dst);\n \treturn 0;\n@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_addf(&buf, \"trace2: unknown value for '%s': '%s'\",\n-\t\t    dst->env_var_name, tgt_value);\n+\t\t    tr2_sysenv_display_name(dst->sysenv_var), tgt_value);\n \twarning(\"%s\", buf.buf);\n \n \tstrbuf_release(&buf);\n@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst)\n \n \tdst->initialized = 1;\n \n-\ttgt_value = getenv(dst->env_var_name);\n+\ttgt_value = tr2_sysenv_get(dst->sysenv_var);\n \n \tif (!tgt_value || !strcmp(tgt_value, \"\") || !strcmp(tgt_value, \"0\") ||\n \t    !strcasecmp(tgt_value, \"false\")) {\n@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)\n \t\treturn;\n \n \tif (tr2_dst_want_warning())\n-\t\twarning(\"unable to write trace to '%s': %s\", dst->env_var_name,\n+\t\twarning(\"unable to write trace to '%s': %s\",\n+\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n \t\t\tstrerror(errno));\n \ttr2_dst_trace_disable(dst);\n }\ndiff --git a/trace2/tr2_dst.h b/trace2/tr2_dst.h\nindex 9a64f05b02..3adf3bac13 100644\n--- a/trace2/tr2_dst.h\n+++ b/trace2/tr2_dst.h\n@@ -2,9 +2,10 @@\n #define TR2_DST_H\n \n struct strbuf;\n+#include \"trace2/tr2_sysenv.h\"\n \n struct tr2_dst {\n-\tconst char *const env_var_name;\n+\tenum tr2_sysenv_variable sysenv_var;\n \tint fd;\n \tunsigned int initialized : 1;\n \tunsigned int need_close : 1;\ndiff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\nnew file mode 100644\nindex 0000000000..c6909f8b2d\n--- /dev/null\n+++ b/trace2/tr2_sysenv.c\n@@ -0,0 +1,128 @@\n+#include \"cache.h\"\n+#include \"config.h\"\n+#include \"dir.h\"\n+#include \"tr2_sysenv.h\"\n+\n+/*\n+ * Each entry represents a trace2 setting.\n+ * See Documentation/technical/api-trace2.txt\n+ */\n+struct tr2_sysenv_entry {\n+\tconst char *env_var_name;\n+\tconst char *git_config_name;\n+\n+\tchar *value;\n+\tunsigned int getenv_called : 1;\n+};\n+\n+/*\n+ * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n+ * These strings are constant and must match the published names as\n+ * described in the documentation.\n+ *\n+ * We do not define entries for the GIT_TR2_PARENT_* environment\n+ * variables because they are transient and used to pass information\n+ * from parent to child git processes, rather than settings.\n+ */\n+/* clang-format off */\n+static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n+\t{ \"GIT_TR2_CONFIG_PARAMS\",   \"trace2.configparams\"     },\n+\n+\t{ \"GIT_TR2_DST_DEBUG\",       \"trace2.destinationdebug\" },\n+\n+\t{ \"GIT_TR2\",                 \"trace2.normaltarget\"     },\n+\t{ \"GIT_TR2_BRIEF\",           \"trace2.normalbrief\"      },\n+\n+\t{ \"GIT_TR2_EVENT\",           \"trace2.eventtarget\"      },\n+\t{ \"GIT_TR2_EVENT_BRIEF\",     \"trace2.eventbrief\"       },\n+\t{ \"GIT_TR2_EVENT_NESTING\",   \"trace2.eventnesting\"     },\n+\n+\t{ \"GIT_TR2_PERF\",            \"trace2.perftarget\"       },\n+\t{ \"GIT_TR2_PERF_BRIEF\",      \"trace2.perfbrief\"        },\n+};\n+/* clang-format on */\n+\n+static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n+{\n+\tint k;\n+\n+\tif (!starts_with(key, \"trace2.\"))\n+\t\treturn 0;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n+\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n+\t\t\tfree(tr2_sysenv_settings[k].value);\n+\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n+ * unless we were built with a runtime-prefix).  These are intended to\n+ * define the default values for Trace2 as requested by the administrator.\n+ */\n+void tr2_sysenv_load(void)\n+{\n+\tconst char *system_config_pathname;\n+\tconst char *test_pathname;\n+\n+\tsystem_config_pathname = git_etc_gitconfig();\n+\n+\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n+\tif (test_pathname) {\n+\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n+\t\t\treturn; /* disable use of system config */\n+\n+\t\t/* mock it with given test file */\n+\t\tsystem_config_pathname = test_pathname;\n+\t}\n+\n+\tif (file_exists(system_config_pathname))\n+\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n+\t\t\t\t     NULL);\n+}\n+\n+/*\n+ * Return the value for the requested setting.  Start with the /etc/gitconfig\n+ * value and allow the corresponding environment variable to override it.\n+ */\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\tif (!tr2_sysenv_settings[var].getenv_called) {\n+\t\tconst char *v = getenv(tr2_sysenv_settings[var].env_var_name);\n+\t\tif (v && *v) {\n+\t\t\tfree(tr2_sysenv_settings[var].value);\n+\t\t\ttr2_sysenv_settings[var].value = xstrdup(v);\n+\t\t}\n+\t\ttr2_sysenv_settings[var].getenv_called = 1;\n+\t}\n+\n+\treturn tr2_sysenv_settings[var].value;\n+}\n+\n+/*\n+ * Return a friendly name for this setting that is suitable for printing\n+ * in an error messages.\n+ */\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\treturn tr2_sysenv_settings[var].env_var_name;\n+}\n+\n+void tr2_sysenv_release(void)\n+{\n+\tint k;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++)\n+\t\tfree(tr2_sysenv_settings[k].value);\n+}\ndiff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h\nnew file mode 100644\nindex 0000000000..369b20bd87\n--- /dev/null\n+++ b/trace2/tr2_sysenv.h\n@@ -0,0 +1,36 @@\n+#ifndef TR2_SYSENV_H\n+#define TR2_SYSENV_H\n+\n+/*\n+ * The Trace2 settings that can be loaded from /etc/gitconfig\n+ * and/or user environment variables.\n+ *\n+ * Note that this set does not contain any of the transient\n+ * environment variables used to pass information from parent\n+ * to child git processes, such \"GIT_TR2_PARENT_SID\".\n+ */\n+enum tr2_sysenv_variable {\n+\tTR2_SYSENV_CFG_PARAM = 0,\n+\n+\tTR2_SYSENV_DST_DEBUG,\n+\n+\tTR2_SYSENV_NORMAL,\n+\tTR2_SYSENV_NORMAL_BRIEF,\n+\n+\tTR2_SYSENV_EVENT,\n+\tTR2_SYSENV_EVENT_BRIEF,\n+\tTR2_SYSENV_EVENT_NESTING,\n+\n+\tTR2_SYSENV_PERF,\n+\tTR2_SYSENV_PERF_BRIEF,\n+\n+\tTR2_SYSENV_MUST_BE_LAST\n+};\n+\n+void tr2_sysenv_load(void);\n+\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable);\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);\n+void tr2_sysenv_release(void);\n+\n+#endif /* TR2_SYSENV_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 89a4d3ae9a..48d9193b2c 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -6,10 +6,11 @@\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };\n \n /*\n  * The version number of the JSON data generated by the EVENT target\n@@ -28,37 +29,36 @@ static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n  * are primarily intended for the performance target during debugging.\n  *\n  * Some of the outer-most messages, however, may be of interest to the\n- * event target.  Set this environment variable to a larger integer for\n- * more detail in the event target.\n+ * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase\n+ * region details in the event target.\n  */\n-#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n-static int tr2env_event_nesting_wanted = 2;\n+static int tr2env_event_max_nesting_levels = 2;\n \n /*\n- * Set this environment variable to true to omit the <time>, <file>, and\n+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and\n  * <line> fields from most events.\n  */\n-#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n-static int tr2env_event_brief;\n+static int tr2env_event_be_brief;\n \n static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_event);\n-\tint want_nesting;\n+\tint max_nesting;\n \tint want_brief;\n-\tchar *nesting;\n-\tchar *brief;\n+\tconst char *nesting;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n-\tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n-\t\ttr2env_event_nesting_wanted = want_nesting;\n+\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n+\tif (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))\n+\t\ttr2env_event_max_nesting_levels = max_nesting;\n \n-\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n-\tif (brief && ((want_brief = atoi(brief)) > 0))\n-\t\ttr2env_event_brief = want_brief;\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n+\tif (brief && *brief &&\n+\t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n+\t\ttr2env_event_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -92,13 +92,13 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t/*\n \t * In brief mode, only emit <time> on these 2 event types.\n \t */\n-\tif (!tr2env_event_brief || !strcmp(event_name, \"version\") ||\n+\tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n \t\ttr2_tbuf_utc_time(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-\tif (!tr2env_event_brief && file && *file) {\n+\tif (!tr2env_event_be_brief && file && *file) {\n \t\tjw_object_string(jw, \"file\", file);\n \t\tjw_object_intmax(jw, \"line\", line);\n \t}\n@@ -459,7 +459,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line,\n {\n \tconst char *event_name = \"region_enter\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \n \t\tjw_object_begin(&jw, 0);\n@@ -484,7 +484,7 @@ static void fn_region_leave_printf_va_fl(\n {\n \tconst char *event_name = \"region_leave\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n \n@@ -511,7 +511,7 @@ static void fn_data_fl(const char *file, int line, uint64_t us_elapsed_absolute,\n {\n \tconst char *event_name = \"data\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n@@ -539,7 +539,7 @@ static void fn_data_json_fl(const char *file, int line,\n {\n \tconst char *event_name = \"data_json\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 57f3e18f5b..1ce6f97863 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -4,20 +4,20 @@\n #include \"quote.h\"\n #include \"version.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_normal = { \"GIT_TR2\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin normal target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n-static int tr2env_normal_brief;\n+static int tr2env_normal_be_brief;\n \n #define TR2FMT_NORMAL_FL_WIDTH (50)\n \n@@ -25,15 +25,15 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_normal);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_normal_brief = want_brief;\n+\t\ttr2env_normal_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf)\n {\n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_normal_brief) {\n+\tif (!tr2env_normal_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex 9c3b4d8a0f..328d2234bd 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -6,20 +6,20 @@\n #include \"json-writer.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_perf = { \"GIT_TR2_PERF\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use TR2_SYSENV_PERF_BRIEF to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin performance target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n-static int tr2env_perf_brief;\n+static int tr2env_perf_be_brief;\n \n #define TR2FMT_PERF_FL_WIDTH (50)\n #define TR2FMT_PERF_MAX_EVENT_NAME (12)\n@@ -36,17 +36,17 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_perf);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n \tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n \n-\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_perf_brief = want_brief;\n+\t\ttr2env_perf_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,\n \n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_perf_brief) {\n+\tif (!tr2env_perf_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\n-- \ngitgitgadget\n\n"},{"id":"372722","messageId":"4352952677a11776a18ec9b6862cf358307cfafd.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 7/7] trace2: make SIDs more unique","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:30Z","receivedAt":"2019-03-29T17:04:38Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate SID component construction to use the current UTC datetime\nand a portion of the SHA1 of the hostname.\n\nUse an simplified date/time format to make it easier to use the\nSID component as a logfile filename.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++----\n trace2/tr2_sid.c                       | 39 +++++++++++++++++++++++---\n trace2/tr2_tbuf.c                      | 16 +++++++++++\n trace2/tr2_tbuf.h                      |  1 +\n 4 files changed, 58 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex db968e31f7..e740db3907 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -571,7 +571,7 @@ The following key/value pairs are common to all events:\n ------------\n {\n \t\"event\":\"version\",\n-\t\"sid\":\"1547659722619736-11614\",\n+\t\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\n \t\"thread\":\"main\",\n \t\"time\":\"2019-01-16T17:28:42.620713Z\",\n \t\"file\":\"common-main.c\",\ndiff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c\nindex 984524a43c..6801113e53 100644\n--- a/trace2/tr2_sid.c\n+++ b/trace2/tr2_sid.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n \n #define TR2_ENVVAR_PARENT_SID \"GIT_TR2_PARENT_SID\"\n@@ -6,6 +7,39 @@\n static struct strbuf tr2sid_buf = STRBUF_INIT;\n static int tr2sid_nr_git_parents;\n \n+/*\n+ * Compute the final component of the SID representing the current process.\n+ * This should uniquely identify the process and be a valid filename (to\n+ * allow writing trace2 data to per-process files).\n+ *\n+ * <yyyymmdd> '-' <hhmmss> '-' <fraction> '-' <sha1-prefix> '-' <pid>\n+ */\n+static void tr2_sid_append_my_sid_component(void)\n+{\n+\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n+\tstruct tr2_tbuf tb_now;\n+\tgit_hash_ctx ctx;\n+\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n+\tchar hex[GIT_MAX_HEXSZ + 1];\n+\tchar hostname[HOST_NAME_MAX + 1];\n+\n+\ttr2_tbuf_utc_datetime_for_filename(&tb_now);\n+\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n+\tstrbuf_addch(&tr2sid_buf, '-');\n+\n+\tif (xgethostname(hostname, sizeof(hostname)))\n+\t\txsnprintf(hostname, sizeof(hostname), \"localhost\");\n+\n+\talgo->init_fn(&ctx);\n+\talgo->update_fn(&ctx, hostname, strlen(hostname));\n+\talgo->final_fn(hash, &ctx);\n+\thash_to_hex_algop_r(hex, hash, algo);\n+\tstrbuf_add(&tr2sid_buf, hex, 8);\n+\n+\tstrbuf_addch(&tr2sid_buf, '-');\n+\tstrbuf_addf(&tr2sid_buf, \"%06\"PRIuMAX, (uintmax_t)getpid());\n+}\n+\n /*\n  * Compute a \"unique\" session id (SID) for the current process.  This allows\n  * all events from this process to have a single label (much like a PID).\n@@ -20,7 +54,6 @@ static int tr2sid_nr_git_parents;\n  */\n static void tr2_sid_compute(void)\n {\n-\tuint64_t us_now;\n \tconst char *parent_sid;\n \n \tif (tr2sid_buf.len)\n@@ -38,9 +71,7 @@ static void tr2_sid_compute(void)\n \t\ttr2sid_nr_git_parents++;\n \t}\n \n-\tus_now = getnanotime() / 1000;\n-\tstrbuf_addf(&tr2sid_buf, \"%\" PRIuMAX \"-%\" PRIdMAX, (uintmax_t)us_now,\n-\t\t    (intmax_t)getpid());\n+\ttr2_sid_append_my_sid_component();\n \n \tsetenv(TR2_ENVVAR_PARENT_SID, tr2sid_buf.buf, 1);\n }\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex eb1b240d8a..c1a50fe084 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -30,3 +30,19 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\n+\n+void tr2_tbuf_utc_datetime_for_filename(struct tr2_tbuf *tb)\n+{\n+\tstruct timeval tv;\n+\tstruct tm tm;\n+\ttime_t secs;\n+\n+\tgettimeofday(&tv, NULL);\n+\tsecs = tv.tv_sec;\n+\tgmtime_r(&secs, &tm);\n+\n+\txsnprintf(tb->buf, sizeof(tb->buf),\n+\t\t  \"%4d%02d%02d-%02d%02d%02d-%06ld\", tm.tm_year + 1900,\n+\t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n+\t\t  (long)tv.tv_usec);\n+}\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 2a1d173ff2..29efff1ef7 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n  * Fill buffer with formatted UTC datatime string.\n  */\n void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime_for_filename(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\n-- \ngitgitgadget\n"},{"id":"372723","messageId":"7f1a34732271f9fbdbec0f4cd0a5990466ebd071.1553879063.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v2 1/7] trace2: refactor setting process starting time","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-03-29T17:04:25Z","receivedAt":"2019-03-29T17:04:38Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreate trace2_initialize_clock() and call from main() to capture\nprocess start time in isolation and before other sub-systems are\nready.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++--\n common-main.c                          |  2 ++\n compat/mingw.c                         |  2 ++\n trace2.c                               |  7 ++++-\n trace2.h                               | 17 ++++++++++++\n trace2/tr2_tls.c                       | 38 ++++++++++++++++----------\n trace2/tr2_tls.h                       |  8 +++++-\n 7 files changed, 67 insertions(+), 19 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 2de565fa3d..f37fccf1da 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -160,17 +160,23 @@ purposes.\n \n These are concerned with the lifetime of the overall git process.\n \n+`void trace2_initialize_clock()`::\n+\n+\tInitialize the Trace2 start clock and nothing else.  This should\n+\tbe called at the very top of main() to capture the process start\n+\ttime and reduce startup order dependencies.\n+\n `void trace2_initialize()`::\n \n \tDetermines if any Trace2 Targets should be enabled and\n-\tinitializes the Trace2 facility.  This includes starting the\n-\telapsed time clocks and thread local storage (TLS).\n+\tinitializes the Trace2 facility.  This includes setting up the\n+\tTrace2 thread local storage (TLS).\n +\n This function emits a \"version\" message containing the version of git\n and the Trace2 protocol.\n +\n This function should be called from `main()` as early as possible in\n-the life of the process.\n+the life of the process after essential process initialization.\n \n `int trace2_is_enabled()`::\n \ndiff --git a/common-main.c b/common-main.c\nindex d484aec209..6137af0e63 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -27,6 +27,8 @@ int main(int argc, const char **argv)\n {\n \tint result;\n \n+\ttrace2_initialize_clock();\n+\n \t/*\n \t * Always open file descriptors 0/1/2 to avoid clobbering files\n \t * in die().  It also avoids messing up when the pipes are dup'ed\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 6b04514cdc..a2f74aca6a 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -2569,6 +2569,8 @@ void mingw_startup(void)\n \twchar_t **wenv, **wargv;\n \t_startupinfo si;\n \n+\ttrace2_initialize_clock();\n+\n \tmaybe_redirect_std_handles();\n \n \t/* get wide char arguments and environment */\ndiff --git a/trace2.c b/trace2.c\nindex ccccd4ef09..6dd51e6aa5 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)\n \traise(signo);\n }\n \n+void trace2_initialize_clock(void)\n+{\n+\ttr2tls_start_process_clock();\n+}\n+\n void trace2_initialize_fl(const char *file, int line)\n {\n \tstruct tr2_tgt *tgt_j;\n@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name)\n \tus_now = getnanotime() / 1000;\n \tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n \n-\ttr2tls_create_self(thread_name);\n+\ttr2tls_create_self(thread_name, us_now);\n \n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_thread_start_fl)\ndiff --git a/trace2.h b/trace2.h\nindex ae5020d0e6..8f89e70c44 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -19,6 +19,23 @@ struct json_writer;\n  * [] trace2_printf*    -- legacy trace[1] messages.\n  */\n \n+/*\n+ * Initialize the TRACE2 clock and do nothing else, in particular\n+ * no mallocs, no system inspection, and no environment inspection.\n+ *\n+ * This should be called at the very top of main() to capture the\n+ * process start time.  This is intended to reduce chicken-n-egg\n+ * bootstrap pressure.\n+ *\n+ * It is safe to call this more than once.  This allows capturing\n+ * absolute startup costs on Windows which uses a little trickery\n+ * to do setup work before common-main.c:main() is called.\n+ *\n+ * The main trace2_initialize_fl() may be called a little later\n+ * after more infrastructure is established.\n+ */\n+void trace2_initialize_clock(void);\n+\n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n  * targets are enabled in the environment.  Emits a 'version' event.\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 8e65b0361d..31fb529f93 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -10,16 +10,30 @@\n #define TR2_REGION_NESTING_INITIAL_SIZE (100)\n \n static struct tr2tls_thread_ctx *tr2tls_thread_main;\n-static uint64_t tr2tls_us_start_main;\n+static uint64_t tr2tls_us_start_process;\n \n static pthread_mutex_t tr2tls_mutex;\n static pthread_key_t tr2tls_key;\n \n static int tr2_next_thread_id; /* modify under lock */\n \n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n+void tr2tls_start_process_clock(void)\n+{\n+\tif (tr2tls_us_start_process)\n+\t\treturn;\n+\n+\t/*\n+\t * Keep the absolute start time of the process (i.e. the main\n+\t * process) in a fixed variable since other threads need to\n+\t * access it.  This allows them to do that without a lock on\n+\t * main thread's array data (because of reallocs).\n+\t */\n+\ttr2tls_us_start_process = getnanotime() / 1000;\n+}\n+\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start)\n {\n-\tuint64_t us_now = getnanotime() / 1000;\n \tstruct tr2tls_thread_ctx *ctx = xcalloc(1, sizeof(*ctx));\n \n \t/*\n@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n \t */\n \tctx->alloc = TR2_REGION_NESTING_INITIAL_SIZE;\n \tctx->array_us_start = (uint64_t *)xcalloc(ctx->alloc, sizeof(uint64_t));\n-\tctx->array_us_start[ctx->nr_open_regions++] = us_now;\n+\tctx->array_us_start[ctx->nr_open_regions++] = us_thread_start;\n \n \tctx->thread_id = tr2tls_locked_increment(&tr2_next_thread_id);\n \n@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)\n \t * here and silently continue.\n \t */\n \tif (!ctx)\n-\t\tctx = tr2tls_create_self(\"unknown\");\n+\t\tctx = tr2tls_create_self(\"unknown\", getnanotime() / 1000);\n \n \treturn ctx;\n }\n@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)\n \tif (!tr2tls_thread_main)\n \t\treturn 0;\n \n-\treturn us - tr2tls_us_start_main;\n+\treturn us - tr2tls_us_start_process;\n }\n \n void tr2tls_init(void)\n {\n+\ttr2tls_start_process_clock();\n+\n \tpthread_key_create(&tr2tls_key, NULL);\n \tinit_recursive_mutex(&tr2tls_mutex);\n \n-\ttr2tls_thread_main = tr2tls_create_self(\"main\");\n-\t/*\n-\t * Keep a copy of the absolute start time of the main thread\n-\t * in a fixed variable since other threads need to access it.\n-\t * This also eliminates the need to lock accesses to the main\n-\t * thread's array (because of reallocs).\n-\t */\n-\ttr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];\n+\ttr2tls_thread_main = tr2tls_create_self(\"main\",\n+\t\t\t\t\t\ttr2tls_us_start_process);\n }\n \n void tr2tls_release(void)\ndiff --git a/trace2/tr2_tls.h b/trace2/tr2_tls.h\nindex bb80e3f8e7..b1e327a928 100644\n--- a/trace2/tr2_tls.h\n+++ b/trace2/tr2_tls.h\n@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {\n  * In this and all following functions the term \"self\" refers to the\n  * current thread.\n  */\n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start);\n \n /*\n  * Get our TLS data.\n@@ -94,4 +95,9 @@ void tr2tls_release(void);\n  */\n int tr2tls_locked_increment(int *p);\n \n+/*\n+ * Capture the process start time and do nothing else.\n+ */\n+void tr2tls_start_process_clock(void);\n+\n #endif /* TR2_TLS_H */\n-- \ngitgitgadget\n\n"},{"id":"372735","messageId":"87lg0x9voz.fsf@evledraar.gmail.com","threadId":"50834","inReplyTo":"4352952677a11776a18ec9b6862cf358307cfafd.1553879063.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 7/7] trace2: make SIDs more unique","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-03-29T22:12:28Z","receivedAt":"2019-03-29T22:12:33Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Mar 29 2019, Jeff Hostetler via GitGitGadget wrote:\n\n> From: Jeff Hostetler <jeffhost@microsoft.com>\n>\n> Update SID component construction to use the current UTC datetime\n> and a portion of the SHA1 of the hostname.\n>\n> Use an simplified date/time format to make it easier to use the\n> SID component as a logfile filename.\n> [...]\n> +static void tr2_sid_append_my_sid_component(void)\n> +{\n> +\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n> +\tstruct tr2_tbuf tb_now;\n> +\tgit_hash_ctx ctx;\n> +\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n> +\tchar hex[GIT_MAX_HEXSZ + 1];\n> +\tchar hostname[HOST_NAME_MAX + 1];\n> +\n> +\ttr2_tbuf_utc_datetime_for_filename(&tb_now);\n> +\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n> +\tstrbuf_addch(&tr2sid_buf, '-');\n> +\n> +\tif (xgethostname(hostname, sizeof(hostname)))\n> +\t\txsnprintf(hostname, sizeof(hostname), \"localhost\");\n> +\n> +\talgo->init_fn(&ctx);\n> +\talgo->update_fn(&ctx, hostname, strlen(hostname));\n> +\talgo->final_fn(hash, &ctx);\n> +\thash_to_hex_algop_r(hex, hash, algo);\n> +\tstrbuf_add(&tr2sid_buf, hex, 8);\n> +\n> +\tstrbuf_addch(&tr2sid_buf, '-');\n> +\tstrbuf_addf(&tr2sid_buf, \"%06\"PRIuMAX, (uintmax_t)getpid());\n> +}\n> +\n\nThanks for turning my shitty half-formed idea into a patch :)\n\nI wrote this on top to bikeshed this a bit further, wonder what you\nthink:\nhttps://github.com/gitgitgadget/git/compare/pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2...avar:pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2\n\nSo e.g.:\n\n    Before: 20190329-220413-446441-c2f5b994-018702\n    After:  20190329T220431.244562Z-Hc2f5b994-P19812F\n\nI.e:\n\n * Using <date>T<time> as is ISO 8601 convention/easier to read\n\n * <dateime>.<microseconds>Z, so seperating with \".\" to indicate it's\n   the same value + add \"Z\" for \"it's UTC\". I'm least sure about the\n   \".\". Is that going to cause issues on Windows these days (the rest\n   being the \"extension\"...).\n\n * I changed the hostname discovery so if gethostbyname() fails we'll\n   print \"-H00000000-\" for that part, instead of \"-H<first 8 chars of\n   the sha1 for 'localhost'>-\". Also prefix with \"H\" for \"Host\".\n\n * Wrap pids to 0xffff, prefix with \"P\" (Pid)\" and trail with either \"F\"\n   = Full or \"W\" = Wrapped (not the real PID).\n\n * I didn't add \"T<datetime>\" like \"H\" and \"P\" for the rest, since it's\n   obvious what sort of value it is.\n\nMaybe this is going a bit overboard, but I think it's easier to read at\na glance for humans, and since it's meant to be opaque to machines\nanyway and the length is simliar enough not to matter I figure it's\nworth it.\n\n"},{"id":"372736","messageId":"87k1gh9vii.fsf@evledraar.gmail.com","threadId":"50834","inReplyTo":"86d8fe28cf2f51a494163f9cec3e3b0541288435.1553879063.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 5/7] trace2: report peak memory usage of the process","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-03-29T22:16:21Z","receivedAt":"2019-03-29T22:16:27Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Mar 29 2019, Jeff Hostetler via GitGitGadget wrote:\n\n> From: Jeff Hostetler <jeffhost@microsoft.com>\n>\n> Teach Windows version of git to report peak memory usage\n> during exit() processing.\n>\n> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n> ---\n>  common-main.c                            |  2 +-\n>  compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++--\n>  trace2.c                                 |  2 +\n>  trace2.h                                 | 14 +++++--\n>  4 files changed, 60 insertions(+), 8 deletions(-)\n>\n> diff --git a/common-main.c b/common-main.c\n> index 299ca62a72..582a7b1886 100644\n> --- a/common-main.c\n> +++ b/common-main.c\n> @@ -41,7 +41,7 @@ int main(int argc, const char **argv)\n>\n>  \ttrace2_initialize();\n>  \ttrace2_cmd_start(argv);\n> -\ttrace2_collect_process_info();\n> +\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);\n>\n>  \tgit_setup_gettext();\n>\n> diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c\n> index 52bd62034b..2a514caed9 100644\n> --- a/compat/win32/trace2_win32_process_info.c\n> +++ b/compat/win32/trace2_win32_process_info.c\n> @@ -1,5 +1,6 @@\n>  #include \"../../cache.h\"\n>  #include \"../../json-writer.h\"\n> +#include \"lazyload.h\"\n>  #include <Psapi.h>\n>  #include <tlHelp32.h>\n>\n> @@ -137,11 +138,54 @@ static void get_is_being_debugged(void)\n>  \t\t\t\t   \"windows/debugger_present\", 1);\n>  }\n>\n> -void trace2_collect_process_info(void)\n> +/*\n> + * Emit JSON data with the peak memory usage of the current process.\n> + */\n> +static void get_peak_memory_info(void)\n> +{\n> +\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo,\n> +\t\t\t  HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);\n> +\n> +\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n> +\t\tPROCESS_MEMORY_COUNTERS pmc;\n> +\n> +\t\tif (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,\n> +\t\t\t\t\t sizeof(pmc))) {\n> +\t\t\tstruct json_writer jw = JSON_WRITER_INIT;\n> +\n> +\t\t\tjw_object_begin(&jw, 0);\n> +\n> +#define KV(kv) #kv, (intmax_t)pmc.kv\n> +\n> +\t\t\tjw_object_intmax(&jw, KV(PageFaultCount));\n> +\t\t\tjw_object_intmax(&jw, KV(PeakWorkingSetSize));\n> +\t\t\tjw_object_intmax(&jw, KV(PeakPagefileUsage));\n> +\n> +\t\t\tjw_end(&jw);\n> +\n> +\t\t\ttrace2_data_json(\"process\", the_repository,\n> +\t\t\t\t\t \"windows/memory\", &jw);\n> +\t\t\tjw_release(&jw);\n> +\t\t}\n> +\t}\n> +}\n> +\n> +void trace2_collect_process_info(enum trace2_process_info_reason reason)\n>  {\n>  \tif (!trace2_is_enabled())\n>  \t\treturn;\n>\n> -\tget_is_being_debugged();\n> -\tget_ancestry();\n> +\tswitch (reason) {\n> +\tcase TRACE2_PROCESS_INFO_STARTUP:\n> +\t\tget_is_being_debugged();\n> +\t\tget_ancestry();\n> +\t\treturn;\n> +\n> +\tcase TRACE2_PROCESS_INFO_EXIT:\n> +\t\tget_peak_memory_info();\n> +\t\treturn;\n> +\n> +\tdefault:\n> +\t\tBUG(\"trace2_collect_process_info: unknown reason '%d'\", reason);\n> +\t}\n>  }\n> diff --git a/trace2.c b/trace2.c\n> index 490b3f071e..6baa65cdf9 100644\n> --- a/trace2.c\n> +++ b/trace2.c\n> @@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)\n>  \tif (!trace2_enabled)\n>  \t\treturn code;\n>\n> +\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);\n> +\n>  \ttr2main_exit_code = code;\n>\n>  \tus_now = getnanotime() / 1000;\n> diff --git a/trace2.h b/trace2.h\n> index 894bfca7e0..888531eb08 100644\n> --- a/trace2.h\n> +++ b/trace2.h\n> @@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);\n>   * Optional platform-specific code to dump information about the\n>   * current and any parent process(es).  This is intended to allow\n>   * post-processors to know who spawned this git instance and anything\n> - * else the platform may be able to tell us about the current process.\n> + * else that the platform may be able to tell us about the current process.\n>   */\n> +\n> +enum trace2_process_info_reason {\n> +\tTRACE2_PROCESS_INFO_STARTUP,\n> +\tTRACE2_PROCESS_INFO_EXIT,\n> +};\n> +\n>  #if defined(GIT_WINDOWS_NATIVE)\n> -void trace2_collect_process_info(void);\n> +void trace2_collect_process_info(enum trace2_process_info_reason reason);\n>  #else\n> -#define trace2_collect_process_info() \\\n> -\tdo {                          \\\n> +#define trace2_collect_process_info(reason) \\\n> +\tdo {                                \\\n>  \t} while (0)\n>  #endif\n\nFWIW this is the \"VmPeak\" line in /proc/$$/status on Linux. I don't know\nif we can/should parse that in practice (I've been bitten in the past by\nthings in /proc having high cost on some kernel versions in the past,\nnotably smaps).\n"},{"id":"372943","messageId":"20190401210034.GD60888@google.com","threadId":"50834","inReplyTo":"d048f3ffb801adc7f1b4e48248ca31ebade1b37d.1553879063.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings","fromName":"Josh Steadmon","fromEmail":"steadmon@google.com","sentAt":"2019-04-01T21:00:34Z","receivedAt":"2019-04-01T21:00:44Z","isPatch":true,"sender":{"key":"steadmon@google.com","avatar":"https://avatars.githubusercontent.com/u/2654920?v=4"},"body":"On 2019.03.29 10:04, Jeff Hostetler via GitGitGadget wrote:\n[...]\n> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\n> index baaa1153bb..13ca595c69 100644\n> --- a/Documentation/technical/api-trace2.txt\n> +++ b/Documentation/technical/api-trace2.txt\n> @@ -117,6 +117,37 @@ values are recognized.\n>  Socket type can be either `stream` or `dgram`.  If the socket type is\n>  omitted, Git will try both.\n>  \n> +== Trace2 Settings in System Config\n> +\n> +Trace2 also reads configuration information from the system config.\n> +This is intended to help adminstrators to gather system-wide Git\n> +performance data.\n> +\n> +Trace2 only reads the system configuration, it does not read global,\n> +local, worktree, or `-c` config settings.\n> +\n> +Trace2 will try to load the following system configuration settings\n> +and then read the corresponding environment variables at startup.\n> +\n> +....\n> +---------------------------------------------------\n> +trace2.normalTarget          GIT_TR2\n> +trace2.normalBrief           GIT_TR2_BRIEF\n> +\n> +trace2.perfTarget            GIT_TR2_PERF\n> +trace2.perfBrief             GIT_TR2_PERF_BRIEF\n> +\n> +trace2.eventTarget           GIT_TR2_EVENT\n> +trace2.eventBrief            GIT_TR2_EVENT_BRIEF\n> +trace2.eventNesting          GIT_TR2_EVENT_NESTING\n> +\n> +trace2.configParams          GIT_TR2_CONFIG_PARAMS\n> +\n> +trace2.destinationDebug      GIT_TR2_DST_DEBUG\n> +---------------------------------------------------\n> +....\n> +\n> +\n\nA question for the list: should these new config vars also be documented\nin the git-config manpage, or is it better to keep these separate since\nthey are only read from the system config?\n"},{"id":"372944","messageId":"20190401210226.GE60888@google.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 0/7] trace2: load trace2 settings from system config","fromName":"Josh Steadmon","fromEmail":"steadmon@google.com","sentAt":"2019-04-01T21:02:26Z","receivedAt":"2019-04-01T21:02:35Z","isPatch":true,"sender":{"key":"steadmon@google.com","avatar":"https://avatars.githubusercontent.com/u/2654920?v=4"},"body":"On 2019.03.29 10:04, Jeff Hostetler via GitGitGadget wrote:\n> Here is version 2. It addresses most the V1 comments WRT the system config\n> changes.\n> \n> It also addresses the format and uniqueness of the SID as discussed in [1].\n> The SID now containes: the UTC date/time, part of SHA1 of the hostname, and\n> the PID and is formatted to make it safe for filenames.\n> \n> It also contains (a somewhat unrelated platform-specific) commit to report\n> total process memory usage at exit. This is helpful when looking for\n> problematic commands that might have scaling problems.\n> \n> [1] \n> https://public-inbox.org/git/51e88650-8667-df1f-13ef-4537f2e70346@jeffhostetler.com/T/#m6b4e6f2b0374d5ba88de8d0350ce6bf51b28d7da\n> \n> \n> ----------------------------------------------------------------------------\n> \n> Teach git to load default Trace2 settings from the system config (usually\n> \"/etc/gitconfig\"). The existing GIT_TR2_* environment variables can be used\n> to override the new system defaults. It also includes a little startup\n> refactoring.\n> \n> Note: I found interactive testing of this feature to be awkward on some\n> platforms because of the use of prefix- or runtime-prefix-relative locations\n> for the system configuration. It was easy to accidentally use an officially\n> installed version of git to set a system config variable in the official\n> system config directory; and then when testing with the test version of git,\n> that value would not be seen because it was looking for the system config\n> file in a different directory.\n> \n> Jeff Hostetler (7):\n>   trace2: refactor setting process starting time\n>   trace2: add absolute elapsed time to start event\n>   trace2: find exec-dir before trace2 initialization\n>   trace2: use system config for default trace2 settings\n>   trace2: report peak memory usage of the process\n>   trace2: clarify UTC datetime formatting\n>   trace2: make SIDs more unique\n> \n>  Documentation/technical/api-trace2.txt   |  66 +++++++++---\n>  Makefile                                 |   1 +\n>  common-main.c                            |   8 +-\n>  compat/mingw.c                           |   2 +\n>  compat/win32/trace2_win32_process_info.c |  50 ++++++++-\n>  t/t0210-trace2-normal.sh                 |  41 +++++++-\n>  t/t0211-trace2-perf.sh                   |  53 ++++++++--\n>  t/t0212-trace2-event.sh                  |  52 ++++++++-\n>  trace2.c                                 |  21 +++-\n>  trace2.h                                 |  43 ++++++--\n>  trace2/tr2_cfg.c                         |   7 +-\n>  trace2/tr2_dst.c                         |  24 ++---\n>  trace2/tr2_dst.h                         |   3 +-\n>  trace2/tr2_sid.c                         |  39 ++++++-\n>  trace2/tr2_sysenv.c                      | 128 +++++++++++++++++++++++\n>  trace2/tr2_sysenv.h                      |  36 +++++++\n>  trace2/tr2_tbuf.c                        |  20 +++-\n>  trace2/tr2_tbuf.h                        |   5 +-\n>  trace2/tr2_tgt.h                         |   1 +\n>  trace2/tr2_tgt_event.c                   |  53 +++++-----\n>  trace2/tr2_tgt_normal.c                  |  19 ++--\n>  trace2/tr2_tgt_perf.c                    |  23 ++--\n>  trace2/tr2_tls.c                         |  38 ++++---\n>  trace2/tr2_tls.h                         |   8 +-\n>  24 files changed, 604 insertions(+), 137 deletions(-)\n>  create mode 100644 trace2/tr2_sysenv.c\n>  create mode 100644 trace2/tr2_sysenv.h\n> \n> \n> base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v2\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2\n> Pull-Request: https://github.com/gitgitgadget/git/pull/169\n\nThis series looks good to me, apart from the open question about\ndocumentation. Thanks!\n\nReviewed-by: Josh Steadmon <steadmon@google.com>\n"},{"id":"372945","messageId":"ded19f10-569a-f6d7-ad77-17a6f9c6b3a5@jeffhostetler.com","threadId":"50834","inReplyTo":"87k1gh9vii.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 5/7] trace2: report peak memory usage of the process","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-01T21:05:09Z","receivedAt":"2019-04-01T21:05:12Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 3/29/2019 6:16 PM, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Fri, Mar 29 2019, Jeff Hostetler via GitGitGadget wrote:\n> \n>> From: Jeff Hostetler <jeffhost@microsoft.com>\n>>\n>> Teach Windows version of git to report peak memory usage\n>> during exit() processing.\n>>\n>> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n>> ---\n>>   common-main.c                            |  2 +-\n>>   compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++--\n>>   trace2.c                                 |  2 +\n>>   trace2.h                                 | 14 +++++--\n>>   4 files changed, 60 insertions(+), 8 deletions(-)\n>>\n>> diff --git a/common-main.c b/common-main.c\n>> index 299ca62a72..582a7b1886 100644\n>> --- a/common-main.c\n>> +++ b/common-main.c\n>> @@ -41,7 +41,7 @@ int main(int argc, const char **argv)\n>>\n>>   \ttrace2_initialize();\n>>   \ttrace2_cmd_start(argv);\n>> -\ttrace2_collect_process_info();\n>> +\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);\n>>\n>>   \tgit_setup_gettext();\n>>\n>> diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c\n>> index 52bd62034b..2a514caed9 100644\n>> --- a/compat/win32/trace2_win32_process_info.c\n>> +++ b/compat/win32/trace2_win32_process_info.c\n>> @@ -1,5 +1,6 @@\n>>   #include \"../../cache.h\"\n>>   #include \"../../json-writer.h\"\n>> +#include \"lazyload.h\"\n>>   #include <Psapi.h>\n>>   #include <tlHelp32.h>\n>>\n>> @@ -137,11 +138,54 @@ static void get_is_being_debugged(void)\n>>   \t\t\t\t   \"windows/debugger_present\", 1);\n>>   }\n>>\n>> -void trace2_collect_process_info(void)\n>> +/*\n>> + * Emit JSON data with the peak memory usage of the current process.\n>> + */\n>> +static void get_peak_memory_info(void)\n>> +{\n>> +\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo,\n>> +\t\t\t  HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);\n>> +\n>> +\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n>> +\t\tPROCESS_MEMORY_COUNTERS pmc;\n>> +\n>> +\t\tif (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,\n>> +\t\t\t\t\t sizeof(pmc))) {\n>> +\t\t\tstruct json_writer jw = JSON_WRITER_INIT;\n>> +\n>> +\t\t\tjw_object_begin(&jw, 0);\n>> +\n>> +#define KV(kv) #kv, (intmax_t)pmc.kv\n>> +\n>> +\t\t\tjw_object_intmax(&jw, KV(PageFaultCount));\n>> +\t\t\tjw_object_intmax(&jw, KV(PeakWorkingSetSize));\n>> +\t\t\tjw_object_intmax(&jw, KV(PeakPagefileUsage));\n>> +\n>> +\t\t\tjw_end(&jw);\n>> +\n>> +\t\t\ttrace2_data_json(\"process\", the_repository,\n>> +\t\t\t\t\t \"windows/memory\", &jw);\n>> +\t\t\tjw_release(&jw);\n>> +\t\t}\n>> +\t}\n>> +}\n>> +\n>> +void trace2_collect_process_info(enum trace2_process_info_reason reason)\n>>   {\n>>   \tif (!trace2_is_enabled())\n>>   \t\treturn;\n>>\n>> -\tget_is_being_debugged();\n>> -\tget_ancestry();\n>> +\tswitch (reason) {\n>> +\tcase TRACE2_PROCESS_INFO_STARTUP:\n>> +\t\tget_is_being_debugged();\n>> +\t\tget_ancestry();\n>> +\t\treturn;\n>> +\n>> +\tcase TRACE2_PROCESS_INFO_EXIT:\n>> +\t\tget_peak_memory_info();\n>> +\t\treturn;\n>> +\n>> +\tdefault:\n>> +\t\tBUG(\"trace2_collect_process_info: unknown reason '%d'\", reason);\n>> +\t}\n>>   }\n>> diff --git a/trace2.c b/trace2.c\n>> index 490b3f071e..6baa65cdf9 100644\n>> --- a/trace2.c\n>> +++ b/trace2.c\n>> @@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)\n>>   \tif (!trace2_enabled)\n>>   \t\treturn code;\n>>\n>> +\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);\n>> +\n>>   \ttr2main_exit_code = code;\n>>\n>>   \tus_now = getnanotime() / 1000;\n>> diff --git a/trace2.h b/trace2.h\n>> index 894bfca7e0..888531eb08 100644\n>> --- a/trace2.h\n>> +++ b/trace2.h\n>> @@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);\n>>    * Optional platform-specific code to dump information about the\n>>    * current and any parent process(es).  This is intended to allow\n>>    * post-processors to know who spawned this git instance and anything\n>> - * else the platform may be able to tell us about the current process.\n>> + * else that the platform may be able to tell us about the current process.\n>>    */\n>> +\n>> +enum trace2_process_info_reason {\n>> +\tTRACE2_PROCESS_INFO_STARTUP,\n>> +\tTRACE2_PROCESS_INFO_EXIT,\n>> +};\n>> +\n>>   #if defined(GIT_WINDOWS_NATIVE)\n>> -void trace2_collect_process_info(void);\n>> +void trace2_collect_process_info(enum trace2_process_info_reason reason);\n>>   #else\n>> -#define trace2_collect_process_info() \\\n>> -\tdo {                          \\\n>> +#define trace2_collect_process_info(reason) \\\n>> +\tdo {                                \\\n>>   \t} while (0)\n>>   #endif\n> \n> FWIW this is the \"VmPeak\" line in /proc/$$/status on Linux. I don't know\n> if we can/should parse that in practice (I've been bitten in the past by\n> things in /proc having high cost on some kernel versions in the past,\n> notably smaps).\n> \n\nThanks,\n\nYeah, I've avoided adding the corresponding platform-specific changes\nin for non-Windows versions because I didn't want to venture off into\nthe weeds and introduce a perf or functional problem (for something\nthat I'm not going to make use of in the short term).  Whereas, we're\nseeing occasional perf problems with our Windows users on the OS repo\nwhere some (yet to be determined) commands will just go out to lunch.\n\nI suspect we'll have similar problems with out Mac users in the near\nfuture, but I didn't want to jump in there just yet.\n\nJeff\n\n\n\n"},{"id":"372946","messageId":"c06fcab0-2aa7-e042-db0f-e2d6c9242212@jeffhostetler.com","threadId":"50834","inReplyTo":"20190401210034.GD60888@google.com","subject":"Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-01T21:06:44Z","receivedAt":"2019-04-01T21:06:48Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 4/1/2019 5:00 PM, Josh Steadmon wrote:\n> On 2019.03.29 10:04, Jeff Hostetler via GitGitGadget wrote:\n> [...]\n>> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\n>> index baaa1153bb..13ca595c69 100644\n>> --- a/Documentation/technical/api-trace2.txt\n>> +++ b/Documentation/technical/api-trace2.txt\n>> @@ -117,6 +117,37 @@ values are recognized.\n>>   Socket type can be either `stream` or `dgram`.  If the socket type is\n>>   omitted, Git will try both.\n>>   \n>> +== Trace2 Settings in System Config\n>> +\n>> +Trace2 also reads configuration information from the system config.\n>> +This is intended to help adminstrators to gather system-wide Git\n>> +performance data.\n>> +\n>> +Trace2 only reads the system configuration, it does not read global,\n>> +local, worktree, or `-c` config settings.\n>> +\n>> +Trace2 will try to load the following system configuration settings\n>> +and then read the corresponding environment variables at startup.\n>> +\n>> +....\n>> +---------------------------------------------------\n>> +trace2.normalTarget          GIT_TR2\n>> +trace2.normalBrief           GIT_TR2_BRIEF\n>> +\n>> +trace2.perfTarget            GIT_TR2_PERF\n>> +trace2.perfBrief             GIT_TR2_PERF_BRIEF\n>> +\n>> +trace2.eventTarget           GIT_TR2_EVENT\n>> +trace2.eventBrief            GIT_TR2_EVENT_BRIEF\n>> +trace2.eventNesting          GIT_TR2_EVENT_NESTING\n>> +\n>> +trace2.configParams          GIT_TR2_CONFIG_PARAMS\n>> +\n>> +trace2.destinationDebug      GIT_TR2_DST_DEBUG\n>> +---------------------------------------------------\n>> +....\n>> +\n>> +\n> \n> A question for the list: should these new config vars also be documented\n> in the git-config manpage, or is it better to keep these separate since\n> they are only read from the system config?\n> \n\nI wasn't sure either, so I just kept them in the trace2 api doc for now.\nJeff\n"},{"id":"372947","messageId":"5a507e32-cf84-21c9-4ffe-246ecef49370@jeffhostetler.com","threadId":"50834","inReplyTo":"87lg0x9voz.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 7/7] trace2: make SIDs more unique","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-01T21:16:49Z","receivedAt":"2019-04-01T21:16:52Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 3/29/2019 6:12 PM, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Fri, Mar 29 2019, Jeff Hostetler via GitGitGadget wrote:\n> \n>> From: Jeff Hostetler <jeffhost@microsoft.com>\n>>\n>> Update SID component construction to use the current UTC datetime\n>> and a portion of the SHA1 of the hostname.\n>>\n>> Use an simplified date/time format to make it easier to use the\n>> SID component as a logfile filename.\n>> [...]\n>> +static void tr2_sid_append_my_sid_component(void)\n>> +{\n>> +\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n>> +\tstruct tr2_tbuf tb_now;\n>> +\tgit_hash_ctx ctx;\n>> +\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n>> +\tchar hex[GIT_MAX_HEXSZ + 1];\n>> +\tchar hostname[HOST_NAME_MAX + 1];\n>> +\n>> +\ttr2_tbuf_utc_datetime_for_filename(&tb_now);\n>> +\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n>> +\tstrbuf_addch(&tr2sid_buf, '-');\n>> +\n>> +\tif (xgethostname(hostname, sizeof(hostname)))\n>> +\t\txsnprintf(hostname, sizeof(hostname), \"localhost\");\n>> +\n>> +\talgo->init_fn(&ctx);\n>> +\talgo->update_fn(&ctx, hostname, strlen(hostname));\n>> +\talgo->final_fn(hash, &ctx);\n>> +\thash_to_hex_algop_r(hex, hash, algo);\n>> +\tstrbuf_add(&tr2sid_buf, hex, 8);\n>> +\n>> +\tstrbuf_addch(&tr2sid_buf, '-');\n>> +\tstrbuf_addf(&tr2sid_buf, \"%06\"PRIuMAX, (uintmax_t)getpid());\n>> +}\n>> +\n> \n> Thanks for turning my shitty half-formed idea into a patch :)\n> \n> I wrote this on top to bikeshed this a bit further, wonder what you\n> think:\n> https://github.com/gitgitgadget/git/compare/pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2...avar:pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2\n> \n> So e.g.:\n> \n>      Before: 20190329-220413-446441-c2f5b994-018702\n>      After:  20190329T220431.244562Z-Hc2f5b994-P19812F\n> \n> I.e:\n> \n>   * Using <date>T<time> as is ISO 8601 convention/easier to read\n> \n>   * <dateime>.<microseconds>Z, so seperating with \".\" to indicate it's\n>     the same value + add \"Z\" for \"it's UTC\". I'm least sure about the\n>     \".\". Is that going to cause issues on Windows these days (the rest\n>     being the \"extension\"...).\n\nI had a version that did just that.  I checked the various ISO and RFCs\nand it seems like the fractional seconds is usually allowed between the\nwhole seconds and the \"Z\".\n\nI've not seen any problems with that format.\n\nI think I got spooked by your original suggestion to put the fraction in\na term after the whole \"<date>T<time>Z\" term.\n\nI'll convert it back to match your suggestion.\n\n> \n>   * I changed the hostname discovery so if gethostbyname() fails we'll\n>     print \"-H00000000-\" for that part, instead of \"-H<first 8 chars of\n>     the sha1 for 'localhost'>-\". Also prefix with \"H\" for \"Host\".\n\nI like that.\n\n> \n>   * Wrap pids to 0xffff, prefix with \"P\" (Pid)\" and trail with either \"F\"\n>     = Full or \"W\" = Wrapped (not the real PID).\n\nI could see the \"P\".  I'm not sure about the hex -- I sometimes want to\ndo a \"ps\" or watch the processes go by in TaskManager and friends and\nthey all print the pid in decimal.  But it's not that big a deal.\n\n> \n>   * I didn't add \"T<datetime>\" like \"H\" and \"P\" for the rest, since it's\n>     obvious what sort of value it is.\n> \n> Maybe this is going a bit overboard, but I think it's easier to read at\n> a glance for humans, and since it's meant to be opaque to machines\n> anyway and the length is simliar enough not to matter I figure it's\n> worth it.\n> \n\nI'll re-roll.\nThanks\nJeff\n\n"},{"id":"372998","messageId":"20190403000032.GA190454@google.com","threadId":"50834","inReplyTo":"d048f3ffb801adc7f1b4e48248ca31ebade1b37d.1553879063.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2019-04-03T00:00:32Z","receivedAt":"2019-04-03T00:00:38Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nJeff Hostetler via GitGitGadget wrote:\n\n> Teach git to read the system config (usually \"/etc/gitconfig\") for\n> default Trace2 settings.  This allows system-wide Trace2 settings to\n> be installed and inherited to make it easier to manage a collection of\n> systems.\n\nYay!  Thanks for writing this, and sorry for the slow review.\n\n[...]\n> Only the system config file is used.  Trace2 config values are ignored\n> in local, global, and other config files.  Likewise, the \"-c\" command\n> line arguments are ignored for Trace2 values.  These limits are for\n> performance reasons.\n\nCan you say a bit more about this?  If I'm willing to pay the\nperformance cost, is there a way for me to turn on respecting other\nconfig files?  What is that performance cost?\n\n[...]\n> --- a/Documentation/technical/api-trace2.txt\n> +++ b/Documentation/technical/api-trace2.txt\n> @@ -117,6 +117,37 @@ values are recognized.\n>  Socket type can be either `stream` or `dgram`.  If the socket type is\n>  omitted, Git will try both.\n>  \n> +== Trace2 Settings in System Config\n> +\n> +Trace2 also reads configuration information from the system config.\n> +This is intended to help adminstrators to gather system-wide Git\n> +performance data.\n> +\n> +Trace2 only reads the system configuration, it does not read global,\n> +local, worktree, or `-c` config settings.\n\nAn additional limitation is that this doesn't appear to support\ninclude.* directives.  Intended?\n\n[...]\n> --- a/t/t0210-trace2-normal.sh\n> +++ b/t/t0210-trace2-normal.sh\n[...]\n> +MOCK=./mock_system_config\n> +\n> +test_expect_success 'setup mocked /etc/gitconfig' '\n> +\tgit config --file $MOCK trace2.normalTarget \"$(pwd)/trace.normal\" &&\n> +\tgit config --file $MOCK trace2.normalBrief 1\n> +'\n> +\n> +test_expect_success 'using mock, normal stream, return code 0' '\n> +\ttest_when_finished \"rm trace.normal actual expect\" &&\n> +\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n\nTests run with GIT_CONFIG_NOSYSTEM=1 to protect themselves from any\nsystem config the user has.\n\nSo this would be easier to test if we can use user-level config for\nit.\n\n[...]\n> --- /dev/null\n> +++ b/trace2/tr2_sysenv.c\n> @@ -0,0 +1,128 @@\n> +#include \"cache.h\"\n> +#include \"config.h\"\n> +#include \"dir.h\"\n> +#include \"tr2_sysenv.h\"\n> +\n> +/*\n> + * Each entry represents a trace2 setting.\n> + * See Documentation/technical/api-trace2.txt\n> + */\n> +struct tr2_sysenv_entry {\n> +\tconst char *env_var_name;\n> +\tconst char *git_config_name;\n> +\n> +\tchar *value;\n> +\tunsigned int getenv_called : 1;\n> +};\n> +\n> +/*\n> + * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n\nCan we deduplicate to avoid the need to match?\n\nPerhaps using C99 array initializers would help:\n\n\t[TR2_SYSENV_CFG_PARAM] = { ... },\n\n[...]\n> +/*\n> + * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n> + * unless we were built with a runtime-prefix).  These are intended to\n> + * define the default values for Trace2 as requested by the administrator.\n> + */\n> +void tr2_sysenv_load(void)\n> +{\n> +\tconst char *system_config_pathname;\n> +\tconst char *test_pathname;\n> +\n> +\tsystem_config_pathname = git_etc_gitconfig();\n> +\n> +\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n> +\tif (test_pathname) {\n> +\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n> +\t\t\treturn; /* disable use of system config */\n> +\n> +\t\t/* mock it with given test file */\n> +\t\tsystem_config_pathname = test_pathname;\n> +\t}\n> +\n> +\tif (file_exists(system_config_pathname))\n> +\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n> +\t\t\t\t     NULL);\n\nThis duplicates functionality from config.c and misses some features\nalong the way (e.g. support for include.*).\n\nWould read_early_config work?  If we want a variant that doesn't\ndiscover_git_directory, we can change that function to handle it.\n\nFor our needs at Google, it would be very helpful to have support for\ninclude.* and reading settings from at least $HOME/.gitconfig in\naddition to /etc/gitconfig (even better if it supports per-repo config\nas well).  I believe it would simplify the code and tests, too.  If\nthere's anything I can to help, please don't hesitate to ask.\n\nThanks,\nJonathan\n"},{"id":"372999","messageId":"20190403000152.GB190454@google.com","threadId":"50834","inReplyTo":"20190401210034.GD60888@google.com","subject":"Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2019-04-03T00:01:52Z","receivedAt":"2019-04-03T00:01:57Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Josh Steadmon wrote:\n\n> A question for the list: should these new config vars also be documented\n> in the git-config manpage, or is it better to keep these separate since\n> they are only read from the system config?\n\nYes, they should be in the git-config manpage.\n\n*If* they are read only from the system config, the documentation\nthere should say so.\n\nThanks,\nJonathan\n"},{"id":"373501","messageId":"a0c89d0d-669e-bf56-25d2-cbb09b012e70@jeffhostetler.com","threadId":"50834","inReplyTo":"20190403000032.GA190454@google.com","subject":"Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-09T15:58:01Z","receivedAt":"2019-04-09T15:58:07Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 4/2/2019 8:00 PM, Jonathan Nieder wrote:\n> Hi,\n> \n> Jeff Hostetler via GitGitGadget wrote:\n> \n>> Teach git to read the system config (usually \"/etc/gitconfig\") for\n>> default Trace2 settings.  This allows system-wide Trace2 settings to\n>> be installed and inherited to make it easier to manage a collection of\n>> systems.\n> \n> Yay!  Thanks for writing this, and sorry for the slow review.\n> \n> [...]\n>> Only the system config file is used.  Trace2 config values are ignored\n>> in local, global, and other config files.  Likewise, the \"-c\" command\n>> line arguments are ignored for Trace2 values.  These limits are for\n>> performance reasons.\n> \n> Can you say a bit more about this?  If I'm willing to pay the\n> performance cost, is there a way for me to turn on respecting other\n> config files?  What is that performance cost?\n\nSeveral thoughts here.  Some are performance-related and some are\nstartup chicken-n-egg problems.  I tried to add trace2 to the code\nbase in the least disruptive way possible and hopefully with minimal\nside-effects on existing behaviors.  And also minimum impact on overall\nperformance when not in use.\n\nSo, with that in mind:\n\n[] Trace2 should be initialized as early as and lightly as possible\n    so that timers are started and it can capture events from other\n    startup activities.  And so that we can tell as early as possible\n    if trace2 should NOT be enabled and short-cut those calls and not\n    waste time collecting unnecessary data.\n\n[] Trace2 is initialized by calls from common-main.c:main().  This\n    happens before cmd_main() is called, so we are very early in the\n    startup process and very few things have been initialized.  For\n    example, I had to let git_resolve_executable_dir() run so that\n    we could find the location of the system config, but that's about\n    it.  We have not even initialized \"the_repository\" yet.\n\n[] WRT \"-c var=val\", this is processed by git.c:handle_options() and\n    called from git.c:cmd_main() and git.c:handle_alias().  So the \"-c\"\n    args won't be respected until after that point.\n\n    Adding trace2 initialization after that point is a bit of a mess.\n    Teaching trace2 to scan the argv for \"-c\" is just duplicating effort.\n    And moving the \"-c\" processing earlier in the startup, changes the\n    behavior of the \"git-*\" commands (which don't currently recognize\n    the \"-c\" option).\n\n    So that's why I'm suggesting we not respect \"-c\" for this.\n\n[] By initializing trace2 inside main() we guarantee that it will get\n    started.  If we wait to initialize it until after handle_options()\n    returns, we miss events for commands that it handles itself (such\n    as \"git --exec-path\" where it just prints and exits or syntax errors\n    where it directly calls usage() and exits).\n\n[] WRT to per-repo config values:\n\n    In common-main.c:main() we have not yet discovered the .git dir,\n    so repo-local config files are questionable at a very early point\n    in the process startup.  Again, it comes down to whether we wait\n    for gitdir discovery (and whatever file system scanning, --gitdir,\n    or -C processing is required) before deciding whether to start\n    trace2 or not.\n\n    Also, per-repo trace2 config settings aren't available at the time\n    of the clone, so just relying on them will leave our telemetry\n    incomplete.  It's better to have a system (or maybe a user) setting\n    and not a per-repo setting.\n\n    Longer term, with submodules and plans to support them in-proc rather\n    than via sub-processes, I don't think there should be any expectation\n    that trace2 settings would adapt during recursive operations.  So for\n    example, a top-level command might see different trace2 settings than\n    a command run inside a submodule.  If submodule operations become\n    in-proc, then to maintain that expected behavior we'd need to have\n    per-repo trace2 settings.  (Granted, not impossible, but by saying no\n    to that now, we can eliminate a possible pain point in the future.)\n\n[] i'll add more on this topic at the bottom of this note in response to\n    your per-user and includes questions.\n\n\n> [...]\n>> --- a/Documentation/technical/api-trace2.txt\n>> +++ b/Documentation/technical/api-trace2.txt\n>> @@ -117,6 +117,37 @@ values are recognized.\n>>   Socket type can be either `stream` or `dgram`.  If the socket type is\n>>   omitted, Git will try both.\n>>   \n>> +== Trace2 Settings in System Config\n>> +\n>> +Trace2 also reads configuration information from the system config.\n>> +This is intended to help adminstrators to gather system-wide Git\n>> +performance data.\n>> +\n>> +Trace2 only reads the system configuration, it does not read global,\n>> +local, worktree, or `-c` config settings.\n> \n> An additional limitation is that this doesn't appear to support\n> include.* directives.  Intended?\n\nI didn't specifically intend to support or not-support include files\nhere.  Frankly, the complexity of the config code makes my eyes bleed.\nI'll investigate adding it.\n\n\n> \n> [...]\n>> --- a/t/t0210-trace2-normal.sh\n>> +++ b/t/t0210-trace2-normal.sh\n> [...]\n>> +MOCK=./mock_system_config\n>> +\n>> +test_expect_success 'setup mocked /etc/gitconfig' '\n>> +\tgit config --file $MOCK trace2.normalTarget \"$(pwd)/trace.normal\" &&\n>> +\tgit config --file $MOCK trace2.normalBrief 1\n>> +'\n>> +\n>> +test_expect_success 'using mock, normal stream, return code 0' '\n>> +\ttest_when_finished \"rm trace.normal actual expect\" &&\n>> +\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n> \n> Tests run with GIT_CONFIG_NOSYSTEM=1 to protect themselves from any\n> system config the user has.\n\nThanks for the pointer.  I'll update the tr2_sysenv_load() to check\ngit_system_config() before trying to use the system config file.\n\n> \n> So this would be easier to test if we can use user-level config for\n> it.\n\nI suppose.  I think it just moves the testing problem to a trick using\n$HOME, right?  But it does get rid of that GIT_TEST_TR2_SYSTEM_CONFIG\nsymbol, so yeah a net win.  I'll investigate.  Thanks.\n\n\n> [...]\n>> --- /dev/null\n>> +++ b/trace2/tr2_sysenv.c\n>> @@ -0,0 +1,128 @@\n>> +#include \"cache.h\"\n>> +#include \"config.h\"\n>> +#include \"dir.h\"\n>> +#include \"tr2_sysenv.h\"\n>> +\n>> +/*\n>> + * Each entry represents a trace2 setting.\n>> + * See Documentation/technical/api-trace2.txt\n>> + */\n>> +struct tr2_sysenv_entry {\n>> +\tconst char *env_var_name;\n>> +\tconst char *git_config_name;\n>> +\n>> +\tchar *value;\n>> +\tunsigned int getenv_called : 1;\n>> +};\n>> +\n>> +/*\n>> + * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n> \n> Can we deduplicate to avoid the need to match?\n> \n> Perhaps using C99 array initializers would help:\n> \n> \t[TR2_SYSENV_CFG_PARAM] = { ... },\n\nCool.  I hadn't seen that syntax before.\n\n> \n> [...]\n>> +/*\n>> + * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n>> + * unless we were built with a runtime-prefix).  These are intended to\n>> + * define the default values for Trace2 as requested by the administrator.\n>> + */\n>> +void tr2_sysenv_load(void)\n>> +{\n>> +\tconst char *system_config_pathname;\n>> +\tconst char *test_pathname;\n>> +\n>> +\tsystem_config_pathname = git_etc_gitconfig();\n>> +\n>> +\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n>> +\tif (test_pathname) {\n>> +\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n>> +\t\t\treturn; /* disable use of system config */\n>> +\n>> +\t\t/* mock it with given test file */\n>> +\t\tsystem_config_pathname = test_pathname;\n>> +\t}\n>> +\n>> +\tif (file_exists(system_config_pathname))\n>> +\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n>> +\t\t\t\t     NULL);\n> \n> This duplicates functionality from config.c and misses some features\n> along the way (e.g. support for include.*).\n> \n> Would read_early_config work?  If we want a variant that doesn't\n> discover_git_directory, we can change that function to handle it.\n> \n> For our needs at Google, it would be very helpful to have support for\n> include.* and reading settings from at least $HOME/.gitconfig in\n> addition to /etc/gitconfig (even better if it supports per-repo config\n> as well).  I believe it would simplify the code and tests, too.  If\n> there's anything I can to help, please don't hesitate to ask.\n\nread_early_config() might work, but it is pretty heavy and doesn't\naddress my above comments.\n\nPerhaps a compromise would be to have it read just the system and\nuser config files (w/ includes turned on).  It shouldn't take too\nmuch time and it shouldn't have the startup-order dependencies, I\nthink.\n\nThoughts??\n\n> \n> Thanks,\n> Jonathan\n> \n\nThanks,\nJeff\n"},{"id":"373658","messageId":"ea8c199f911a84505b1aba5735a280ffc989e2a1.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 01/10] config: initialize opts structure in repo_read_config()","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:38Z","receivedAt":"2019-04-11T15:18:42Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nInitialize opts structure in repo_read_config().\n\nThis change fixes a crash in later commit after a new field is added\nto the structure.\n\nIn commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config()\nwas added.  It only initializes 3 fields in the opts structure.  It is\npassed to config_with_options() and then to do_git_config_sequence().\nHowever, do_git_config_sequence() drops the opts on the floor and calls\ngit_config_from_file() rather than git_config_from_file_with_options(),\nso that may be why this hasn't been a problem in the past.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/config.c b/config.c\nindex 0f0cdd8c0f..8e5f45fa20 100644\n--- a/config.c\n+++ b/config.c\n@@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha\n /* Functions use to read configuration from a repository */\n static void repo_read_config(struct repository *repo)\n {\n-\tstruct config_options opts;\n+\tstruct config_options opts = {0};\n \n \topts.respect_includes = 1;\n \topts.commondir = repo->commondir;\n-- \ngitgitgadget\n\n"},{"id":"373659","messageId":"pull.169.v3.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v2.git.gitgitgadget@gmail.com","subject":"[PATCH v3 00/10] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:37Z","receivedAt":"2019-04-11T15:18:44Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"Here is version 3.\n[] It incorporates Ævar's suggestions WRT the format and uniqueness of the\nSID. [] It now reads both system and global config for trace2 settings and\nhandles includes as Jonathan suggested.\n\nI added a read_very_early_config() function that is similar to \nread_early_config()but omits repo local, worktree, and -c command line\nsettings. This felt like a little bit of a hack, but it made the intent\nclear. And it avoided asserting the various global variables were in a\ncertain known state before calling the read_early_config().\n\nIn doing so, I uncovered an uninitialized opts variable in\nread_repo_config(). The first patch in this series addresses it in\nisolation. As the commit message suggests, this went undetected because opts \nvariable doesn't get passed all the way down, but I'm not familiar enough\nwith that code to know whether that's an accident or by design. Callers of \nconfig_with_options() all setopts.respect_includes and that changes the args\nthat config_with_options()passes to the functions that it calls. What makes\nthis a little more troubling is theopts.event_fn field added in\n8032cc4462b8af268fe457c2a0431473334dfd18 that might not be initialized.\nAgain, I'm not familiar enough with this code and the actually observable\ncontrol flows thru it to know if that could cause an issue.\n\nJeff Hostetler (10):\n  config: initialize opts structure in repo_read_config()\n  trace2: refactor setting process starting time\n  trace2: add absolute elapsed time to start event\n  trace2: find exec-dir before trace2 initialization\n  config: add read_very_early_config()\n  trace2: use system/global config for default trace2 settings\n  trace2: report peak memory usage of the process\n  trace2: clarify UTC datetime formatting\n  trace2: make SIDs more unique\n  trace2: update docs to describe system/global config settings\n\n Documentation/config.txt                 |   2 +\n Documentation/config/trace2.txt          |  56 ++++++++\n Documentation/technical/api-trace2.txt   | 176 +++++++++++++----------\n Documentation/trace2-target-values.txt   |  10 ++\n Makefile                                 |   1 +\n common-main.c                            |   8 +-\n compat/mingw.c                           |   2 +\n compat/win32/trace2_win32_process_info.c |  50 ++++++-\n config.c                                 |  27 +++-\n config.h                                 |   4 +\n t/t0210-trace2-normal.sh                 |  49 ++++++-\n t/t0211-trace2-perf.sh                   |  43 ++++--\n t/t0212-trace2-event.sh                  |  42 +++++-\n trace2.c                                 |  21 ++-\n trace2.h                                 |  43 ++++--\n trace2/tr2_cfg.c                         |   7 +-\n trace2/tr2_dst.c                         |  24 ++--\n trace2/tr2_dst.h                         |   3 +-\n trace2/tr2_sid.c                         |  55 ++++++-\n trace2/tr2_sysenv.c                      | 127 ++++++++++++++++\n trace2/tr2_sysenv.h                      |  36 +++++\n trace2/tr2_tbuf.c                        |  20 ++-\n trace2/tr2_tbuf.h                        |   5 +-\n trace2/tr2_tgt.h                         |   1 +\n trace2/tr2_tgt_event.c                   |  53 +++----\n trace2/tr2_tgt_normal.c                  |  19 +--\n trace2/tr2_tgt_perf.c                    |  23 +--\n trace2/tr2_tls.c                         |  38 +++--\n trace2/tr2_tls.h                         |   8 +-\n 29 files changed, 750 insertions(+), 203 deletions(-)\n create mode 100644 Documentation/config/trace2.txt\n create mode 100644 Documentation/trace2-target-values.txt\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\n\nbase-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/169\n\nRange-diff vs v2:\n\n  -:  ---------- >  1:  ea8c199f91 config: initialize opts structure in repo_read_config()\n  1:  7f1a347322 =  2:  3dbcfc6a8d trace2: refactor setting process starting time\n  2:  c15f783c26 =  3:  8b00025af5 trace2: add absolute elapsed time to start event\n  3:  d4023acde7 =  4:  c3c5f6a96b trace2: find exec-dir before trace2 initialization\n  -:  ---------- >  5:  d15be7b63a config: add read_very_early_config()\n  4:  d048f3ffb8 !  6:  c085a482dd trace2: use system config for default trace2 settings\n     @@ -1,8 +1,8 @@\n      Author: Jeff Hostetler <jeffhost@microsoft.com>\n      \n     -    trace2: use system config for default trace2 settings\n     +    trace2: use system/global config for default trace2 settings\n      \n     -    Teach git to read the system config (usually \"/etc/gitconfig\") for\n     +    Teach git to read the system and global config files for\n          default Trace2 settings.  This allows system-wide Trace2 settings to\n          be installed and inherited to make it easier to manage a collection of\n          systems.\n     @@ -10,10 +10,9 @@\n          The original GIT_TR2* environment variables are loaded afterwards and\n          can be used to override the system settings.\n      \n     -    Only the system config file is used.  Trace2 config values are ignored\n     -    in local, global, and other config files.  Likewise, the \"-c\" command\n     -    line arguments are ignored for Trace2 values.  These limits are for\n     -    performance reasons.\n     +    Only the system and global config files are used.  Repo and worktree\n     +    local config files are ignored.  Likewise, the \"-c\" command line\n     +    arguments are also ignored.  These limits are for performance reasons.\n      \n          (1) For users not using Trace2, there should be minimal overhead to\n          detect that Trace2 is not enabled.  In particular, Trace2 should not\n     @@ -24,54 +23,8 @@\n          git process initialization (which involves discovering the .git directory\n          and reading a hierarchy of config files).\n      \n     -    Added the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing\n     -    purposes to specify the pathname of a fake \"system\" config or disable\n     -    use of the system config.\n     -\n          Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n      \n     - diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\n     - --- a/Documentation/technical/api-trace2.txt\n     - +++ b/Documentation/technical/api-trace2.txt\n     -@@\n     - Socket type can be either `stream` or `dgram`.  If the socket type is\n     - omitted, Git will try both.\n     - \n     -+== Trace2 Settings in System Config\n     -+\n     -+Trace2 also reads configuration information from the system config.\n     -+This is intended to help adminstrators to gather system-wide Git\n     -+performance data.\n     -+\n     -+Trace2 only reads the system configuration, it does not read global,\n     -+local, worktree, or `-c` config settings.\n     -+\n     -+Trace2 will try to load the following system configuration settings\n     -+and then read the corresponding environment variables at startup.\n     -+\n     -+....\n     -+---------------------------------------------------\n     -+trace2.normalTarget          GIT_TR2\n     -+trace2.normalBrief           GIT_TR2_BRIEF\n     -+\n     -+trace2.perfTarget            GIT_TR2_PERF\n     -+trace2.perfBrief             GIT_TR2_PERF_BRIEF\n     -+\n     -+trace2.eventTarget           GIT_TR2_EVENT\n     -+trace2.eventBrief            GIT_TR2_EVENT_BRIEF\n     -+trace2.eventNesting          GIT_TR2_EVENT_NESTING\n     -+\n     -+trace2.configParams          GIT_TR2_CONFIG_PARAMS\n     -+\n     -+trace2.destinationDebug      GIT_TR2_DST_DEBUG\n     -+---------------------------------------------------\n     -+....\n     -+\n     -+\n     - == Trace2 API\n     - \n     - All public Trace2 functions and macros are defined in `trace2.h` and\n     -\n       diff --git a/Makefile b/Makefile\n       --- a/Makefile\n       +++ b/Makefile\n     @@ -90,10 +43,6 @@\n      @@\n       #!/bin/sh\n       \n     -+# Disable loading of Trace2 settings from the system config\n     -+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n     -+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n     -+\n      +# Turn off any inherited trace2 settings for this test.\n      +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n      +unset GIT_TR2_BRIEF\n     @@ -118,22 +67,34 @@\n       \ttest_cmp expect actual\n       '\n       \n     -+# Now test using system config by using a mocked up config file\n     -+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n     -+# GIT_TR2* environment variables.\n     -+\n      +unset GIT_TR2_BRIEF\n      +\n     -+MOCK=./mock_system_config\n     ++# Now test without environment variables and get all Trace2 settings\n     ++# from the global config.\n      +\n     -+test_expect_success 'setup mocked /etc/gitconfig' '\n     -+\tgit config --file $MOCK trace2.normalTarget \"$(pwd)/trace.normal\" &&\n     -+\tgit config --file $MOCK trace2.normalBrief 1\n     ++test_expect_success 'using global config, normal stream, return code 0' '\n     ++\ttest_when_finished \"rm trace.normal actual expect\" &&\n     ++\ttest_config_global trace2.normalBrief 1 &&\n     ++\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n     ++\ttest-tool trace2 001return 0 &&\n     ++\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n     ++\tcat >expect <<-EOF &&\n     ++\t\tversion $V\n     ++\t\tstart _EXE_ trace2 001return 0\n     ++\t\tcmd_name trace2 (trace2)\n     ++\t\texit elapsed:_TIME_ code:0\n     ++\t\tatexit elapsed:_TIME_ code:0\n     ++\tEOF\n     ++\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'using mock, normal stream, return code 0' '\n     -+\ttest_when_finished \"rm trace.normal actual expect\" &&\n     -+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n     ++test_expect_success 'using global config with include' '\n     ++\ttest_when_finished \"rm trace.normal actual expect real.gitconfig\" &&\n     ++\ttest_config_global trace2.normalBrief 1 &&\n     ++\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n     ++\tmv \"$(pwd)/.gitconfig\" \"$(pwd)/real.gitconfig\" &&\n     ++\ttest_config_global include.path \"$(pwd)/real.gitconfig\" &&\n     ++\ttest-tool trace2 001return 0 &&\n      +\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n      +\tcat >expect <<-EOF &&\n      +\t\tversion $V\n     @@ -153,10 +114,6 @@\n      @@\n       #!/bin/sh\n       \n     -+# Disable loading of Trace2 settings from the system config\n     -+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n     -+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n     -+\n      +# Turn off any inherited trace2 settings for this test.\n      +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n      +unset GIT_TR2_PERF_BRIEF\n     @@ -181,22 +138,16 @@\n       \ttest_cmp expect actual\n       '\n       \n     -+# Now test using system config by using a mocked up config file\n     -+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n     -+# GIT_TR2* environment variables.\n     -+\n      +unset GIT_TR2_PERF_BRIEF\n      +\n     -+MOCK=./mock_system_config\n     -+\n     -+test_expect_success 'setup mocked /etc/gitconfig' '\n     -+\tgit config --file $MOCK trace2.perfTarget \"$(pwd)/trace.perf\" &&\n     -+\tgit config --file $MOCK trace2.perfBrief 1\n     -+'\n     ++# Now test without environment variables and get all Trace2 settings\n     ++# from the global config.\n      +\n     -+test_expect_success 'using mock, perf stream, return code 0' '\n     ++test_expect_success 'using global config, perf stream, return code 0' '\n      +\ttest_when_finished \"rm trace.perf actual expect\" &&\n     -+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 001return 0 &&\n     ++\ttest_config_global trace2.perfBrief 1 &&\n     ++\ttest_config_global trace2.perfTarget \"$(pwd)/trace.perf\" &&\n     ++\ttest-tool trace2 001return 0 &&\n      +\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n      +\tcat >expect <<-EOF &&\n      +\t\td0|main|version|||||$V\n     @@ -216,10 +167,6 @@\n      @@\n       #!/bin/sh\n       \n     -+# Disable loading of Trace2 settings from the system config\n     -+# (usually \"/etc/gitconfig\") to eliminate system dependencies.\n     -+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG\n     -+\n      +# Turn off any inherited trace2 settings for this test.\n      +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n      +unset GIT_TR2_BARE\n     @@ -244,19 +191,13 @@\n       \ttest_cmp expect actual\n       '\n       \n     -+# Now test using system config by using a mocked up config file\n     -+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n     -+# GIT_TR2* environment variables.\n     -+\n     -+MOCK=./mock_system_config\n     ++# Now test without environment variables and get all Trace2 settings\n     ++# from the global config.\n      +\n     -+test_expect_success 'setup mocked /etc/gitconfig' '\n     -+\tgit config --file $MOCK trace2.eventTarget \"$(pwd)/trace.event\"\n     -+'\n     -+\n     -+test_expect_success JSON_PP 'using mock, event stream, error event' '\n     ++test_expect_success JSON_PP 'using global config, event stream, error event' '\n      +\ttest_when_finished \"rm trace.event actual expect\" &&\n     -+\tGIT_TEST_TR2_SYSTEM_CONFIG=\"$MOCK\" test-tool trace2 003error \"hello world\" \"this is a test\" &&\n     ++\ttest_config_global trace2.eventTarget \"$(pwd)/trace.event\" &&\n     ++\ttest-tool trace2 003error \"hello world\" \"this is a test\" &&\n      +\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n      +\tsed -e \"s/^|//\" >expect <<-EOF &&\n      +\t|VAR1 = {\n     @@ -503,8 +444,9 @@\n      +\n      +/*\n      + * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n     -+ * These strings are constant and must match the published names as\n     -+ * described in the documentation.\n     ++ *\n     ++ * The strings in this table are constant and must match the published\n     ++ * config and environment variable names as described in the documentation.\n      + *\n      + * We do not define entries for the GIT_TR2_PARENT_* environment\n      + * variables because they are transient and used to pass information\n     @@ -512,19 +454,28 @@\n      + */\n      +/* clang-format off */\n      +static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n     -+\t{ \"GIT_TR2_CONFIG_PARAMS\",   \"trace2.configparams\"     },\n     -+\n     -+\t{ \"GIT_TR2_DST_DEBUG\",       \"trace2.destinationdebug\" },\n     -+\n     -+\t{ \"GIT_TR2\",                 \"trace2.normaltarget\"     },\n     -+\t{ \"GIT_TR2_BRIEF\",           \"trace2.normalbrief\"      },\n     -+\n     -+\t{ \"GIT_TR2_EVENT\",           \"trace2.eventtarget\"      },\n     -+\t{ \"GIT_TR2_EVENT_BRIEF\",     \"trace2.eventbrief\"       },\n     -+\t{ \"GIT_TR2_EVENT_NESTING\",   \"trace2.eventnesting\"     },\n     -+\n     -+\t{ \"GIT_TR2_PERF\",            \"trace2.perftarget\"       },\n     -+\t{ \"GIT_TR2_PERF_BRIEF\",      \"trace2.perfbrief\"        },\n     ++\t[TR2_SYSENV_CFG_PARAM]     = { \"GIT_TR2_CONFIG_PARAMS\",\n     ++\t\t\t\t       \"trace2.configparams\" },\n     ++\n     ++\t[TR2_SYSENV_DST_DEBUG]     = { \"GIT_TR2_DST_DEBUG\",\n     ++\t\t\t\t       \"trace2.destinationdebug\" },\n     ++\n     ++\t[TR2_SYSENV_NORMAL]        = { \"GIT_TR2\",\n     ++\t\t\t\t       \"trace2.normaltarget\" },\n     ++\t[TR2_SYSENV_NORMAL_BRIEF]  = { \"GIT_TR2_BRIEF\",\n     ++\t\t\t\t       \"trace2.normalbrief\" },\n     ++\n     ++\t[TR2_SYSENV_EVENT]         = { \"GIT_TR2_EVENT\",\n     ++\t\t\t\t       \"trace2.eventtarget\" },\n     ++\t[TR2_SYSENV_EVENT_BRIEF]   = { \"GIT_TR2_EVENT_BRIEF\",\n     ++\t\t\t\t       \"trace2.eventbrief\" },\n     ++\t[TR2_SYSENV_EVENT_NESTING] = { \"GIT_TR2_EVENT_NESTING\",\n     ++\t\t\t\t       \"trace2.eventnesting\" },\n     ++\n     ++\t[TR2_SYSENV_PERF]          = { \"GIT_TR2_PERF\",\n     ++\t\t\t\t       \"trace2.perftarget\" },\n     ++\t[TR2_SYSENV_PERF_BRIEF]    = { \"GIT_TR2_PERF_BRIEF\",\n     ++\t\t\t\t       \"trace2.perfbrief\" },\n      +};\n      +/* clang-format on */\n      +\n     @@ -550,31 +501,20 @@\n      + * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n      + * unless we were built with a runtime-prefix).  These are intended to\n      + * define the default values for Trace2 as requested by the administrator.\n     ++ *\n     ++ * Then override with the Trace2 settings from the global config.\n      + */\n      +void tr2_sysenv_load(void)\n      +{\n     -+\tconst char *system_config_pathname;\n     -+\tconst char *test_pathname;\n     -+\n     -+\tsystem_config_pathname = git_etc_gitconfig();\n     -+\n     -+\ttest_pathname = getenv(\"GIT_TEST_TR2_SYSTEM_CONFIG\");\n     -+\tif (test_pathname) {\n     -+\t\tif (!*test_pathname || !strcmp(test_pathname, \"0\"))\n     -+\t\t\treturn; /* disable use of system config */\n     -+\n     -+\t\t/* mock it with given test file */\n     -+\t\tsystem_config_pathname = test_pathname;\n     -+\t}\n     ++\tif (ARRAY_SIZE(tr2_sysenv_settings) != TR2_SYSENV_MUST_BE_LAST)\n     ++\t\tBUG(\"tr2_sysenv_settings size is wrong\");\n      +\n     -+\tif (file_exists(system_config_pathname))\n     -+\t\tgit_config_from_file(tr2_sysenv_cb, system_config_pathname,\n     -+\t\t\t\t     NULL);\n     ++\tread_very_early_config(tr2_sysenv_cb, NULL);\n      +}\n      +\n      +/*\n     -+ * Return the value for the requested setting.  Start with the /etc/gitconfig\n     -+ * value and allow the corresponding environment variable to override it.\n     ++ * Return the value for the requested Trace2 setting from these sources:\n     ++ * the system config, the global config, and the environment.\n      + */\n      +const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n      +{\n  5:  86d8fe28cf =  7:  2a7a933875 trace2: report peak memory usage of the process\n  6:  ae11cc4186 =  8:  56f357dc7b trace2: clarify UTC datetime formatting\n  7:  4352952677 !  9:  156ffde489 trace2: make SIDs more unique\n     @@ -22,11 +22,11 @@\n      -{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n      -{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n      -{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n     -+{\"event\":\"version\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n     -+{\"event\":\"start\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n     -+{\"event\":\"cmd_name\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n     -+{\"event\":\"exit\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n     -+{\"event\":\"atexit\",\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n     ++{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n     ++{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n     ++{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n     ++{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n     ++{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n       ------------\n       \n       == Enabling a Target\n     @@ -35,10 +35,16 @@\n       {\n       \t\"event\":\"version\",\n      -\t\"sid\":\"1547659722619736-11614\",\n     -+\t\"sid\":\"20190329-144314-319944-9b68c35f-012232\",\n     ++\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n       \t\"thread\":\"main\",\n     - \t\"time\":\"2019-01-16T17:28:42.620713Z\",\n     +-\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n     ++\t\"time\":\"2019-04-08T19:18:27.282761Z\",\n       \t\"file\":\"common-main.c\",\n     +-\t\"line\":38,\n     ++\t\"line\":42,\n     + \t...\n     + }\n     + ------------\n      \n       diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c\n       --- a/trace2/tr2_sid.c\n     @@ -56,34 +62,50 @@\n      +/*\n      + * Compute the final component of the SID representing the current process.\n      + * This should uniquely identify the process and be a valid filename (to\n     -+ * allow writing trace2 data to per-process files).\n     ++ * allow writing trace2 data to per-process files).  It should also be fixed\n     ++ * possible length for use as a database key.\n     ++ *\n     ++ * \"<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>\"\n     ++ *\n     ++ * where <host> is a 9 character string:\n     ++ *    \"H<first_8_chars_of_sha1_of_hostname>\"\n     ++ *    \"Localhost\" when no hostname.\n      + *\n     -+ * <yyyymmdd> '-' <hhmmss> '-' <fraction> '-' <sha1-prefix> '-' <pid>\n     ++ * where <process> is a possibly wrapped PID:\n     ++ *    \"P<6-digit-pid>\"\n     ++ *    \"W<wrapped-6-digit-pid>\" when PID too big.\n     ++ *    \n      + */\n      +static void tr2_sid_append_my_sid_component(void)\n      +{\n      +\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n      +\tstruct tr2_tbuf tb_now;\n      +\tgit_hash_ctx ctx;\n     ++\tuintmax_t pid = getpid();\n      +\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n      +\tchar hex[GIT_MAX_HEXSZ + 1];\n      +\tchar hostname[HOST_NAME_MAX + 1];\n      +\n     -+\ttr2_tbuf_utc_datetime_for_filename(&tb_now);\n     ++\ttr2_tbuf_utc_datetime(&tb_now);\n      +\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n     -+\tstrbuf_addch(&tr2sid_buf, '-');\n      +\n     ++\tstrbuf_addch(&tr2sid_buf, '-');\n      +\tif (xgethostname(hostname, sizeof(hostname)))\n     -+\t\txsnprintf(hostname, sizeof(hostname), \"localhost\");\n     -+\n     -+\talgo->init_fn(&ctx);\n     -+\talgo->update_fn(&ctx, hostname, strlen(hostname));\n     -+\talgo->final_fn(hash, &ctx);\n     -+\thash_to_hex_algop_r(hex, hash, algo);\n     -+\tstrbuf_add(&tr2sid_buf, hex, 8);\n     ++\t\tstrbuf_add(&tr2sid_buf, \"Localhost\", 9);\n     ++\telse {\n     ++\t\talgo->init_fn(&ctx);\n     ++\t\talgo->update_fn(&ctx, hostname, strlen(hostname));\n     ++\t\talgo->final_fn(hash, &ctx);\n     ++\t\thash_to_hex_algop_r(hex, hash, algo);\n     ++\t\tstrbuf_addch(&tr2sid_buf, 'H');\n     ++\t\tstrbuf_add(&tr2sid_buf, hex, 8);\n     ++\t}\n      +\n      +\tstrbuf_addch(&tr2sid_buf, '-');\n     -+\tstrbuf_addf(&tr2sid_buf, \"%06\"PRIuMAX, (uintmax_t)getpid());\n     ++\tif (pid > 999999)\n     ++\t\tstrbuf_addf(&tr2sid_buf, \"W%06d\", (int)(pid % 1000000));\n     ++\telse\n     ++\t\tstrbuf_addf(&tr2sid_buf, \"P%06d\", (int)pid);\n      +}\n      +\n       /*\n     @@ -117,7 +139,7 @@\n       \t\t  (long)tv.tv_usec);\n       }\n      +\n     -+void tr2_tbuf_utc_datetime_for_filename(struct tr2_tbuf *tb)\n     ++void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)\n      +{\n      +\tstruct timeval tv;\n      +\tstruct tm tm;\n     @@ -128,7 +150,7 @@\n      +\tgmtime_r(&secs, &tm);\n      +\n      +\txsnprintf(tb->buf, sizeof(tb->buf),\n     -+\t\t  \"%4d%02d%02d-%02d%02d%02d-%06ld\", tm.tm_year + 1900,\n     ++\t\t  \"%4d%02d%02dT%02d%02d%02d.%06ldZ\", tm.tm_year + 1900,\n      +\t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n      +\t\t  (long)tv.tv_usec);\n      +}\n     @@ -140,6 +162,6 @@\n        * Fill buffer with formatted UTC datatime string.\n        */\n       void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n     -+void tr2_tbuf_utc_datetime_for_filename(struct tr2_tbuf *tb);\n     ++void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb);\n       \n       #endif /* TR2_TBUF_H */\n  -:  ---------- > 10:  285beb2b2d trace2: update docs to describe system/global config settings\n\n-- \ngitgitgadget\n"},{"id":"373660","messageId":"8b00025af54fe32fe47adb4daa75d1324441acbc.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 03/10] trace2: add absolute elapsed time to start event","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:39Z","receivedAt":"2019-04-11T15:18:45Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nAdd elapsed process time to \"start\" event to measure\nthe performance of early process startup.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 11 ++++++-----\n t/t0211-trace2-perf.sh                 | 12 ++++++------\n trace2.c                               |  8 +++++++-\n trace2/tr2_tgt.h                       |  1 +\n trace2/tr2_tgt_event.c                 |  5 ++++-\n trace2/tr2_tgt_normal.c                |  3 ++-\n trace2/tr2_tgt_perf.c                  |  7 ++++---\n 7 files changed, 30 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex f37fccf1da..baaa1153bb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n-12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |           |           |            | git version\n+12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |  0.001173 |           |            | git version\n 12:28:42.621111 git.c:432                         | d0 | main                     | cmd_name     |     |           |           |            | version (version)\n 12:28:42.621225 git.c:662                         | d0 | main                     | exit         |     |  0.001227 |           |            | code:0\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.event\n {\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n {\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n {\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n {\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the \"start\" and\n {\n \t\"event\":\"start\",\n \t...\n+\t\"t_abs\":0.001227, # elapsed time in seconds\n \t\"argv\":[\"git\",\"version\"]\n }\n ------------\n@@ -1118,7 +1119,7 @@ $ git status\n \n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.160.g5676107ecd.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1163,7 +1164,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.162.gb4ccea44db.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1219,7 +1220,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.156.gf9916ae094.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n d0 | main                     | region_enter | r1  |  0.001791 |           | index      | label:do_read_index .git/index\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex 953e2f7847..c9694b29f7 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:0\n \t\td0|main|atexit||_T_ABS_|||code:0\n@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 1\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 1\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:1\n \t\td0|main|atexit||_T_ABS_|||code:1\n@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|error|||||hello world\n \t\td0|main|error|||||this is a test\n@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0\n \t\td1|main|version|||||$V\n-\t\td1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0\n+\t\td1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0\n \t\td1|main|cmd_name|||||trace2 (trace2/trace2)\n \t\td1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0\n \t\td2|main|version|||||$V\n-\t\td2|main|start|||||_EXE_ trace2 001return 0\n+\t\td2|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td2|main|cmd_name|||||trace2 (trace2/trace2/trace2)\n \t\td2|main|exit||_T_ABS_|||code:0\n \t\td2|main|atexit||_T_ABS_|||code:0\ndiff --git a/trace2.c b/trace2.c\nindex 6dd51e6aa5..1c180062dd 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv)\n {\n \tstruct tr2_tgt *tgt_j;\n \tint j;\n+\tuint64_t us_now;\n+\tuint64_t us_elapsed_absolute;\n \n \tif (!trace2_enabled)\n \t\treturn;\n \n+\tus_now = getnanotime() / 1000;\n+\tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n+\n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_start_fl)\n-\t\t\ttgt_j->pfn_start_fl(file, line, argv);\n+\t\t\ttgt_j->pfn_start_fl(file, line, us_elapsed_absolute,\n+\t\t\t\t\t    argv);\n }\n \n int trace2_cmd_exit_fl(const char *file, int line, int code)\ndiff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h\nindex 297bb8ffbe..7b90469212 100644\n--- a/trace2/tr2_tgt.h\n+++ b/trace2/tr2_tgt.h\n@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);\n typedef void(tr2_tgt_evt_version_fl_t)(const char *file, int line);\n \n typedef void(tr2_tgt_evt_start_fl_t)(const char *file, int line,\n+\t\t\t\t     uint64_t us_elapsed_absolute,\n \t\t\t\t     const char **argv);\n typedef void(tr2_tgt_evt_exit_fl_t)(const char *file, int line,\n \t\t\t\t    uint64_t us_elapsed_absolute, int code);\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 107cb5317d..89a4d3ae9a 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)\n \tjw_release(&jw);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct json_writer jw = JSON_WRITER_INIT;\n+\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \n \tjw_object_begin(&jw, 0);\n \tevent_fmt_prepare(event_name, file, line, NULL, &jw);\n+\tjw_object_double(&jw, \"t_abs\", 6, t_abs);\n \tjw_object_inline_begin_array(&jw, \"argv\");\n \tjw_array_argv(&jw, argv);\n \tjw_end(&jw);\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 547183d5b6..57f3e18f5b 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex f0746fcf86..9c3b4d8a0f 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \n \tsq_quote_argv_pretty(&buf_payload, argv);\n \n-\tperf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,\n-\t\t\t &buf_payload);\n+\tperf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,\n+\t\t\t NULL, NULL, &buf_payload);\n \tstrbuf_release(&buf_payload);\n }\n \n-- \ngitgitgadget\n\n"},{"id":"373661","messageId":"d15be7b63a539f113355590aadba44bd48238472.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 05/10] config: add read_very_early_config()","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:41Z","receivedAt":"2019-04-11T15:18:47Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreated an even lighter version of read_early_config() that\nonly looks at system and global config settings.  It omits\nrepo-local, worktree-local, and command-line settings.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 25 ++++++++++++++++++++++---\n config.h |  4 ++++\n 2 files changed, 26 insertions(+), 3 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 8e5f45fa20..5b10f18088 100644\n--- a/config.c\n+++ b/config.c\n@@ -1688,14 +1688,16 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t\tret += git_config_from_file(fn, user_config, data);\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_REPO;\n-\tif (repo_config && !access_or_die(repo_config, R_OK, 0))\n+\tif (!opts->ignore_repo &&\n+\t    repo_config && !access_or_die(repo_config, R_OK, 0))\n \t\tret += git_config_from_file(fn, repo_config, data);\n \n \t/*\n \t * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.\n \t * But let's not complicate things before it's actually needed.\n \t */\n-\tif (repository_format_worktree_config) {\n+\tif (!opts->ignore_worktree &&\n+\t    repository_format_worktree_config) {\n \t\tchar *path = git_pathdup(\"config.worktree\");\n \t\tif (!access_or_die(path, R_OK, 0))\n \t\t\tret += git_config_from_file(fn, path, data);\n@@ -1703,7 +1705,8 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t}\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_CMDLINE;\n-\tif (git_config_from_parameters(fn, data) < 0)\n+\tif (!opts->ignore_cmdline &&\n+\t    git_config_from_parameters(fn, data) < 0)\n \t\tdie(_(\"unable to parse command-line config\"));\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_UNKNOWN;\n@@ -1794,6 +1797,22 @@ void read_early_config(config_fn_t cb, void *data)\n \tstrbuf_release(&gitdir);\n }\n \n+/*\n+ * Read config but only enumerate system and global settings.\n+ * Omit any repo-local, worktree-local, or command-line settings.\n+ */\n+void read_very_early_config(config_fn_t cb, void *data)\n+{\n+\tstruct config_options opts = {0};\n+\n+\topts.respect_includes = 1;\n+\topts.ignore_repo = 1;\n+\topts.ignore_worktree = 1;\n+\topts.ignore_cmdline = 1;\n+\n+\tconfig_with_options(cb, data, NULL, &opts);\n+}\n+\n static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)\n {\n \tstruct config_set_element k;\ndiff --git a/config.h b/config.h\nindex ee5d3fa7b4..6a58d61d22 100644\n--- a/config.h\n+++ b/config.h\n@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,\n \n struct config_options {\n \tunsigned int respect_includes : 1;\n+\tunsigned int ignore_repo : 1;\n+\tunsigned int ignore_worktree : 1;\n+\tunsigned int ignore_cmdline : 1;\n \tconst char *commondir;\n \tconst char *git_dir;\n \tconfig_parser_event_fn_t event_fn;\n@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,\n extern void git_config_push_parameter(const char *text);\n extern int git_config_from_parameters(config_fn_t fn, void *data);\n extern void read_early_config(config_fn_t cb, void *data);\n+extern void read_very_early_config(config_fn_t cb, void *data);\n extern void git_config(config_fn_t fn, void *);\n extern int config_with_options(config_fn_t fn, void *,\n \t\t\t       struct git_config_source *config_source,\n-- \ngitgitgadget\n\n"},{"id":"373662","messageId":"56f357dc7b9264c8258185a5d6613962e4450d0e.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 08/10] trace2: clarify UTC datetime formatting","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:44Z","receivedAt":"2019-04-11T15:18:53Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate tr2_tbuf_utc_datetime to generate extended UTC format.\nUpdate tr2_tgt_event target to use extended format in 'time' columns.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++------\n trace2/tr2_tbuf.c                      |  4 ++--\n trace2/tr2_tbuf.h                      |  4 ++--\n trace2/tr2_tgt_event.c                 |  2 +-\n 4 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex baaa1153bb..cdc00bcc5d 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -542,7 +542,7 @@ The following key/value pairs are common to all events:\n \t\"event\":\"version\",\n \t\"sid\":\"1547659722619736-11614\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16 17:28:42.620713\",\n+\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n \t\"file\":\"common-main.c\",\n \t\"line\":38,\n \t...\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex 0844910423..eb1b240d8a 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb)\n \t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n }\n \n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n {\n \tstruct timeval tv;\n \tstruct tm tm;\n@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n \tgmtime_r(&secs, &tm);\n \n \txsnprintf(tb->buf, sizeof(tb->buf),\n-\t\t  \"%4d-%02d-%02d %02d:%02d:%02d.%06ld\", tm.tm_year + 1900,\n+\t\t  \"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ\", tm.tm_year + 1900,\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 9cdefa3957..2a1d173ff2 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -16,8 +16,8 @@ struct tr2_tbuf {\n void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n \n /*\n- * Fill buffer with formatted UTC time string.\n+ * Fill buffer with formatted UTC datatime string.\n  */\n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 48d9193b2c..2c97cf54be 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t */\n \tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n-\t\ttr2_tbuf_utc_time(&tb_now);\n+\t\ttr2_tbuf_utc_datetime_extended(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"373663","messageId":"2a7a9338758f915d00f78671e50a3a7b618e94e5.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 07/10] trace2: report peak memory usage of the process","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:43Z","receivedAt":"2019-04-11T15:18:55Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Windows version of git to report peak memory usage\nduring exit() processing.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c                            |  2 +-\n compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++--\n trace2.c                                 |  2 +\n trace2.h                                 | 14 +++++--\n 4 files changed, 60 insertions(+), 8 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 299ca62a72..582a7b1886 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -41,7 +41,7 @@ int main(int argc, const char **argv)\n \n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n-\ttrace2_collect_process_info();\n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);\n \n \tgit_setup_gettext();\n \ndiff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c\nindex 52bd62034b..2a514caed9 100644\n--- a/compat/win32/trace2_win32_process_info.c\n+++ b/compat/win32/trace2_win32_process_info.c\n@@ -1,5 +1,6 @@\n #include \"../../cache.h\"\n #include \"../../json-writer.h\"\n+#include \"lazyload.h\"\n #include <Psapi.h>\n #include <tlHelp32.h>\n \n@@ -137,11 +138,54 @@ static void get_is_being_debugged(void)\n \t\t\t\t   \"windows/debugger_present\", 1);\n }\n \n-void trace2_collect_process_info(void)\n+/*\n+ * Emit JSON data with the peak memory usage of the current process.\n+ */\n+static void get_peak_memory_info(void)\n+{\n+\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo,\n+\t\t\t  HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);\n+\n+\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n+\t\tPROCESS_MEMORY_COUNTERS pmc;\n+\n+\t\tif (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,\n+\t\t\t\t\t sizeof(pmc))) {\n+\t\t\tstruct json_writer jw = JSON_WRITER_INIT;\n+\n+\t\t\tjw_object_begin(&jw, 0);\n+\n+#define KV(kv) #kv, (intmax_t)pmc.kv\n+\n+\t\t\tjw_object_intmax(&jw, KV(PageFaultCount));\n+\t\t\tjw_object_intmax(&jw, KV(PeakWorkingSetSize));\n+\t\t\tjw_object_intmax(&jw, KV(PeakPagefileUsage));\n+\n+\t\t\tjw_end(&jw);\n+\n+\t\t\ttrace2_data_json(\"process\", the_repository,\n+\t\t\t\t\t \"windows/memory\", &jw);\n+\t\t\tjw_release(&jw);\n+\t\t}\n+\t}\n+}\n+\n+void trace2_collect_process_info(enum trace2_process_info_reason reason)\n {\n \tif (!trace2_is_enabled())\n \t\treturn;\n \n-\tget_is_being_debugged();\n-\tget_ancestry();\n+\tswitch (reason) {\n+\tcase TRACE2_PROCESS_INFO_STARTUP:\n+\t\tget_is_being_debugged();\n+\t\tget_ancestry();\n+\t\treturn;\n+\n+\tcase TRACE2_PROCESS_INFO_EXIT:\n+\t\tget_peak_memory_info();\n+\t\treturn;\n+\n+\tdefault:\n+\t\tBUG(\"trace2_collect_process_info: unknown reason '%d'\", reason);\n+\t}\n }\ndiff --git a/trace2.c b/trace2.c\nindex 490b3f071e..6baa65cdf9 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)\n \tif (!trace2_enabled)\n \t\treturn code;\n \n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);\n+\n \ttr2main_exit_code = code;\n \n \tus_now = getnanotime() / 1000;\ndiff --git a/trace2.h b/trace2.h\nindex 894bfca7e0..888531eb08 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);\n  * Optional platform-specific code to dump information about the\n  * current and any parent process(es).  This is intended to allow\n  * post-processors to know who spawned this git instance and anything\n- * else the platform may be able to tell us about the current process.\n+ * else that the platform may be able to tell us about the current process.\n  */\n+\n+enum trace2_process_info_reason {\n+\tTRACE2_PROCESS_INFO_STARTUP,\n+\tTRACE2_PROCESS_INFO_EXIT,\n+};\n+\n #if defined(GIT_WINDOWS_NATIVE)\n-void trace2_collect_process_info(void);\n+void trace2_collect_process_info(enum trace2_process_info_reason reason);\n #else\n-#define trace2_collect_process_info() \\\n-\tdo {                          \\\n+#define trace2_collect_process_info(reason) \\\n+\tdo {                                \\\n \t} while (0)\n #endif\n \n-- \ngitgitgadget\n\n"},{"id":"373664","messageId":"285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 10/10] trace2: update docs to describe system/global config settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:45Z","receivedAt":"2019-04-11T15:18:57Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/config.txt               |   2 +\n Documentation/config/trace2.txt        |  56 ++++++++++\n Documentation/technical/api-trace2.txt | 141 ++++++++++++++-----------\n Documentation/trace2-target-values.txt |  10 ++\n 4 files changed, 147 insertions(+), 62 deletions(-)\n create mode 100644 Documentation/config/trace2.txt\n create mode 100644 Documentation/trace2-target-values.txt\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d87846faa6..7e2a6f61f5 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -422,6 +422,8 @@ include::config/submodule.txt[]\n \n include::config/tag.txt[]\n \n+include::config/trace2.txt[]\n+\n include::config/transfer.txt[]\n \n include::config/uploadarchive.txt[]\ndiff --git a/Documentation/config/trace2.txt b/Documentation/config/trace2.txt\nnew file mode 100644\nindex 0000000000..a5f409c1c1\n--- /dev/null\n+++ b/Documentation/config/trace2.txt\n@@ -0,0 +1,56 @@\n+Trace2 config settings are only read from the system and global\n+config files; repository local and worktree config files and `-c`\n+command line arguments are not respected.\n+\n+trace2.normalTarget::\n+\tThis variable controls the normal target destination.\n+\tIt may be overridden by the `GIT_TR2` environment variable.\n+\tThe following table shows possible values.\n+\n+trace2.perfTarget::\n+\tThis variable controls the performance target destination.\n+\tIt may be overridden by the `GIT_TR2_PERF` environment variable.\n+\tThe following table shows possible values.\n+\n+trace2.eventTarget::\n+\tThis variable controls the event target destination.\n+\tIt may be overridden by the `GIT_TR2_EVENT` environment variable.\n+\tThe following table shows possible values.\n++\n+include::../trace2-target-values.txt[]\n+\n+trace2.normalBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from normal output.  May be overridden by the\n+\t`GIT_TR2_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.perfBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from PERF output.  May be overridden by the\n+\t`GIT_TR2_PERF_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.eventBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from event output.  May be overridden by the\n+\t`GIT_TR2_EVENT_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.eventNesting::\n+\tInteger.  Specifies desired depth of nested regions in the\n+\tevent output.  Regions deeper than this value will be\n+\tomitted.  May be overridden by the `GIT_TR2_EVENT_NESTING`\n+\tenvironment variable.  Defaults to 2.\n+\n+trace2.configParams::\n+\tA comma-separated list of patterns of \"important\" config\n+\tsettings that should be recorded in the trace2 output.\n+\tFor example, `core.*,remote.*.url` would cause the trace2\n+\toutput to contain events listing each configured remote.\n+\tMay be overridden by the `GIT_TR2_CONFIG_PARAMS` environment\n+\tvariable.  Unset by default.\n+\n+trace2.destinationDebug::\n+\tBoolean.  When true Git will print error messages when a\n+\ttrace target destination cannot be opened for writing.\n+\tBy default, these errors are suppressed and tracing is\n+\tsilently disabled.  May be overridden by the\n+\t`GIT_TR2_DST_DEBUG` environment variable.\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 43adbf00eb..e8eee25226 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -22,21 +22,41 @@ Targets are defined using a VTable allowing easy extension to other\n formats in the future.  This might be used to define a binary format,\n for example.\n \n+Trace2 is controlled using `trace2.*` config values in the system and\n+global config files and `GIT_TR2*` environment variables.  Trace2 does\n+not read from repo local or worktree config files or respect `-c`\n+command line config settings.\n+\n == Trace2 Targets\n \n Trace2 defines the following set of Trace2 Targets.\n Format details are given in a later section.\n \n-`GIT_TR2` (NORMAL)::\n+=== The Normal Format Target\n+\n+The normal format target is a tradition printf format and similar\n+to GIT_TRACE format.  This format is enabled with the `GIT_TR`\n+environment variable or the `trace2.normalTarget` system or global\n+config setting.\n+\n+For example\n \n-\ta simple printf format like GIT_TRACE.\n-+\n ------------\n $ export GIT_TR2=~/log.normal\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.normalTarget ~/log.normal\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.normal\n 12:28:42.620009 common-main.c:38                  version 2.20.1.155.g426c96fcdb\n@@ -46,17 +66,32 @@ $ cat ~/log.normal\n 12:28:42.621250 trace2/tr2_tgt_normal.c:124       atexit elapsed:0.001265 code:0\n ------------\n \n-`GIT_TR2_PERF` (PERF)::\n+=== The Performance Format Target\n+\n+The performance format target (PERF) is a column-based format to\n+replace GIT_TRACE_PERFORMANCE and is suitable for development and\n+testing, possibly to complement tools like gprof.  This format is\n+enabled with the `GIT_TR2_PERF` environment variable or the\n+`trace2.perfTarget` system or global config setting.\n+\n+For example\n \n-\ta column-based format to replace GIT_TRACE_PERFORMANCE suitable for\n-\tdevelopment and testing, possibly to complement tools like gprof.\n-+\n ------------\n $ export GIT_TR2_PERF=~/log.perf\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.perfTarget ~/log.perf\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n@@ -66,16 +101,31 @@ $ cat ~/log.perf\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n ------------\n \n-`GIT_TR2_EVENT` (EVENT)::\n+=== The Event Format Target\n+\n+The event format target is a JSON-based format of event data suitable\n+for telemetry analysis.  This format is enabled with the `GIT_TR2_EVENT`\n+environment variable or the `trace2.eventTarget` system or global config\n+setting.\n+\n+For example\n \n-\ta JSON-based format of event data suitable for telemetry analysis.\n-+\n ------------\n $ export GIT_TR2_EVENT=~/log.event\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.eventTarget ~/log.event\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.event\n {\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n@@ -85,37 +135,12 @@ $ cat ~/log.event\n {\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n-== Enabling a Target\n-\n-A Trace2 Target is enabled when the corresponding environment variable\n-(`GIT_TR2`, `GIT_TR2_PERF`, or `GIT_TR2_EVENT`) is set.  The following\n-values are recognized.\n+=== Enabling a Target\n \n-`0`::\n-`false`::\n+To enable a target, set the corresponding environment variable or\n+system or global config value to one of the following:\n \n-\tDisables the target.\n-\n-`1`::\n-`true`::\n-\n-\tEnables the target and writes stream to `STDERR`.\n-\n-`[2-9]`::\n-\n-\tEnables the target and writes to the already opened file descriptor.\n-\n-`<absolute-pathname>`::\n-\n-\tEnables the target, opens and writes to the file in append mode.\n-\n-`af_unix:[<socket_type>:]<absolute-pathname>`::\n-\n-\tEnables the target, opens and writes to a Unix Domain Socket\n-\t(on platforms that support them).\n-+\n-Socket type can be either `stream` or `dgram`.  If the socket type is\n-omitted, Git will try both.\n+include::../trace2-target-values.txt[]\n \n == Trace2 API\n \n@@ -243,15 +268,16 @@ significantly affects program performance or behavior, such as\n \tEmits a \"def_param\" messages for \"important\" configuration\n \tsettings.\n +\n-The environment variable `GIT_TR2_CONFIG_PARAMS` can be set to a\n+The environment variable `GIT_TR2_CONFIG_PARAMS` or the `trace2.configParams`\n+config value can be set to a\n list of patterns of important configuration settings, for example:\n `core.*,remote.*.url`.  This function will iterate over all config\n settings and emit a \"def_param\" message for each match.\n \n `void trace2_cmd_set_config(const char *key, const char *value)`::\n \n-\tEmits a \"def_param\" message for a specific configuration\n-\tsetting IFF it matches the `GIT_TR2_CONFIG_PARAMS` pattern.\n+\tEmits a \"def_param\" message for a new or updated key/value\n+\tpair IF `key` is considered important.\n +\n This is used to hook into `git_config_set()` and catch any\n configuration changes and update a value previously reported by\n@@ -418,9 +444,6 @@ recursive tree walk.\n \n === NORMAL Format\n \n-NORMAL format is enabled when the `GIT_TR2` environment variable is\n-set.\n-\n Events are written as lines of the form:\n \n ------------\n@@ -437,8 +460,8 @@ Events are written as lines of the form:\n Note that this may contain embedded LF or CRLF characters that are\n not escaped, so the event may spill across multiple lines.\n \n-If `GIT_TR2_BRIEF` is true, the `time`, `filename`, and `line` fields\n-are omitted.\n+If `GIT_TR2_BRIEF` or `trace2.normalBrief` is true, the `time`, `filename`,\n+and `line` fields are omitted.\n \n This target is intended to be more of a summary (like GIT_TRACE) and\n less detailed than the other targets.  It ignores thread, region, and\n@@ -446,9 +469,6 @@ data messages, for example.\n \n === PERF Format\n \n-PERF format is enabled when the `GIT_TR2_PERF` environment variable\n-is set.\n-\n Events are written as lines of the form:\n \n ------------\n@@ -508,8 +528,8 @@ This field is in anticipation of in-proc submodules in the future.\n 15:33:33.532712 wt-status.c:2331                  | d0 | main                     | region_leave | r1  |  0.127568 |  0.001504 | status     | label:print\n ------------\n \n-If `GIT_TR2_PERF_BRIEF` is true, the `time`, `file`, and `line`\n-fields are omitted.\n+If `GIT_TR2_PERF_BRIEF` or `trace2.perfBrief` is true, the `time`, `file`,\n+and `line` fields are omitted.\n \n ------------\n d0 | main                     | region_leave | r1  |  0.011717 |  0.009122 | index      | label:preload\n@@ -520,9 +540,6 @@ during development and is quite noisy.\n \n === EVENT Format\n \n-EVENT format is enabled when the `GIT_TR2_EVENT` environment\n-variable is set.\n-\n Each event is a JSON-object containing multiple key/value pairs\n written as a single line and followed by a LF.\n \n@@ -576,9 +593,9 @@ The following key/value pairs are common to all events:\n `\"repo\":<repo-id>`::\n \twhen present, is the integer repo-id as described previously.\n \n-If `GIT_TR2_EVENT_BRIEF` is true, the `file` and `line` fields are omitted\n-from all events and the `time` field is only present on the \"start\" and\n-\"atexit\" events.\n+If `GIT_TR2_EVENT_BRIEF` or `trace2.eventBrief` is true, the `file`\n+and `line` fields are omitted from all events and the `time` field is\n+only present on the \"start\" and \"atexit\" events.\n \n ==== Event-Specific Key/Value Pairs\n \n@@ -889,7 +906,7 @@ visited.\n The `category` field may be used in a future enhancement to\n do category-based filtering.\n +\n-The `GIT_TR2_EVENT_NESTING` environment variable can be used to\n+`GIT_TR2_EVENT_NESTING` or `trace2.eventNesting` can be used to\n filter deeply nested regions and data events.  It defaults to \"2\".\n \n `\"region_leave\"`::\ndiff --git a/Documentation/trace2-target-values.txt b/Documentation/trace2-target-values.txt\nnew file mode 100644\nindex 0000000000..27d3c64e66\n--- /dev/null\n+++ b/Documentation/trace2-target-values.txt\n@@ -0,0 +1,10 @@\n+--\n+* `0` or `false` - Disables the target.\n+* `1` or `true` - Writes to `STDERR`.\n+* `[2-9]` - Writes to the already opened file descriptor.\n+* `<absolute-pathname>` - Writes to the file in append mode.\n+* `af_unix:[<socket_type>:]<absolute-pathname>` - Write to a\n+Unix DomainSocket (on platforms that support them).  Socket\n+type can be either `stream` or `dgram`; if omitted Git will\n+try both.\n+--\n-- \ngitgitgadget\n"},{"id":"373665","messageId":"156ffde4895ac1a64e033341a313ccb3ba7485cd.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 09/10] trace2: make SIDs more unique","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:45Z","receivedAt":"2019-04-11T15:18:58Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate SID component construction to use the current UTC datetime\nand a portion of the SHA1 of the hostname.\n\nUse an simplified date/time format to make it easier to use the\nSID component as a logfile filename.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 16 ++++----\n trace2/tr2_sid.c                       | 55 ++++++++++++++++++++++++--\n trace2/tr2_tbuf.c                      | 16 ++++++++\n trace2/tr2_tbuf.h                      |  1 +\n 4 files changed, 76 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex cdc00bcc5d..43adbf00eb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -540,11 +540,11 @@ The following key/value pairs are common to all events:\n ------------\n {\n \t\"event\":\"version\",\n-\t\"sid\":\"1547659722619736-11614\",\n+\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n+\t\"time\":\"2019-04-08T19:18:27.282761Z\",\n \t\"file\":\"common-main.c\",\n-\t\"line\":38,\n+\t\"line\":42,\n \t...\n }\n ------------\ndiff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c\nindex 984524a43c..68d723bc6c 100644\n--- a/trace2/tr2_sid.c\n+++ b/trace2/tr2_sid.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n \n #define TR2_ENVVAR_PARENT_SID \"GIT_TR2_PARENT_SID\"\n@@ -6,6 +7,55 @@\n static struct strbuf tr2sid_buf = STRBUF_INIT;\n static int tr2sid_nr_git_parents;\n \n+/*\n+ * Compute the final component of the SID representing the current process.\n+ * This should uniquely identify the process and be a valid filename (to\n+ * allow writing trace2 data to per-process files).  It should also be fixed\n+ * possible length for use as a database key.\n+ *\n+ * \"<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>\"\n+ *\n+ * where <host> is a 9 character string:\n+ *    \"H<first_8_chars_of_sha1_of_hostname>\"\n+ *    \"Localhost\" when no hostname.\n+ *\n+ * where <process> is a possibly wrapped PID:\n+ *    \"P<6-digit-pid>\"\n+ *    \"W<wrapped-6-digit-pid>\" when PID too big.\n+ *    \n+ */\n+static void tr2_sid_append_my_sid_component(void)\n+{\n+\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n+\tstruct tr2_tbuf tb_now;\n+\tgit_hash_ctx ctx;\n+\tuintmax_t pid = getpid();\n+\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n+\tchar hex[GIT_MAX_HEXSZ + 1];\n+\tchar hostname[HOST_NAME_MAX + 1];\n+\n+\ttr2_tbuf_utc_datetime(&tb_now);\n+\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n+\n+\tstrbuf_addch(&tr2sid_buf, '-');\n+\tif (xgethostname(hostname, sizeof(hostname)))\n+\t\tstrbuf_add(&tr2sid_buf, \"Localhost\", 9);\n+\telse {\n+\t\talgo->init_fn(&ctx);\n+\t\talgo->update_fn(&ctx, hostname, strlen(hostname));\n+\t\talgo->final_fn(hash, &ctx);\n+\t\thash_to_hex_algop_r(hex, hash, algo);\n+\t\tstrbuf_addch(&tr2sid_buf, 'H');\n+\t\tstrbuf_add(&tr2sid_buf, hex, 8);\n+\t}\n+\n+\tstrbuf_addch(&tr2sid_buf, '-');\n+\tif (pid > 999999)\n+\t\tstrbuf_addf(&tr2sid_buf, \"W%06d\", (int)(pid % 1000000));\n+\telse\n+\t\tstrbuf_addf(&tr2sid_buf, \"P%06d\", (int)pid);\n+}\n+\n /*\n  * Compute a \"unique\" session id (SID) for the current process.  This allows\n  * all events from this process to have a single label (much like a PID).\n@@ -20,7 +70,6 @@ static int tr2sid_nr_git_parents;\n  */\n static void tr2_sid_compute(void)\n {\n-\tuint64_t us_now;\n \tconst char *parent_sid;\n \n \tif (tr2sid_buf.len)\n@@ -38,9 +87,7 @@ static void tr2_sid_compute(void)\n \t\ttr2sid_nr_git_parents++;\n \t}\n \n-\tus_now = getnanotime() / 1000;\n-\tstrbuf_addf(&tr2sid_buf, \"%\" PRIuMAX \"-%\" PRIdMAX, (uintmax_t)us_now,\n-\t\t    (intmax_t)getpid());\n+\ttr2_sid_append_my_sid_component();\n \n \tsetenv(TR2_ENVVAR_PARENT_SID, tr2sid_buf.buf, 1);\n }\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex eb1b240d8a..c8a19ac341 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -30,3 +30,19 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\n+\n+void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)\n+{\n+\tstruct timeval tv;\n+\tstruct tm tm;\n+\ttime_t secs;\n+\n+\tgettimeofday(&tv, NULL);\n+\tsecs = tv.tv_sec;\n+\tgmtime_r(&secs, &tm);\n+\n+\txsnprintf(tb->buf, sizeof(tb->buf),\n+\t\t  \"%4d%02d%02dT%02d%02d%02d.%06ldZ\", tm.tm_year + 1900,\n+\t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n+\t\t  (long)tv.tv_usec);\n+}\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 2a1d173ff2..fa853d8f42 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n  * Fill buffer with formatted UTC datatime string.\n  */\n void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\n-- \ngitgitgadget\n\n"},{"id":"373666","messageId":"3dbcfc6a8dce98dfec502c4b2a090450c9f9c66b.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 02/10] trace2: refactor setting process starting time","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:39Z","receivedAt":"2019-04-11T15:18:59Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreate trace2_initialize_clock() and call from main() to capture\nprocess start time in isolation and before other sub-systems are\nready.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++--\n common-main.c                          |  2 ++\n compat/mingw.c                         |  2 ++\n trace2.c                               |  7 ++++-\n trace2.h                               | 17 ++++++++++++\n trace2/tr2_tls.c                       | 38 ++++++++++++++++----------\n trace2/tr2_tls.h                       |  8 +++++-\n 7 files changed, 67 insertions(+), 19 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 2de565fa3d..f37fccf1da 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -160,17 +160,23 @@ purposes.\n \n These are concerned with the lifetime of the overall git process.\n \n+`void trace2_initialize_clock()`::\n+\n+\tInitialize the Trace2 start clock and nothing else.  This should\n+\tbe called at the very top of main() to capture the process start\n+\ttime and reduce startup order dependencies.\n+\n `void trace2_initialize()`::\n \n \tDetermines if any Trace2 Targets should be enabled and\n-\tinitializes the Trace2 facility.  This includes starting the\n-\telapsed time clocks and thread local storage (TLS).\n+\tinitializes the Trace2 facility.  This includes setting up the\n+\tTrace2 thread local storage (TLS).\n +\n This function emits a \"version\" message containing the version of git\n and the Trace2 protocol.\n +\n This function should be called from `main()` as early as possible in\n-the life of the process.\n+the life of the process after essential process initialization.\n \n `int trace2_is_enabled()`::\n \ndiff --git a/common-main.c b/common-main.c\nindex d484aec209..6137af0e63 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -27,6 +27,8 @@ int main(int argc, const char **argv)\n {\n \tint result;\n \n+\ttrace2_initialize_clock();\n+\n \t/*\n \t * Always open file descriptors 0/1/2 to avoid clobbering files\n \t * in die().  It also avoids messing up when the pipes are dup'ed\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 6b04514cdc..a2f74aca6a 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -2569,6 +2569,8 @@ void mingw_startup(void)\n \twchar_t **wenv, **wargv;\n \t_startupinfo si;\n \n+\ttrace2_initialize_clock();\n+\n \tmaybe_redirect_std_handles();\n \n \t/* get wide char arguments and environment */\ndiff --git a/trace2.c b/trace2.c\nindex ccccd4ef09..6dd51e6aa5 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)\n \traise(signo);\n }\n \n+void trace2_initialize_clock(void)\n+{\n+\ttr2tls_start_process_clock();\n+}\n+\n void trace2_initialize_fl(const char *file, int line)\n {\n \tstruct tr2_tgt *tgt_j;\n@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name)\n \tus_now = getnanotime() / 1000;\n \tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n \n-\ttr2tls_create_self(thread_name);\n+\ttr2tls_create_self(thread_name, us_now);\n \n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_thread_start_fl)\ndiff --git a/trace2.h b/trace2.h\nindex ae5020d0e6..8f89e70c44 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -19,6 +19,23 @@ struct json_writer;\n  * [] trace2_printf*    -- legacy trace[1] messages.\n  */\n \n+/*\n+ * Initialize the TRACE2 clock and do nothing else, in particular\n+ * no mallocs, no system inspection, and no environment inspection.\n+ *\n+ * This should be called at the very top of main() to capture the\n+ * process start time.  This is intended to reduce chicken-n-egg\n+ * bootstrap pressure.\n+ *\n+ * It is safe to call this more than once.  This allows capturing\n+ * absolute startup costs on Windows which uses a little trickery\n+ * to do setup work before common-main.c:main() is called.\n+ *\n+ * The main trace2_initialize_fl() may be called a little later\n+ * after more infrastructure is established.\n+ */\n+void trace2_initialize_clock(void);\n+\n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n  * targets are enabled in the environment.  Emits a 'version' event.\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 8e65b0361d..31fb529f93 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -10,16 +10,30 @@\n #define TR2_REGION_NESTING_INITIAL_SIZE (100)\n \n static struct tr2tls_thread_ctx *tr2tls_thread_main;\n-static uint64_t tr2tls_us_start_main;\n+static uint64_t tr2tls_us_start_process;\n \n static pthread_mutex_t tr2tls_mutex;\n static pthread_key_t tr2tls_key;\n \n static int tr2_next_thread_id; /* modify under lock */\n \n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n+void tr2tls_start_process_clock(void)\n+{\n+\tif (tr2tls_us_start_process)\n+\t\treturn;\n+\n+\t/*\n+\t * Keep the absolute start time of the process (i.e. the main\n+\t * process) in a fixed variable since other threads need to\n+\t * access it.  This allows them to do that without a lock on\n+\t * main thread's array data (because of reallocs).\n+\t */\n+\ttr2tls_us_start_process = getnanotime() / 1000;\n+}\n+\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start)\n {\n-\tuint64_t us_now = getnanotime() / 1000;\n \tstruct tr2tls_thread_ctx *ctx = xcalloc(1, sizeof(*ctx));\n \n \t/*\n@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n \t */\n \tctx->alloc = TR2_REGION_NESTING_INITIAL_SIZE;\n \tctx->array_us_start = (uint64_t *)xcalloc(ctx->alloc, sizeof(uint64_t));\n-\tctx->array_us_start[ctx->nr_open_regions++] = us_now;\n+\tctx->array_us_start[ctx->nr_open_regions++] = us_thread_start;\n \n \tctx->thread_id = tr2tls_locked_increment(&tr2_next_thread_id);\n \n@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)\n \t * here and silently continue.\n \t */\n \tif (!ctx)\n-\t\tctx = tr2tls_create_self(\"unknown\");\n+\t\tctx = tr2tls_create_self(\"unknown\", getnanotime() / 1000);\n \n \treturn ctx;\n }\n@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)\n \tif (!tr2tls_thread_main)\n \t\treturn 0;\n \n-\treturn us - tr2tls_us_start_main;\n+\treturn us - tr2tls_us_start_process;\n }\n \n void tr2tls_init(void)\n {\n+\ttr2tls_start_process_clock();\n+\n \tpthread_key_create(&tr2tls_key, NULL);\n \tinit_recursive_mutex(&tr2tls_mutex);\n \n-\ttr2tls_thread_main = tr2tls_create_self(\"main\");\n-\t/*\n-\t * Keep a copy of the absolute start time of the main thread\n-\t * in a fixed variable since other threads need to access it.\n-\t * This also eliminates the need to lock accesses to the main\n-\t * thread's array (because of reallocs).\n-\t */\n-\ttr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];\n+\ttr2tls_thread_main = tr2tls_create_self(\"main\",\n+\t\t\t\t\t\ttr2tls_us_start_process);\n }\n \n void tr2tls_release(void)\ndiff --git a/trace2/tr2_tls.h b/trace2/tr2_tls.h\nindex bb80e3f8e7..b1e327a928 100644\n--- a/trace2/tr2_tls.h\n+++ b/trace2/tr2_tls.h\n@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {\n  * In this and all following functions the term \"self\" refers to the\n  * current thread.\n  */\n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start);\n \n /*\n  * Get our TLS data.\n@@ -94,4 +95,9 @@ void tr2tls_release(void);\n  */\n int tr2tls_locked_increment(int *p);\n \n+/*\n+ * Capture the process start time and do nothing else.\n+ */\n+void tr2tls_start_process_clock(void);\n+\n #endif /* TR2_TLS_H */\n-- \ngitgitgadget\n\n"},{"id":"373667","messageId":"c085a482dda1159799b9eb512eef2ab7ee33981e.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 06/10] trace2: use system/global config for default trace2 settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:42Z","receivedAt":"2019-04-11T15:19:02Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach git to read the system and global config files for\ndefault Trace2 settings.  This allows system-wide Trace2 settings to\nbe installed and inherited to make it easier to manage a collection of\nsystems.\n\nThe original GIT_TR2* environment variables are loaded afterwards and\ncan be used to override the system settings.\n\nOnly the system and global config files are used.  Repo and worktree\nlocal config files are ignored.  Likewise, the \"-c\" command line\narguments are also ignored.  These limits are for performance reasons.\n\n(1) For users not using Trace2, there should be minimal overhead to\ndetect that Trace2 is not enabled.  In particular, Trace2 should not\nallocate lots of otherwise unused data strucutres.\n\n(2) For accurate performance measurements, Trace2 should be initialized\nas early in the git process as possible, and before most of the normal\ngit process initialization (which involves discovering the .git directory\nand reading a hierarchy of config files).\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Makefile                 |   1 +\n t/t0210-trace2-normal.sh |  49 +++++++++++++--\n t/t0211-trace2-perf.sh   |  31 ++++++++--\n t/t0212-trace2-event.sh  |  42 +++++++++++--\n trace2.c                 |   4 ++\n trace2.h                 |  12 ++--\n trace2/tr2_cfg.c         |   7 +--\n trace2/tr2_dst.c         |  24 ++++----\n trace2/tr2_dst.h         |   3 +-\n trace2/tr2_sysenv.c      | 127 +++++++++++++++++++++++++++++++++++++++\n trace2/tr2_sysenv.h      |  36 +++++++++++\n trace2/tr2_tgt_event.c   |  46 +++++++-------\n trace2/tr2_tgt_normal.c  |  16 ++---\n trace2/tr2_tgt_perf.c    |  16 ++---\n 14 files changed, 338 insertions(+), 76 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\ndiff --git a/Makefile b/Makefile\nindex 3e03290d8f..9ddfa3dfe7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o\n LIB_OBJS += trace2/tr2_cmd_name.o\n LIB_OBJS += trace2/tr2_dst.o\n LIB_OBJS += trace2/tr2_sid.o\n+LIB_OBJS += trace2/tr2_sysenv.o\n LIB_OBJS += trace2/tr2_tbuf.o\n LIB_OBJS += trace2/tr2_tgt_event.o\n LIB_OBJS += trace2/tr2_tgt_normal.o\ndiff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh\nindex 03a0aedb1d..4e2d4c7997 100755\n--- a/t/t0210-trace2-normal.sh\n+++ b/t/t0210-trace2-normal.sh\n@@ -1,5 +1,10 @@\n #!/bin/sh\n \n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_BRIEF\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility (normal target)'\n . ./test-lib.sh\n \n@@ -15,11 +20,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -132,4 +132,43 @@ test_expect_success 'normal stream, error event' '\n \ttest_cmp expect actual\n '\n \n+unset GIT_TR2_BRIEF\n+\n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success 'using global config, normal stream, return code 0' '\n+\ttest_when_finished \"rm trace.normal actual expect\" &&\n+\ttest_config_global trace2.normalBrief 1 &&\n+\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'using global config with include' '\n+\ttest_when_finished \"rm trace.normal actual expect real.gitconfig\" &&\n+\ttest_config_global trace2.normalBrief 1 &&\n+\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\tmv \"$(pwd)/.gitconfig\" \"$(pwd)/real.gitconfig\" &&\n+\ttest_config_global include.path \"$(pwd)/real.gitconfig\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex c9694b29f7..2a90e56db3 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -1,5 +1,10 @@\n #!/bin/sh\n \n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_PERF_BRIEF\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility (perf target)'\n . ./test-lib.sh\n \n@@ -15,11 +20,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_PERF_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -150,4 +150,25 @@ test_expect_success 'perf stream, child processes' '\n \ttest_cmp expect actual\n '\n \n+unset GIT_TR2_PERF_BRIEF\n+\n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success 'using global config, perf stream, return code 0' '\n+\ttest_when_finished \"rm trace.perf actual expect\" &&\n+\ttest_config_global trace2.perfBrief 1 &&\n+\ttest_config_global trace2.perfTarget \"$(pwd)/trace.perf\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n+\tcat >expect <<-EOF &&\n+\t\td0|main|version|||||$V\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n+\t\td0|main|cmd_name|||||trace2 (trace2)\n+\t\td0|main|exit||_T_ABS_|||code:0\n+\t\td0|main|atexit||_T_ABS_|||code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh\nindex 028b6c5671..a3943561c3 100755\n--- a/t/t0212-trace2-event.sh\n+++ b/t/t0212-trace2-event.sh\n@@ -1,5 +1,10 @@\n #!/bin/sh\n \n+# Turn off any inherited trace2 settings for this test.\n+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+unset GIT_TR2_BARE\n+unset GIT_TR2_CONFIG_PARAMS\n+\n test_description='test trace2 facility'\n . ./test-lib.sh\n \n@@ -17,11 +22,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BARE\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -233,4 +233,36 @@ test_expect_success JSON_PP 'basic trace2_data' '\n \ttest_cmp expect actual\n '\n \n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success JSON_PP 'using global config, event stream, error event' '\n+\ttest_when_finished \"rm trace.event actual expect\" &&\n+\ttest_config_global trace2.eventTarget \"$(pwd)/trace.event\" &&\n+\ttest-tool trace2 003error \"hello world\" \"this is a test\" &&\n+\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n+\tsed -e \"s/^|//\" >expect <<-EOF &&\n+\t|VAR1 = {\n+\t|  \"_SID0_\":{\n+\t|    \"argv\":[\n+\t|      \"_EXE_\",\n+\t|      \"trace2\",\n+\t|      \"003error\",\n+\t|      \"hello world\",\n+\t|      \"this is a test\"\n+\t|    ],\n+\t|    \"errors\":[\n+\t|      \"%s\",\n+\t|      \"%s\"\n+\t|    ],\n+\t|    \"exit_code\":0,\n+\t|    \"hierarchy\":\"trace2\",\n+\t|    \"name\":\"trace2\",\n+\t|    \"version\":\"$V\"\n+\t|  }\n+\t|};\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/trace2.c b/trace2.c\nindex 1c180062dd..490b3f071e 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -10,6 +10,7 @@\n #include \"trace2/tr2_cmd_name.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)\n \ttr2_sid_release();\n \ttr2_cmd_name_release();\n \ttr2_cfg_free_patterns();\n+\ttr2_sysenv_release();\n \n \ttrace2_enabled = 0;\n }\n@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)\n \tif (trace2_enabled)\n \t\treturn;\n \n+\ttr2_sysenv_load();\n+\n \tif (!tr2_tgt_want_builtins())\n \t\treturn;\n \ttrace2_enabled = 1;\ndiff --git a/trace2.h b/trace2.h\nindex 8f89e70c44..894bfca7e0 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n \n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n- * targets are enabled in the environment.  Emits a 'version' event.\n+ * targets are enabled in the system config or the environment.\n+ * Emits a 'version' event.\n  *\n  * Cleanup/Termination is handled automatically by a registered\n  * atexit() routine.\n@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n  * Emit one or more 'def_param' events for \"interesting\" configuration\n  * settings.\n  *\n- * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n- * list of patterns considered important.  For example:\n- *\n- *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n+ * Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated\n+ * list of patterns configured important.  For example:\n+ *     git config --system trace2.configParams 'core.*,remote.*.url'\n+ * or:\n+ *     GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url\"\n  *\n  * Note: this routine does a read-only iteration on the config data\n  * (using read_early_config()), so it must not be called until enough\ndiff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\nindex b329921ac5..caa7f06948 100644\n--- a/trace2/tr2_cfg.c\n+++ b/trace2/tr2_cfg.c\n@@ -1,8 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n-#include \"tr2_cfg.h\"\n-\n-#define TR2_ENVVAR_CFG_PARAM \"GIT_TR2_CONFIG_PARAMS\"\n+#include \"trace2/tr2_cfg.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n static struct strbuf **tr2_cfg_patterns;\n static int tr2_cfg_count_patterns;\n@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)\n \t\treturn tr2_cfg_count_patterns;\n \ttr2_cfg_loaded = 1;\n \n-\tenvvar = getenv(TR2_ENVVAR_CFG_PARAM);\n+\tenvvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM);\n \tif (!envvar || !*envvar)\n \t\treturn tr2_cfg_count_patterns;\n \ndiff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c\nindex fd490a43ad..575cd69aa9 100644\n--- a/trace2/tr2_dst.c\n+++ b/trace2/tr2_dst.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n /*\n  * If a Trace2 target cannot be opened for writing, we should issue a\n@@ -7,17 +8,13 @@\n  * or socket and beyond the user's control -- especially since every\n  * git command (and sub-command) will print the message.  So we silently\n  * eat these warnings and just discard the trace data.\n- *\n- * Enable the following environment variable to see these warnings.\n  */\n-#define TR2_ENVVAR_DST_DEBUG \"GIT_TR2_DST_DEBUG\"\n-\n static int tr2_dst_want_warning(void)\n {\n \tstatic int tr2env_dst_debug = -1;\n \n \tif (tr2env_dst_debug == -1) {\n-\t\tconst char *env_value = getenv(TR2_ENVVAR_DST_DEBUG);\n+\t\tconst char *env_value = tr2_sysenv_get(TR2_SYSENV_DST_DEBUG);\n \t\tif (!env_value || !*env_value)\n \t\t\ttr2env_dst_debug = 0;\n \t\telse\n@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)\n \tif (fd == -1) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: could not open '%s' for '%s' tracing: %s\",\n-\t\t\t\ttgt_value, dst->env_var_name, strerror(errno));\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\t\tstrerror(errno));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \tif (!path || !*path) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n-\t\t\t\ttgt_value, dst->env_var_name);\n+\t\t\t\ttgt_value, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \t    strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX path '%s' for '%s' tracing\",\n-\t\t\t\tpath, dst->env_var_name);\n+\t\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n error:\n \tif (tr2_dst_want_warning())\n \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n-\t\t\tpath, dst->env_var_name, strerror(e));\n+\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var), strerror(e));\n \n \ttr2_dst_trace_disable(dst);\n \treturn 0;\n@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_addf(&buf, \"trace2: unknown value for '%s': '%s'\",\n-\t\t    dst->env_var_name, tgt_value);\n+\t\t    tr2_sysenv_display_name(dst->sysenv_var), tgt_value);\n \twarning(\"%s\", buf.buf);\n \n \tstrbuf_release(&buf);\n@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst)\n \n \tdst->initialized = 1;\n \n-\ttgt_value = getenv(dst->env_var_name);\n+\ttgt_value = tr2_sysenv_get(dst->sysenv_var);\n \n \tif (!tgt_value || !strcmp(tgt_value, \"\") || !strcmp(tgt_value, \"0\") ||\n \t    !strcasecmp(tgt_value, \"false\")) {\n@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)\n \t\treturn;\n \n \tif (tr2_dst_want_warning())\n-\t\twarning(\"unable to write trace to '%s': %s\", dst->env_var_name,\n+\t\twarning(\"unable to write trace to '%s': %s\",\n+\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n \t\t\tstrerror(errno));\n \ttr2_dst_trace_disable(dst);\n }\ndiff --git a/trace2/tr2_dst.h b/trace2/tr2_dst.h\nindex 9a64f05b02..3adf3bac13 100644\n--- a/trace2/tr2_dst.h\n+++ b/trace2/tr2_dst.h\n@@ -2,9 +2,10 @@\n #define TR2_DST_H\n \n struct strbuf;\n+#include \"trace2/tr2_sysenv.h\"\n \n struct tr2_dst {\n-\tconst char *const env_var_name;\n+\tenum tr2_sysenv_variable sysenv_var;\n \tint fd;\n \tunsigned int initialized : 1;\n \tunsigned int need_close : 1;\ndiff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\nnew file mode 100644\nindex 0000000000..9025b86303\n--- /dev/null\n+++ b/trace2/tr2_sysenv.c\n@@ -0,0 +1,127 @@\n+#include \"cache.h\"\n+#include \"config.h\"\n+#include \"dir.h\"\n+#include \"tr2_sysenv.h\"\n+\n+/*\n+ * Each entry represents a trace2 setting.\n+ * See Documentation/technical/api-trace2.txt\n+ */\n+struct tr2_sysenv_entry {\n+\tconst char *env_var_name;\n+\tconst char *git_config_name;\n+\n+\tchar *value;\n+\tunsigned int getenv_called : 1;\n+};\n+\n+/*\n+ * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n+ *\n+ * The strings in this table are constant and must match the published\n+ * config and environment variable names as described in the documentation.\n+ *\n+ * We do not define entries for the GIT_TR2_PARENT_* environment\n+ * variables because they are transient and used to pass information\n+ * from parent to child git processes, rather than settings.\n+ */\n+/* clang-format off */\n+static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n+\t[TR2_SYSENV_CFG_PARAM]     = { \"GIT_TR2_CONFIG_PARAMS\",\n+\t\t\t\t       \"trace2.configparams\" },\n+\n+\t[TR2_SYSENV_DST_DEBUG]     = { \"GIT_TR2_DST_DEBUG\",\n+\t\t\t\t       \"trace2.destinationdebug\" },\n+\n+\t[TR2_SYSENV_NORMAL]        = { \"GIT_TR2\",\n+\t\t\t\t       \"trace2.normaltarget\" },\n+\t[TR2_SYSENV_NORMAL_BRIEF]  = { \"GIT_TR2_BRIEF\",\n+\t\t\t\t       \"trace2.normalbrief\" },\n+\n+\t[TR2_SYSENV_EVENT]         = { \"GIT_TR2_EVENT\",\n+\t\t\t\t       \"trace2.eventtarget\" },\n+\t[TR2_SYSENV_EVENT_BRIEF]   = { \"GIT_TR2_EVENT_BRIEF\",\n+\t\t\t\t       \"trace2.eventbrief\" },\n+\t[TR2_SYSENV_EVENT_NESTING] = { \"GIT_TR2_EVENT_NESTING\",\n+\t\t\t\t       \"trace2.eventnesting\" },\n+\n+\t[TR2_SYSENV_PERF]          = { \"GIT_TR2_PERF\",\n+\t\t\t\t       \"trace2.perftarget\" },\n+\t[TR2_SYSENV_PERF_BRIEF]    = { \"GIT_TR2_PERF_BRIEF\",\n+\t\t\t\t       \"trace2.perfbrief\" },\n+};\n+/* clang-format on */\n+\n+static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n+{\n+\tint k;\n+\n+\tif (!starts_with(key, \"trace2.\"))\n+\t\treturn 0;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n+\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n+\t\t\tfree(tr2_sysenv_settings[k].value);\n+\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n+ * unless we were built with a runtime-prefix).  These are intended to\n+ * define the default values for Trace2 as requested by the administrator.\n+ *\n+ * Then override with the Trace2 settings from the global config.\n+ */\n+void tr2_sysenv_load(void)\n+{\n+\tif (ARRAY_SIZE(tr2_sysenv_settings) != TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_settings size is wrong\");\n+\n+\tread_very_early_config(tr2_sysenv_cb, NULL);\n+}\n+\n+/*\n+ * Return the value for the requested Trace2 setting from these sources:\n+ * the system config, the global config, and the environment.\n+ */\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\tif (!tr2_sysenv_settings[var].getenv_called) {\n+\t\tconst char *v = getenv(tr2_sysenv_settings[var].env_var_name);\n+\t\tif (v && *v) {\n+\t\t\tfree(tr2_sysenv_settings[var].value);\n+\t\t\ttr2_sysenv_settings[var].value = xstrdup(v);\n+\t\t}\n+\t\ttr2_sysenv_settings[var].getenv_called = 1;\n+\t}\n+\n+\treturn tr2_sysenv_settings[var].value;\n+}\n+\n+/*\n+ * Return a friendly name for this setting that is suitable for printing\n+ * in an error messages.\n+ */\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\treturn tr2_sysenv_settings[var].env_var_name;\n+}\n+\n+void tr2_sysenv_release(void)\n+{\n+\tint k;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++)\n+\t\tfree(tr2_sysenv_settings[k].value);\n+}\ndiff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h\nnew file mode 100644\nindex 0000000000..369b20bd87\n--- /dev/null\n+++ b/trace2/tr2_sysenv.h\n@@ -0,0 +1,36 @@\n+#ifndef TR2_SYSENV_H\n+#define TR2_SYSENV_H\n+\n+/*\n+ * The Trace2 settings that can be loaded from /etc/gitconfig\n+ * and/or user environment variables.\n+ *\n+ * Note that this set does not contain any of the transient\n+ * environment variables used to pass information from parent\n+ * to child git processes, such \"GIT_TR2_PARENT_SID\".\n+ */\n+enum tr2_sysenv_variable {\n+\tTR2_SYSENV_CFG_PARAM = 0,\n+\n+\tTR2_SYSENV_DST_DEBUG,\n+\n+\tTR2_SYSENV_NORMAL,\n+\tTR2_SYSENV_NORMAL_BRIEF,\n+\n+\tTR2_SYSENV_EVENT,\n+\tTR2_SYSENV_EVENT_BRIEF,\n+\tTR2_SYSENV_EVENT_NESTING,\n+\n+\tTR2_SYSENV_PERF,\n+\tTR2_SYSENV_PERF_BRIEF,\n+\n+\tTR2_SYSENV_MUST_BE_LAST\n+};\n+\n+void tr2_sysenv_load(void);\n+\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable);\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);\n+void tr2_sysenv_release(void);\n+\n+#endif /* TR2_SYSENV_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 89a4d3ae9a..48d9193b2c 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -6,10 +6,11 @@\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };\n \n /*\n  * The version number of the JSON data generated by the EVENT target\n@@ -28,37 +29,36 @@ static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n  * are primarily intended for the performance target during debugging.\n  *\n  * Some of the outer-most messages, however, may be of interest to the\n- * event target.  Set this environment variable to a larger integer for\n- * more detail in the event target.\n+ * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase\n+ * region details in the event target.\n  */\n-#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n-static int tr2env_event_nesting_wanted = 2;\n+static int tr2env_event_max_nesting_levels = 2;\n \n /*\n- * Set this environment variable to true to omit the <time>, <file>, and\n+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and\n  * <line> fields from most events.\n  */\n-#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n-static int tr2env_event_brief;\n+static int tr2env_event_be_brief;\n \n static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_event);\n-\tint want_nesting;\n+\tint max_nesting;\n \tint want_brief;\n-\tchar *nesting;\n-\tchar *brief;\n+\tconst char *nesting;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n-\tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n-\t\ttr2env_event_nesting_wanted = want_nesting;\n+\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n+\tif (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))\n+\t\ttr2env_event_max_nesting_levels = max_nesting;\n \n-\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n-\tif (brief && ((want_brief = atoi(brief)) > 0))\n-\t\ttr2env_event_brief = want_brief;\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n+\tif (brief && *brief &&\n+\t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n+\t\ttr2env_event_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -92,13 +92,13 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t/*\n \t * In brief mode, only emit <time> on these 2 event types.\n \t */\n-\tif (!tr2env_event_brief || !strcmp(event_name, \"version\") ||\n+\tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n \t\ttr2_tbuf_utc_time(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-\tif (!tr2env_event_brief && file && *file) {\n+\tif (!tr2env_event_be_brief && file && *file) {\n \t\tjw_object_string(jw, \"file\", file);\n \t\tjw_object_intmax(jw, \"line\", line);\n \t}\n@@ -459,7 +459,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line,\n {\n \tconst char *event_name = \"region_enter\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \n \t\tjw_object_begin(&jw, 0);\n@@ -484,7 +484,7 @@ static void fn_region_leave_printf_va_fl(\n {\n \tconst char *event_name = \"region_leave\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n \n@@ -511,7 +511,7 @@ static void fn_data_fl(const char *file, int line, uint64_t us_elapsed_absolute,\n {\n \tconst char *event_name = \"data\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n@@ -539,7 +539,7 @@ static void fn_data_json_fl(const char *file, int line,\n {\n \tconst char *event_name = \"data_json\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 57f3e18f5b..1ce6f97863 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -4,20 +4,20 @@\n #include \"quote.h\"\n #include \"version.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_normal = { \"GIT_TR2\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin normal target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n-static int tr2env_normal_brief;\n+static int tr2env_normal_be_brief;\n \n #define TR2FMT_NORMAL_FL_WIDTH (50)\n \n@@ -25,15 +25,15 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_normal);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_normal_brief = want_brief;\n+\t\ttr2env_normal_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf)\n {\n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_normal_brief) {\n+\tif (!tr2env_normal_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex 9c3b4d8a0f..328d2234bd 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -6,20 +6,20 @@\n #include \"json-writer.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_perf = { \"GIT_TR2_PERF\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use TR2_SYSENV_PERF_BRIEF to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin performance target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n-static int tr2env_perf_brief;\n+static int tr2env_perf_be_brief;\n \n #define TR2FMT_PERF_FL_WIDTH (50)\n #define TR2FMT_PERF_MAX_EVENT_NAME (12)\n@@ -36,17 +36,17 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_perf);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n \tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n \n-\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_perf_brief = want_brief;\n+\t\ttr2env_perf_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,\n \n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_perf_brief) {\n+\tif (!tr2env_perf_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\n-- \ngitgitgadget\n\n"},{"id":"373668","messageId":"c3c5f6a96b280fc934b179de671e28ade8381f69.1554995916.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v3 04/10] trace2: find exec-dir before trace2 initialization","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-11T15:18:40Z","receivedAt":"2019-04-11T15:19:02Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Git to resolve the executable directory before initializing\nTrace2.  This allows the system configuration directory to be\ndiscovered earlier (because it is sometimes relative to the prefix\nor runtime-prefix).\n\nThis will be used by the next commit to allow trace2 settings to\nbe loaded from the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 6137af0e63..299ca62a72 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -37,12 +37,12 @@ int main(int argc, const char **argv)\n \tsanitize_stdfds();\n \trestore_sigpipe_to_default();\n \n+\tgit_resolve_executable_dir(argv[0]);\n+\n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n \ttrace2_collect_process_info();\n \n-\tgit_resolve_executable_dir(argv[0]);\n-\n \tgit_setup_gettext();\n \n \tinitialize_the_repository();\n-- \ngitgitgadget\n\n"},{"id":"373702","messageId":"xmqqv9zkymzd.fsf@gitster-ct.c.googlers.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 00/10] trace2: load trace2 settings from system config","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-12T02:29:58Z","receivedAt":"2019-04-12T02:30:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Jeff Hostetler via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> Here is version 3.\n> [] It incorporates Ævar's suggestions WRT the format and uniqueness of the\n> SID. [] It now reads both system and global config for trace2 settings and\n> handles includes as Jonathan suggested.\n\nFollowing the ISO more closely with Ts and Zs in the format looks\nlike a good idea (i.e. it gives a more familiar-looking result).  I\nhave no string opinions on the per-user config or inclusion, but I\nthink it probably is an essential ingredient to give an opt-out\nescape hatch to make this appear less big-brotherly [*1*].\n\n\tSide note *1*: and hence less scary.  An otherwise useful\n\tmechanism can have an appearance that it can also be misused\n\tfor bad purposes, and at that point, to those with fear, it\n\tdoes not matter how useful an application the mechanism has.\n\n\tI think \"by default you are opting in due to your belonging\n\tto this organization in the first place (hence we give you\n\t/etc/gitconfig that lets us collect your usage patterns) but\n\tyou could easily opt-out by overriding in $HOME/.gitconfig\"\n\tstrikes a good balance.\n\n> I added a read_very_early_config() function that is similar to \n> read_early_config()but omits repo local, worktree, and -c command line\n> settings. This felt like a little bit of a hack, but it made the intent\n> clear.\n\nI am not yet judging if the \"very early config\" itself is a good\nthing to have (and if it is good, then it is not a \"hack\" ;-)), but\nI very much agree that it is a very good change to have a helper\nthat makes the intent clear.\n\n>      -+# Now test using system config by using a mocked up config file\n>      -+# rather than inheriting \"/etc/gitconfig\".  Here we do not use\n>      -+# GIT_TR2* environment variables.\n>      -+\n>       +unset GIT_TR2_BRIEF\n\n\nThis does not have to be sane_unset, as we are not aiming for making\nour tests \"set -e\" clean.  But in tXXXX-*.sh scripts, it may not be\na bad idea to stick to sane_unset regardless, as people tend to cut\nand paste without thinking enough.\n\n>      @@ -512,19 +454,28 @@\n>       + */\n>       +/* clang-format off */\n>\n>      ++\t[TR2_SYSENV_CFG_PARAM]     = { \"GIT_TR2_CONFIG_PARAMS\",\n>      ++\t\t\t\t       \"trace2.configparams\" },\n>      ++\n>      ++\t[TR2_SYSENV_DST_DEBUG]     = { \"GIT_TR2_DST_DEBUG\",\n>      ++\t\t\t\t       \"trace2.destinationdebug\" },\n>      ++\n>      ++\t[TR2_SYSENV_NORMAL]        = { \"GIT_TR2\",\n>      ++\t\t\t\t       \"trace2.normaltarget\" },\n>      ++\t[TR2_SYSENV_NORMAL_BRIEF]  = { \"GIT_TR2_BRIEF\",\n>      ++\t\t\t\t       \"trace2.normalbrief\" },\n>      ++\n>      ++\t[TR2_SYSENV_EVENT]         = { \"GIT_TR2_EVENT\",\n>      ++\t\t\t\t       \"trace2.eventtarget\" },\n>      ++\t[TR2_SYSENV_EVENT_BRIEF]   = { \"GIT_TR2_EVENT_BRIEF\",\n>      ++\t\t\t\t       \"trace2.eventbrief\" },\n>      ++\t[TR2_SYSENV_EVENT_NESTING] = { \"GIT_TR2_EVENT_NESTING\",\n>      ++\t\t\t\t       \"trace2.eventnesting\" },\n>      ++\n>      ++\t[TR2_SYSENV_PERF]          = { \"GIT_TR2_PERF\",\n>      ++\t\t\t\t       \"trace2.perftarget\" },\n>      ++\t[TR2_SYSENV_PERF_BRIEF]    = { \"GIT_TR2_PERF_BRIEF\",\n>      ++\t\t\t\t       \"trace2.perfbrief\" },\n\n\nWith use of designated initializers, the table got a lot cleaner to\nread.  Is the above \"format off\" still needed (I am a bit curious\nhow clang-format wants these entries to look like)?\n\n>      ++\tif (pid > 999999)\n>      ++\t\tstrbuf_addf(&tr2sid_buf, \"W%06d\", (int)(pid % 1000000));\n>      ++\telse\n>      ++\t\tstrbuf_addf(&tr2sid_buf, \"P%06d\", (int)pid);\n\nI do not think it matters too much, but this is kind-of curious.\n\nHow would the users of the log utilize the distinction between W and\nP?  Do they discard the ones with W when they care about the exact\nprocess that left the trace entries, or something?  If it's not a\nplausibly useful use pattern (and I do not think it is), I wonder if\nwe want to go with only W (i.e. truncated to the lower N digits)\nentries, if you are shooting for a fixed-width output from this\nfunction.  If you want less chance of collisions, you obviously\ncould use hexadecimal to gain back a few more bits.\n\nAfter all, if the application does care the PID, that could be in\nthe log data itself (i.e. an \"start\" event can say \"my pid is blah\").\n\nThanks.  I'll wait until learning what others think.\n"},{"id":"373708","messageId":"20190412035220.GA26967@google.com","threadId":"50834","inReplyTo":"ea8c199f911a84505b1aba5735a280ffc989e2a1.1554995916.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 01/10] config: initialize opts structure in repo_read_config()","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2019-04-12T03:52:20Z","receivedAt":"2019-04-12T03:52:25Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nJeff Hostetler wrote:\n\n> Initialize opts structure in repo_read_config().\n\nGood find.  I wonder if there are some flags we can turn on with\nDEVELOPER=1 to prevent this kind of issue going undetected in the\nfuture (or maybe this means we need to get the valgrind or ASan\ntesting modes to be fast enough for people to consistently run them).\n\n[...]\n>  config.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThanks.\n"},{"id":"373747","messageId":"b4236c9b-8fc2-3704-dfcd-ae71962ac6eb@jeffhostetler.com","threadId":"50834","inReplyTo":"xmqqv9zkymzd.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v3 00/10] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-12T13:47:51Z","receivedAt":"2019-04-12T13:47:56Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 4/11/2019 10:29 PM, Junio C Hamano wrote:\n> \"Jeff Hostetler via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> \n[...]\n>>       @@ -512,19 +454,28 @@\n>>        + */\n>>        +/* clang-format off */\n>>\n>>       ++\t[TR2_SYSENV_CFG_PARAM]     = { \"GIT_TR2_CONFIG_PARAMS\",\n>>       ++\t\t\t\t       \"trace2.configparams\" },\n>>       ++\n>>       ++\t[TR2_SYSENV_DST_DEBUG]     = { \"GIT_TR2_DST_DEBUG\",\n>>       ++\t\t\t\t       \"trace2.destinationdebug\" },\n>>       ++\n>>       ++\t[TR2_SYSENV_NORMAL]        = { \"GIT_TR2\",\n>>       ++\t\t\t\t       \"trace2.normaltarget\" },\n>>       ++\t[TR2_SYSENV_NORMAL_BRIEF]  = { \"GIT_TR2_BRIEF\",\n>>       ++\t\t\t\t       \"trace2.normalbrief\" },\n>>       ++\n>>       ++\t[TR2_SYSENV_EVENT]         = { \"GIT_TR2_EVENT\",\n>>       ++\t\t\t\t       \"trace2.eventtarget\" },\n>>       ++\t[TR2_SYSENV_EVENT_BRIEF]   = { \"GIT_TR2_EVENT_BRIEF\",\n>>       ++\t\t\t\t       \"trace2.eventbrief\" },\n>>       ++\t[TR2_SYSENV_EVENT_NESTING] = { \"GIT_TR2_EVENT_NESTING\",\n>>       ++\t\t\t\t       \"trace2.eventnesting\" },\n>>       ++\n>>       ++\t[TR2_SYSENV_PERF]          = { \"GIT_TR2_PERF\",\n>>       ++\t\t\t\t       \"trace2.perftarget\" },\n>>       ++\t[TR2_SYSENV_PERF_BRIEF]    = { \"GIT_TR2_PERF_BRIEF\",\n>>       ++\t\t\t\t       \"trace2.perfbrief\" },\n> \n> \n> With use of designated initializers, the table got a lot cleaner to\n> read.  Is the above \"format off\" still needed (I am a bit curious\n> how clang-format wants these entries to look like)?\n\nclang-format suggests getting rid of the extra whitespace on the\nlines, so we lose all of the column alignment.  Then it wants to\nline-wrap some but not all of the lines.  So it is a bit of a mess\nto look at.\n\n\n> \n>>       ++\tif (pid > 999999)\n>>       ++\t\tstrbuf_addf(&tr2sid_buf, \"W%06d\", (int)(pid % 1000000));\n>>       ++\telse\n>>       ++\t\tstrbuf_addf(&tr2sid_buf, \"P%06d\", (int)pid);\n> \n> I do not think it matters too much, but this is kind-of curious.\n> \n> How would the users of the log utilize the distinction between W and\n> P?  Do they discard the ones with W when they care about the exact\n> process that left the trace entries, or something?  If it's not a\n> plausibly useful use pattern (and I do not think it is), I wonder if\n> we want to go with only W (i.e. truncated to the lower N digits)\n> entries, if you are shooting for a fixed-width output from this\n> function.  If you want less chance of collisions, you obviously\n> could use hexadecimal to gain back a few more bits.\n> \n> After all, if the application does care the PID, that could be in\n> the log data itself (i.e. an \"start\" event can say \"my pid is blah\").\n\nRight. Ævar suggested adding the full or wrapped PID so that the SID\nwould be a fixed length.  I stuck with decimal rather than hex because\nit's easier to match up a running command with '/usr/bin/ps' output,\nbut that's no big deal either way.  It might be simpler to just %08lx\nit and be done with it.\n\nJeff\n\n"},{"id":"373877","messageId":"nycvar.QRO.7.76.6.1904151629020.12614@tvgsbejvaqbjf.bet","threadId":"50834","inReplyTo":"20190412035220.GA26967@google.com","subject":"Re: [PATCH v3 01/10] config: initialize opts structure in repo_read_config()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-04-15T14:34:52Z","receivedAt":"2019-04-15T14:35:11Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Jonathan,\n\nOn Thu, 11 Apr 2019, Jonathan Nieder wrote:\n\n> Jeff Hostetler wrote:\n>\n> > Initialize opts structure in repo_read_config().\n>\n> Good find.\n\nHeh, it really was our CI that found it, and it was I (with valgrind's\nhelp) who identified the problem and proposed the fix. So: thank you!\n\n> I wonder if there are some flags we can turn on with\n> DEVELOPER=1 to prevent this kind of issue going undetected in the\n> future (or maybe this means we need to get the valgrind or ASan\n> testing modes to be fast enough for people to consistently run them).\n\nSadly, I do not think that either is an option. Such uninitialized memory\nis really hard to catch without in-depth analysis, so DEVELOPER=1 is out.\nAnd `valgrind` (or the faster alternative, DrMemory) have to spend quite a\nbit of time to do what they do, and it is unlikely that that could ever be\nmade faster.\n\nA better approach might be static analysis (and I do not mean the diet\ncoke of static analysis that we run as part of our CI, but something as\npowerful as Coverity).\n\nSadly, Coverity makes it super hard to switch off false positives\nregarding e.g. our use of FLEX_ARRAY or strbuf's strbuf_slopbuf.\n\nFor quite a while, I wanted to play with [infer](https://fbinfer.com/), in\nthe hopes that it would be possible to do customize what cannot be\ncustomized with Coverity. Alas, their use of OCaml (why do they make it so\nhard?) puts quite the bit of a road block ahead of me in that endeavor.\n\nCiao,\nDscho\n"},{"id":"373895","messageId":"f6653f1c5914d4ed0edee87a56277a35625135ca.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 01/10] config: initialize opts structure in repo_read_config()","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:42Z","receivedAt":"2019-04-15T20:39:47Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nInitialize opts structure in repo_read_config().\n\nThis change fixes a crash in later commit after a new field is added\nto the structure.\n\nIn commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config()\nwas added.  It only initializes 3 fields in the opts structure.  It is\npassed to config_with_options() and then to do_git_config_sequence().\nHowever, do_git_config_sequence() drops the opts on the floor and calls\ngit_config_from_file() rather than git_config_from_file_with_options(),\nso that may be why this hasn't been a problem in the past.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/config.c b/config.c\nindex 0f0cdd8c0f..c809f76219 100644\n--- a/config.c\n+++ b/config.c\n@@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha\n /* Functions use to read configuration from a repository */\n static void repo_read_config(struct repository *repo)\n {\n-\tstruct config_options opts;\n+\tstruct config_options opts = { 0 };\n \n \topts.respect_includes = 1;\n \topts.commondir = repo->commondir;\n-- \ngitgitgadget\n\n"},{"id":"373896","messageId":"pull.169.v4.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v3.git.gitgitgadget@gmail.com","subject":"[PATCH v4 00/10] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:41Z","receivedAt":"2019-04-15T20:39:47Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"Version 4 fixes a few clang-format warnings and simplifies the PID field in\nthe SID.\n\nJeff Hostetler (10):\n  config: initialize opts structure in repo_read_config()\n  trace2: refactor setting process starting time\n  trace2: add absolute elapsed time to start event\n  trace2: find exec-dir before trace2 initialization\n  config: add read_very_early_config()\n  trace2: use system/global config for default trace2 settings\n  trace2: report peak memory usage of the process\n  trace2: clarify UTC datetime formatting\n  trace2: make SIDs more unique\n  trace2: update docs to describe system/global config settings\n\n Documentation/config.txt                 |   2 +\n Documentation/config/trace2.txt          |  56 ++++++++\n Documentation/technical/api-trace2.txt   | 176 +++++++++++++----------\n Documentation/trace2-target-values.txt   |  10 ++\n Makefile                                 |   1 +\n common-main.c                            |   8 +-\n compat/mingw.c                           |   2 +\n compat/win32/trace2_win32_process_info.c |  50 ++++++-\n config.c                                 |  25 +++-\n config.h                                 |   4 +\n t/t0210-trace2-normal.sh                 |  49 ++++++-\n t/t0211-trace2-perf.sh                   |  43 ++++--\n t/t0212-trace2-event.sh                  |  42 +++++-\n trace2.c                                 |  21 ++-\n trace2.h                                 |  43 ++++--\n trace2/tr2_cfg.c                         |   7 +-\n trace2/tr2_dst.c                         |  26 ++--\n trace2/tr2_dst.h                         |   3 +-\n trace2/tr2_sid.c                         |  53 ++++++-\n trace2/tr2_sysenv.c                      | 127 ++++++++++++++++\n trace2/tr2_sysenv.h                      |  36 +++++\n trace2/tr2_tbuf.c                        |  19 ++-\n trace2/tr2_tbuf.h                        |   5 +-\n trace2/tr2_tgt.h                         |   1 +\n trace2/tr2_tgt_event.c                   |  53 +++----\n trace2/tr2_tgt_normal.c                  |  19 +--\n trace2/tr2_tgt_perf.c                    |  23 +--\n trace2/tr2_tls.c                         |  38 +++--\n trace2/tr2_tls.h                         |   8 +-\n 29 files changed, 747 insertions(+), 203 deletions(-)\n create mode 100644 Documentation/config/trace2.txt\n create mode 100644 Documentation/trace2-target-values.txt\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\n\nbase-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v4\nPull-Request: https://github.com/gitgitgadget/git/pull/169\n\nRange-diff vs v3:\n\n  1:  ea8c199f91 !  1:  f6653f1c59 config: initialize opts structure in repo_read_config()\n     @@ -25,7 +25,7 @@\n       static void repo_read_config(struct repository *repo)\n       {\n      -\tstruct config_options opts;\n     -+\tstruct config_options opts = {0};\n     ++\tstruct config_options opts = { 0 };\n       \n       \topts.respect_includes = 1;\n       \topts.commondir = repo->commondir;\n  2:  3dbcfc6a8d !  2:  48e34834b6 trace2: refactor setting process starting time\n     @@ -196,8 +196,8 @@\n      -\t * thread's array (because of reallocs).\n      -\t */\n      -\ttr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];\n     -+\ttr2tls_thread_main = tr2tls_create_self(\"main\",\n     -+\t\t\t\t\t\ttr2tls_us_start_process);\n     ++\ttr2tls_thread_main =\n     ++\t\ttr2tls_create_self(\"main\", tr2tls_us_start_process);\n       }\n       \n       void tr2tls_release(void)\n  3:  8b00025af5 =  3:  175371fb54 trace2: add absolute elapsed time to start event\n  4:  c3c5f6a96b =  4:  94729b284c trace2: find exec-dir before trace2 initialization\n  5:  d15be7b63a !  5:  b0fe1385f1 config: add read_very_early_config()\n     @@ -16,8 +16,8 @@\n       \n       \tcurrent_parsing_scope = CONFIG_SCOPE_REPO;\n      -\tif (repo_config && !access_or_die(repo_config, R_OK, 0))\n     -+\tif (!opts->ignore_repo &&\n     -+\t    repo_config && !access_or_die(repo_config, R_OK, 0))\n     ++\tif (!opts->ignore_repo && repo_config &&\n     ++\t    !access_or_die(repo_config, R_OK, 0))\n       \t\tret += git_config_from_file(fn, repo_config, data);\n       \n       \t/*\n     @@ -25,8 +25,7 @@\n       \t * But let's not complicate things before it's actually needed.\n       \t */\n      -\tif (repository_format_worktree_config) {\n     -+\tif (!opts->ignore_worktree &&\n     -+\t    repository_format_worktree_config) {\n     ++\tif (!opts->ignore_worktree && repository_format_worktree_config) {\n       \t\tchar *path = git_pathdup(\"config.worktree\");\n       \t\tif (!access_or_die(path, R_OK, 0))\n       \t\t\tret += git_config_from_file(fn, path, data);\n     @@ -35,8 +34,7 @@\n       \n       \tcurrent_parsing_scope = CONFIG_SCOPE_CMDLINE;\n      -\tif (git_config_from_parameters(fn, data) < 0)\n     -+\tif (!opts->ignore_cmdline &&\n     -+\t    git_config_from_parameters(fn, data) < 0)\n     ++\tif (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)\n       \t\tdie(_(\"unable to parse command-line config\"));\n       \n       \tcurrent_parsing_scope = CONFIG_SCOPE_UNKNOWN;\n     @@ -50,7 +48,7 @@\n      + */\n      +void read_very_early_config(config_fn_t cb, void *data)\n      +{\n     -+\tstruct config_options opts = {0};\n     ++\tstruct config_options opts = { 0 };\n      +\n      +\topts.respect_includes = 1;\n      +\topts.ignore_repo = 1;\n  6:  c085a482dd !  6:  550cad6189 trace2: use system/global config for default trace2 settings\n     @@ -41,16 +41,17 @@\n       --- a/t/t0210-trace2-normal.sh\n       +++ b/t/t0210-trace2-normal.sh\n      @@\n     - #!/bin/sh\n     - \n     -+# Turn off any inherited trace2 settings for this test.\n     -+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n     -+unset GIT_TR2_BRIEF\n     -+unset GIT_TR2_CONFIG_PARAMS\n     -+\n       test_description='test trace2 facility (normal target)'\n       . ./test-lib.sh\n       \n     ++# Turn off any inherited trace2 settings for this test.\n     ++sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n     ++sane_unset GIT_TR2_BRIEF\n     ++sane_unset GIT_TR2_CONFIG_PARAMS\n     ++\n     + # Add t/helper directory to PATH so that we can use a relative\n     + # path to run nested instances of test-tool.exe (see 004child).\n     + # This helps with HEREDOC comparisons later.\n      @@\n       # Warning: So you may see extra lines in artifact files when\n       # Warning: interactively debugging.\n     @@ -67,7 +68,7 @@\n       \ttest_cmp expect actual\n       '\n       \n     -+unset GIT_TR2_BRIEF\n     ++sane_unset GIT_TR2_BRIEF\n      +\n      +# Now test without environment variables and get all Trace2 settings\n      +# from the global config.\n     @@ -112,16 +113,17 @@\n       --- a/t/t0211-trace2-perf.sh\n       +++ b/t/t0211-trace2-perf.sh\n      @@\n     - #!/bin/sh\n     - \n     -+# Turn off any inherited trace2 settings for this test.\n     -+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n     -+unset GIT_TR2_PERF_BRIEF\n     -+unset GIT_TR2_CONFIG_PARAMS\n     -+\n       test_description='test trace2 facility (perf target)'\n       . ./test-lib.sh\n       \n     ++# Turn off any inherited trace2 settings for this test.\n     ++sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n     ++sane_unset GIT_TR2_PERF_BRIEF\n     ++sane_unset GIT_TR2_CONFIG_PARAMS\n     ++\n     + # Add t/helper directory to PATH so that we can use a relative\n     + # path to run nested instances of test-tool.exe (see 004child).\n     + # This helps with HEREDOC comparisons later.\n      @@\n       # Warning: So you may see extra lines in artifact files when\n       # Warning: interactively debugging.\n     @@ -138,7 +140,7 @@\n       \ttest_cmp expect actual\n       '\n       \n     -+unset GIT_TR2_PERF_BRIEF\n     ++sane_unset GIT_TR2_PERF_BRIEF\n      +\n      +# Now test without environment variables and get all Trace2 settings\n      +# from the global config.\n     @@ -165,16 +167,17 @@\n       --- a/t/t0212-trace2-event.sh\n       +++ b/t/t0212-trace2-event.sh\n      @@\n     - #!/bin/sh\n     + test_description='test trace2 facility'\n     + . ./test-lib.sh\n       \n      +# Turn off any inherited trace2 settings for this test.\n     -+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n     -+unset GIT_TR2_BARE\n     -+unset GIT_TR2_CONFIG_PARAMS\n     ++sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n     ++sane_unset GIT_TR2_BARE\n     ++sane_unset GIT_TR2_CONFIG_PARAMS\n      +\n     - test_description='test trace2 facility'\n     - . ./test-lib.sh\n     + perl -MJSON::PP -e 0 >/dev/null 2>&1 && test_set_prereq JSON_PP\n       \n     + # Add t/helper directory to PATH so that we can use a relative\n      @@\n       # Warning: So you may see extra lines in artifact files when\n       # Warning: interactively debugging.\n     @@ -353,7 +356,8 @@\n       \t\tif (tr2_dst_want_warning())\n       \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n      -\t\t\t\ttgt_value, dst->env_var_name);\n     -+\t\t\t\ttgt_value, tr2_sysenv_display_name(dst->sysenv_var));\n     ++\t\t\t\ttgt_value,\n     ++\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var));\n       \n       \t\ttr2_dst_trace_disable(dst);\n       \t\treturn 0;\n     @@ -371,7 +375,8 @@\n       \tif (tr2_dst_want_warning())\n       \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n      -\t\t\tpath, dst->env_var_name, strerror(e));\n     -+\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var), strerror(e));\n     ++\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var),\n     ++\t\t\tstrerror(e));\n       \n       \ttr2_dst_trace_disable(dst);\n       \treturn 0;\n  7:  2a7a933875 !  7:  56d8ce3fd6 trace2: report peak memory usage of the process\n     @@ -40,8 +40,8 @@\n      + */\n      +static void get_peak_memory_info(void)\n      +{\n     -+\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo,\n     -+\t\t\t  HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);\n     ++\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE,\n     ++\t\t\t  PPROCESS_MEMORY_COUNTERS, DWORD);\n      +\n      +\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n      +\t\tPROCESS_MEMORY_COUNTERS pmc;\n  8:  56f357dc7b =  8:  196a9d2c85 trace2: clarify UTC datetime formatting\n  9:  156ffde489 !  9:  9fdcb50140 trace2: make SIDs more unique\n     @@ -63,7 +63,7 @@\n      + * Compute the final component of the SID representing the current process.\n      + * This should uniquely identify the process and be a valid filename (to\n      + * allow writing trace2 data to per-process files).  It should also be fixed\n     -+ * possible length for use as a database key.\n     ++ * length for possible use as a database key.\n      + *\n      + * \"<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>\"\n      + *\n     @@ -71,17 +71,19 @@\n      + *    \"H<first_8_chars_of_sha1_of_hostname>\"\n      + *    \"Localhost\" when no hostname.\n      + *\n     -+ * where <process> is a possibly wrapped PID:\n     -+ *    \"P<6-digit-pid>\"\n     -+ *    \"W<wrapped-6-digit-pid>\" when PID too big.\n     -+ *    \n     ++ * where <process> is a 9 character string containing the least signifcant\n     ++ * 32 bits in the process-id.\n     ++ *    \"P<pid>\"\n     ++ * (This is an abribrary choice.  On most systems pid_t is a 32 bit value,\n     ++ * so limit doesn't matter.  On larger systems, a truncated value is fine\n     ++ * for our purposes here.)\n      + */\n      +static void tr2_sid_append_my_sid_component(void)\n      +{\n      +\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n      +\tstruct tr2_tbuf tb_now;\n      +\tgit_hash_ctx ctx;\n     -+\tuintmax_t pid = getpid();\n     ++\tpid_t pid = getpid();\n      +\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n      +\tchar hex[GIT_MAX_HEXSZ + 1];\n      +\tchar hostname[HOST_NAME_MAX + 1];\n     @@ -101,11 +103,7 @@\n      +\t\tstrbuf_add(&tr2sid_buf, hex, 8);\n      +\t}\n      +\n     -+\tstrbuf_addch(&tr2sid_buf, '-');\n     -+\tif (pid > 999999)\n     -+\t\tstrbuf_addf(&tr2sid_buf, \"W%06d\", (int)(pid % 1000000));\n     -+\telse\n     -+\t\tstrbuf_addf(&tr2sid_buf, \"P%06d\", (int)pid);\n     ++\tstrbuf_addf(&tr2sid_buf, \"-P%08\"PRIx32, (uint32_t)pid);\n      +}\n      +\n       /*\n     @@ -149,10 +147,9 @@\n      +\tsecs = tv.tv_sec;\n      +\tgmtime_r(&secs, &tm);\n      +\n     -+\txsnprintf(tb->buf, sizeof(tb->buf),\n     -+\t\t  \"%4d%02d%02dT%02d%02d%02d.%06ldZ\", tm.tm_year + 1900,\n     -+\t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n     -+\t\t  (long)tv.tv_usec);\n     ++\txsnprintf(tb->buf, sizeof(tb->buf), \"%4d%02d%02dT%02d%02d%02d.%06ldZ\",\n     ++\t\t  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,\n     ++\t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n      +}\n      \n       diff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\n 10:  285beb2b2d ! 10:  3414016d04 trace2: update docs to describe system/global config settings\n     @@ -188,53 +188,59 @@\n       git version 2.20.1.155.g426c96fcdb\n       ------------\n      -+\n     -+\n     -+or\n     -+\n     -+------------\n     -+$ git config --global trace2.eventTarget ~/log.event\n     -+$ git version\n     -+git version 2.20.1.155.g426c96fcdb\n     -+------------\n     -+\n     -+yields\n     -+\n     - ------------\n     - $ cat ~/log.event\n     - {\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n     -@@\n     - {\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n     - ------------\n     - \n     +-------------\n     +-$ cat ~/log.event\n     +-{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n     +-{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n     +-{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n     +-{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n     +-{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n     +-------------\n     +-\n      -== Enabling a Target\n      -\n      -A Trace2 Target is enabled when the corresponding environment variable\n      -(`GIT_TR2`, `GIT_TR2_PERF`, or `GIT_TR2_EVENT`) is set.  The following\n      -values are recognized.\n     -+=== Enabling a Target\n     - \n     +-\n      -`0`::\n      -`false`::\n     -+To enable a target, set the corresponding environment variable or\n     -+system or global config value to one of the following:\n     - \n     --\tDisables the target.\n      -\n     +-\tDisables the target.\n     + \n      -`1`::\n      -`true`::\n     --\n     ++or\n     + \n      -\tEnables the target and writes stream to `STDERR`.\n      -\n      -`[2-9]`::\n     --\n     ++------------\n     ++$ git config --global trace2.eventTarget ~/log.event\n     ++$ git version\n     ++git version 2.20.1.155.g426c96fcdb\n     ++------------\n     + \n      -\tEnables the target and writes to the already opened file descriptor.\n     --\n     ++yields\n     + \n      -`<absolute-pathname>`::\n     --\n     ++------------\n     ++$ cat ~/log.event\n     ++{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n     ++{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n     ++{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n     ++{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n     ++{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n     ++------------\n     + \n      -\tEnables the target, opens and writes to the file in append mode.\n     --\n     ++=== Enabling a Target\n     + \n      -`af_unix:[<socket_type>:]<absolute-pathname>`::\n     --\n     ++To enable a target, set the corresponding environment variable or\n     ++system or global config value to one of the following:\n     + \n      -\tEnables the target, opens and writes to a Unix Domain Socket\n      -\t(on platforms that support them).\n      -+\n     @@ -316,6 +322,15 @@\n       Each event is a JSON-object containing multiple key/value pairs\n       written as a single line and followed by a LF.\n       \n     +@@\n     + ------------\n     + {\n     + \t\"event\":\"version\",\n     +-\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n     ++\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P00003510\",\n     + \t\"thread\":\"main\",\n     + \t\"time\":\"2019-04-08T19:18:27.282761Z\",\n     + \t\"file\":\"common-main.c\",\n      @@\n       `\"repo\":<repo-id>`::\n       \twhen present, is the integer repo-id as described previously.\n\n-- \ngitgitgadget\n"},{"id":"373897","messageId":"48e34834b6a65b9f2c68d4f4e459586b2948b6cd.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 02/10] trace2: refactor setting process starting time","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:43Z","receivedAt":"2019-04-15T20:39:49Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreate trace2_initialize_clock() and call from main() to capture\nprocess start time in isolation and before other sub-systems are\nready.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++--\n common-main.c                          |  2 ++\n compat/mingw.c                         |  2 ++\n trace2.c                               |  7 ++++-\n trace2.h                               | 17 ++++++++++++\n trace2/tr2_tls.c                       | 38 ++++++++++++++++----------\n trace2/tr2_tls.h                       |  8 +++++-\n 7 files changed, 67 insertions(+), 19 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 2de565fa3d..f37fccf1da 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -160,17 +160,23 @@ purposes.\n \n These are concerned with the lifetime of the overall git process.\n \n+`void trace2_initialize_clock()`::\n+\n+\tInitialize the Trace2 start clock and nothing else.  This should\n+\tbe called at the very top of main() to capture the process start\n+\ttime and reduce startup order dependencies.\n+\n `void trace2_initialize()`::\n \n \tDetermines if any Trace2 Targets should be enabled and\n-\tinitializes the Trace2 facility.  This includes starting the\n-\telapsed time clocks and thread local storage (TLS).\n+\tinitializes the Trace2 facility.  This includes setting up the\n+\tTrace2 thread local storage (TLS).\n +\n This function emits a \"version\" message containing the version of git\n and the Trace2 protocol.\n +\n This function should be called from `main()` as early as possible in\n-the life of the process.\n+the life of the process after essential process initialization.\n \n `int trace2_is_enabled()`::\n \ndiff --git a/common-main.c b/common-main.c\nindex d484aec209..6137af0e63 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -27,6 +27,8 @@ int main(int argc, const char **argv)\n {\n \tint result;\n \n+\ttrace2_initialize_clock();\n+\n \t/*\n \t * Always open file descriptors 0/1/2 to avoid clobbering files\n \t * in die().  It also avoids messing up when the pipes are dup'ed\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 6b04514cdc..a2f74aca6a 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -2569,6 +2569,8 @@ void mingw_startup(void)\n \twchar_t **wenv, **wargv;\n \t_startupinfo si;\n \n+\ttrace2_initialize_clock();\n+\n \tmaybe_redirect_std_handles();\n \n \t/* get wide char arguments and environment */\ndiff --git a/trace2.c b/trace2.c\nindex ccccd4ef09..6dd51e6aa5 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)\n \traise(signo);\n }\n \n+void trace2_initialize_clock(void)\n+{\n+\ttr2tls_start_process_clock();\n+}\n+\n void trace2_initialize_fl(const char *file, int line)\n {\n \tstruct tr2_tgt *tgt_j;\n@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name)\n \tus_now = getnanotime() / 1000;\n \tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n \n-\ttr2tls_create_self(thread_name);\n+\ttr2tls_create_self(thread_name, us_now);\n \n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_thread_start_fl)\ndiff --git a/trace2.h b/trace2.h\nindex ae5020d0e6..8f89e70c44 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -19,6 +19,23 @@ struct json_writer;\n  * [] trace2_printf*    -- legacy trace[1] messages.\n  */\n \n+/*\n+ * Initialize the TRACE2 clock and do nothing else, in particular\n+ * no mallocs, no system inspection, and no environment inspection.\n+ *\n+ * This should be called at the very top of main() to capture the\n+ * process start time.  This is intended to reduce chicken-n-egg\n+ * bootstrap pressure.\n+ *\n+ * It is safe to call this more than once.  This allows capturing\n+ * absolute startup costs on Windows which uses a little trickery\n+ * to do setup work before common-main.c:main() is called.\n+ *\n+ * The main trace2_initialize_fl() may be called a little later\n+ * after more infrastructure is established.\n+ */\n+void trace2_initialize_clock(void);\n+\n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n  * targets are enabled in the environment.  Emits a 'version' event.\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 8e65b0361d..e76d8c5d92 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -10,16 +10,30 @@\n #define TR2_REGION_NESTING_INITIAL_SIZE (100)\n \n static struct tr2tls_thread_ctx *tr2tls_thread_main;\n-static uint64_t tr2tls_us_start_main;\n+static uint64_t tr2tls_us_start_process;\n \n static pthread_mutex_t tr2tls_mutex;\n static pthread_key_t tr2tls_key;\n \n static int tr2_next_thread_id; /* modify under lock */\n \n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n+void tr2tls_start_process_clock(void)\n+{\n+\tif (tr2tls_us_start_process)\n+\t\treturn;\n+\n+\t/*\n+\t * Keep the absolute start time of the process (i.e. the main\n+\t * process) in a fixed variable since other threads need to\n+\t * access it.  This allows them to do that without a lock on\n+\t * main thread's array data (because of reallocs).\n+\t */\n+\ttr2tls_us_start_process = getnanotime() / 1000;\n+}\n+\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start)\n {\n-\tuint64_t us_now = getnanotime() / 1000;\n \tstruct tr2tls_thread_ctx *ctx = xcalloc(1, sizeof(*ctx));\n \n \t/*\n@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n \t */\n \tctx->alloc = TR2_REGION_NESTING_INITIAL_SIZE;\n \tctx->array_us_start = (uint64_t *)xcalloc(ctx->alloc, sizeof(uint64_t));\n-\tctx->array_us_start[ctx->nr_open_regions++] = us_now;\n+\tctx->array_us_start[ctx->nr_open_regions++] = us_thread_start;\n \n \tctx->thread_id = tr2tls_locked_increment(&tr2_next_thread_id);\n \n@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)\n \t * here and silently continue.\n \t */\n \tif (!ctx)\n-\t\tctx = tr2tls_create_self(\"unknown\");\n+\t\tctx = tr2tls_create_self(\"unknown\", getnanotime() / 1000);\n \n \treturn ctx;\n }\n@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)\n \tif (!tr2tls_thread_main)\n \t\treturn 0;\n \n-\treturn us - tr2tls_us_start_main;\n+\treturn us - tr2tls_us_start_process;\n }\n \n void tr2tls_init(void)\n {\n+\ttr2tls_start_process_clock();\n+\n \tpthread_key_create(&tr2tls_key, NULL);\n \tinit_recursive_mutex(&tr2tls_mutex);\n \n-\ttr2tls_thread_main = tr2tls_create_self(\"main\");\n-\t/*\n-\t * Keep a copy of the absolute start time of the main thread\n-\t * in a fixed variable since other threads need to access it.\n-\t * This also eliminates the need to lock accesses to the main\n-\t * thread's array (because of reallocs).\n-\t */\n-\ttr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];\n+\ttr2tls_thread_main =\n+\t\ttr2tls_create_self(\"main\", tr2tls_us_start_process);\n }\n \n void tr2tls_release(void)\ndiff --git a/trace2/tr2_tls.h b/trace2/tr2_tls.h\nindex bb80e3f8e7..b1e327a928 100644\n--- a/trace2/tr2_tls.h\n+++ b/trace2/tr2_tls.h\n@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {\n  * In this and all following functions the term \"self\" refers to the\n  * current thread.\n  */\n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start);\n \n /*\n  * Get our TLS data.\n@@ -94,4 +95,9 @@ void tr2tls_release(void);\n  */\n int tr2tls_locked_increment(int *p);\n \n+/*\n+ * Capture the process start time and do nothing else.\n+ */\n+void tr2tls_start_process_clock(void);\n+\n #endif /* TR2_TLS_H */\n-- \ngitgitgadget\n\n"},{"id":"373898","messageId":"175371fb54cbf41e5cf90d8d23ec5fde30036266.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 03/10] trace2: add absolute elapsed time to start event","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:44Z","receivedAt":"2019-04-15T20:39:50Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nAdd elapsed process time to \"start\" event to measure\nthe performance of early process startup.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 11 ++++++-----\n t/t0211-trace2-perf.sh                 | 12 ++++++------\n trace2.c                               |  8 +++++++-\n trace2/tr2_tgt.h                       |  1 +\n trace2/tr2_tgt_event.c                 |  5 ++++-\n trace2/tr2_tgt_normal.c                |  3 ++-\n trace2/tr2_tgt_perf.c                  |  7 ++++---\n 7 files changed, 30 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex f37fccf1da..baaa1153bb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n-12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |           |           |            | git version\n+12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |  0.001173 |           |            | git version\n 12:28:42.621111 git.c:432                         | d0 | main                     | cmd_name     |     |           |           |            | version (version)\n 12:28:42.621225 git.c:662                         | d0 | main                     | exit         |     |  0.001227 |           |            | code:0\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.event\n {\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n {\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n {\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n {\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the \"start\" and\n {\n \t\"event\":\"start\",\n \t...\n+\t\"t_abs\":0.001227, # elapsed time in seconds\n \t\"argv\":[\"git\",\"version\"]\n }\n ------------\n@@ -1118,7 +1119,7 @@ $ git status\n \n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.160.g5676107ecd.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1163,7 +1164,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.162.gb4ccea44db.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1219,7 +1220,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.156.gf9916ae094.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n d0 | main                     | region_enter | r1  |  0.001791 |           | index      | label:do_read_index .git/index\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex 953e2f7847..c9694b29f7 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:0\n \t\td0|main|atexit||_T_ABS_|||code:0\n@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 1\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 1\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:1\n \t\td0|main|atexit||_T_ABS_|||code:1\n@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|error|||||hello world\n \t\td0|main|error|||||this is a test\n@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0\n \t\td1|main|version|||||$V\n-\t\td1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0\n+\t\td1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0\n \t\td1|main|cmd_name|||||trace2 (trace2/trace2)\n \t\td1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0\n \t\td2|main|version|||||$V\n-\t\td2|main|start|||||_EXE_ trace2 001return 0\n+\t\td2|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td2|main|cmd_name|||||trace2 (trace2/trace2/trace2)\n \t\td2|main|exit||_T_ABS_|||code:0\n \t\td2|main|atexit||_T_ABS_|||code:0\ndiff --git a/trace2.c b/trace2.c\nindex 6dd51e6aa5..1c180062dd 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv)\n {\n \tstruct tr2_tgt *tgt_j;\n \tint j;\n+\tuint64_t us_now;\n+\tuint64_t us_elapsed_absolute;\n \n \tif (!trace2_enabled)\n \t\treturn;\n \n+\tus_now = getnanotime() / 1000;\n+\tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n+\n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_start_fl)\n-\t\t\ttgt_j->pfn_start_fl(file, line, argv);\n+\t\t\ttgt_j->pfn_start_fl(file, line, us_elapsed_absolute,\n+\t\t\t\t\t    argv);\n }\n \n int trace2_cmd_exit_fl(const char *file, int line, int code)\ndiff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h\nindex 297bb8ffbe..7b90469212 100644\n--- a/trace2/tr2_tgt.h\n+++ b/trace2/tr2_tgt.h\n@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);\n typedef void(tr2_tgt_evt_version_fl_t)(const char *file, int line);\n \n typedef void(tr2_tgt_evt_start_fl_t)(const char *file, int line,\n+\t\t\t\t     uint64_t us_elapsed_absolute,\n \t\t\t\t     const char **argv);\n typedef void(tr2_tgt_evt_exit_fl_t)(const char *file, int line,\n \t\t\t\t    uint64_t us_elapsed_absolute, int code);\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 107cb5317d..89a4d3ae9a 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)\n \tjw_release(&jw);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct json_writer jw = JSON_WRITER_INIT;\n+\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \n \tjw_object_begin(&jw, 0);\n \tevent_fmt_prepare(event_name, file, line, NULL, &jw);\n+\tjw_object_double(&jw, \"t_abs\", 6, t_abs);\n \tjw_object_inline_begin_array(&jw, \"argv\");\n \tjw_array_argv(&jw, argv);\n \tjw_end(&jw);\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 547183d5b6..57f3e18f5b 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex f0746fcf86..9c3b4d8a0f 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \n \tsq_quote_argv_pretty(&buf_payload, argv);\n \n-\tperf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,\n-\t\t\t &buf_payload);\n+\tperf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,\n+\t\t\t NULL, NULL, &buf_payload);\n \tstrbuf_release(&buf_payload);\n }\n \n-- \ngitgitgadget\n\n"},{"id":"373899","messageId":"b0fe1385f1a96efbcab38fe02a3d5b3c1b6eaa37.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 05/10] config: add read_very_early_config()","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:46Z","receivedAt":"2019-04-15T20:39:51Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreated an even lighter version of read_early_config() that\nonly looks at system and global config settings.  It omits\nrepo-local, worktree-local, and command-line settings.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 23 ++++++++++++++++++++---\n config.h |  4 ++++\n 2 files changed, 24 insertions(+), 3 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex c809f76219..d7a08713a8 100644\n--- a/config.c\n+++ b/config.c\n@@ -1688,14 +1688,15 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t\tret += git_config_from_file(fn, user_config, data);\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_REPO;\n-\tif (repo_config && !access_or_die(repo_config, R_OK, 0))\n+\tif (!opts->ignore_repo && repo_config &&\n+\t    !access_or_die(repo_config, R_OK, 0))\n \t\tret += git_config_from_file(fn, repo_config, data);\n \n \t/*\n \t * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.\n \t * But let's not complicate things before it's actually needed.\n \t */\n-\tif (repository_format_worktree_config) {\n+\tif (!opts->ignore_worktree && repository_format_worktree_config) {\n \t\tchar *path = git_pathdup(\"config.worktree\");\n \t\tif (!access_or_die(path, R_OK, 0))\n \t\t\tret += git_config_from_file(fn, path, data);\n@@ -1703,7 +1704,7 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t}\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_CMDLINE;\n-\tif (git_config_from_parameters(fn, data) < 0)\n+\tif (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)\n \t\tdie(_(\"unable to parse command-line config\"));\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_UNKNOWN;\n@@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data)\n \tstrbuf_release(&gitdir);\n }\n \n+/*\n+ * Read config but only enumerate system and global settings.\n+ * Omit any repo-local, worktree-local, or command-line settings.\n+ */\n+void read_very_early_config(config_fn_t cb, void *data)\n+{\n+\tstruct config_options opts = { 0 };\n+\n+\topts.respect_includes = 1;\n+\topts.ignore_repo = 1;\n+\topts.ignore_worktree = 1;\n+\topts.ignore_cmdline = 1;\n+\n+\tconfig_with_options(cb, data, NULL, &opts);\n+}\n+\n static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)\n {\n \tstruct config_set_element k;\ndiff --git a/config.h b/config.h\nindex ee5d3fa7b4..6a58d61d22 100644\n--- a/config.h\n+++ b/config.h\n@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,\n \n struct config_options {\n \tunsigned int respect_includes : 1;\n+\tunsigned int ignore_repo : 1;\n+\tunsigned int ignore_worktree : 1;\n+\tunsigned int ignore_cmdline : 1;\n \tconst char *commondir;\n \tconst char *git_dir;\n \tconfig_parser_event_fn_t event_fn;\n@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,\n extern void git_config_push_parameter(const char *text);\n extern int git_config_from_parameters(config_fn_t fn, void *data);\n extern void read_early_config(config_fn_t cb, void *data);\n+extern void read_very_early_config(config_fn_t cb, void *data);\n extern void git_config(config_fn_t fn, void *);\n extern int config_with_options(config_fn_t fn, void *,\n \t\t\t       struct git_config_source *config_source,\n-- \ngitgitgadget\n\n"},{"id":"373900","messageId":"56d8ce3fd60acc3808a5c8c1e5e1e6ba87fa1d5a.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 07/10] trace2: report peak memory usage of the process","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:48Z","receivedAt":"2019-04-15T20:39:55Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Windows version of git to report peak memory usage\nduring exit() processing.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c                            |  2 +-\n compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++--\n trace2.c                                 |  2 +\n trace2.h                                 | 14 +++++--\n 4 files changed, 60 insertions(+), 8 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 299ca62a72..582a7b1886 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -41,7 +41,7 @@ int main(int argc, const char **argv)\n \n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n-\ttrace2_collect_process_info();\n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);\n \n \tgit_setup_gettext();\n \ndiff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c\nindex 52bd62034b..8ccbd1c2c6 100644\n--- a/compat/win32/trace2_win32_process_info.c\n+++ b/compat/win32/trace2_win32_process_info.c\n@@ -1,5 +1,6 @@\n #include \"../../cache.h\"\n #include \"../../json-writer.h\"\n+#include \"lazyload.h\"\n #include <Psapi.h>\n #include <tlHelp32.h>\n \n@@ -137,11 +138,54 @@ static void get_is_being_debugged(void)\n \t\t\t\t   \"windows/debugger_present\", 1);\n }\n \n-void trace2_collect_process_info(void)\n+/*\n+ * Emit JSON data with the peak memory usage of the current process.\n+ */\n+static void get_peak_memory_info(void)\n+{\n+\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE,\n+\t\t\t  PPROCESS_MEMORY_COUNTERS, DWORD);\n+\n+\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n+\t\tPROCESS_MEMORY_COUNTERS pmc;\n+\n+\t\tif (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,\n+\t\t\t\t\t sizeof(pmc))) {\n+\t\t\tstruct json_writer jw = JSON_WRITER_INIT;\n+\n+\t\t\tjw_object_begin(&jw, 0);\n+\n+#define KV(kv) #kv, (intmax_t)pmc.kv\n+\n+\t\t\tjw_object_intmax(&jw, KV(PageFaultCount));\n+\t\t\tjw_object_intmax(&jw, KV(PeakWorkingSetSize));\n+\t\t\tjw_object_intmax(&jw, KV(PeakPagefileUsage));\n+\n+\t\t\tjw_end(&jw);\n+\n+\t\t\ttrace2_data_json(\"process\", the_repository,\n+\t\t\t\t\t \"windows/memory\", &jw);\n+\t\t\tjw_release(&jw);\n+\t\t}\n+\t}\n+}\n+\n+void trace2_collect_process_info(enum trace2_process_info_reason reason)\n {\n \tif (!trace2_is_enabled())\n \t\treturn;\n \n-\tget_is_being_debugged();\n-\tget_ancestry();\n+\tswitch (reason) {\n+\tcase TRACE2_PROCESS_INFO_STARTUP:\n+\t\tget_is_being_debugged();\n+\t\tget_ancestry();\n+\t\treturn;\n+\n+\tcase TRACE2_PROCESS_INFO_EXIT:\n+\t\tget_peak_memory_info();\n+\t\treturn;\n+\n+\tdefault:\n+\t\tBUG(\"trace2_collect_process_info: unknown reason '%d'\", reason);\n+\t}\n }\ndiff --git a/trace2.c b/trace2.c\nindex 490b3f071e..6baa65cdf9 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)\n \tif (!trace2_enabled)\n \t\treturn code;\n \n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);\n+\n \ttr2main_exit_code = code;\n \n \tus_now = getnanotime() / 1000;\ndiff --git a/trace2.h b/trace2.h\nindex 894bfca7e0..888531eb08 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);\n  * Optional platform-specific code to dump information about the\n  * current and any parent process(es).  This is intended to allow\n  * post-processors to know who spawned this git instance and anything\n- * else the platform may be able to tell us about the current process.\n+ * else that the platform may be able to tell us about the current process.\n  */\n+\n+enum trace2_process_info_reason {\n+\tTRACE2_PROCESS_INFO_STARTUP,\n+\tTRACE2_PROCESS_INFO_EXIT,\n+};\n+\n #if defined(GIT_WINDOWS_NATIVE)\n-void trace2_collect_process_info(void);\n+void trace2_collect_process_info(enum trace2_process_info_reason reason);\n #else\n-#define trace2_collect_process_info() \\\n-\tdo {                          \\\n+#define trace2_collect_process_info(reason) \\\n+\tdo {                                \\\n \t} while (0)\n #endif\n \n-- \ngitgitgadget\n\n"},{"id":"373901","messageId":"550cad618923c6e5aa1bd5f901f2968791d7566b.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 06/10] trace2: use system/global config for default trace2 settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:47Z","receivedAt":"2019-04-15T20:39:55Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach git to read the system and global config files for\ndefault Trace2 settings.  This allows system-wide Trace2 settings to\nbe installed and inherited to make it easier to manage a collection of\nsystems.\n\nThe original GIT_TR2* environment variables are loaded afterwards and\ncan be used to override the system settings.\n\nOnly the system and global config files are used.  Repo and worktree\nlocal config files are ignored.  Likewise, the \"-c\" command line\narguments are also ignored.  These limits are for performance reasons.\n\n(1) For users not using Trace2, there should be minimal overhead to\ndetect that Trace2 is not enabled.  In particular, Trace2 should not\nallocate lots of otherwise unused data strucutres.\n\n(2) For accurate performance measurements, Trace2 should be initialized\nas early in the git process as possible, and before most of the normal\ngit process initialization (which involves discovering the .git directory\nand reading a hierarchy of config files).\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Makefile                 |   1 +\n t/t0210-trace2-normal.sh |  49 +++++++++++++--\n t/t0211-trace2-perf.sh   |  31 ++++++++--\n t/t0212-trace2-event.sh  |  42 +++++++++++--\n trace2.c                 |   4 ++\n trace2.h                 |  12 ++--\n trace2/tr2_cfg.c         |   7 +--\n trace2/tr2_dst.c         |  26 ++++----\n trace2/tr2_dst.h         |   3 +-\n trace2/tr2_sysenv.c      | 127 +++++++++++++++++++++++++++++++++++++++\n trace2/tr2_sysenv.h      |  36 +++++++++++\n trace2/tr2_tgt_event.c   |  46 +++++++-------\n trace2/tr2_tgt_normal.c  |  16 ++---\n trace2/tr2_tgt_perf.c    |  16 ++---\n 14 files changed, 340 insertions(+), 76 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\ndiff --git a/Makefile b/Makefile\nindex 3e03290d8f..9ddfa3dfe7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o\n LIB_OBJS += trace2/tr2_cmd_name.o\n LIB_OBJS += trace2/tr2_dst.o\n LIB_OBJS += trace2/tr2_sid.o\n+LIB_OBJS += trace2/tr2_sysenv.o\n LIB_OBJS += trace2/tr2_tbuf.o\n LIB_OBJS += trace2/tr2_tgt_event.o\n LIB_OBJS += trace2/tr2_tgt_normal.o\ndiff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh\nindex 03a0aedb1d..8d17e1e6f1 100755\n--- a/t/t0210-trace2-normal.sh\n+++ b/t/t0210-trace2-normal.sh\n@@ -3,6 +3,11 @@\n test_description='test trace2 facility (normal target)'\n . ./test-lib.sh\n \n+# Turn off any inherited trace2 settings for this test.\n+sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+sane_unset GIT_TR2_BRIEF\n+sane_unset GIT_TR2_CONFIG_PARAMS\n+\n # Add t/helper directory to PATH so that we can use a relative\n # path to run nested instances of test-tool.exe (see 004child).\n # This helps with HEREDOC comparisons later.\n@@ -15,11 +20,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -132,4 +132,43 @@ test_expect_success 'normal stream, error event' '\n \ttest_cmp expect actual\n '\n \n+sane_unset GIT_TR2_BRIEF\n+\n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success 'using global config, normal stream, return code 0' '\n+\ttest_when_finished \"rm trace.normal actual expect\" &&\n+\ttest_config_global trace2.normalBrief 1 &&\n+\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'using global config with include' '\n+\ttest_when_finished \"rm trace.normal actual expect real.gitconfig\" &&\n+\ttest_config_global trace2.normalBrief 1 &&\n+\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\tmv \"$(pwd)/.gitconfig\" \"$(pwd)/real.gitconfig\" &&\n+\ttest_config_global include.path \"$(pwd)/real.gitconfig\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex c9694b29f7..b501e867af 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -3,6 +3,11 @@\n test_description='test trace2 facility (perf target)'\n . ./test-lib.sh\n \n+# Turn off any inherited trace2 settings for this test.\n+sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+sane_unset GIT_TR2_PERF_BRIEF\n+sane_unset GIT_TR2_CONFIG_PARAMS\n+\n # Add t/helper directory to PATH so that we can use a relative\n # path to run nested instances of test-tool.exe (see 004child).\n # This helps with HEREDOC comparisons later.\n@@ -15,11 +20,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_PERF_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -150,4 +150,25 @@ test_expect_success 'perf stream, child processes' '\n \ttest_cmp expect actual\n '\n \n+sane_unset GIT_TR2_PERF_BRIEF\n+\n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success 'using global config, perf stream, return code 0' '\n+\ttest_when_finished \"rm trace.perf actual expect\" &&\n+\ttest_config_global trace2.perfBrief 1 &&\n+\ttest_config_global trace2.perfTarget \"$(pwd)/trace.perf\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n+\tcat >expect <<-EOF &&\n+\t\td0|main|version|||||$V\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n+\t\td0|main|cmd_name|||||trace2 (trace2)\n+\t\td0|main|exit||_T_ABS_|||code:0\n+\t\td0|main|atexit||_T_ABS_|||code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh\nindex 028b6c5671..59adae8123 100755\n--- a/t/t0212-trace2-event.sh\n+++ b/t/t0212-trace2-event.sh\n@@ -3,6 +3,11 @@\n test_description='test trace2 facility'\n . ./test-lib.sh\n \n+# Turn off any inherited trace2 settings for this test.\n+sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+sane_unset GIT_TR2_BARE\n+sane_unset GIT_TR2_CONFIG_PARAMS\n+\n perl -MJSON::PP -e 0 >/dev/null 2>&1 && test_set_prereq JSON_PP\n \n # Add t/helper directory to PATH so that we can use a relative\n@@ -17,11 +22,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BARE\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -233,4 +233,36 @@ test_expect_success JSON_PP 'basic trace2_data' '\n \ttest_cmp expect actual\n '\n \n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success JSON_PP 'using global config, event stream, error event' '\n+\ttest_when_finished \"rm trace.event actual expect\" &&\n+\ttest_config_global trace2.eventTarget \"$(pwd)/trace.event\" &&\n+\ttest-tool trace2 003error \"hello world\" \"this is a test\" &&\n+\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n+\tsed -e \"s/^|//\" >expect <<-EOF &&\n+\t|VAR1 = {\n+\t|  \"_SID0_\":{\n+\t|    \"argv\":[\n+\t|      \"_EXE_\",\n+\t|      \"trace2\",\n+\t|      \"003error\",\n+\t|      \"hello world\",\n+\t|      \"this is a test\"\n+\t|    ],\n+\t|    \"errors\":[\n+\t|      \"%s\",\n+\t|      \"%s\"\n+\t|    ],\n+\t|    \"exit_code\":0,\n+\t|    \"hierarchy\":\"trace2\",\n+\t|    \"name\":\"trace2\",\n+\t|    \"version\":\"$V\"\n+\t|  }\n+\t|};\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/trace2.c b/trace2.c\nindex 1c180062dd..490b3f071e 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -10,6 +10,7 @@\n #include \"trace2/tr2_cmd_name.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)\n \ttr2_sid_release();\n \ttr2_cmd_name_release();\n \ttr2_cfg_free_patterns();\n+\ttr2_sysenv_release();\n \n \ttrace2_enabled = 0;\n }\n@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)\n \tif (trace2_enabled)\n \t\treturn;\n \n+\ttr2_sysenv_load();\n+\n \tif (!tr2_tgt_want_builtins())\n \t\treturn;\n \ttrace2_enabled = 1;\ndiff --git a/trace2.h b/trace2.h\nindex 8f89e70c44..894bfca7e0 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n \n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n- * targets are enabled in the environment.  Emits a 'version' event.\n+ * targets are enabled in the system config or the environment.\n+ * Emits a 'version' event.\n  *\n  * Cleanup/Termination is handled automatically by a registered\n  * atexit() routine.\n@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n  * Emit one or more 'def_param' events for \"interesting\" configuration\n  * settings.\n  *\n- * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n- * list of patterns considered important.  For example:\n- *\n- *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n+ * Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated\n+ * list of patterns configured important.  For example:\n+ *     git config --system trace2.configParams 'core.*,remote.*.url'\n+ * or:\n+ *     GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url\"\n  *\n  * Note: this routine does a read-only iteration on the config data\n  * (using read_early_config()), so it must not be called until enough\ndiff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\nindex b329921ac5..caa7f06948 100644\n--- a/trace2/tr2_cfg.c\n+++ b/trace2/tr2_cfg.c\n@@ -1,8 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n-#include \"tr2_cfg.h\"\n-\n-#define TR2_ENVVAR_CFG_PARAM \"GIT_TR2_CONFIG_PARAMS\"\n+#include \"trace2/tr2_cfg.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n static struct strbuf **tr2_cfg_patterns;\n static int tr2_cfg_count_patterns;\n@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)\n \t\treturn tr2_cfg_count_patterns;\n \ttr2_cfg_loaded = 1;\n \n-\tenvvar = getenv(TR2_ENVVAR_CFG_PARAM);\n+\tenvvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM);\n \tif (!envvar || !*envvar)\n \t\treturn tr2_cfg_count_patterns;\n \ndiff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c\nindex fd490a43ad..7d96f33420 100644\n--- a/trace2/tr2_dst.c\n+++ b/trace2/tr2_dst.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n /*\n  * If a Trace2 target cannot be opened for writing, we should issue a\n@@ -7,17 +8,13 @@\n  * or socket and beyond the user's control -- especially since every\n  * git command (and sub-command) will print the message.  So we silently\n  * eat these warnings and just discard the trace data.\n- *\n- * Enable the following environment variable to see these warnings.\n  */\n-#define TR2_ENVVAR_DST_DEBUG \"GIT_TR2_DST_DEBUG\"\n-\n static int tr2_dst_want_warning(void)\n {\n \tstatic int tr2env_dst_debug = -1;\n \n \tif (tr2env_dst_debug == -1) {\n-\t\tconst char *env_value = getenv(TR2_ENVVAR_DST_DEBUG);\n+\t\tconst char *env_value = tr2_sysenv_get(TR2_SYSENV_DST_DEBUG);\n \t\tif (!env_value || !*env_value)\n \t\t\ttr2env_dst_debug = 0;\n \t\telse\n@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)\n \tif (fd == -1) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: could not open '%s' for '%s' tracing: %s\",\n-\t\t\t\ttgt_value, dst->env_var_name, strerror(errno));\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\t\tstrerror(errno));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -116,7 +115,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \tif (!path || !*path) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n-\t\t\t\ttgt_value, dst->env_var_name);\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -126,7 +126,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \t    strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX path '%s' for '%s' tracing\",\n-\t\t\t\tpath, dst->env_var_name);\n+\t\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -148,7 +148,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n error:\n \tif (tr2_dst_want_warning())\n \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n-\t\t\tpath, dst->env_var_name, strerror(e));\n+\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\tstrerror(e));\n \n \ttr2_dst_trace_disable(dst);\n \treturn 0;\n@@ -168,7 +169,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_addf(&buf, \"trace2: unknown value for '%s': '%s'\",\n-\t\t    dst->env_var_name, tgt_value);\n+\t\t    tr2_sysenv_display_name(dst->sysenv_var), tgt_value);\n \twarning(\"%s\", buf.buf);\n \n \tstrbuf_release(&buf);\n@@ -184,7 +185,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst)\n \n \tdst->initialized = 1;\n \n-\ttgt_value = getenv(dst->env_var_name);\n+\ttgt_value = tr2_sysenv_get(dst->sysenv_var);\n \n \tif (!tgt_value || !strcmp(tgt_value, \"\") || !strcmp(tgt_value, \"0\") ||\n \t    !strcasecmp(tgt_value, \"false\")) {\n@@ -246,7 +247,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)\n \t\treturn;\n \n \tif (tr2_dst_want_warning())\n-\t\twarning(\"unable to write trace to '%s': %s\", dst->env_var_name,\n+\t\twarning(\"unable to write trace to '%s': %s\",\n+\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n \t\t\tstrerror(errno));\n \ttr2_dst_trace_disable(dst);\n }\ndiff --git a/trace2/tr2_dst.h b/trace2/tr2_dst.h\nindex 9a64f05b02..3adf3bac13 100644\n--- a/trace2/tr2_dst.h\n+++ b/trace2/tr2_dst.h\n@@ -2,9 +2,10 @@\n #define TR2_DST_H\n \n struct strbuf;\n+#include \"trace2/tr2_sysenv.h\"\n \n struct tr2_dst {\n-\tconst char *const env_var_name;\n+\tenum tr2_sysenv_variable sysenv_var;\n \tint fd;\n \tunsigned int initialized : 1;\n \tunsigned int need_close : 1;\ndiff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\nnew file mode 100644\nindex 0000000000..9025b86303\n--- /dev/null\n+++ b/trace2/tr2_sysenv.c\n@@ -0,0 +1,127 @@\n+#include \"cache.h\"\n+#include \"config.h\"\n+#include \"dir.h\"\n+#include \"tr2_sysenv.h\"\n+\n+/*\n+ * Each entry represents a trace2 setting.\n+ * See Documentation/technical/api-trace2.txt\n+ */\n+struct tr2_sysenv_entry {\n+\tconst char *env_var_name;\n+\tconst char *git_config_name;\n+\n+\tchar *value;\n+\tunsigned int getenv_called : 1;\n+};\n+\n+/*\n+ * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n+ *\n+ * The strings in this table are constant and must match the published\n+ * config and environment variable names as described in the documentation.\n+ *\n+ * We do not define entries for the GIT_TR2_PARENT_* environment\n+ * variables because they are transient and used to pass information\n+ * from parent to child git processes, rather than settings.\n+ */\n+/* clang-format off */\n+static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n+\t[TR2_SYSENV_CFG_PARAM]     = { \"GIT_TR2_CONFIG_PARAMS\",\n+\t\t\t\t       \"trace2.configparams\" },\n+\n+\t[TR2_SYSENV_DST_DEBUG]     = { \"GIT_TR2_DST_DEBUG\",\n+\t\t\t\t       \"trace2.destinationdebug\" },\n+\n+\t[TR2_SYSENV_NORMAL]        = { \"GIT_TR2\",\n+\t\t\t\t       \"trace2.normaltarget\" },\n+\t[TR2_SYSENV_NORMAL_BRIEF]  = { \"GIT_TR2_BRIEF\",\n+\t\t\t\t       \"trace2.normalbrief\" },\n+\n+\t[TR2_SYSENV_EVENT]         = { \"GIT_TR2_EVENT\",\n+\t\t\t\t       \"trace2.eventtarget\" },\n+\t[TR2_SYSENV_EVENT_BRIEF]   = { \"GIT_TR2_EVENT_BRIEF\",\n+\t\t\t\t       \"trace2.eventbrief\" },\n+\t[TR2_SYSENV_EVENT_NESTING] = { \"GIT_TR2_EVENT_NESTING\",\n+\t\t\t\t       \"trace2.eventnesting\" },\n+\n+\t[TR2_SYSENV_PERF]          = { \"GIT_TR2_PERF\",\n+\t\t\t\t       \"trace2.perftarget\" },\n+\t[TR2_SYSENV_PERF_BRIEF]    = { \"GIT_TR2_PERF_BRIEF\",\n+\t\t\t\t       \"trace2.perfbrief\" },\n+};\n+/* clang-format on */\n+\n+static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n+{\n+\tint k;\n+\n+\tif (!starts_with(key, \"trace2.\"))\n+\t\treturn 0;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n+\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n+\t\t\tfree(tr2_sysenv_settings[k].value);\n+\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n+ * unless we were built with a runtime-prefix).  These are intended to\n+ * define the default values for Trace2 as requested by the administrator.\n+ *\n+ * Then override with the Trace2 settings from the global config.\n+ */\n+void tr2_sysenv_load(void)\n+{\n+\tif (ARRAY_SIZE(tr2_sysenv_settings) != TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_settings size is wrong\");\n+\n+\tread_very_early_config(tr2_sysenv_cb, NULL);\n+}\n+\n+/*\n+ * Return the value for the requested Trace2 setting from these sources:\n+ * the system config, the global config, and the environment.\n+ */\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\tif (!tr2_sysenv_settings[var].getenv_called) {\n+\t\tconst char *v = getenv(tr2_sysenv_settings[var].env_var_name);\n+\t\tif (v && *v) {\n+\t\t\tfree(tr2_sysenv_settings[var].value);\n+\t\t\ttr2_sysenv_settings[var].value = xstrdup(v);\n+\t\t}\n+\t\ttr2_sysenv_settings[var].getenv_called = 1;\n+\t}\n+\n+\treturn tr2_sysenv_settings[var].value;\n+}\n+\n+/*\n+ * Return a friendly name for this setting that is suitable for printing\n+ * in an error messages.\n+ */\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\treturn tr2_sysenv_settings[var].env_var_name;\n+}\n+\n+void tr2_sysenv_release(void)\n+{\n+\tint k;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++)\n+\t\tfree(tr2_sysenv_settings[k].value);\n+}\ndiff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h\nnew file mode 100644\nindex 0000000000..369b20bd87\n--- /dev/null\n+++ b/trace2/tr2_sysenv.h\n@@ -0,0 +1,36 @@\n+#ifndef TR2_SYSENV_H\n+#define TR2_SYSENV_H\n+\n+/*\n+ * The Trace2 settings that can be loaded from /etc/gitconfig\n+ * and/or user environment variables.\n+ *\n+ * Note that this set does not contain any of the transient\n+ * environment variables used to pass information from parent\n+ * to child git processes, such \"GIT_TR2_PARENT_SID\".\n+ */\n+enum tr2_sysenv_variable {\n+\tTR2_SYSENV_CFG_PARAM = 0,\n+\n+\tTR2_SYSENV_DST_DEBUG,\n+\n+\tTR2_SYSENV_NORMAL,\n+\tTR2_SYSENV_NORMAL_BRIEF,\n+\n+\tTR2_SYSENV_EVENT,\n+\tTR2_SYSENV_EVENT_BRIEF,\n+\tTR2_SYSENV_EVENT_NESTING,\n+\n+\tTR2_SYSENV_PERF,\n+\tTR2_SYSENV_PERF_BRIEF,\n+\n+\tTR2_SYSENV_MUST_BE_LAST\n+};\n+\n+void tr2_sysenv_load(void);\n+\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable);\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);\n+void tr2_sysenv_release(void);\n+\n+#endif /* TR2_SYSENV_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 89a4d3ae9a..48d9193b2c 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -6,10 +6,11 @@\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };\n \n /*\n  * The version number of the JSON data generated by the EVENT target\n@@ -28,37 +29,36 @@ static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n  * are primarily intended for the performance target during debugging.\n  *\n  * Some of the outer-most messages, however, may be of interest to the\n- * event target.  Set this environment variable to a larger integer for\n- * more detail in the event target.\n+ * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase\n+ * region details in the event target.\n  */\n-#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n-static int tr2env_event_nesting_wanted = 2;\n+static int tr2env_event_max_nesting_levels = 2;\n \n /*\n- * Set this environment variable to true to omit the <time>, <file>, and\n+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and\n  * <line> fields from most events.\n  */\n-#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n-static int tr2env_event_brief;\n+static int tr2env_event_be_brief;\n \n static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_event);\n-\tint want_nesting;\n+\tint max_nesting;\n \tint want_brief;\n-\tchar *nesting;\n-\tchar *brief;\n+\tconst char *nesting;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n-\tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n-\t\ttr2env_event_nesting_wanted = want_nesting;\n+\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n+\tif (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))\n+\t\ttr2env_event_max_nesting_levels = max_nesting;\n \n-\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n-\tif (brief && ((want_brief = atoi(brief)) > 0))\n-\t\ttr2env_event_brief = want_brief;\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n+\tif (brief && *brief &&\n+\t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n+\t\ttr2env_event_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -92,13 +92,13 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t/*\n \t * In brief mode, only emit <time> on these 2 event types.\n \t */\n-\tif (!tr2env_event_brief || !strcmp(event_name, \"version\") ||\n+\tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n \t\ttr2_tbuf_utc_time(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-\tif (!tr2env_event_brief && file && *file) {\n+\tif (!tr2env_event_be_brief && file && *file) {\n \t\tjw_object_string(jw, \"file\", file);\n \t\tjw_object_intmax(jw, \"line\", line);\n \t}\n@@ -459,7 +459,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line,\n {\n \tconst char *event_name = \"region_enter\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \n \t\tjw_object_begin(&jw, 0);\n@@ -484,7 +484,7 @@ static void fn_region_leave_printf_va_fl(\n {\n \tconst char *event_name = \"region_leave\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n \n@@ -511,7 +511,7 @@ static void fn_data_fl(const char *file, int line, uint64_t us_elapsed_absolute,\n {\n \tconst char *event_name = \"data\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n@@ -539,7 +539,7 @@ static void fn_data_json_fl(const char *file, int line,\n {\n \tconst char *event_name = \"data_json\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 57f3e18f5b..1ce6f97863 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -4,20 +4,20 @@\n #include \"quote.h\"\n #include \"version.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_normal = { \"GIT_TR2\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin normal target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n-static int tr2env_normal_brief;\n+static int tr2env_normal_be_brief;\n \n #define TR2FMT_NORMAL_FL_WIDTH (50)\n \n@@ -25,15 +25,15 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_normal);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_normal_brief = want_brief;\n+\t\ttr2env_normal_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf)\n {\n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_normal_brief) {\n+\tif (!tr2env_normal_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex 9c3b4d8a0f..328d2234bd 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -6,20 +6,20 @@\n #include \"json-writer.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_perf = { \"GIT_TR2_PERF\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use TR2_SYSENV_PERF_BRIEF to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin performance target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n-static int tr2env_perf_brief;\n+static int tr2env_perf_be_brief;\n \n #define TR2FMT_PERF_FL_WIDTH (50)\n #define TR2FMT_PERF_MAX_EVENT_NAME (12)\n@@ -36,17 +36,17 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_perf);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n \tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n \n-\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_perf_brief = want_brief;\n+\t\ttr2env_perf_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,\n \n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_perf_brief) {\n+\tif (!tr2env_perf_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\n-- \ngitgitgadget\n\n"},{"id":"373902","messageId":"3414016d04fc1c457ba865822af561325ba0c753.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 10/10] trace2: update docs to describe system/global config settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:50Z","receivedAt":"2019-04-15T20:39:56Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/config.txt               |   2 +\n Documentation/config/trace2.txt        |  56 +++++++++\n Documentation/technical/api-trace2.txt | 151 ++++++++++++++-----------\n Documentation/trace2-target-values.txt |  10 ++\n 4 files changed, 152 insertions(+), 67 deletions(-)\n create mode 100644 Documentation/config/trace2.txt\n create mode 100644 Documentation/trace2-target-values.txt\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d87846faa6..7e2a6f61f5 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -422,6 +422,8 @@ include::config/submodule.txt[]\n \n include::config/tag.txt[]\n \n+include::config/trace2.txt[]\n+\n include::config/transfer.txt[]\n \n include::config/uploadarchive.txt[]\ndiff --git a/Documentation/config/trace2.txt b/Documentation/config/trace2.txt\nnew file mode 100644\nindex 0000000000..a5f409c1c1\n--- /dev/null\n+++ b/Documentation/config/trace2.txt\n@@ -0,0 +1,56 @@\n+Trace2 config settings are only read from the system and global\n+config files; repository local and worktree config files and `-c`\n+command line arguments are not respected.\n+\n+trace2.normalTarget::\n+\tThis variable controls the normal target destination.\n+\tIt may be overridden by the `GIT_TR2` environment variable.\n+\tThe following table shows possible values.\n+\n+trace2.perfTarget::\n+\tThis variable controls the performance target destination.\n+\tIt may be overridden by the `GIT_TR2_PERF` environment variable.\n+\tThe following table shows possible values.\n+\n+trace2.eventTarget::\n+\tThis variable controls the event target destination.\n+\tIt may be overridden by the `GIT_TR2_EVENT` environment variable.\n+\tThe following table shows possible values.\n++\n+include::../trace2-target-values.txt[]\n+\n+trace2.normalBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from normal output.  May be overridden by the\n+\t`GIT_TR2_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.perfBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from PERF output.  May be overridden by the\n+\t`GIT_TR2_PERF_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.eventBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from event output.  May be overridden by the\n+\t`GIT_TR2_EVENT_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.eventNesting::\n+\tInteger.  Specifies desired depth of nested regions in the\n+\tevent output.  Regions deeper than this value will be\n+\tomitted.  May be overridden by the `GIT_TR2_EVENT_NESTING`\n+\tenvironment variable.  Defaults to 2.\n+\n+trace2.configParams::\n+\tA comma-separated list of patterns of \"important\" config\n+\tsettings that should be recorded in the trace2 output.\n+\tFor example, `core.*,remote.*.url` would cause the trace2\n+\toutput to contain events listing each configured remote.\n+\tMay be overridden by the `GIT_TR2_CONFIG_PARAMS` environment\n+\tvariable.  Unset by default.\n+\n+trace2.destinationDebug::\n+\tBoolean.  When true Git will print error messages when a\n+\ttrace target destination cannot be opened for writing.\n+\tBy default, these errors are suppressed and tracing is\n+\tsilently disabled.  May be overridden by the\n+\t`GIT_TR2_DST_DEBUG` environment variable.\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 43adbf00eb..8b6a5e6d4b 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -22,21 +22,41 @@ Targets are defined using a VTable allowing easy extension to other\n formats in the future.  This might be used to define a binary format,\n for example.\n \n+Trace2 is controlled using `trace2.*` config values in the system and\n+global config files and `GIT_TR2*` environment variables.  Trace2 does\n+not read from repo local or worktree config files or respect `-c`\n+command line config settings.\n+\n == Trace2 Targets\n \n Trace2 defines the following set of Trace2 Targets.\n Format details are given in a later section.\n \n-`GIT_TR2` (NORMAL)::\n+=== The Normal Format Target\n+\n+The normal format target is a tradition printf format and similar\n+to GIT_TRACE format.  This format is enabled with the `GIT_TR`\n+environment variable or the `trace2.normalTarget` system or global\n+config setting.\n+\n+For example\n \n-\ta simple printf format like GIT_TRACE.\n-+\n ------------\n $ export GIT_TR2=~/log.normal\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.normalTarget ~/log.normal\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.normal\n 12:28:42.620009 common-main.c:38                  version 2.20.1.155.g426c96fcdb\n@@ -46,17 +66,32 @@ $ cat ~/log.normal\n 12:28:42.621250 trace2/tr2_tgt_normal.c:124       atexit elapsed:0.001265 code:0\n ------------\n \n-`GIT_TR2_PERF` (PERF)::\n+=== The Performance Format Target\n+\n+The performance format target (PERF) is a column-based format to\n+replace GIT_TRACE_PERFORMANCE and is suitable for development and\n+testing, possibly to complement tools like gprof.  This format is\n+enabled with the `GIT_TR2_PERF` environment variable or the\n+`trace2.perfTarget` system or global config setting.\n+\n+For example\n \n-\ta column-based format to replace GIT_TRACE_PERFORMANCE suitable for\n-\tdevelopment and testing, possibly to complement tools like gprof.\n-+\n ------------\n $ export GIT_TR2_PERF=~/log.perf\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.perfTarget ~/log.perf\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n@@ -66,56 +101,46 @@ $ cat ~/log.perf\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n ------------\n \n-`GIT_TR2_EVENT` (EVENT)::\n+=== The Event Format Target\n+\n+The event format target is a JSON-based format of event data suitable\n+for telemetry analysis.  This format is enabled with the `GIT_TR2_EVENT`\n+environment variable or the `trace2.eventTarget` system or global config\n+setting.\n+\n+For example\n \n-\ta JSON-based format of event data suitable for telemetry analysis.\n-+\n ------------\n $ export GIT_TR2_EVENT=~/log.event\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n-------------\n-$ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n-------------\n-\n-== Enabling a Target\n-\n-A Trace2 Target is enabled when the corresponding environment variable\n-(`GIT_TR2`, `GIT_TR2_PERF`, or `GIT_TR2_EVENT`) is set.  The following\n-values are recognized.\n-\n-`0`::\n-`false`::\n-\n-\tDisables the target.\n \n-`1`::\n-`true`::\n+or\n \n-\tEnables the target and writes stream to `STDERR`.\n-\n-`[2-9]`::\n+------------\n+$ git config --global trace2.eventTarget ~/log.event\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n \n-\tEnables the target and writes to the already opened file descriptor.\n+yields\n \n-`<absolute-pathname>`::\n+------------\n+$ cat ~/log.event\n+{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+------------\n \n-\tEnables the target, opens and writes to the file in append mode.\n+=== Enabling a Target\n \n-`af_unix:[<socket_type>:]<absolute-pathname>`::\n+To enable a target, set the corresponding environment variable or\n+system or global config value to one of the following:\n \n-\tEnables the target, opens and writes to a Unix Domain Socket\n-\t(on platforms that support them).\n-+\n-Socket type can be either `stream` or `dgram`.  If the socket type is\n-omitted, Git will try both.\n+include::../trace2-target-values.txt[]\n \n == Trace2 API\n \n@@ -243,15 +268,16 @@ significantly affects program performance or behavior, such as\n \tEmits a \"def_param\" messages for \"important\" configuration\n \tsettings.\n +\n-The environment variable `GIT_TR2_CONFIG_PARAMS` can be set to a\n+The environment variable `GIT_TR2_CONFIG_PARAMS` or the `trace2.configParams`\n+config value can be set to a\n list of patterns of important configuration settings, for example:\n `core.*,remote.*.url`.  This function will iterate over all config\n settings and emit a \"def_param\" message for each match.\n \n `void trace2_cmd_set_config(const char *key, const char *value)`::\n \n-\tEmits a \"def_param\" message for a specific configuration\n-\tsetting IFF it matches the `GIT_TR2_CONFIG_PARAMS` pattern.\n+\tEmits a \"def_param\" message for a new or updated key/value\n+\tpair IF `key` is considered important.\n +\n This is used to hook into `git_config_set()` and catch any\n configuration changes and update a value previously reported by\n@@ -418,9 +444,6 @@ recursive tree walk.\n \n === NORMAL Format\n \n-NORMAL format is enabled when the `GIT_TR2` environment variable is\n-set.\n-\n Events are written as lines of the form:\n \n ------------\n@@ -437,8 +460,8 @@ Events are written as lines of the form:\n Note that this may contain embedded LF or CRLF characters that are\n not escaped, so the event may spill across multiple lines.\n \n-If `GIT_TR2_BRIEF` is true, the `time`, `filename`, and `line` fields\n-are omitted.\n+If `GIT_TR2_BRIEF` or `trace2.normalBrief` is true, the `time`, `filename`,\n+and `line` fields are omitted.\n \n This target is intended to be more of a summary (like GIT_TRACE) and\n less detailed than the other targets.  It ignores thread, region, and\n@@ -446,9 +469,6 @@ data messages, for example.\n \n === PERF Format\n \n-PERF format is enabled when the `GIT_TR2_PERF` environment variable\n-is set.\n-\n Events are written as lines of the form:\n \n ------------\n@@ -508,8 +528,8 @@ This field is in anticipation of in-proc submodules in the future.\n 15:33:33.532712 wt-status.c:2331                  | d0 | main                     | region_leave | r1  |  0.127568 |  0.001504 | status     | label:print\n ------------\n \n-If `GIT_TR2_PERF_BRIEF` is true, the `time`, `file`, and `line`\n-fields are omitted.\n+If `GIT_TR2_PERF_BRIEF` or `trace2.perfBrief` is true, the `time`, `file`,\n+and `line` fields are omitted.\n \n ------------\n d0 | main                     | region_leave | r1  |  0.011717 |  0.009122 | index      | label:preload\n@@ -520,9 +540,6 @@ during development and is quite noisy.\n \n === EVENT Format\n \n-EVENT format is enabled when the `GIT_TR2_EVENT` environment\n-variable is set.\n-\n Each event is a JSON-object containing multiple key/value pairs\n written as a single line and followed by a LF.\n \n@@ -540,7 +557,7 @@ The following key/value pairs are common to all events:\n ------------\n {\n \t\"event\":\"version\",\n-\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n+\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P00003510\",\n \t\"thread\":\"main\",\n \t\"time\":\"2019-04-08T19:18:27.282761Z\",\n \t\"file\":\"common-main.c\",\n@@ -576,9 +593,9 @@ The following key/value pairs are common to all events:\n `\"repo\":<repo-id>`::\n \twhen present, is the integer repo-id as described previously.\n \n-If `GIT_TR2_EVENT_BRIEF` is true, the `file` and `line` fields are omitted\n-from all events and the `time` field is only present on the \"start\" and\n-\"atexit\" events.\n+If `GIT_TR2_EVENT_BRIEF` or `trace2.eventBrief` is true, the `file`\n+and `line` fields are omitted from all events and the `time` field is\n+only present on the \"start\" and \"atexit\" events.\n \n ==== Event-Specific Key/Value Pairs\n \n@@ -889,7 +906,7 @@ visited.\n The `category` field may be used in a future enhancement to\n do category-based filtering.\n +\n-The `GIT_TR2_EVENT_NESTING` environment variable can be used to\n+`GIT_TR2_EVENT_NESTING` or `trace2.eventNesting` can be used to\n filter deeply nested regions and data events.  It defaults to \"2\".\n \n `\"region_leave\"`::\ndiff --git a/Documentation/trace2-target-values.txt b/Documentation/trace2-target-values.txt\nnew file mode 100644\nindex 0000000000..27d3c64e66\n--- /dev/null\n+++ b/Documentation/trace2-target-values.txt\n@@ -0,0 +1,10 @@\n+--\n+* `0` or `false` - Disables the target.\n+* `1` or `true` - Writes to `STDERR`.\n+* `[2-9]` - Writes to the already opened file descriptor.\n+* `<absolute-pathname>` - Writes to the file in append mode.\n+* `af_unix:[<socket_type>:]<absolute-pathname>` - Write to a\n+Unix DomainSocket (on platforms that support them).  Socket\n+type can be either `stream` or `dgram`; if omitted Git will\n+try both.\n+--\n-- \ngitgitgadget\n"},{"id":"373903","messageId":"94729b284c4338aa40d4287eea909e835820ff4b.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 04/10] trace2: find exec-dir before trace2 initialization","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:45Z","receivedAt":"2019-04-15T20:39:57Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Git to resolve the executable directory before initializing\nTrace2.  This allows the system configuration directory to be\ndiscovered earlier (because it is sometimes relative to the prefix\nor runtime-prefix).\n\nThis will be used by the next commit to allow trace2 settings to\nbe loaded from the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 6137af0e63..299ca62a72 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -37,12 +37,12 @@ int main(int argc, const char **argv)\n \tsanitize_stdfds();\n \trestore_sigpipe_to_default();\n \n+\tgit_resolve_executable_dir(argv[0]);\n+\n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n \ttrace2_collect_process_info();\n \n-\tgit_resolve_executable_dir(argv[0]);\n-\n \tgit_setup_gettext();\n \n \tinitialize_the_repository();\n-- \ngitgitgadget\n\n"},{"id":"373904","messageId":"9fdcb50140571f888712366f9187a23342d56ac7.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 09/10] trace2: make SIDs more unique","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:49Z","receivedAt":"2019-04-15T20:39:58Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate SID component construction to use the current UTC datetime\nand a portion of the SHA1 of the hostname.\n\nUse an simplified date/time format to make it easier to use the\nSID component as a logfile filename.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 16 ++++----\n trace2/tr2_sid.c                       | 53 ++++++++++++++++++++++++--\n trace2/tr2_tbuf.c                      | 15 ++++++++\n trace2/tr2_tbuf.h                      |  1 +\n 4 files changed, 73 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex cdc00bcc5d..43adbf00eb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -540,11 +540,11 @@ The following key/value pairs are common to all events:\n ------------\n {\n \t\"event\":\"version\",\n-\t\"sid\":\"1547659722619736-11614\",\n+\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n+\t\"time\":\"2019-04-08T19:18:27.282761Z\",\n \t\"file\":\"common-main.c\",\n-\t\"line\":38,\n+\t\"line\":42,\n \t...\n }\n ------------\ndiff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c\nindex 984524a43c..5047095478 100644\n--- a/trace2/tr2_sid.c\n+++ b/trace2/tr2_sid.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n \n #define TR2_ENVVAR_PARENT_SID \"GIT_TR2_PARENT_SID\"\n@@ -6,6 +7,53 @@\n static struct strbuf tr2sid_buf = STRBUF_INIT;\n static int tr2sid_nr_git_parents;\n \n+/*\n+ * Compute the final component of the SID representing the current process.\n+ * This should uniquely identify the process and be a valid filename (to\n+ * allow writing trace2 data to per-process files).  It should also be fixed\n+ * length for possible use as a database key.\n+ *\n+ * \"<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>\"\n+ *\n+ * where <host> is a 9 character string:\n+ *    \"H<first_8_chars_of_sha1_of_hostname>\"\n+ *    \"Localhost\" when no hostname.\n+ *\n+ * where <process> is a 9 character string containing the least signifcant\n+ * 32 bits in the process-id.\n+ *    \"P<pid>\"\n+ * (This is an abribrary choice.  On most systems pid_t is a 32 bit value,\n+ * so limit doesn't matter.  On larger systems, a truncated value is fine\n+ * for our purposes here.)\n+ */\n+static void tr2_sid_append_my_sid_component(void)\n+{\n+\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n+\tstruct tr2_tbuf tb_now;\n+\tgit_hash_ctx ctx;\n+\tpid_t pid = getpid();\n+\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n+\tchar hex[GIT_MAX_HEXSZ + 1];\n+\tchar hostname[HOST_NAME_MAX + 1];\n+\n+\ttr2_tbuf_utc_datetime(&tb_now);\n+\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n+\n+\tstrbuf_addch(&tr2sid_buf, '-');\n+\tif (xgethostname(hostname, sizeof(hostname)))\n+\t\tstrbuf_add(&tr2sid_buf, \"Localhost\", 9);\n+\telse {\n+\t\talgo->init_fn(&ctx);\n+\t\talgo->update_fn(&ctx, hostname, strlen(hostname));\n+\t\talgo->final_fn(hash, &ctx);\n+\t\thash_to_hex_algop_r(hex, hash, algo);\n+\t\tstrbuf_addch(&tr2sid_buf, 'H');\n+\t\tstrbuf_add(&tr2sid_buf, hex, 8);\n+\t}\n+\n+\tstrbuf_addf(&tr2sid_buf, \"-P%08\"PRIx32, (uint32_t)pid);\n+}\n+\n /*\n  * Compute a \"unique\" session id (SID) for the current process.  This allows\n  * all events from this process to have a single label (much like a PID).\n@@ -20,7 +68,6 @@ static int tr2sid_nr_git_parents;\n  */\n static void tr2_sid_compute(void)\n {\n-\tuint64_t us_now;\n \tconst char *parent_sid;\n \n \tif (tr2sid_buf.len)\n@@ -38,9 +85,7 @@ static void tr2_sid_compute(void)\n \t\ttr2sid_nr_git_parents++;\n \t}\n \n-\tus_now = getnanotime() / 1000;\n-\tstrbuf_addf(&tr2sid_buf, \"%\" PRIuMAX \"-%\" PRIdMAX, (uintmax_t)us_now,\n-\t\t    (intmax_t)getpid());\n+\ttr2_sid_append_my_sid_component();\n \n \tsetenv(TR2_ENVVAR_PARENT_SID, tr2sid_buf.buf, 1);\n }\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex eb1b240d8a..2498482d9a 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -30,3 +30,18 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\n+\n+void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)\n+{\n+\tstruct timeval tv;\n+\tstruct tm tm;\n+\ttime_t secs;\n+\n+\tgettimeofday(&tv, NULL);\n+\tsecs = tv.tv_sec;\n+\tgmtime_r(&secs, &tm);\n+\n+\txsnprintf(tb->buf, sizeof(tb->buf), \"%4d%02d%02dT%02d%02d%02d.%06ldZ\",\n+\t\t  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,\n+\t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n+}\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 2a1d173ff2..fa853d8f42 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n  * Fill buffer with formatted UTC datatime string.\n  */\n void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\n-- \ngitgitgadget\n\n"},{"id":"373905","messageId":"196a9d2c852c110f951ccd19fc05741399ec59c1.1555360780.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v4 08/10] trace2: clarify UTC datetime formatting","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-15T20:39:48Z","receivedAt":"2019-04-15T20:40:00Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate tr2_tbuf_utc_datetime to generate extended UTC format.\nUpdate tr2_tgt_event target to use extended format in 'time' columns.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++------\n trace2/tr2_tbuf.c                      |  4 ++--\n trace2/tr2_tbuf.h                      |  4 ++--\n trace2/tr2_tgt_event.c                 |  2 +-\n 4 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex baaa1153bb..cdc00bcc5d 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -542,7 +542,7 @@ The following key/value pairs are common to all events:\n \t\"event\":\"version\",\n \t\"sid\":\"1547659722619736-11614\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16 17:28:42.620713\",\n+\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n \t\"file\":\"common-main.c\",\n \t\"line\":38,\n \t...\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex 0844910423..eb1b240d8a 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb)\n \t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n }\n \n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n {\n \tstruct timeval tv;\n \tstruct tm tm;\n@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n \tgmtime_r(&secs, &tm);\n \n \txsnprintf(tb->buf, sizeof(tb->buf),\n-\t\t  \"%4d-%02d-%02d %02d:%02d:%02d.%06ld\", tm.tm_year + 1900,\n+\t\t  \"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ\", tm.tm_year + 1900,\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 9cdefa3957..2a1d173ff2 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -16,8 +16,8 @@ struct tr2_tbuf {\n void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n \n /*\n- * Fill buffer with formatted UTC time string.\n+ * Fill buffer with formatted UTC datatime string.\n  */\n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 48d9193b2c..2c97cf54be 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t */\n \tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n-\t\ttr2_tbuf_utc_time(&tb_now);\n+\t\ttr2_tbuf_utc_datetime_extended(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"374601","messageId":"20190427134316.GE8695@szeder.dev","threadId":"50834","inReplyTo":"550cad618923c6e5aa1bd5f901f2968791d7566b.1555360780.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 06/10] trace2: use system/global config for default trace2 settings","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-27T13:43:16Z","receivedAt":"2019-04-27T13:43:22Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, Apr 15, 2019 at 01:39:47PM -0700, Jeff Hostetler via GitGitGadget wrote:\n> From: Jeff Hostetler <jeffhost@microsoft.com>\n> \n> Teach git to read the system and global config files for\n> default Trace2 settings.  This allows system-wide Trace2 settings to\n> be installed and inherited to make it easier to manage a collection of\n> systems.\n> \n> The original GIT_TR2* environment variables are loaded afterwards and\n> can be used to override the system settings.\n> \n> Only the system and global config files are used.  Repo and worktree\n> local config files are ignored.  Likewise, the \"-c\" command line\n> arguments are also ignored.  These limits are for performance reasons.\n> \n> (1) For users not using Trace2, there should be minimal overhead to\n> detect that Trace2 is not enabled.  In particular, Trace2 should not\n> allocate lots of otherwise unused data strucutres.\n> \n> (2) For accurate performance measurements, Trace2 should be initialized\n> as early in the git process as possible, and before most of the normal\n> git process initialization (which involves discovering the .git directory\n> and reading a hierarchy of config files).\n\nReading the configuration that early causes unexpected and undesired\nbehavior change:\n\n  $ sudo chmod a-rwx /usr/local/etc/gitconfig\n  $ ./BUILDS/v2.21.0/bin/git\n  usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]\n  <... snip rest of usage ...>\n  $ strace ./BUILDS/v2.21.0/bin/git 2>&1 |grep config -c\n  0\n  $ ./git\n  fatal: unable to access '/usr/local/etc/gitconfig': Permission denied\n  $ ./git --version\n  fatal: unable to access '/usr/local/etc/gitconfig': Permission denied\n\nI think at least 'git', 'git --help', and 'git --version' should Just\nWork, no matter what.\n\n\nThis breaks the 32 bit Linux build job on Travis CI, because:\n\n  - In the 32 bit Docker image we change UID from root to regular user\n    while preserving the environment, including $HOME.\n    \n  - Since $HOME is the default build prefix, Git will look for the\n    system-wide configuration under '/root/etc/gitconfig', which fails\n    as a regular user.\n\n  - Our test harness checks early (i.e. earlier than setting\n    GIT_CONFIG_NOSYSTEM=1) whether Git has been built successfully by\n    attempting to run '$GIT_BUILD_DIR}/git', which fails because of\n    the inaccessible system-wide config file, and in turn the harness\n    assumes that Git hasn't been built and aborts.\n\n  https://travis-ci.org/git/git/jobs/524403682#L1258\n\n"},{"id":"374650","messageId":"465993c8-0eb2-d9fa-5d22-b8b584b3de15@jeffhostetler.com","threadId":"50834","inReplyTo":"20190427134316.GE8695@szeder.dev","subject":"Re: [PATCH v4 06/10] trace2: use system/global config for default trace2 settings","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-29T19:03:19Z","receivedAt":"2019-04-29T19:03:23Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 4/27/2019 9:43 AM, SZEDER Gábor wrote:\n> On Mon, Apr 15, 2019 at 01:39:47PM -0700, Jeff Hostetler via GitGitGadget wrote:\n>> From: Jeff Hostetler <jeffhost@microsoft.com>\n>>\n>> Teach git to read the system and global config files for\n>> default Trace2 settings.  This allows system-wide Trace2 settings to\n>> be installed and inherited to make it easier to manage a collection of\n>> systems.\n>>\n>> The original GIT_TR2* environment variables are loaded afterwards and\n>> can be used to override the system settings.\n>>\n>> Only the system and global config files are used.  Repo and worktree\n>> local config files are ignored.  Likewise, the \"-c\" command line\n>> arguments are also ignored.  These limits are for performance reasons.\n>>\n>> (1) For users not using Trace2, there should be minimal overhead to\n>> detect that Trace2 is not enabled.  In particular, Trace2 should not\n>> allocate lots of otherwise unused data strucutres.\n>>\n>> (2) For accurate performance measurements, Trace2 should be initialized\n>> as early in the git process as possible, and before most of the normal\n>> git process initialization (which involves discovering the .git directory\n>> and reading a hierarchy of config files).\n> \n> Reading the configuration that early causes unexpected and undesired\n> behavior change:\n> \n>    $ sudo chmod a-rwx /usr/local/etc/gitconfig\n>    $ ./BUILDS/v2.21.0/bin/git\n>    usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]\n>    <... snip rest of usage ...>\n>    $ strace ./BUILDS/v2.21.0/bin/git 2>&1 |grep config -c\n>    0\n>    $ ./git\n>    fatal: unable to access '/usr/local/etc/gitconfig': Permission denied\n>    $ ./git --version\n>    fatal: unable to access '/usr/local/etc/gitconfig': Permission denied\n> \n> I think at least 'git', 'git --help', and 'git --version' should Just\n> Work, no matter what.\n> \n> \n> This breaks the 32 bit Linux build job on Travis CI, because:\n> \n>    - In the 32 bit Docker image we change UID from root to regular user\n>      while preserving the environment, including $HOME.\n>      \n>    - Since $HOME is the default build prefix, Git will look for the\n>      system-wide configuration under '/root/etc/gitconfig', which fails\n>      as a regular user.\n> \n>    - Our test harness checks early (i.e. earlier than setting\n>      GIT_CONFIG_NOSYSTEM=1) whether Git has been built successfully by\n>      attempting to run '$GIT_BUILD_DIR}/git', which fails because of\n>      the inaccessible system-wide config file, and in turn the harness\n>      assumes that Git hasn't been built and aborts.\n> \n>    https://travis-ci.org/git/git/jobs/524403682#L1258\n> \n\nIt appears that config.c:do_git_config_sequence() passes flags = 0\nto access_or_die() rather than ACCESS_EACCES_OK as it does for the\nother scopes.  This causes the fatal error, rather than ignoring the\nproblem.\n\nReasons for this were discussed in:\n     4698c8feb1 config: allow inaccessible configuration under $HOME\n\nI'll push a fix shortly.\n\nThanks\nJeff\n"},{"id":"374652","messageId":"f6653f1c5914d4ed0edee87a56277a35625135ca.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 01/11] config: initialize opts structure in repo_read_config()","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:14Z","receivedAt":"2019-04-29T20:14:18Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nInitialize opts structure in repo_read_config().\n\nThis change fixes a crash in later commit after a new field is added\nto the structure.\n\nIn commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config()\nwas added.  It only initializes 3 fields in the opts structure.  It is\npassed to config_with_options() and then to do_git_config_sequence().\nHowever, do_git_config_sequence() drops the opts on the floor and calls\ngit_config_from_file() rather than git_config_from_file_with_options(),\nso that may be why this hasn't been a problem in the past.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/config.c b/config.c\nindex 0f0cdd8c0f..c809f76219 100644\n--- a/config.c\n+++ b/config.c\n@@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha\n /* Functions use to read configuration from a repository */\n static void repo_read_config(struct repository *repo)\n {\n-\tstruct config_options opts;\n+\tstruct config_options opts = { 0 };\n \n \topts.respect_includes = 1;\n \topts.commondir = repo->commondir;\n-- \ngitgitgadget\n\n"},{"id":"374653","messageId":"pull.169.v5.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v4.git.gitgitgadget@gmail.com","subject":"[PATCH v5 00/11] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:13Z","receivedAt":"2019-04-29T20:14:18Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"Version 4 fixes a few clang-format warnings and simplifies the PID field in\nthe SID.\n\nJeff Hostetler (11):\n  config: initialize opts structure in repo_read_config()\n  trace2: refactor setting process starting time\n  trace2: add absolute elapsed time to start event\n  trace2: find exec-dir before trace2 initialization\n  config: add read_very_early_config()\n  trace2: use system/global config for default trace2 settings\n  trace2: report peak memory usage of the process\n  trace2: clarify UTC datetime formatting\n  trace2: make SIDs more unique\n  trace2: update docs to describe system/global config settings\n  trace2: fixup access problem on /etc/gitconfig in\n    read_very_early_config\n\n Documentation/config.txt                 |   2 +\n Documentation/config/trace2.txt          |  56 ++++++++\n Documentation/technical/api-trace2.txt   | 176 +++++++++++++----------\n Documentation/trace2-target-values.txt   |  10 ++\n Makefile                                 |   1 +\n common-main.c                            |   8 +-\n compat/mingw.c                           |   2 +\n compat/win32/trace2_win32_process_info.c |  50 ++++++-\n config.c                                 |  30 +++-\n config.h                                 |   5 +\n t/t0210-trace2-normal.sh                 |  49 ++++++-\n t/t0211-trace2-perf.sh                   |  43 ++++--\n t/t0212-trace2-event.sh                  |  42 +++++-\n trace2.c                                 |  21 ++-\n trace2.h                                 |  43 ++++--\n trace2/tr2_cfg.c                         |   7 +-\n trace2/tr2_dst.c                         |  26 ++--\n trace2/tr2_dst.h                         |   3 +-\n trace2/tr2_sid.c                         |  53 ++++++-\n trace2/tr2_sysenv.c                      | 127 ++++++++++++++++\n trace2/tr2_sysenv.h                      |  36 +++++\n trace2/tr2_tbuf.c                        |  19 ++-\n trace2/tr2_tbuf.h                        |   5 +-\n trace2/tr2_tgt.h                         |   1 +\n trace2/tr2_tgt_event.c                   |  53 +++----\n trace2/tr2_tgt_normal.c                  |  19 +--\n trace2/tr2_tgt_perf.c                    |  23 +--\n trace2/tr2_tls.c                         |  38 +++--\n trace2/tr2_tls.h                         |   8 +-\n 29 files changed, 752 insertions(+), 204 deletions(-)\n create mode 100644 Documentation/config/trace2.txt\n create mode 100644 Documentation/trace2-target-values.txt\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\n\nbase-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v5\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v5\nPull-Request: https://github.com/gitgitgadget/git/pull/169\n\nRange-diff vs v4:\n\n  1:  f6653f1c59 =  1:  f6653f1c59 config: initialize opts structure in repo_read_config()\n  2:  48e34834b6 =  2:  48e34834b6 trace2: refactor setting process starting time\n  3:  175371fb54 =  3:  175371fb54 trace2: add absolute elapsed time to start event\n  4:  94729b284c =  4:  94729b284c trace2: find exec-dir before trace2 initialization\n  5:  b0fe1385f1 =  5:  b0fe1385f1 config: add read_very_early_config()\n  6:  550cad6189 =  6:  550cad6189 trace2: use system/global config for default trace2 settings\n  7:  56d8ce3fd6 =  7:  56d8ce3fd6 trace2: report peak memory usage of the process\n  8:  196a9d2c85 =  8:  196a9d2c85 trace2: clarify UTC datetime formatting\n  9:  9fdcb50140 =  9:  9fdcb50140 trace2: make SIDs more unique\n 10:  3414016d04 = 10:  3414016d04 trace2: update docs to describe system/global config settings\n  -:  ---------- > 11:  18ce795360 trace2: fixup access problem on /etc/gitconfig in read_very_early_config\n\n-- \ngitgitgadget\n"},{"id":"374654","messageId":"175371fb54cbf41e5cf90d8d23ec5fde30036266.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 03/11] trace2: add absolute elapsed time to start event","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:15Z","receivedAt":"2019-04-29T20:14:21Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nAdd elapsed process time to \"start\" event to measure\nthe performance of early process startup.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 11 ++++++-----\n t/t0211-trace2-perf.sh                 | 12 ++++++------\n trace2.c                               |  8 +++++++-\n trace2/tr2_tgt.h                       |  1 +\n trace2/tr2_tgt_event.c                 |  5 ++++-\n trace2/tr2_tgt_normal.c                |  3 ++-\n trace2/tr2_tgt_perf.c                  |  7 ++++---\n 7 files changed, 30 insertions(+), 17 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex f37fccf1da..baaa1153bb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n-12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |           |           |            | git version\n+12:28:42.621001 common-main.c:39                  | d0 | main                     | start        |     |  0.001173 |           |            | git version\n 12:28:42.621111 git.c:432                         | d0 | main                     | cmd_name     |     |           |           |            | version (version)\n 12:28:42.621225 git.c:662                         | d0 | main                     | exit         |     |  0.001227 |           |            | code:0\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb\n ------------\n $ cat ~/log.event\n {\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n {\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n {\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n {\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the \"start\" and\n {\n \t\"event\":\"start\",\n \t...\n+\t\"t_abs\":0.001227, # elapsed time in seconds\n \t\"argv\":[\"git\",\"version\"]\n }\n ------------\n@@ -1118,7 +1119,7 @@ $ git status\n \n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.160.g5676107ecd.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1163,7 +1164,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.162.gb4ccea44db.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n ...\n@@ -1219,7 +1220,7 @@ $ git status\n ...\n $ cat ~/log.perf\n d0 | main                     | version      |     |           |           |            | 2.20.1.156.gf9916ae094.dirty\n-d0 | main                     | start        |     |           |           |            | git status\n+d0 | main                     | start        |     |  0.001173 |           |            | git status\n d0 | main                     | def_repo     | r1  |           |           |            | worktree:/Users/jeffhost/work/gfw\n d0 | main                     | cmd_name     |     |           |           |            | status (status)\n d0 | main                     | region_enter | r1  |  0.001791 |           | index      | label:do_read_index .git/index\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex 953e2f7847..c9694b29f7 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:0\n \t\td0|main|atexit||_T_ABS_|||code:0\n@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 001return 1\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 1\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|exit||_T_ABS_|||code:1\n \t\td0|main|atexit||_T_ABS_|||code:1\n@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 003error '\\''hello world'\\'' '\\''this is a test'\\''\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|error|||||hello world\n \t\td0|main|error|||||this is a test\n@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' '\n \tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n \tcat >expect <<-EOF &&\n \t\td0|main|version|||||$V\n-\t\td0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0\n \t\td0|main|cmd_name|||||trace2 (trace2)\n \t\td0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0\n \t\td1|main|version|||||$V\n-\t\td1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0\n+\t\td1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0\n \t\td1|main|cmd_name|||||trace2 (trace2/trace2)\n \t\td1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0\n \t\td2|main|version|||||$V\n-\t\td2|main|start|||||_EXE_ trace2 001return 0\n+\t\td2|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n \t\td2|main|cmd_name|||||trace2 (trace2/trace2/trace2)\n \t\td2|main|exit||_T_ABS_|||code:0\n \t\td2|main|atexit||_T_ABS_|||code:0\ndiff --git a/trace2.c b/trace2.c\nindex 6dd51e6aa5..1c180062dd 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv)\n {\n \tstruct tr2_tgt *tgt_j;\n \tint j;\n+\tuint64_t us_now;\n+\tuint64_t us_elapsed_absolute;\n \n \tif (!trace2_enabled)\n \t\treturn;\n \n+\tus_now = getnanotime() / 1000;\n+\tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n+\n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_start_fl)\n-\t\t\ttgt_j->pfn_start_fl(file, line, argv);\n+\t\t\ttgt_j->pfn_start_fl(file, line, us_elapsed_absolute,\n+\t\t\t\t\t    argv);\n }\n \n int trace2_cmd_exit_fl(const char *file, int line, int code)\ndiff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h\nindex 297bb8ffbe..7b90469212 100644\n--- a/trace2/tr2_tgt.h\n+++ b/trace2/tr2_tgt.h\n@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);\n typedef void(tr2_tgt_evt_version_fl_t)(const char *file, int line);\n \n typedef void(tr2_tgt_evt_start_fl_t)(const char *file, int line,\n+\t\t\t\t     uint64_t us_elapsed_absolute,\n \t\t\t\t     const char **argv);\n typedef void(tr2_tgt_evt_exit_fl_t)(const char *file, int line,\n \t\t\t\t    uint64_t us_elapsed_absolute, int code);\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 107cb5317d..89a4d3ae9a 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)\n \tjw_release(&jw);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct json_writer jw = JSON_WRITER_INIT;\n+\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \n \tjw_object_begin(&jw, 0);\n \tevent_fmt_prepare(event_name, file, line, NULL, &jw);\n+\tjw_object_double(&jw, \"t_abs\", 6, t_abs);\n \tjw_object_inline_begin_array(&jw, \"argv\");\n \tjw_array_argv(&jw, argv);\n \tjw_end(&jw);\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 547183d5b6..57f3e18f5b 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex f0746fcf86..9c3b4d8a0f 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)\n \tstrbuf_release(&buf_payload);\n }\n \n-static void fn_start_fl(const char *file, int line, const char **argv)\n+static void fn_start_fl(const char *file, int line,\n+\t\t\tuint64_t us_elapsed_absolute, const char **argv)\n {\n \tconst char *event_name = \"start\";\n \tstruct strbuf buf_payload = STRBUF_INIT;\n \n \tsq_quote_argv_pretty(&buf_payload, argv);\n \n-\tperf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,\n-\t\t\t &buf_payload);\n+\tperf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute,\n+\t\t\t NULL, NULL, &buf_payload);\n \tstrbuf_release(&buf_payload);\n }\n \n-- \ngitgitgadget\n\n"},{"id":"374655","messageId":"48e34834b6a65b9f2c68d4f4e459586b2948b6cd.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 02/11] trace2: refactor setting process starting time","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:14Z","receivedAt":"2019-04-29T20:14:23Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreate trace2_initialize_clock() and call from main() to capture\nprocess start time in isolation and before other sub-systems are\nready.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++--\n common-main.c                          |  2 ++\n compat/mingw.c                         |  2 ++\n trace2.c                               |  7 ++++-\n trace2.h                               | 17 ++++++++++++\n trace2/tr2_tls.c                       | 38 ++++++++++++++++----------\n trace2/tr2_tls.h                       |  8 +++++-\n 7 files changed, 67 insertions(+), 19 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 2de565fa3d..f37fccf1da 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -160,17 +160,23 @@ purposes.\n \n These are concerned with the lifetime of the overall git process.\n \n+`void trace2_initialize_clock()`::\n+\n+\tInitialize the Trace2 start clock and nothing else.  This should\n+\tbe called at the very top of main() to capture the process start\n+\ttime and reduce startup order dependencies.\n+\n `void trace2_initialize()`::\n \n \tDetermines if any Trace2 Targets should be enabled and\n-\tinitializes the Trace2 facility.  This includes starting the\n-\telapsed time clocks and thread local storage (TLS).\n+\tinitializes the Trace2 facility.  This includes setting up the\n+\tTrace2 thread local storage (TLS).\n +\n This function emits a \"version\" message containing the version of git\n and the Trace2 protocol.\n +\n This function should be called from `main()` as early as possible in\n-the life of the process.\n+the life of the process after essential process initialization.\n \n `int trace2_is_enabled()`::\n \ndiff --git a/common-main.c b/common-main.c\nindex d484aec209..6137af0e63 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -27,6 +27,8 @@ int main(int argc, const char **argv)\n {\n \tint result;\n \n+\ttrace2_initialize_clock();\n+\n \t/*\n \t * Always open file descriptors 0/1/2 to avoid clobbering files\n \t * in die().  It also avoids messing up when the pipes are dup'ed\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 6b04514cdc..a2f74aca6a 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -2569,6 +2569,8 @@ void mingw_startup(void)\n \twchar_t **wenv, **wargv;\n \t_startupinfo si;\n \n+\ttrace2_initialize_clock();\n+\n \tmaybe_redirect_std_handles();\n \n \t/* get wide char arguments and environment */\ndiff --git a/trace2.c b/trace2.c\nindex ccccd4ef09..6dd51e6aa5 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)\n \traise(signo);\n }\n \n+void trace2_initialize_clock(void)\n+{\n+\ttr2tls_start_process_clock();\n+}\n+\n void trace2_initialize_fl(const char *file, int line)\n {\n \tstruct tr2_tgt *tgt_j;\n@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name)\n \tus_now = getnanotime() / 1000;\n \tus_elapsed_absolute = tr2tls_absolute_elapsed(us_now);\n \n-\ttr2tls_create_self(thread_name);\n+\ttr2tls_create_self(thread_name, us_now);\n \n \tfor_each_wanted_builtin (j, tgt_j)\n \t\tif (tgt_j->pfn_thread_start_fl)\ndiff --git a/trace2.h b/trace2.h\nindex ae5020d0e6..8f89e70c44 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -19,6 +19,23 @@ struct json_writer;\n  * [] trace2_printf*    -- legacy trace[1] messages.\n  */\n \n+/*\n+ * Initialize the TRACE2 clock and do nothing else, in particular\n+ * no mallocs, no system inspection, and no environment inspection.\n+ *\n+ * This should be called at the very top of main() to capture the\n+ * process start time.  This is intended to reduce chicken-n-egg\n+ * bootstrap pressure.\n+ *\n+ * It is safe to call this more than once.  This allows capturing\n+ * absolute startup costs on Windows which uses a little trickery\n+ * to do setup work before common-main.c:main() is called.\n+ *\n+ * The main trace2_initialize_fl() may be called a little later\n+ * after more infrastructure is established.\n+ */\n+void trace2_initialize_clock(void);\n+\n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n  * targets are enabled in the environment.  Emits a 'version' event.\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 8e65b0361d..e76d8c5d92 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -10,16 +10,30 @@\n #define TR2_REGION_NESTING_INITIAL_SIZE (100)\n \n static struct tr2tls_thread_ctx *tr2tls_thread_main;\n-static uint64_t tr2tls_us_start_main;\n+static uint64_t tr2tls_us_start_process;\n \n static pthread_mutex_t tr2tls_mutex;\n static pthread_key_t tr2tls_key;\n \n static int tr2_next_thread_id; /* modify under lock */\n \n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n+void tr2tls_start_process_clock(void)\n+{\n+\tif (tr2tls_us_start_process)\n+\t\treturn;\n+\n+\t/*\n+\t * Keep the absolute start time of the process (i.e. the main\n+\t * process) in a fixed variable since other threads need to\n+\t * access it.  This allows them to do that without a lock on\n+\t * main thread's array data (because of reallocs).\n+\t */\n+\ttr2tls_us_start_process = getnanotime() / 1000;\n+}\n+\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start)\n {\n-\tuint64_t us_now = getnanotime() / 1000;\n \tstruct tr2tls_thread_ctx *ctx = xcalloc(1, sizeof(*ctx));\n \n \t/*\n@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)\n \t */\n \tctx->alloc = TR2_REGION_NESTING_INITIAL_SIZE;\n \tctx->array_us_start = (uint64_t *)xcalloc(ctx->alloc, sizeof(uint64_t));\n-\tctx->array_us_start[ctx->nr_open_regions++] = us_now;\n+\tctx->array_us_start[ctx->nr_open_regions++] = us_thread_start;\n \n \tctx->thread_id = tr2tls_locked_increment(&tr2_next_thread_id);\n \n@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)\n \t * here and silently continue.\n \t */\n \tif (!ctx)\n-\t\tctx = tr2tls_create_self(\"unknown\");\n+\t\tctx = tr2tls_create_self(\"unknown\", getnanotime() / 1000);\n \n \treturn ctx;\n }\n@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)\n \tif (!tr2tls_thread_main)\n \t\treturn 0;\n \n-\treturn us - tr2tls_us_start_main;\n+\treturn us - tr2tls_us_start_process;\n }\n \n void tr2tls_init(void)\n {\n+\ttr2tls_start_process_clock();\n+\n \tpthread_key_create(&tr2tls_key, NULL);\n \tinit_recursive_mutex(&tr2tls_mutex);\n \n-\ttr2tls_thread_main = tr2tls_create_self(\"main\");\n-\t/*\n-\t * Keep a copy of the absolute start time of the main thread\n-\t * in a fixed variable since other threads need to access it.\n-\t * This also eliminates the need to lock accesses to the main\n-\t * thread's array (because of reallocs).\n-\t */\n-\ttr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];\n+\ttr2tls_thread_main =\n+\t\ttr2tls_create_self(\"main\", tr2tls_us_start_process);\n }\n \n void tr2tls_release(void)\ndiff --git a/trace2/tr2_tls.h b/trace2/tr2_tls.h\nindex bb80e3f8e7..b1e327a928 100644\n--- a/trace2/tr2_tls.h\n+++ b/trace2/tr2_tls.h\n@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {\n  * In this and all following functions the term \"self\" refers to the\n  * current thread.\n  */\n-struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);\n+struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n+\t\t\t\t\t     uint64_t us_thread_start);\n \n /*\n  * Get our TLS data.\n@@ -94,4 +95,9 @@ void tr2tls_release(void);\n  */\n int tr2tls_locked_increment(int *p);\n \n+/*\n+ * Capture the process start time and do nothing else.\n+ */\n+void tr2tls_start_process_clock(void);\n+\n #endif /* TR2_TLS_H */\n-- \ngitgitgadget\n\n"},{"id":"374656","messageId":"56d8ce3fd60acc3808a5c8c1e5e1e6ba87fa1d5a.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 07/11] trace2: report peak memory usage of the process","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:19Z","receivedAt":"2019-04-29T20:14:24Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Windows version of git to report peak memory usage\nduring exit() processing.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c                            |  2 +-\n compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++--\n trace2.c                                 |  2 +\n trace2.h                                 | 14 +++++--\n 4 files changed, 60 insertions(+), 8 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 299ca62a72..582a7b1886 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -41,7 +41,7 @@ int main(int argc, const char **argv)\n \n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n-\ttrace2_collect_process_info();\n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);\n \n \tgit_setup_gettext();\n \ndiff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c\nindex 52bd62034b..8ccbd1c2c6 100644\n--- a/compat/win32/trace2_win32_process_info.c\n+++ b/compat/win32/trace2_win32_process_info.c\n@@ -1,5 +1,6 @@\n #include \"../../cache.h\"\n #include \"../../json-writer.h\"\n+#include \"lazyload.h\"\n #include <Psapi.h>\n #include <tlHelp32.h>\n \n@@ -137,11 +138,54 @@ static void get_is_being_debugged(void)\n \t\t\t\t   \"windows/debugger_present\", 1);\n }\n \n-void trace2_collect_process_info(void)\n+/*\n+ * Emit JSON data with the peak memory usage of the current process.\n+ */\n+static void get_peak_memory_info(void)\n+{\n+\tDECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE,\n+\t\t\t  PPROCESS_MEMORY_COUNTERS, DWORD);\n+\n+\tif (INIT_PROC_ADDR(GetProcessMemoryInfo)) {\n+\t\tPROCESS_MEMORY_COUNTERS pmc;\n+\n+\t\tif (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,\n+\t\t\t\t\t sizeof(pmc))) {\n+\t\t\tstruct json_writer jw = JSON_WRITER_INIT;\n+\n+\t\t\tjw_object_begin(&jw, 0);\n+\n+#define KV(kv) #kv, (intmax_t)pmc.kv\n+\n+\t\t\tjw_object_intmax(&jw, KV(PageFaultCount));\n+\t\t\tjw_object_intmax(&jw, KV(PeakWorkingSetSize));\n+\t\t\tjw_object_intmax(&jw, KV(PeakPagefileUsage));\n+\n+\t\t\tjw_end(&jw);\n+\n+\t\t\ttrace2_data_json(\"process\", the_repository,\n+\t\t\t\t\t \"windows/memory\", &jw);\n+\t\t\tjw_release(&jw);\n+\t\t}\n+\t}\n+}\n+\n+void trace2_collect_process_info(enum trace2_process_info_reason reason)\n {\n \tif (!trace2_is_enabled())\n \t\treturn;\n \n-\tget_is_being_debugged();\n-\tget_ancestry();\n+\tswitch (reason) {\n+\tcase TRACE2_PROCESS_INFO_STARTUP:\n+\t\tget_is_being_debugged();\n+\t\tget_ancestry();\n+\t\treturn;\n+\n+\tcase TRACE2_PROCESS_INFO_EXIT:\n+\t\tget_peak_memory_info();\n+\t\treturn;\n+\n+\tdefault:\n+\t\tBUG(\"trace2_collect_process_info: unknown reason '%d'\", reason);\n+\t}\n }\ndiff --git a/trace2.c b/trace2.c\nindex 490b3f071e..6baa65cdf9 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)\n \tif (!trace2_enabled)\n \t\treturn code;\n \n+\ttrace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);\n+\n \ttr2main_exit_code = code;\n \n \tus_now = getnanotime() / 1000;\ndiff --git a/trace2.h b/trace2.h\nindex 894bfca7e0..888531eb08 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);\n  * Optional platform-specific code to dump information about the\n  * current and any parent process(es).  This is intended to allow\n  * post-processors to know who spawned this git instance and anything\n- * else the platform may be able to tell us about the current process.\n+ * else that the platform may be able to tell us about the current process.\n  */\n+\n+enum trace2_process_info_reason {\n+\tTRACE2_PROCESS_INFO_STARTUP,\n+\tTRACE2_PROCESS_INFO_EXIT,\n+};\n+\n #if defined(GIT_WINDOWS_NATIVE)\n-void trace2_collect_process_info(void);\n+void trace2_collect_process_info(enum trace2_process_info_reason reason);\n #else\n-#define trace2_collect_process_info() \\\n-\tdo {                          \\\n+#define trace2_collect_process_info(reason) \\\n+\tdo {                                \\\n \t} while (0)\n #endif\n \n-- \ngitgitgadget\n\n"},{"id":"374657","messageId":"196a9d2c852c110f951ccd19fc05741399ec59c1.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 08/11] trace2: clarify UTC datetime formatting","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:20Z","receivedAt":"2019-04-29T20:14:25Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate tr2_tbuf_utc_datetime to generate extended UTC format.\nUpdate tr2_tgt_event target to use extended format in 'time' columns.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 12 ++++++------\n trace2/tr2_tbuf.c                      |  4 ++--\n trace2/tr2_tbuf.h                      |  4 ++--\n trace2/tr2_tgt_event.c                 |  2 +-\n 4 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex baaa1153bb..cdc00bcc5d 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.620713\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621027\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621122\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621236\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16 17:28:42.621268\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -542,7 +542,7 @@ The following key/value pairs are common to all events:\n \t\"event\":\"version\",\n \t\"sid\":\"1547659722619736-11614\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16 17:28:42.620713\",\n+\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n \t\"file\":\"common-main.c\",\n \t\"line\":38,\n \t...\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex 0844910423..eb1b240d8a 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb)\n \t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n }\n \n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n {\n \tstruct timeval tv;\n \tstruct tm tm;\n@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)\n \tgmtime_r(&secs, &tm);\n \n \txsnprintf(tb->buf, sizeof(tb->buf),\n-\t\t  \"%4d-%02d-%02d %02d:%02d:%02d.%06ld\", tm.tm_year + 1900,\n+\t\t  \"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ\", tm.tm_year + 1900,\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 9cdefa3957..2a1d173ff2 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -16,8 +16,8 @@ struct tr2_tbuf {\n void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n \n /*\n- * Fill buffer with formatted UTC time string.\n+ * Fill buffer with formatted UTC datatime string.\n  */\n-void tr2_tbuf_utc_time(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 48d9193b2c..2c97cf54be 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t */\n \tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n-\t\ttr2_tbuf_utc_time(&tb_now);\n+\t\ttr2_tbuf_utc_datetime_extended(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"374658","messageId":"9fdcb50140571f888712366f9187a23342d56ac7.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 09/11] trace2: make SIDs more unique","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:20Z","receivedAt":"2019-04-29T20:14:27Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUpdate SID component construction to use the current UTC datetime\nand a portion of the SHA1 of the hostname.\n\nUse an simplified date/time format to make it easier to use the\nSID component as a logfile filename.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/technical/api-trace2.txt | 16 ++++----\n trace2/tr2_sid.c                       | 53 ++++++++++++++++++++++++--\n trace2/tr2_tbuf.c                      | 15 ++++++++\n trace2/tr2_tbuf.h                      |  1 +\n 4 files changed, 73 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex cdc00bcc5d..43adbf00eb 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb\n +\n ------------\n $ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"1547659722619736-11614\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n ------------\n \n == Enabling a Target\n@@ -540,11 +540,11 @@ The following key/value pairs are common to all events:\n ------------\n {\n \t\"event\":\"version\",\n-\t\"sid\":\"1547659722619736-11614\",\n+\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n \t\"thread\":\"main\",\n-\t\"time\":\"2019-01-16T17:28:42.620713Z\",\n+\t\"time\":\"2019-04-08T19:18:27.282761Z\",\n \t\"file\":\"common-main.c\",\n-\t\"line\":38,\n+\t\"line\":42,\n \t...\n }\n ------------\ndiff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c\nindex 984524a43c..5047095478 100644\n--- a/trace2/tr2_sid.c\n+++ b/trace2/tr2_sid.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n \n #define TR2_ENVVAR_PARENT_SID \"GIT_TR2_PARENT_SID\"\n@@ -6,6 +7,53 @@\n static struct strbuf tr2sid_buf = STRBUF_INIT;\n static int tr2sid_nr_git_parents;\n \n+/*\n+ * Compute the final component of the SID representing the current process.\n+ * This should uniquely identify the process and be a valid filename (to\n+ * allow writing trace2 data to per-process files).  It should also be fixed\n+ * length for possible use as a database key.\n+ *\n+ * \"<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>\"\n+ *\n+ * where <host> is a 9 character string:\n+ *    \"H<first_8_chars_of_sha1_of_hostname>\"\n+ *    \"Localhost\" when no hostname.\n+ *\n+ * where <process> is a 9 character string containing the least signifcant\n+ * 32 bits in the process-id.\n+ *    \"P<pid>\"\n+ * (This is an abribrary choice.  On most systems pid_t is a 32 bit value,\n+ * so limit doesn't matter.  On larger systems, a truncated value is fine\n+ * for our purposes here.)\n+ */\n+static void tr2_sid_append_my_sid_component(void)\n+{\n+\tconst struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];\n+\tstruct tr2_tbuf tb_now;\n+\tgit_hash_ctx ctx;\n+\tpid_t pid = getpid();\n+\tunsigned char hash[GIT_MAX_RAWSZ + 1];\n+\tchar hex[GIT_MAX_HEXSZ + 1];\n+\tchar hostname[HOST_NAME_MAX + 1];\n+\n+\ttr2_tbuf_utc_datetime(&tb_now);\n+\tstrbuf_addstr(&tr2sid_buf, tb_now.buf);\n+\n+\tstrbuf_addch(&tr2sid_buf, '-');\n+\tif (xgethostname(hostname, sizeof(hostname)))\n+\t\tstrbuf_add(&tr2sid_buf, \"Localhost\", 9);\n+\telse {\n+\t\talgo->init_fn(&ctx);\n+\t\talgo->update_fn(&ctx, hostname, strlen(hostname));\n+\t\talgo->final_fn(hash, &ctx);\n+\t\thash_to_hex_algop_r(hex, hash, algo);\n+\t\tstrbuf_addch(&tr2sid_buf, 'H');\n+\t\tstrbuf_add(&tr2sid_buf, hex, 8);\n+\t}\n+\n+\tstrbuf_addf(&tr2sid_buf, \"-P%08\"PRIx32, (uint32_t)pid);\n+}\n+\n /*\n  * Compute a \"unique\" session id (SID) for the current process.  This allows\n  * all events from this process to have a single label (much like a PID).\n@@ -20,7 +68,6 @@ static int tr2sid_nr_git_parents;\n  */\n static void tr2_sid_compute(void)\n {\n-\tuint64_t us_now;\n \tconst char *parent_sid;\n \n \tif (tr2sid_buf.len)\n@@ -38,9 +85,7 @@ static void tr2_sid_compute(void)\n \t\ttr2sid_nr_git_parents++;\n \t}\n \n-\tus_now = getnanotime() / 1000;\n-\tstrbuf_addf(&tr2sid_buf, \"%\" PRIuMAX \"-%\" PRIdMAX, (uintmax_t)us_now,\n-\t\t    (intmax_t)getpid());\n+\ttr2_sid_append_my_sid_component();\n \n \tsetenv(TR2_ENVVAR_PARENT_SID, tr2sid_buf.buf, 1);\n }\ndiff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c\nindex eb1b240d8a..2498482d9a 100644\n--- a/trace2/tr2_tbuf.c\n+++ b/trace2/tr2_tbuf.c\n@@ -30,3 +30,18 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)\n \t\t  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\n \t\t  (long)tv.tv_usec);\n }\n+\n+void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)\n+{\n+\tstruct timeval tv;\n+\tstruct tm tm;\n+\ttime_t secs;\n+\n+\tgettimeofday(&tv, NULL);\n+\tsecs = tv.tv_sec;\n+\tgmtime_r(&secs, &tm);\n+\n+\txsnprintf(tb->buf, sizeof(tb->buf), \"%4d%02d%02dT%02d%02d%02d.%06ldZ\",\n+\t\t  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,\n+\t\t  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);\n+}\ndiff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h\nindex 2a1d173ff2..fa853d8f42 100644\n--- a/trace2/tr2_tbuf.h\n+++ b/trace2/tr2_tbuf.h\n@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);\n  * Fill buffer with formatted UTC datatime string.\n  */\n void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);\n+void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb);\n \n #endif /* TR2_TBUF_H */\n-- \ngitgitgadget\n\n"},{"id":"374659","messageId":"550cad618923c6e5aa1bd5f901f2968791d7566b.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 06/11] trace2: use system/global config for default trace2 settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:18Z","receivedAt":"2019-04-29T20:14:30Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach git to read the system and global config files for\ndefault Trace2 settings.  This allows system-wide Trace2 settings to\nbe installed and inherited to make it easier to manage a collection of\nsystems.\n\nThe original GIT_TR2* environment variables are loaded afterwards and\ncan be used to override the system settings.\n\nOnly the system and global config files are used.  Repo and worktree\nlocal config files are ignored.  Likewise, the \"-c\" command line\narguments are also ignored.  These limits are for performance reasons.\n\n(1) For users not using Trace2, there should be minimal overhead to\ndetect that Trace2 is not enabled.  In particular, Trace2 should not\nallocate lots of otherwise unused data strucutres.\n\n(2) For accurate performance measurements, Trace2 should be initialized\nas early in the git process as possible, and before most of the normal\ngit process initialization (which involves discovering the .git directory\nand reading a hierarchy of config files).\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Makefile                 |   1 +\n t/t0210-trace2-normal.sh |  49 +++++++++++++--\n t/t0211-trace2-perf.sh   |  31 ++++++++--\n t/t0212-trace2-event.sh  |  42 +++++++++++--\n trace2.c                 |   4 ++\n trace2.h                 |  12 ++--\n trace2/tr2_cfg.c         |   7 +--\n trace2/tr2_dst.c         |  26 ++++----\n trace2/tr2_dst.h         |   3 +-\n trace2/tr2_sysenv.c      | 127 +++++++++++++++++++++++++++++++++++++++\n trace2/tr2_sysenv.h      |  36 +++++++++++\n trace2/tr2_tgt_event.c   |  46 +++++++-------\n trace2/tr2_tgt_normal.c  |  16 ++---\n trace2/tr2_tgt_perf.c    |  16 ++---\n 14 files changed, 340 insertions(+), 76 deletions(-)\n create mode 100644 trace2/tr2_sysenv.c\n create mode 100644 trace2/tr2_sysenv.h\n\ndiff --git a/Makefile b/Makefile\nindex 3e03290d8f..9ddfa3dfe7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o\n LIB_OBJS += trace2/tr2_cmd_name.o\n LIB_OBJS += trace2/tr2_dst.o\n LIB_OBJS += trace2/tr2_sid.o\n+LIB_OBJS += trace2/tr2_sysenv.o\n LIB_OBJS += trace2/tr2_tbuf.o\n LIB_OBJS += trace2/tr2_tgt_event.o\n LIB_OBJS += trace2/tr2_tgt_normal.o\ndiff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh\nindex 03a0aedb1d..8d17e1e6f1 100755\n--- a/t/t0210-trace2-normal.sh\n+++ b/t/t0210-trace2-normal.sh\n@@ -3,6 +3,11 @@\n test_description='test trace2 facility (normal target)'\n . ./test-lib.sh\n \n+# Turn off any inherited trace2 settings for this test.\n+sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+sane_unset GIT_TR2_BRIEF\n+sane_unset GIT_TR2_CONFIG_PARAMS\n+\n # Add t/helper directory to PATH so that we can use a relative\n # path to run nested instances of test-tool.exe (see 004child).\n # This helps with HEREDOC comparisons later.\n@@ -15,11 +20,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -132,4 +132,43 @@ test_expect_success 'normal stream, error event' '\n \ttest_cmp expect actual\n '\n \n+sane_unset GIT_TR2_BRIEF\n+\n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success 'using global config, normal stream, return code 0' '\n+\ttest_when_finished \"rm trace.normal actual expect\" &&\n+\ttest_config_global trace2.normalBrief 1 &&\n+\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'using global config with include' '\n+\ttest_when_finished \"rm trace.normal actual expect real.gitconfig\" &&\n+\ttest_config_global trace2.normalBrief 1 &&\n+\ttest_config_global trace2.normalTarget \"$(pwd)/trace.normal\" &&\n+\tmv \"$(pwd)/.gitconfig\" \"$(pwd)/real.gitconfig\" &&\n+\ttest_config_global include.path \"$(pwd)/real.gitconfig\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0210/scrub_normal.perl\" <trace.normal >actual &&\n+\tcat >expect <<-EOF &&\n+\t\tversion $V\n+\t\tstart _EXE_ trace2 001return 0\n+\t\tcmd_name trace2 (trace2)\n+\t\texit elapsed:_TIME_ code:0\n+\t\tatexit elapsed:_TIME_ code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh\nindex c9694b29f7..b501e867af 100755\n--- a/t/t0211-trace2-perf.sh\n+++ b/t/t0211-trace2-perf.sh\n@@ -3,6 +3,11 @@\n test_description='test trace2 facility (perf target)'\n . ./test-lib.sh\n \n+# Turn off any inherited trace2 settings for this test.\n+sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+sane_unset GIT_TR2_PERF_BRIEF\n+sane_unset GIT_TR2_CONFIG_PARAMS\n+\n # Add t/helper directory to PATH so that we can use a relative\n # path to run nested instances of test-tool.exe (see 004child).\n # This helps with HEREDOC comparisons later.\n@@ -15,11 +20,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_PERF_BRIEF\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -150,4 +150,25 @@ test_expect_success 'perf stream, child processes' '\n \ttest_cmp expect actual\n '\n \n+sane_unset GIT_TR2_PERF_BRIEF\n+\n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success 'using global config, perf stream, return code 0' '\n+\ttest_when_finished \"rm trace.perf actual expect\" &&\n+\ttest_config_global trace2.perfBrief 1 &&\n+\ttest_config_global trace2.perfTarget \"$(pwd)/trace.perf\" &&\n+\ttest-tool trace2 001return 0 &&\n+\tperl \"$TEST_DIRECTORY/t0211/scrub_perf.perl\" <trace.perf >actual &&\n+\tcat >expect <<-EOF &&\n+\t\td0|main|version|||||$V\n+\t\td0|main|start||_T_ABS_|||_EXE_ trace2 001return 0\n+\t\td0|main|cmd_name|||||trace2 (trace2)\n+\t\td0|main|exit||_T_ABS_|||code:0\n+\t\td0|main|atexit||_T_ABS_|||code:0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t0212-trace2-event.sh b/t/t0212-trace2-event.sh\nindex 028b6c5671..59adae8123 100755\n--- a/t/t0212-trace2-event.sh\n+++ b/t/t0212-trace2-event.sh\n@@ -3,6 +3,11 @@\n test_description='test trace2 facility'\n . ./test-lib.sh\n \n+# Turn off any inherited trace2 settings for this test.\n+sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n+sane_unset GIT_TR2_BARE\n+sane_unset GIT_TR2_CONFIG_PARAMS\n+\n perl -MJSON::PP -e 0 >/dev/null 2>&1 && test_set_prereq JSON_PP\n \n # Add t/helper directory to PATH so that we can use a relative\n@@ -17,11 +22,6 @@ PATH=\"$TTDIR:$PATH\" && export PATH\n # Warning: So you may see extra lines in artifact files when\n # Warning: interactively debugging.\n \n-# Turn off any inherited trace2 settings for this test.\n-unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT\n-unset GIT_TR2_BARE\n-unset GIT_TR2_CONFIG_PARAMS\n-\n V=$(git version | sed -e 's/^git version //') && export V\n \n # There are multiple trace2 targets: normal, perf, and event.\n@@ -233,4 +233,36 @@ test_expect_success JSON_PP 'basic trace2_data' '\n \ttest_cmp expect actual\n '\n \n+# Now test without environment variables and get all Trace2 settings\n+# from the global config.\n+\n+test_expect_success JSON_PP 'using global config, event stream, error event' '\n+\ttest_when_finished \"rm trace.event actual expect\" &&\n+\ttest_config_global trace2.eventTarget \"$(pwd)/trace.event\" &&\n+\ttest-tool trace2 003error \"hello world\" \"this is a test\" &&\n+\tperl \"$TEST_DIRECTORY/t0212/parse_events.perl\" <trace.event >actual &&\n+\tsed -e \"s/^|//\" >expect <<-EOF &&\n+\t|VAR1 = {\n+\t|  \"_SID0_\":{\n+\t|    \"argv\":[\n+\t|      \"_EXE_\",\n+\t|      \"trace2\",\n+\t|      \"003error\",\n+\t|      \"hello world\",\n+\t|      \"this is a test\"\n+\t|    ],\n+\t|    \"errors\":[\n+\t|      \"%s\",\n+\t|      \"%s\"\n+\t|    ],\n+\t|    \"exit_code\":0,\n+\t|    \"hierarchy\":\"trace2\",\n+\t|    \"name\":\"trace2\",\n+\t|    \"version\":\"$V\"\n+\t|  }\n+\t|};\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/trace2.c b/trace2.c\nindex 1c180062dd..490b3f071e 100644\n--- a/trace2.c\n+++ b/trace2.c\n@@ -10,6 +10,7 @@\n #include \"trace2/tr2_cmd_name.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)\n \ttr2_sid_release();\n \ttr2_cmd_name_release();\n \ttr2_cfg_free_patterns();\n+\ttr2_sysenv_release();\n \n \ttrace2_enabled = 0;\n }\n@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)\n \tif (trace2_enabled)\n \t\treturn;\n \n+\ttr2_sysenv_load();\n+\n \tif (!tr2_tgt_want_builtins())\n \t\treturn;\n \ttrace2_enabled = 1;\ndiff --git a/trace2.h b/trace2.h\nindex 8f89e70c44..894bfca7e0 100644\n--- a/trace2.h\n+++ b/trace2.h\n@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);\n \n /*\n  * Initialize TRACE2 tracing facility if any of the builtin TRACE2\n- * targets are enabled in the environment.  Emits a 'version' event.\n+ * targets are enabled in the system config or the environment.\n+ * Emits a 'version' event.\n  *\n  * Cleanup/Termination is handled automatically by a registered\n  * atexit() routine.\n@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,\n  * Emit one or more 'def_param' events for \"interesting\" configuration\n  * settings.\n  *\n- * The environment variable \"GIT_TR2_CONFIG_PARAMS\" can be set to a\n- * list of patterns considered important.  For example:\n- *\n- *    GIT_TR2_CONFIG_PARAMS=\"core.*,remote.*.url\"\n+ * Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated\n+ * list of patterns configured important.  For example:\n+ *     git config --system trace2.configParams 'core.*,remote.*.url'\n+ * or:\n+ *     GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url\"\n  *\n  * Note: this routine does a read-only iteration on the config data\n  * (using read_early_config()), so it must not be called until enough\ndiff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c\nindex b329921ac5..caa7f06948 100644\n--- a/trace2/tr2_cfg.c\n+++ b/trace2/tr2_cfg.c\n@@ -1,8 +1,7 @@\n #include \"cache.h\"\n #include \"config.h\"\n-#include \"tr2_cfg.h\"\n-\n-#define TR2_ENVVAR_CFG_PARAM \"GIT_TR2_CONFIG_PARAMS\"\n+#include \"trace2/tr2_cfg.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n static struct strbuf **tr2_cfg_patterns;\n static int tr2_cfg_count_patterns;\n@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)\n \t\treturn tr2_cfg_count_patterns;\n \ttr2_cfg_loaded = 1;\n \n-\tenvvar = getenv(TR2_ENVVAR_CFG_PARAM);\n+\tenvvar = tr2_sysenv_get(TR2_SYSENV_CFG_PARAM);\n \tif (!envvar || !*envvar)\n \t\treturn tr2_cfg_count_patterns;\n \ndiff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c\nindex fd490a43ad..7d96f33420 100644\n--- a/trace2/tr2_dst.c\n+++ b/trace2/tr2_dst.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n \n /*\n  * If a Trace2 target cannot be opened for writing, we should issue a\n@@ -7,17 +8,13 @@\n  * or socket and beyond the user's control -- especially since every\n  * git command (and sub-command) will print the message.  So we silently\n  * eat these warnings and just discard the trace data.\n- *\n- * Enable the following environment variable to see these warnings.\n  */\n-#define TR2_ENVVAR_DST_DEBUG \"GIT_TR2_DST_DEBUG\"\n-\n static int tr2_dst_want_warning(void)\n {\n \tstatic int tr2env_dst_debug = -1;\n \n \tif (tr2env_dst_debug == -1) {\n-\t\tconst char *env_value = getenv(TR2_ENVVAR_DST_DEBUG);\n+\t\tconst char *env_value = tr2_sysenv_get(TR2_SYSENV_DST_DEBUG);\n \t\tif (!env_value || !*env_value)\n \t\t\ttr2env_dst_debug = 0;\n \t\telse\n@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)\n \tif (fd == -1) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: could not open '%s' for '%s' tracing: %s\",\n-\t\t\t\ttgt_value, dst->env_var_name, strerror(errno));\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\t\tstrerror(errno));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -116,7 +115,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \tif (!path || !*path) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX value '%s' for '%s' tracing\",\n-\t\t\t\ttgt_value, dst->env_var_name);\n+\t\t\t\ttgt_value,\n+\t\t\t\ttr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -126,7 +126,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n \t    strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {\n \t\tif (tr2_dst_want_warning())\n \t\t\twarning(\"trace2: invalid AF_UNIX path '%s' for '%s' tracing\",\n-\t\t\t\tpath, dst->env_var_name);\n+\t\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var));\n \n \t\ttr2_dst_trace_disable(dst);\n \t\treturn 0;\n@@ -148,7 +148,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,\n error:\n \tif (tr2_dst_want_warning())\n \t\twarning(\"trace2: could not connect to socket '%s' for '%s' tracing: %s\",\n-\t\t\tpath, dst->env_var_name, strerror(e));\n+\t\t\tpath, tr2_sysenv_display_name(dst->sysenv_var),\n+\t\t\tstrerror(e));\n \n \ttr2_dst_trace_disable(dst);\n \treturn 0;\n@@ -168,7 +169,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_addf(&buf, \"trace2: unknown value for '%s': '%s'\",\n-\t\t    dst->env_var_name, tgt_value);\n+\t\t    tr2_sysenv_display_name(dst->sysenv_var), tgt_value);\n \twarning(\"%s\", buf.buf);\n \n \tstrbuf_release(&buf);\n@@ -184,7 +185,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst)\n \n \tdst->initialized = 1;\n \n-\ttgt_value = getenv(dst->env_var_name);\n+\ttgt_value = tr2_sysenv_get(dst->sysenv_var);\n \n \tif (!tgt_value || !strcmp(tgt_value, \"\") || !strcmp(tgt_value, \"0\") ||\n \t    !strcasecmp(tgt_value, \"false\")) {\n@@ -246,7 +247,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)\n \t\treturn;\n \n \tif (tr2_dst_want_warning())\n-\t\twarning(\"unable to write trace to '%s': %s\", dst->env_var_name,\n+\t\twarning(\"unable to write trace to '%s': %s\",\n+\t\t\ttr2_sysenv_display_name(dst->sysenv_var),\n \t\t\tstrerror(errno));\n \ttr2_dst_trace_disable(dst);\n }\ndiff --git a/trace2/tr2_dst.h b/trace2/tr2_dst.h\nindex 9a64f05b02..3adf3bac13 100644\n--- a/trace2/tr2_dst.h\n+++ b/trace2/tr2_dst.h\n@@ -2,9 +2,10 @@\n #define TR2_DST_H\n \n struct strbuf;\n+#include \"trace2/tr2_sysenv.h\"\n \n struct tr2_dst {\n-\tconst char *const env_var_name;\n+\tenum tr2_sysenv_variable sysenv_var;\n \tint fd;\n \tunsigned int initialized : 1;\n \tunsigned int need_close : 1;\ndiff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c\nnew file mode 100644\nindex 0000000000..9025b86303\n--- /dev/null\n+++ b/trace2/tr2_sysenv.c\n@@ -0,0 +1,127 @@\n+#include \"cache.h\"\n+#include \"config.h\"\n+#include \"dir.h\"\n+#include \"tr2_sysenv.h\"\n+\n+/*\n+ * Each entry represents a trace2 setting.\n+ * See Documentation/technical/api-trace2.txt\n+ */\n+struct tr2_sysenv_entry {\n+\tconst char *env_var_name;\n+\tconst char *git_config_name;\n+\n+\tchar *value;\n+\tunsigned int getenv_called : 1;\n+};\n+\n+/*\n+ * This table must match \"enum tr2_sysenv_variable\" in tr2_sysenv.h.\n+ *\n+ * The strings in this table are constant and must match the published\n+ * config and environment variable names as described in the documentation.\n+ *\n+ * We do not define entries for the GIT_TR2_PARENT_* environment\n+ * variables because they are transient and used to pass information\n+ * from parent to child git processes, rather than settings.\n+ */\n+/* clang-format off */\n+static struct tr2_sysenv_entry tr2_sysenv_settings[] = {\n+\t[TR2_SYSENV_CFG_PARAM]     = { \"GIT_TR2_CONFIG_PARAMS\",\n+\t\t\t\t       \"trace2.configparams\" },\n+\n+\t[TR2_SYSENV_DST_DEBUG]     = { \"GIT_TR2_DST_DEBUG\",\n+\t\t\t\t       \"trace2.destinationdebug\" },\n+\n+\t[TR2_SYSENV_NORMAL]        = { \"GIT_TR2\",\n+\t\t\t\t       \"trace2.normaltarget\" },\n+\t[TR2_SYSENV_NORMAL_BRIEF]  = { \"GIT_TR2_BRIEF\",\n+\t\t\t\t       \"trace2.normalbrief\" },\n+\n+\t[TR2_SYSENV_EVENT]         = { \"GIT_TR2_EVENT\",\n+\t\t\t\t       \"trace2.eventtarget\" },\n+\t[TR2_SYSENV_EVENT_BRIEF]   = { \"GIT_TR2_EVENT_BRIEF\",\n+\t\t\t\t       \"trace2.eventbrief\" },\n+\t[TR2_SYSENV_EVENT_NESTING] = { \"GIT_TR2_EVENT_NESTING\",\n+\t\t\t\t       \"trace2.eventnesting\" },\n+\n+\t[TR2_SYSENV_PERF]          = { \"GIT_TR2_PERF\",\n+\t\t\t\t       \"trace2.perftarget\" },\n+\t[TR2_SYSENV_PERF_BRIEF]    = { \"GIT_TR2_PERF_BRIEF\",\n+\t\t\t\t       \"trace2.perfbrief\" },\n+};\n+/* clang-format on */\n+\n+static int tr2_sysenv_cb(const char *key, const char *value, void *d)\n+{\n+\tint k;\n+\n+\tif (!starts_with(key, \"trace2.\"))\n+\t\treturn 0;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {\n+\t\tif (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {\n+\t\t\tfree(tr2_sysenv_settings[k].value);\n+\t\t\ttr2_sysenv_settings[k].value = xstrdup(value);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Load Trace2 settings from the system config (usually \"/etc/gitconfig\"\n+ * unless we were built with a runtime-prefix).  These are intended to\n+ * define the default values for Trace2 as requested by the administrator.\n+ *\n+ * Then override with the Trace2 settings from the global config.\n+ */\n+void tr2_sysenv_load(void)\n+{\n+\tif (ARRAY_SIZE(tr2_sysenv_settings) != TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_settings size is wrong\");\n+\n+\tread_very_early_config(tr2_sysenv_cb, NULL);\n+}\n+\n+/*\n+ * Return the value for the requested Trace2 setting from these sources:\n+ * the system config, the global config, and the environment.\n+ */\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\tif (!tr2_sysenv_settings[var].getenv_called) {\n+\t\tconst char *v = getenv(tr2_sysenv_settings[var].env_var_name);\n+\t\tif (v && *v) {\n+\t\t\tfree(tr2_sysenv_settings[var].value);\n+\t\t\ttr2_sysenv_settings[var].value = xstrdup(v);\n+\t\t}\n+\t\ttr2_sysenv_settings[var].getenv_called = 1;\n+\t}\n+\n+\treturn tr2_sysenv_settings[var].value;\n+}\n+\n+/*\n+ * Return a friendly name for this setting that is suitable for printing\n+ * in an error messages.\n+ */\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var)\n+{\n+\tif (var >= TR2_SYSENV_MUST_BE_LAST)\n+\t\tBUG(\"tr2_sysenv_get invalid var '%d'\", var);\n+\n+\treturn tr2_sysenv_settings[var].env_var_name;\n+}\n+\n+void tr2_sysenv_release(void)\n+{\n+\tint k;\n+\n+\tfor (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++)\n+\t\tfree(tr2_sysenv_settings[k].value);\n+}\ndiff --git a/trace2/tr2_sysenv.h b/trace2/tr2_sysenv.h\nnew file mode 100644\nindex 0000000000..369b20bd87\n--- /dev/null\n+++ b/trace2/tr2_sysenv.h\n@@ -0,0 +1,36 @@\n+#ifndef TR2_SYSENV_H\n+#define TR2_SYSENV_H\n+\n+/*\n+ * The Trace2 settings that can be loaded from /etc/gitconfig\n+ * and/or user environment variables.\n+ *\n+ * Note that this set does not contain any of the transient\n+ * environment variables used to pass information from parent\n+ * to child git processes, such \"GIT_TR2_PARENT_SID\".\n+ */\n+enum tr2_sysenv_variable {\n+\tTR2_SYSENV_CFG_PARAM = 0,\n+\n+\tTR2_SYSENV_DST_DEBUG,\n+\n+\tTR2_SYSENV_NORMAL,\n+\tTR2_SYSENV_NORMAL_BRIEF,\n+\n+\tTR2_SYSENV_EVENT,\n+\tTR2_SYSENV_EVENT_BRIEF,\n+\tTR2_SYSENV_EVENT_NESTING,\n+\n+\tTR2_SYSENV_PERF,\n+\tTR2_SYSENV_PERF_BRIEF,\n+\n+\tTR2_SYSENV_MUST_BE_LAST\n+};\n+\n+void tr2_sysenv_load(void);\n+\n+const char *tr2_sysenv_get(enum tr2_sysenv_variable);\n+const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);\n+void tr2_sysenv_release(void);\n+\n+#endif /* TR2_SYSENV_H */\ndiff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c\nindex 89a4d3ae9a..48d9193b2c 100644\n--- a/trace2/tr2_tgt_event.c\n+++ b/trace2/tr2_tgt_event.c\n@@ -6,10 +6,11 @@\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 };\n \n /*\n  * The version number of the JSON data generated by the EVENT target\n@@ -28,37 +29,36 @@ static struct tr2_dst tr2dst_event = { \"GIT_TR2_EVENT\", 0, 0, 0 };\n  * are primarily intended for the performance target during debugging.\n  *\n  * Some of the outer-most messages, however, may be of interest to the\n- * event target.  Set this environment variable to a larger integer for\n- * more detail in the event target.\n+ * event target.  Use the TR2_SYSENV_EVENT_NESTING setting to increase\n+ * region details in the event target.\n  */\n-#define TR2_ENVVAR_EVENT_NESTING \"GIT_TR2_EVENT_NESTING\"\n-static int tr2env_event_nesting_wanted = 2;\n+static int tr2env_event_max_nesting_levels = 2;\n \n /*\n- * Set this environment variable to true to omit the <time>, <file>, and\n+ * Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and\n  * <line> fields from most events.\n  */\n-#define TR2_ENVVAR_EVENT_BRIEF \"GIT_TR2_EVENT_BRIEF\"\n-static int tr2env_event_brief;\n+static int tr2env_event_be_brief;\n \n static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_event);\n-\tint want_nesting;\n+\tint max_nesting;\n \tint want_brief;\n-\tchar *nesting;\n-\tchar *brief;\n+\tconst char *nesting;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tnesting = getenv(TR2_ENVVAR_EVENT_NESTING);\n-\tif (nesting && ((want_nesting = atoi(nesting)) > 0))\n-\t\ttr2env_event_nesting_wanted = want_nesting;\n+\tnesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);\n+\tif (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))\n+\t\ttr2env_event_max_nesting_levels = max_nesting;\n \n-\tbrief = getenv(TR2_ENVVAR_EVENT_BRIEF);\n-\tif (brief && ((want_brief = atoi(brief)) > 0))\n-\t\ttr2env_event_brief = want_brief;\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);\n+\tif (brief && *brief &&\n+\t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n+\t\ttr2env_event_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -92,13 +92,13 @@ static void event_fmt_prepare(const char *event_name, const char *file,\n \t/*\n \t * In brief mode, only emit <time> on these 2 event types.\n \t */\n-\tif (!tr2env_event_brief || !strcmp(event_name, \"version\") ||\n+\tif (!tr2env_event_be_brief || !strcmp(event_name, \"version\") ||\n \t    !strcmp(event_name, \"atexit\")) {\n \t\ttr2_tbuf_utc_time(&tb_now);\n \t\tjw_object_string(jw, \"time\", tb_now.buf);\n \t}\n \n-\tif (!tr2env_event_brief && file && *file) {\n+\tif (!tr2env_event_be_brief && file && *file) {\n \t\tjw_object_string(jw, \"file\", file);\n \t\tjw_object_intmax(jw, \"line\", line);\n \t}\n@@ -459,7 +459,7 @@ static void fn_region_enter_printf_va_fl(const char *file, int line,\n {\n \tconst char *event_name = \"region_enter\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \n \t\tjw_object_begin(&jw, 0);\n@@ -484,7 +484,7 @@ static void fn_region_leave_printf_va_fl(\n {\n \tconst char *event_name = \"region_leave\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n \n@@ -511,7 +511,7 @@ static void fn_data_fl(const char *file, int line, uint64_t us_elapsed_absolute,\n {\n \tconst char *event_name = \"data\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\n@@ -539,7 +539,7 @@ static void fn_data_json_fl(const char *file, int line,\n {\n \tconst char *event_name = \"data_json\";\n \tstruct tr2tls_thread_ctx *ctx = tr2tls_get_self();\n-\tif (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {\n+\tif (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {\n \t\tstruct json_writer jw = JSON_WRITER_INIT;\n \t\tdouble t_abs = (double)us_elapsed_absolute / 1000000.0;\n \t\tdouble t_rel = (double)us_elapsed_region / 1000000.0;\ndiff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c\nindex 57f3e18f5b..1ce6f97863 100644\n--- a/trace2/tr2_tgt_normal.c\n+++ b/trace2/tr2_tgt_normal.c\n@@ -4,20 +4,20 @@\n #include \"quote.h\"\n #include \"version.h\"\n #include \"trace2/tr2_dst.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_normal = { \"GIT_TR2\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin normal target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_NORMAL_BRIEF \"GIT_TR2_BRIEF\"\n-static int tr2env_normal_brief;\n+static int tr2env_normal_be_brief;\n \n #define TR2FMT_NORMAL_FL_WIDTH (50)\n \n@@ -25,15 +25,15 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_normal);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n-\tbrief = getenv(TR2_ENVVAR_NORMAL_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_normal_brief = want_brief;\n+\t\ttr2env_normal_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf)\n {\n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_normal_brief) {\n+\tif (!tr2env_normal_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex 9c3b4d8a0f..328d2234bd 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -6,20 +6,20 @@\n #include \"json-writer.h\"\n #include \"trace2/tr2_dst.h\"\n #include \"trace2/tr2_sid.h\"\n+#include \"trace2/tr2_sysenv.h\"\n #include \"trace2/tr2_tbuf.h\"\n #include \"trace2/tr2_tgt.h\"\n #include \"trace2/tr2_tls.h\"\n \n-static struct tr2_dst tr2dst_perf = { \"GIT_TR2_PERF\", 0, 0, 0 };\n+static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 };\n \n /*\n- * Set this environment variable to true to omit the \"<time> <file>:<line>\"\n+ * Use TR2_SYSENV_PERF_BRIEF to omit the \"<time> <file>:<line>\"\n  * fields from each line written to the builtin performance target.\n  *\n  * Unit tests may want to use this to help with testing.\n  */\n-#define TR2_ENVVAR_PERF_BRIEF \"GIT_TR2_PERF_BRIEF\"\n-static int tr2env_perf_brief;\n+static int tr2env_perf_be_brief;\n \n #define TR2FMT_PERF_FL_WIDTH (50)\n #define TR2FMT_PERF_MAX_EVENT_NAME (12)\n@@ -36,17 +36,17 @@ static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_perf);\n \tint want_brief;\n-\tchar *brief;\n+\tconst char *brief;\n \n \tif (!want)\n \t\treturn want;\n \n \tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n \n-\tbrief = getenv(TR2_ENVVAR_PERF_BRIEF);\n+\tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n-\t\ttr2env_perf_brief = want_brief;\n+\t\ttr2env_perf_be_brief = want_brief;\n \n \treturn want;\n }\n@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,\n \n \tstrbuf_setlen(buf, 0);\n \n-\tif (!tr2env_perf_brief) {\n+\tif (!tr2env_perf_be_brief) {\n \t\tstruct tr2_tbuf tb_now;\n \n \t\ttr2_tbuf_local_time(&tb_now);\n-- \ngitgitgadget\n\n"},{"id":"374660","messageId":"18ce7953609f5d9d5165cb443138ebf7e3026795.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 11/11] trace2: fixup access problem on /etc/gitconfig in read_very_early_config","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:22Z","receivedAt":"2019-04-29T20:14:37Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach do_git_config_sequence() to optionally gently check for access to\nthe system config.  Use this option in read_very_early_config() when\ninitializing trace2.\n\nIn [1] SZEDER Gábor reported that my changes in [2] introduced a\nregression when the user does not have permission to read the system\nconfig.\n\nThis commit addresses that problem by optionally ignoring that error.\n\n[1] https://public-inbox.org/git/285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com/T/#m342e839289aec515523a98b5e34d7f42d3f1fd79\n[2] https://public-inbox.org/git/285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com/T/#m11b59c9228c698442f750ee8f9b10c629399ae48\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 5 ++++-\n config.h | 1 +\n 2 files changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/config.c b/config.c\nindex d7a08713a8..3f5ad9dc3c 100644\n--- a/config.c\n+++ b/config.c\n@@ -1676,7 +1676,9 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t\trepo_config = NULL;\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_SYSTEM;\n-\tif (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))\n+\tif (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK,\n+\t\t\t\t\t\t  opts->system_gently ?\n+\t\t\t\t\t\t  ACCESS_EACCES_OK : 0))\n \t\tret += git_config_from_file(fn, git_etc_gitconfig(),\n \t\t\t\t\t    data);\n \n@@ -1807,6 +1809,7 @@ void read_very_early_config(config_fn_t cb, void *data)\n \topts.ignore_repo = 1;\n \topts.ignore_worktree = 1;\n \topts.ignore_cmdline = 1;\n+\topts.system_gently = 1;\n \n \tconfig_with_options(cb, data, NULL, &opts);\n }\ndiff --git a/config.h b/config.h\nindex 6a58d61d22..36bb23a9d9 100644\n--- a/config.h\n+++ b/config.h\n@@ -58,6 +58,7 @@ struct config_options {\n \tunsigned int ignore_repo : 1;\n \tunsigned int ignore_worktree : 1;\n \tunsigned int ignore_cmdline : 1;\n+\tunsigned int system_gently : 1;\n \tconst char *commondir;\n \tconst char *git_dir;\n \tconfig_parser_event_fn_t event_fn;\n-- \ngitgitgadget\n"},{"id":"374661","messageId":"3414016d04fc1c457ba865822af561325ba0c753.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 10/11] trace2: update docs to describe system/global config settings","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:21Z","receivedAt":"2019-04-29T20:14:37Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n Documentation/config.txt               |   2 +\n Documentation/config/trace2.txt        |  56 +++++++++\n Documentation/technical/api-trace2.txt | 151 ++++++++++++++-----------\n Documentation/trace2-target-values.txt |  10 ++\n 4 files changed, 152 insertions(+), 67 deletions(-)\n create mode 100644 Documentation/config/trace2.txt\n create mode 100644 Documentation/trace2-target-values.txt\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d87846faa6..7e2a6f61f5 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -422,6 +422,8 @@ include::config/submodule.txt[]\n \n include::config/tag.txt[]\n \n+include::config/trace2.txt[]\n+\n include::config/transfer.txt[]\n \n include::config/uploadarchive.txt[]\ndiff --git a/Documentation/config/trace2.txt b/Documentation/config/trace2.txt\nnew file mode 100644\nindex 0000000000..a5f409c1c1\n--- /dev/null\n+++ b/Documentation/config/trace2.txt\n@@ -0,0 +1,56 @@\n+Trace2 config settings are only read from the system and global\n+config files; repository local and worktree config files and `-c`\n+command line arguments are not respected.\n+\n+trace2.normalTarget::\n+\tThis variable controls the normal target destination.\n+\tIt may be overridden by the `GIT_TR2` environment variable.\n+\tThe following table shows possible values.\n+\n+trace2.perfTarget::\n+\tThis variable controls the performance target destination.\n+\tIt may be overridden by the `GIT_TR2_PERF` environment variable.\n+\tThe following table shows possible values.\n+\n+trace2.eventTarget::\n+\tThis variable controls the event target destination.\n+\tIt may be overridden by the `GIT_TR2_EVENT` environment variable.\n+\tThe following table shows possible values.\n++\n+include::../trace2-target-values.txt[]\n+\n+trace2.normalBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from normal output.  May be overridden by the\n+\t`GIT_TR2_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.perfBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from PERF output.  May be overridden by the\n+\t`GIT_TR2_PERF_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.eventBrief::\n+\tBoolean.  When true `time`, `filename`, and `line` fields are\n+\tomitted from event output.  May be overridden by the\n+\t`GIT_TR2_EVENT_BRIEF` environment variable.  Defaults to false.\n+\n+trace2.eventNesting::\n+\tInteger.  Specifies desired depth of nested regions in the\n+\tevent output.  Regions deeper than this value will be\n+\tomitted.  May be overridden by the `GIT_TR2_EVENT_NESTING`\n+\tenvironment variable.  Defaults to 2.\n+\n+trace2.configParams::\n+\tA comma-separated list of patterns of \"important\" config\n+\tsettings that should be recorded in the trace2 output.\n+\tFor example, `core.*,remote.*.url` would cause the trace2\n+\toutput to contain events listing each configured remote.\n+\tMay be overridden by the `GIT_TR2_CONFIG_PARAMS` environment\n+\tvariable.  Unset by default.\n+\n+trace2.destinationDebug::\n+\tBoolean.  When true Git will print error messages when a\n+\ttrace target destination cannot be opened for writing.\n+\tBy default, these errors are suppressed and tracing is\n+\tsilently disabled.  May be overridden by the\n+\t`GIT_TR2_DST_DEBUG` environment variable.\ndiff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt\nindex 43adbf00eb..8b6a5e6d4b 100644\n--- a/Documentation/technical/api-trace2.txt\n+++ b/Documentation/technical/api-trace2.txt\n@@ -22,21 +22,41 @@ Targets are defined using a VTable allowing easy extension to other\n formats in the future.  This might be used to define a binary format,\n for example.\n \n+Trace2 is controlled using `trace2.*` config values in the system and\n+global config files and `GIT_TR2*` environment variables.  Trace2 does\n+not read from repo local or worktree config files or respect `-c`\n+command line config settings.\n+\n == Trace2 Targets\n \n Trace2 defines the following set of Trace2 Targets.\n Format details are given in a later section.\n \n-`GIT_TR2` (NORMAL)::\n+=== The Normal Format Target\n+\n+The normal format target is a tradition printf format and similar\n+to GIT_TRACE format.  This format is enabled with the `GIT_TR`\n+environment variable or the `trace2.normalTarget` system or global\n+config setting.\n+\n+For example\n \n-\ta simple printf format like GIT_TRACE.\n-+\n ------------\n $ export GIT_TR2=~/log.normal\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.normalTarget ~/log.normal\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.normal\n 12:28:42.620009 common-main.c:38                  version 2.20.1.155.g426c96fcdb\n@@ -46,17 +66,32 @@ $ cat ~/log.normal\n 12:28:42.621250 trace2/tr2_tgt_normal.c:124       atexit elapsed:0.001265 code:0\n ------------\n \n-`GIT_TR2_PERF` (PERF)::\n+=== The Performance Format Target\n+\n+The performance format target (PERF) is a column-based format to\n+replace GIT_TRACE_PERFORMANCE and is suitable for development and\n+testing, possibly to complement tools like gprof.  This format is\n+enabled with the `GIT_TR2_PERF` environment variable or the\n+`trace2.perfTarget` system or global config setting.\n+\n+For example\n \n-\ta column-based format to replace GIT_TRACE_PERFORMANCE suitable for\n-\tdevelopment and testing, possibly to complement tools like gprof.\n-+\n ------------\n $ export GIT_TR2_PERF=~/log.perf\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n+\n+or\n+\n+------------\n+$ git config --global trace2.perfTarget ~/log.perf\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n+\n+yields\n+\n ------------\n $ cat ~/log.perf\n 12:28:42.620675 common-main.c:38                  | d0 | main                     | version      |     |           |           |            | 2.20.1.155.g426c96fcdb\n@@ -66,56 +101,46 @@ $ cat ~/log.perf\n 12:28:42.621259 trace2/tr2_tgt_perf.c:211         | d0 | main                     | atexit       |     |  0.001265 |           |            | code:0\n ------------\n \n-`GIT_TR2_EVENT` (EVENT)::\n+=== The Event Format Target\n+\n+The event format target is a JSON-based format of event data suitable\n+for telemetry analysis.  This format is enabled with the `GIT_TR2_EVENT`\n+environment variable or the `trace2.eventTarget` system or global config\n+setting.\n+\n+For example\n \n-\ta JSON-based format of event data suitable for telemetry analysis.\n-+\n ------------\n $ export GIT_TR2_EVENT=~/log.event\n $ git version\n git version 2.20.1.155.g426c96fcdb\n ------------\n-+\n-------------\n-$ cat ~/log.event\n-{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n-{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n-{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n-{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n-{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P028492\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n-------------\n-\n-== Enabling a Target\n-\n-A Trace2 Target is enabled when the corresponding environment variable\n-(`GIT_TR2`, `GIT_TR2_PERF`, or `GIT_TR2_EVENT`) is set.  The following\n-values are recognized.\n-\n-`0`::\n-`false`::\n-\n-\tDisables the target.\n \n-`1`::\n-`true`::\n+or\n \n-\tEnables the target and writes stream to `STDERR`.\n-\n-`[2-9]`::\n+------------\n+$ git config --global trace2.eventTarget ~/log.event\n+$ git version\n+git version 2.20.1.155.g426c96fcdb\n+------------\n \n-\tEnables the target and writes to the already opened file descriptor.\n+yields\n \n-`<absolute-pathname>`::\n+------------\n+$ cat ~/log.event\n+{\"event\":\"version\",\"sid\":\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.620713Z\",\"file\":\"common-main.c\",\"line\":38,\"evt\":\"1\",\"exe\":\"2.20.1.155.g426c96fcdb\"}\n+{\"event\":\"start\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621027Z\",\"file\":\"common-main.c\",\"line\":39,\"t_abs\":0.001173,\"argv\":[\"git\",\"version\"]}\n+{\"event\":\"cmd_name\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621122Z\",\"file\":\"git.c\",\"line\":432,\"name\":\"version\",\"hierarchy\":\"version\"}\n+{\"event\":\"exit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621236Z\",\"file\":\"git.c\",\"line\":662,\"t_abs\":0.001227,\"code\":0}\n+{\"event\":\"atexit\",\"sid\":\"20190408T191610.507018Z-H9b68c35f-P000059a8\",\"thread\":\"main\",\"time\":\"2019-01-16T17:28:42.621268Z\",\"file\":\"trace2/tr2_tgt_event.c\",\"line\":163,\"t_abs\":0.001265,\"code\":0}\n+------------\n \n-\tEnables the target, opens and writes to the file in append mode.\n+=== Enabling a Target\n \n-`af_unix:[<socket_type>:]<absolute-pathname>`::\n+To enable a target, set the corresponding environment variable or\n+system or global config value to one of the following:\n \n-\tEnables the target, opens and writes to a Unix Domain Socket\n-\t(on platforms that support them).\n-+\n-Socket type can be either `stream` or `dgram`.  If the socket type is\n-omitted, Git will try both.\n+include::../trace2-target-values.txt[]\n \n == Trace2 API\n \n@@ -243,15 +268,16 @@ significantly affects program performance or behavior, such as\n \tEmits a \"def_param\" messages for \"important\" configuration\n \tsettings.\n +\n-The environment variable `GIT_TR2_CONFIG_PARAMS` can be set to a\n+The environment variable `GIT_TR2_CONFIG_PARAMS` or the `trace2.configParams`\n+config value can be set to a\n list of patterns of important configuration settings, for example:\n `core.*,remote.*.url`.  This function will iterate over all config\n settings and emit a \"def_param\" message for each match.\n \n `void trace2_cmd_set_config(const char *key, const char *value)`::\n \n-\tEmits a \"def_param\" message for a specific configuration\n-\tsetting IFF it matches the `GIT_TR2_CONFIG_PARAMS` pattern.\n+\tEmits a \"def_param\" message for a new or updated key/value\n+\tpair IF `key` is considered important.\n +\n This is used to hook into `git_config_set()` and catch any\n configuration changes and update a value previously reported by\n@@ -418,9 +444,6 @@ recursive tree walk.\n \n === NORMAL Format\n \n-NORMAL format is enabled when the `GIT_TR2` environment variable is\n-set.\n-\n Events are written as lines of the form:\n \n ------------\n@@ -437,8 +460,8 @@ Events are written as lines of the form:\n Note that this may contain embedded LF or CRLF characters that are\n not escaped, so the event may spill across multiple lines.\n \n-If `GIT_TR2_BRIEF` is true, the `time`, `filename`, and `line` fields\n-are omitted.\n+If `GIT_TR2_BRIEF` or `trace2.normalBrief` is true, the `time`, `filename`,\n+and `line` fields are omitted.\n \n This target is intended to be more of a summary (like GIT_TRACE) and\n less detailed than the other targets.  It ignores thread, region, and\n@@ -446,9 +469,6 @@ data messages, for example.\n \n === PERF Format\n \n-PERF format is enabled when the `GIT_TR2_PERF` environment variable\n-is set.\n-\n Events are written as lines of the form:\n \n ------------\n@@ -508,8 +528,8 @@ This field is in anticipation of in-proc submodules in the future.\n 15:33:33.532712 wt-status.c:2331                  | d0 | main                     | region_leave | r1  |  0.127568 |  0.001504 | status     | label:print\n ------------\n \n-If `GIT_TR2_PERF_BRIEF` is true, the `time`, `file`, and `line`\n-fields are omitted.\n+If `GIT_TR2_PERF_BRIEF` or `trace2.perfBrief` is true, the `time`, `file`,\n+and `line` fields are omitted.\n \n ------------\n d0 | main                     | region_leave | r1  |  0.011717 |  0.009122 | index      | label:preload\n@@ -520,9 +540,6 @@ during development and is quite noisy.\n \n === EVENT Format\n \n-EVENT format is enabled when the `GIT_TR2_EVENT` environment\n-variable is set.\n-\n Each event is a JSON-object containing multiple key/value pairs\n written as a single line and followed by a LF.\n \n@@ -540,7 +557,7 @@ The following key/value pairs are common to all events:\n ------------\n {\n \t\"event\":\"version\",\n-\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P011764\",\n+\t\"sid\":\"20190408T191827.272759Z-H9b68c35f-P00003510\",\n \t\"thread\":\"main\",\n \t\"time\":\"2019-04-08T19:18:27.282761Z\",\n \t\"file\":\"common-main.c\",\n@@ -576,9 +593,9 @@ The following key/value pairs are common to all events:\n `\"repo\":<repo-id>`::\n \twhen present, is the integer repo-id as described previously.\n \n-If `GIT_TR2_EVENT_BRIEF` is true, the `file` and `line` fields are omitted\n-from all events and the `time` field is only present on the \"start\" and\n-\"atexit\" events.\n+If `GIT_TR2_EVENT_BRIEF` or `trace2.eventBrief` is true, the `file`\n+and `line` fields are omitted from all events and the `time` field is\n+only present on the \"start\" and \"atexit\" events.\n \n ==== Event-Specific Key/Value Pairs\n \n@@ -889,7 +906,7 @@ visited.\n The `category` field may be used in a future enhancement to\n do category-based filtering.\n +\n-The `GIT_TR2_EVENT_NESTING` environment variable can be used to\n+`GIT_TR2_EVENT_NESTING` or `trace2.eventNesting` can be used to\n filter deeply nested regions and data events.  It defaults to \"2\".\n \n `\"region_leave\"`::\ndiff --git a/Documentation/trace2-target-values.txt b/Documentation/trace2-target-values.txt\nnew file mode 100644\nindex 0000000000..27d3c64e66\n--- /dev/null\n+++ b/Documentation/trace2-target-values.txt\n@@ -0,0 +1,10 @@\n+--\n+* `0` or `false` - Disables the target.\n+* `1` or `true` - Writes to `STDERR`.\n+* `[2-9]` - Writes to the already opened file descriptor.\n+* `<absolute-pathname>` - Writes to the file in append mode.\n+* `af_unix:[<socket_type>:]<absolute-pathname>` - Write to a\n+Unix DomainSocket (on platforms that support them).  Socket\n+type can be either `stream` or `dgram`; if omitted Git will\n+try both.\n+--\n-- \ngitgitgadget\n\n"},{"id":"374662","messageId":"b0fe1385f1a96efbcab38fe02a3d5b3c1b6eaa37.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 05/11] config: add read_very_early_config()","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:17Z","receivedAt":"2019-04-29T20:14:38Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nCreated an even lighter version of read_early_config() that\nonly looks at system and global config settings.  It omits\nrepo-local, worktree-local, and command-line settings.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n config.c | 23 ++++++++++++++++++++---\n config.h |  4 ++++\n 2 files changed, 24 insertions(+), 3 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex c809f76219..d7a08713a8 100644\n--- a/config.c\n+++ b/config.c\n@@ -1688,14 +1688,15 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t\tret += git_config_from_file(fn, user_config, data);\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_REPO;\n-\tif (repo_config && !access_or_die(repo_config, R_OK, 0))\n+\tif (!opts->ignore_repo && repo_config &&\n+\t    !access_or_die(repo_config, R_OK, 0))\n \t\tret += git_config_from_file(fn, repo_config, data);\n \n \t/*\n \t * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.\n \t * But let's not complicate things before it's actually needed.\n \t */\n-\tif (repository_format_worktree_config) {\n+\tif (!opts->ignore_worktree && repository_format_worktree_config) {\n \t\tchar *path = git_pathdup(\"config.worktree\");\n \t\tif (!access_or_die(path, R_OK, 0))\n \t\t\tret += git_config_from_file(fn, path, data);\n@@ -1703,7 +1704,7 @@ static int do_git_config_sequence(const struct config_options *opts,\n \t}\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_CMDLINE;\n-\tif (git_config_from_parameters(fn, data) < 0)\n+\tif (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)\n \t\tdie(_(\"unable to parse command-line config\"));\n \n \tcurrent_parsing_scope = CONFIG_SCOPE_UNKNOWN;\n@@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data)\n \tstrbuf_release(&gitdir);\n }\n \n+/*\n+ * Read config but only enumerate system and global settings.\n+ * Omit any repo-local, worktree-local, or command-line settings.\n+ */\n+void read_very_early_config(config_fn_t cb, void *data)\n+{\n+\tstruct config_options opts = { 0 };\n+\n+\topts.respect_includes = 1;\n+\topts.ignore_repo = 1;\n+\topts.ignore_worktree = 1;\n+\topts.ignore_cmdline = 1;\n+\n+\tconfig_with_options(cb, data, NULL, &opts);\n+}\n+\n static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)\n {\n \tstruct config_set_element k;\ndiff --git a/config.h b/config.h\nindex ee5d3fa7b4..6a58d61d22 100644\n--- a/config.h\n+++ b/config.h\n@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,\n \n struct config_options {\n \tunsigned int respect_includes : 1;\n+\tunsigned int ignore_repo : 1;\n+\tunsigned int ignore_worktree : 1;\n+\tunsigned int ignore_cmdline : 1;\n \tconst char *commondir;\n \tconst char *git_dir;\n \tconfig_parser_event_fn_t event_fn;\n@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,\n extern void git_config_push_parameter(const char *text);\n extern int git_config_from_parameters(config_fn_t fn, void *data);\n extern void read_early_config(config_fn_t cb, void *data);\n+extern void read_very_early_config(config_fn_t cb, void *data);\n extern void git_config(config_fn_t fn, void *);\n extern int config_with_options(config_fn_t fn, void *,\n \t\t\t       struct git_config_source *config_source,\n-- \ngitgitgadget\n\n"},{"id":"374663","messageId":"94729b284c4338aa40d4287eea909e835820ff4b.1556568852.git.gitgitgadget@gmail.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"[PATCH v5 04/11] trace2: find exec-dir before trace2 initialization","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-04-29T20:14:16Z","receivedAt":"2019-04-29T20:14:39Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach Git to resolve the executable directory before initializing\nTrace2.  This allows the system configuration directory to be\ndiscovered earlier (because it is sometimes relative to the prefix\nor runtime-prefix).\n\nThis will be used by the next commit to allow trace2 settings to\nbe loaded from the system config.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n common-main.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/common-main.c b/common-main.c\nindex 6137af0e63..299ca62a72 100644\n--- a/common-main.c\n+++ b/common-main.c\n@@ -37,12 +37,12 @@ int main(int argc, const char **argv)\n \tsanitize_stdfds();\n \trestore_sigpipe_to_default();\n \n+\tgit_resolve_executable_dir(argv[0]);\n+\n \ttrace2_initialize();\n \ttrace2_cmd_start(argv);\n \ttrace2_collect_process_info();\n \n-\tgit_resolve_executable_dir(argv[0]);\n-\n \tgit_setup_gettext();\n \n \tinitialize_the_repository();\n-- \ngitgitgadget\n\n"},{"id":"374664","messageId":"da481a55-a363-9eb9-6cde-59468f18947d@jeffhostetler.com","threadId":"50834","inReplyTo":"pull.169.v5.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v5 00/11] trace2: load trace2 settings from system config","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-04-29T20:21:59Z","receivedAt":"2019-04-29T20:22:04Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\nI forgot to update the cover letter for V5.\nV5 adds a commit to fix the permission problem in /etc/gitconfig\nreported by SZEDER.\n\nThis commit could/should be squashed into commit 5 if wanted.\nI left it on top for review purposes.\n\nJeff\n\n\nOn 4/29/2019 4:14 PM, Jeff Hostetler via GitGitGadget wrote:\n> Version 4 fixes a few clang-format warnings and simplifies the PID field in\n> the SID.\n> \n> Jeff Hostetler (11):\n>    config: initialize opts structure in repo_read_config()\n>    trace2: refactor setting process starting time\n>    trace2: add absolute elapsed time to start event\n>    trace2: find exec-dir before trace2 initialization\n>    config: add read_very_early_config()\n>    trace2: use system/global config for default trace2 settings\n>    trace2: report peak memory usage of the process\n>    trace2: clarify UTC datetime formatting\n>    trace2: make SIDs more unique\n>    trace2: update docs to describe system/global config settings\n>    trace2: fixup access problem on /etc/gitconfig in\n>      read_very_early_config\n> \n>   Documentation/config.txt                 |   2 +\n>   Documentation/config/trace2.txt          |  56 ++++++++\n>   Documentation/technical/api-trace2.txt   | 176 +++++++++++++----------\n>   Documentation/trace2-target-values.txt   |  10 ++\n>   Makefile                                 |   1 +\n>   common-main.c                            |   8 +-\n>   compat/mingw.c                           |   2 +\n>   compat/win32/trace2_win32_process_info.c |  50 ++++++-\n>   config.c                                 |  30 +++-\n>   config.h                                 |   5 +\n>   t/t0210-trace2-normal.sh                 |  49 ++++++-\n>   t/t0211-trace2-perf.sh                   |  43 ++++--\n>   t/t0212-trace2-event.sh                  |  42 +++++-\n>   trace2.c                                 |  21 ++-\n>   trace2.h                                 |  43 ++++--\n>   trace2/tr2_cfg.c                         |   7 +-\n>   trace2/tr2_dst.c                         |  26 ++--\n>   trace2/tr2_dst.h                         |   3 +-\n>   trace2/tr2_sid.c                         |  53 ++++++-\n>   trace2/tr2_sysenv.c                      | 127 ++++++++++++++++\n>   trace2/tr2_sysenv.h                      |  36 +++++\n>   trace2/tr2_tbuf.c                        |  19 ++-\n>   trace2/tr2_tbuf.h                        |   5 +-\n>   trace2/tr2_tgt.h                         |   1 +\n>   trace2/tr2_tgt_event.c                   |  53 +++----\n>   trace2/tr2_tgt_normal.c                  |  19 +--\n>   trace2/tr2_tgt_perf.c                    |  23 +--\n>   trace2/tr2_tls.c                         |  38 +++--\n>   trace2/tr2_tls.h                         |   8 +-\n>   29 files changed, 752 insertions(+), 204 deletions(-)\n>   create mode 100644 Documentation/config/trace2.txt\n>   create mode 100644 Documentation/trace2-target-values.txt\n>   create mode 100644 trace2/tr2_sysenv.c\n>   create mode 100644 trace2/tr2_sysenv.h\n> \n> \n> base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v5\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v5\n> Pull-Request: https://github.com/gitgitgadget/git/pull/169\n> \n> Range-diff vs v4:\n> \n>    1:  f6653f1c59 =  1:  f6653f1c59 config: initialize opts structure in repo_read_config()\n>    2:  48e34834b6 =  2:  48e34834b6 trace2: refactor setting process starting time\n>    3:  175371fb54 =  3:  175371fb54 trace2: add absolute elapsed time to start event\n>    4:  94729b284c =  4:  94729b284c trace2: find exec-dir before trace2 initialization\n>    5:  b0fe1385f1 =  5:  b0fe1385f1 config: add read_very_early_config()\n>    6:  550cad6189 =  6:  550cad6189 trace2: use system/global config for default trace2 settings\n>    7:  56d8ce3fd6 =  7:  56d8ce3fd6 trace2: report peak memory usage of the process\n>    8:  196a9d2c85 =  8:  196a9d2c85 trace2: clarify UTC datetime formatting\n>    9:  9fdcb50140 =  9:  9fdcb50140 trace2: make SIDs more unique\n>   10:  3414016d04 = 10:  3414016d04 trace2: update docs to describe system/global config settings\n>    -:  ---------- > 11:  18ce795360 trace2: fixup access problem on /etc/gitconfig in read_very_early_config\n> \n"},{"id":"374972","messageId":"xmqqftprrrjh.fsf@gitster-ct.c.googlers.com","threadId":"50834","inReplyTo":"da481a55-a363-9eb9-6cde-59468f18947d@jeffhostetler.com","subject":"Re: [PATCH v5 00/11] trace2: load trace2 settings from system config","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-05-07T01:18:10Z","receivedAt":"2019-05-07T01:18:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff Hostetler <git@jeffhostetler.com> writes:\n\n> I forgot to update the cover letter for V5.\n> V5 adds a commit to fix the permission problem in /etc/gitconfig\n> reported by SZEDER.\n>\n> This commit could/should be squashed into commit 5 if wanted.\n> I left it on top for review purposes.\n\nI think v4 has been in 'next' for several days already, so an\nincremental update like PATCH 11/11 is good.  The first 10 patches\nare identical to the previous round, so all is good ;-)\n"}]}