trace2: load trace2 settings from system config
Subsystems (2)
cover trace2: load trace2 settings from system config
Teach git to load default Trace2 settings from the system config (usually "/etc/gitconfig"). The existing GIT_TR2_* environment variables can be used to override the new system defaults. It also includes a little startup refactoring.
Note: I found interactive testing of this feature to be awkward on some platforms because of the use of prefix- or runtime-prefix-relative locations for the system configuration. It was easy to accidentally use an officially installed version of git to set a system config variable in the official system config directory; and then when testing with the test version of git, that value would not be seen because it was looking for the system config file in a different directory.
Jeff Hostetler (4):
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
trace2: use system config for default trace2 settings
Documentation/technical/api-trace2.txt | 54 +++++++++-- Makefile | 1 + common-main.c | 6 +- compat/mingw.c | 2 + t/t0210-trace2-normal.sh | 41 +++++++- t/t0211-trace2-perf.sh | 53 ++++++++--- t/t0212-trace2-event.sh | 52 +++++++++- trace2.c | 19 +++- trace2.h | 24 ++++- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++--- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 125 +++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++ trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 24 ++--- trace2/tr2_tgt_normal.c | 13 +-- trace2/tr2_tgt_perf.c | 17 ++-- trace2/tr2_tls.c | 38 +++++--- trace2/tr2_tls.h | 8 +- 20 files changed, 455 insertions(+), 93 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/169
Signature · 1 line
gitgitgadget
PATCH 1/4 trace2: refactor setting process starting time
From: Jeff Hostetler <[email protected]>
Create trace2_initialize_clock() and call from main() to capture process start time in isolation and before other sub-systems are ready.
--- Documentation/technical/api-trace2.txt | 12 ++++++-- common-main.c | 2 ++ compat/mingw.c | 2 ++ trace2.c | 7 ++++- trace2.h | 17 ++++++++++++ trace2/tr2_tls.c | 38 ++++++++++++++++---------- trace2/tr2_tls.h | 8 +++++- 7 files changed, 67 insertions(+), 19 deletions(-)
Documentation/technical/api-trace2.txt +9 -3
@@ -160,17 +160,23 @@ purposes. These are concerned with the lifetime of the overall git process. +`void trace2_initialize_clock()`:: + + Initialize the Trace2 start clock and nothing else. This should + be called at the very top of main() to capture the process start + time and reduce startup order dependencies. + `void trace2_initialize()`:: Determines if any Trace2 Targets should be enabled and - initializes the Trace2 facility. This includes starting the - elapsed time clocks and thread local storage (TLS). + initializes the Trace2 facility. This includes setting up the + Trace2 thread local storage (TLS). + This function emits a "version" message containing the version of git and the Trace2 protocol. + This function should be called from `main()` as early as possible in -the life of the process. +the life of the process after essential process initialization. `int trace2_is_enabled()`::
common-main.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, const char **argv) {int result; +trace2_initialize_clock (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed
compat/mingw.c +2 -0
@@ -2569,6 +2569,8 @@ void mingw_startup(void)wchar_t **wenv, **wargv;_startupinfo si; +trace2_initialize_clock (); +maybe_redirect_std_handles ();/* get wide char arguments and environment */
trace2.c +6 -1
@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)raise (signo); } +void trace2_initialize_clock (void ) +{ +tr2tls_start_process_clock (); +} +void trace2_initialize_fl (const char *file,int line) {struct tr2_tgt *tgt_j;
@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name) us_now =getnanotime () /1000 ; us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); -tr2tls_create_self (thread_name); +tr2tls_create_self (thread_name, us_now);for_each_wanted_builtin (j, tgt_j) if (tgt_j->pfn_thread_start_fl)
trace2.h +17 -0
@@ -19,6 +19,23 @@ struct json_writer;* [] trace2_printf* -- legacy trace[1] messages. */ +/* +* Initialize the TRACE2 clock and do nothing else, in particular +* no mallocs, no system inspection, and no environment inspection. +* +* This should be called at the very top of main() to capture the +* process start time. This is intended to reduce chicken-n-egg +* bootstrap pressure. +* +* It is safe to call this more than once. This allows capturing +* absolute startup costs on Windows which uses a little trickery +* to do setup work before common-main.c:main() is called. +* +* The main trace2_initialize_fl() may be called a little later +* after more infrastructure is established. +*/ +void trace2_initialize_clock (void ); +/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 * targets are enabled in the environment. Emits a 'version' event.
trace2/tr2_tls.c +24 -14
@@ -10,16 +10,30 @@#define TR2_REGION_NESTING_INITIAL_SIZE (100)static struct tr2tls_thread_ctx *tr2tls_thread_main; -static uint64_t tr2tls_us_start_main; +static uint64_t tr2tls_us_start_process;static pthread_mutex_t tr2tls_mutex;static pthread_key_t tr2tls_key;static int tr2_next_thread_id;/* modify under lock */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name) +void tr2tls_start_process_clock (void ) +{ +if (tr2tls_us_start_process) +return ; + +/* +* Keep the absolute start time of the process (i.e. the main +* process) in a fixed variable since other threads need to +* access it. This allows them to do that without a lock on +* main thread's array data (because of reallocs). +*/ + tr2tls_us_start_process =getnanotime () /1000 ; +} + +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start) { -uint64_t us_now =getnanotime () /1000 ;struct tr2tls_thread_ctx *ctx =xcalloc (1 ,sizeof (*ctx));/*
@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)*/ ctx->alloc =TR2_REGION_NESTING_INITIAL_SIZE ; ctx->array_us_start = (uint64_t *)xcalloc (ctx->alloc,sizeof (uint64_t )); - ctx->array_us_start[ctx->nr_open_regions++] = us_now; + ctx->array_us_start[ctx->nr_open_regions++] = us_thread_start; ctx->thread_id =tr2tls_locked_increment (&tr2_next_thread_id);
@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)* here and silently continue. */ if (!ctx) - ctx =tr2tls_create_self ("unknown" ); + ctx =tr2tls_create_self ("unknown" ,getnanotime () /1000 );return ctx; }
@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)if (!tr2tls_thread_main)return 0 ; -return us - tr2tls_us_start_main; +return us - tr2tls_us_start_process; }void tr2tls_init (void ) { +tr2tls_start_process_clock (); +pthread_key_create (&tr2tls_key,NULL );init_recursive_mutex (&tr2tls_mutex); - tr2tls_thread_main =tr2tls_create_self ("main" ); -/* -* Keep a copy of the absolute start time of the main thread -* in a fixed variable since other threads need to access it. -* This also eliminates the need to lock accesses to the main -* thread's array (because of reallocs). -*/ - tr2tls_us_start_main = tr2tls_thread_main->array_us_start[0 ]; + tr2tls_thread_main =tr2tls_create_self ("main" , + tr2tls_us_start_process); }void tr2tls_release (void )
trace2/tr2_tls.h +7 -1
@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {* In this and all following functions the term "self" refers to the * current thread. */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name); +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start);/* * Get our TLS data.
@@ -94,4 +95,9 @@ void tr2tls_release(void);*/ int tr2tls_locked_increment (int *p); +/* +* Capture the process start time and do nothing else. +*/ +void tr2tls_start_process_clock (void ); +#endif /* TR2_TLS_H */
Signature · 1 line
gitgitgadget
PATCH 2/4 trace2: add absolute elapsed time to start event
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Add elapsed process time to "start" event to measure the performance of early process startup.
--- Documentation/technical/api-trace2.txt | 11 ++++++----- t/t0211-trace2-perf.sh | 12 ++++++------ trace2.c | 8 +++++++- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 5 ++++- trace2/tr2_tgt_normal.c | 3 ++- trace2/tr2_tgt_perf.c | 7 ++++--- 7 files changed, 30 insertions(+), 17 deletions(-)
Documentation/technical/api-trace2.txt +6 -5
@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.perf 12:28:42.620675 common-main.c:38 | d0 | main | version | | | | | 2.20.1.155.g426c96fcdb -12:28:42.621001 common-main.c:39 | d0 | main | start | | | | | git version +12:28:42.621001 common-main.c:39 | d0 | main | start | | 0.001173 | | | git version 12:28:42.621111 git.c:432 | d0 | main | cmd_name | | | | | version (version) 12:28:42.621225 git.c:662 | d0 | main | exit | | 0.001227 | | | code:0 12:28:42.621259 trace2/tr2_tgt_perf.c:211 | d0 | main | atexit | | 0.001265 | | | code:0
@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.event {"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"} -{"event":"start","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16 17:28:42.621027","file":"common-main.c","line":39,"argv":["git","version"]} +{"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"]} {"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"} {"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} {"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}
@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the "start" and { "event":"start", ... + "t_abs":0.001227, # elapsed time in seconds "argv":["git","version"] } ------------
@@ -1118,7 +1119,7 @@ $ git status $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.160.g5676107ecd.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1163,7 +1164,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.162.gb4ccea44db.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1219,7 +1220,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.156.gf9916ae094.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) d0 | main | region_enter | r1 | 0.001791 | | index | label:do_read_index .git/index
t/t0211-trace2-perf.sh +6 -6
@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:0 d0|main|atexit||_T_ABS_|||code:0
@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 1 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:1 d0|main|atexit||_T_ABS_|||code:1
@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' + d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' d0|main|cmd_name|||||trace2 (trace2) d0|main|error|||||hello world d0|main|error|||||this is a test
@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0 d1|main|version|||||$V - d1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0 + d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0 d1|main|cmd_name|||||trace2 (trace2/trace2) d1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0 d2|main|version|||||$V - d2|main|start|||||_EXE_ trace2 001return 0 + d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d2|main|cmd_name|||||trace2 (trace2/trace2/trace2) d2|main|exit||_T_ABS_|||code:0 d2|main|atexit||_T_ABS_|||code:0
trace2.c +7 -1
@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv) {struct tr2_tgt *tgt_j;int j; +uint64_t us_now; +uint64_t us_elapsed_absolute;if (!trace2_enabled)return ; + us_now =getnanotime () /1000 ; + us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); + for_each_wanted_builtin (j, tgt_j)if (tgt_j->pfn_start_fl) - tgt_j->pfn_start_fl (file, line, argv); + tgt_j->pfn_start_fl (file, line, us_elapsed_absolute, + argv); }int trace2_cmd_exit_fl (const char *file,int line,int code)
trace2/tr2_tgt.h +1 -0
@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);typedef void (tr2_tgt_evt_version_fl_t )(const char *file,int line);typedef void (tr2_tgt_evt_start_fl_t )(const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv);typedef void (tr2_tgt_evt_exit_fl_t )(const char *file,int line,uint64_t us_elapsed_absolute,int code);
trace2/tr2_tgt_event.c +4 -1
@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)jw_release (&jw); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct json_writer jw =JSON_WRITER_INIT ; +double t_abs = (double )us_elapsed_absolute /1000000.0 ;jw_object_begin (&jw,0 );event_fmt_prepare (event_name, file, line,NULL , &jw); +jw_object_double (&jw,"t_abs" ,6 , t_abs);jw_object_inline_begin_array (&jw,"argv" );jw_array_argv (&jw, argv);jw_end (&jw);
trace2/tr2_tgt_normal.c +2 -1
@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {struct strbuf buf_payload =STRBUF_INIT ;
trace2/tr2_tgt_perf.c +4 -3
@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct strbuf buf_payload =STRBUF_INIT ;sq_quote_argv_pretty (&buf_payload, argv); -perf_io_write_fl (file, line, event_name,NULL ,NULL ,NULL ,NULL , - &buf_payload); +perf_io_write_fl (file, line, event_name,NULL , &us_elapsed_absolute, +NULL ,NULL , &buf_payload);strbuf_release (&buf_payload); }
Signature · 1 line
gitgitgadget
PATCH 3/4 trace2: find exec-dir before trace2 initialization
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Git to resolve the executable directory before initializing Trace2. This allows the system configuration directory to be discovered earlier (because it is sometimes relative to the prefix or runtime-prefix).
This will be used by the next commit to allow trace2 settings to be loaded from the system config.
--- common-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common-main.c +2 -2
@@ -37,12 +37,12 @@ int main(int argc, const char **argv)sanitize_stdfds ();restore_sigpipe_to_default (); +git_resolve_executable_dir (argv[0 ]); +trace2_initialize ();trace2_cmd_start (argv);trace2_collect_process_info (); -git_resolve_executable_dir (argv[0 ]); -git_setup_gettext ();initialize_the_repository ();
Signature · 1 line
gitgitgadget
PATCH 4/4 trace2: use system config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach git to read the system config (usually "/etc/gitconfig") for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system config file is used. Trace2 config values are ignored in local, global, and other config files. Likewise, the "-c" command line arguments are ignored for Trace2 values. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
Added the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing purposes to specify the pathname of a fake "system" config or disable use of the system config.
--- Documentation/technical/api-trace2.txt | 31 ++++++ Makefile | 1 + t/t0210-trace2-normal.sh | 41 +++++++- t/t0211-trace2-perf.sh | 41 +++++++- t/t0212-trace2-event.sh | 52 +++++++++- trace2.c | 4 + trace2.h | 7 +- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++--- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 125 +++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++ trace2/tr2_tgt_event.c | 19 ++-- trace2/tr2_tgt_normal.c | 10 +- trace2/tr2_tgt_perf.c | 10 +- 15 files changed, 356 insertions(+), 55 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
Documentation/technical/api-trace2.txt +31 -0
@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is omitted, Git will try both. +== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings. + +Trace2 will try to load the following system configuration settings +and then read the corresponding environment variables at startup. + +.... +--------------------------------------------------- +trace2.normalTarget GIT_TR2 +trace2.normalBrief GIT_TR2_BRIEF + +trace2.perfTarget GIT_TR2_PERF +trace2.perfBrief GIT_TR2_PERF_BRIEF + +trace2.eventTarget GIT_TR2_EVENT +trace2.eventBrief GIT_TR2_EVENT_BRIEF +trace2.eventNesting GIT_TR2_EVENT_NESTING + +trace2.configParams GIT_TR2_CONFIG_PARAMS + +trace2.destinationDebug GIT_TR2_DST_DEBUG +--------------------------------------------------- +.... + + == Trace2 API All public Trace2 functions and macros are defined in `trace2.h` and
Makefile +1 -0
@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o LIB_OBJS += trace2/tr2_cmd_name.o LIB_OBJS += trace2/tr2_dst.o LIB_OBJS += trace2/tr2_sid.o +LIB_OBJS += trace2/tr2_sysenv.o LIB_OBJS += trace2/tr2_tbuf.o LIB_OBJS += trace2/tr2_tgt_event.o LIB_OBJS += trace2/tr2_tgt_normal.o
t/t0210-trace2-normal.sh +36 -5
56 lines not on this page · raw message
t/t0211-trace2-perf.sh +36 -5
56 lines not on this page · raw message
t/t0212-trace2-event.sh +47 -5
67 lines not on this page · raw message
trace2.c +4 -0
@@ -10,6 +10,7 @@#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h"
@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)tr2_sid_release ();tr2_cmd_name_release ();tr2_cfg_free_patterns (); +tr2_sysenv_release (); trace2_enabled =0 ; }
@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)if (trace2_enabled)return ; +tr2_sysenv_load (); +if (!tr2_tgt_want_builtins ())return ; trace2_enabled =1 ;
trace2.h +4 -3
@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine.
@@ -125,8 +126,8 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: +* Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns +* configured important. For example: * * GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" *
trace2/tr2_cfg.c +3 -4
@@ -1,8 +1,7 @@#include "cache.h" #include "config.h" -#include "tr2_cfg.h" - -#define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS" +#include "trace2/tr2_cfg.h" +#include "trace2/tr2_sysenv.h" static struct strbuf **tr2_cfg_patterns;static int tr2_cfg_count_patterns;
@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)return tr2_cfg_count_patterns; tr2_cfg_loaded =1 ; - envvar =getenv (TR2_ENVVAR_CFG_PARAM ); + envvar =tr2_sysenv_get (TR2_SYSENV_CFG_PARAM );if (!envvar || !*envvar)return tr2_cfg_count_patterns;
trace2/tr2_dst.c +12 -12
@@ -1,5 +1,6 @@#include "cache.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" /* * If a Trace2 target cannot be opened for writing, we should issue a
@@ -7,17 +8,13 @@* or socket and beyond the user's control -- especially since every * git command (and sub-command) will print the message. So we silently * eat these warnings and just discard the trace data. -* -* Enable the following environment variable to see these warnings. */ -#define TR2_ENVVAR_DST_DEBUG "GIT_TR2_DST_DEBUG" -static int tr2_dst_want_warning (void ) {static int tr2env_dst_debug =-1 ;if (tr2env_dst_debug ==-1 ) { -const char *env_value =getenv (TR2_ENVVAR_DST_DEBUG ); +const char *env_value =tr2_sysenv_get (TR2_SYSENV_DST_DEBUG );if (!env_value || !*env_value) tr2env_dst_debug =0 ;else
@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)if (fd ==-1 ) {if (tr2_dst_want_warning ())warning ("trace2: could not open '%s' for '%s' tracing: %s" , - tgt_value, dst->env_var_name,strerror (errno)); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var), +strerror (errno));tr2_dst_trace_disable (dst);return 0 ;
@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,if (!path || !*path) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX value '%s' for '%s' tracing" , - tgt_value, dst->env_var_name); + tgt_value,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX path '%s' for '%s' tracing" , - path, dst->env_var_name); + path,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, error:if (tr2_dst_want_warning ())warning ("trace2: could not connect to socket '%s' for '%s' tracing: %s" , - path, dst->env_var_name,strerror (e)); + path,tr2_sysenv_display_name (dst->sysenv_var),strerror (e));tr2_dst_trace_disable (dst);return 0 ;
@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"trace2: unknown value for '%s': '%s'" , - dst->env_var_name, tgt_value); +tr2_sysenv_display_name (dst->sysenv_var), tgt_value);warning ("%s" , buf.buf);strbuf_release (&buf);
@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst) dst->initialized =1 ; - tgt_value =getenv (dst->env_var_name); + tgt_value =tr2_sysenv_get (dst->sysenv_var);if (!tgt_value || !strcmp (tgt_value,"" ) || !strcmp (tgt_value,"0" ) || !strcasecmp (tgt_value,"false" )) {
@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)return ;if (tr2_dst_want_warning ()) -warning ("unable to write trace to '%s': %s" , dst->env_var_name, +warning ("unable to write trace to '%s': %s" , +tr2_sysenv_display_name (dst->sysenv_var),strerror (errno));tr2_dst_trace_disable (dst); }
trace2/tr2_dst.h +2 -1
@@ -2,9 +2,10 @@#define TR2_DST_H struct strbuf ; +#include "trace2/tr2_sysenv.h" struct tr2_dst { -const char *const env_var_name; +enum tr2_sysenv_variable sysenv_var;int fd;unsigned int initialized :1 ;unsigned int need_close :1 ;
trace2/tr2_sysenv.c new file +125 -0
125 lines not on this page · raw message
trace2/tr2_sysenv.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef TR2_SYSENV_H +#define TR2_SYSENV_H + +/* +* The Trace2 settings that can be loaded from /etc/gitconfig +* and/or user environment variables. +* +* Note that this set does not contain any of the transient +* environment variables used to pass information from parent +* to child git processes, such "GIT_TR2_PARENT_SID". +*/ +enum tr2_sysenv_variable { +TR2_SYSENV_CFG_PARAM =0 , + +TR2_SYSENV_DST_DEBUG , + +TR2_SYSENV_NORMAL , +TR2_SYSENV_NORMAL_BRIEF , + +TR2_SYSENV_EVENT , +TR2_SYSENV_EVENT_BRIEF , +TR2_SYSENV_EVENT_NESTING , + +TR2_SYSENV_PERF , +TR2_SYSENV_PERF_BRIEF , + +TR2_SYSENV_MUST_BE_LAST +}; + +void tr2_sysenv_load (void ); + +const char *tr2_sysenv_get (enum tr2_sysenv_variable ); +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var); +void tr2_sysenv_release (void ); + +#endif /* TR2_SYSENV_H */
trace2/tr2_tgt_event.c +9 -10
@@ -6,10 +6,11 @@#include "trace2/tr2_dst.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_event = {"GIT_TR2_EVENT" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_event = {TR2_SYSENV_EVENT ,0 ,0 ,0 };/* * The version number of the JSON data generated by the EVENT target
@@ -28,17 +29,15 @@ static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 };* are primarily intended for the performance target during debugging. * * Some of the outer-most messages, however, may be of interest to the -* event target. Set this environment variable to a larger integer for -* more detail in the event target. +* event target. Use the TR2_SYSENV_EVENT_NESTING setting to increase +* region details in the event target. */ -#define TR2_ENVVAR_EVENT_NESTING "GIT_TR2_EVENT_NESTING"static int tr2env_event_nesting_wanted =2 ;/* -* Set this environment variable to true to omit the <time>, <file>, and +* Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and * <line> fields from most events. */ -#define TR2_ENVVAR_EVENT_BRIEF "GIT_TR2_EVENT_BRIEF"static int tr2env_event_brief;static int fn_init (void )
@@ -46,17 +45,17 @@ static int fn_init(void)int want =tr2_dst_trace_want (&tr2dst_event);int want_nesting;int want_brief; -char *nesting; -char *brief; +const char *nesting; +const char *brief;if (!want)return want; - nesting =getenv (TR2_ENVVAR_EVENT_NESTING ); + nesting =tr2_sysenv_get (TR2_SYSENV_EVENT_NESTING );if (nesting && ((want_nesting =atoi (nesting)) >0 )) tr2env_event_nesting_wanted = want_nesting; - brief =getenv (TR2_ENVVAR_EVENT_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_EVENT_BRIEF );if (brief && ((want_brief =atoi (brief)) >0 )) tr2env_event_brief = want_brief;
trace2/tr2_tgt_normal.c +5 -5
@@ -4,19 +4,19 @@#include "quote.h" #include "version.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = {"GIT_TR2" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_normal = {TR2_SYSENV_NORMAL ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>" * fields from each line written to the builtin normal target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF"static int tr2env_normal_brief;#define TR2FMT_NORMAL_FL_WIDTH (50)
@@ -25,12 +25,12 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_normal);int want_brief; -char *brief; +const char *brief;if (!want)return want; - brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) tr2env_normal_brief = want_brief;
trace2/tr2_tgt_perf.c +5 -5
@@ -6,19 +6,19 @@#include "json-writer.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = {"GIT_TR2_PERF" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_perf = {TR2_SYSENV_PERF ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" * fields from each line written to the builtin performance target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF"static int tr2env_perf_brief;#define TR2FMT_PERF_FL_WIDTH (50)
@@ -36,14 +36,14 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_perf);int want_brief; -char *brief; +const char *brief;if (!want)return want;strbuf_addchars (&dots,'.' ,TR2_DOTS_BUFFER_SIZE ); - brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) tr2env_perf_brief = want_brief;
Signature · 1 line
gitgitgadget
Re: [PATCH 4/4] trace2: use system config for default trace2 settings
On Thu, Mar 28 2019, Jeff Hostetler via GitGitGadget wrote:
Thanks for working on this!
Haven't given this any deep testing. Just some observations:
Quoted 537 lines
From: Jeff Hostetler <[email protected]>
Teach git to read the system config (usually "
/etc/gitconfig") for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system config file is used. Trace2 config values are ignored in local, global, and other config files. Likewise, the "-c" command line arguments are ignored for Trace2 values. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
Added the
GIT_TEST_TR2_SYSTEM_CONFIGenvironment variable for testing purposes to specify the pathname of a fake "system" config or disable use of the system config.Signed-off-by Jeff Hostetler <[email protected]>--- Documentation/technical/api-trace2.txt | 31 ++++++ Makefile | 1 + t/t0210-trace2-normal.sh | 41 +++++++- t/t0211-trace2-perf.sh | 41 +++++++- t/t0212-trace2-event.sh | 52 +++++++++- trace2.c | 4 + trace2.h | 7 +- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++--- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 125 +++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++ trace2/tr2_tgt_event.c | 19 ++-- trace2/tr2_tgt_normal.c | 10 +- trace2/tr2_tgt_perf.c | 10 +- 15 files changed, 356 insertions(+), 55 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.hDocumentation/technical/api-trace2.txt +31
-0@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is omitted, Git will try both. +== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings. + +Trace2 will try to load the following system configuration settings +and then read the corresponding environment variables at startup. + +.... +--------------------------------------------------- +trace2.normalTarget GIT_TR2 +trace2.normalBrief GIT_TR2_BRIEF + +trace2.perfTarget GIT_TR2_PERF +trace2.perfBrief GIT_TR2_PERF_BRIEF + +trace2.eventTarget GIT_TR2_EVENT +trace2.eventBrief GIT_TR2_EVENT_BRIEF +trace2.eventNesting GIT_TR2_EVENT_NESTING + +trace2.configParams GIT_TR2_CONFIG_PARAMS + +trace2.destinationDebug GIT_TR2_DST_DEBUG +--------------------------------------------------- +.... + + == Trace2 API All public Trace2 functions and macros are defined in `trace2.h` andMakefile +1
-0@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o LIB_OBJS += trace2/tr2_cmd_name.o LIB_OBJS += trace2/tr2_dst.o LIB_OBJS += trace2/tr2_sid.o +LIB_OBJS += trace2/tr2_sysenv.o LIB_OBJS += trace2/tr2_tbuf.o LIB_OBJS += trace2/tr2_tgt_event.o LIB_OBJS += trace2/tr2_tgt_normal.ot/t0210-trace2-normal.sh +36
-5@@ -1,5 +1,14 @@ #!/bin/sh +# Disable loading of Trace2 settings from the system config +# (usually "/etc/gitconfig") to eliminate system dependencies. +GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG + +# Turn off any inherited trace2 settings for this test. +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT +unset GIT_TR2_BRIEF +unset GIT_TR2_CONFIG_PARAMS + test_description='test trace2 facility (normal target)' . ./test-lib.sh@@ -15,11 +24,6 @@ PATH="$TTDIR:$PATH" && export PATH # Warning: So you may see extra lines in artifact files when # Warning: interactively debugging. -# Turn off any inherited trace2 settings for this test. -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT -unset GIT_TR2_BRIEF -unset GIT_TR2_CONFIG_PARAMS - V=$(git version | sed -e 's/^git version //') && export V # There are multiple trace2 targets: normal, perf, and event.@@ -132,4 +136,31 @@ test_expect_success 'normal stream, error event' ' test_cmp expect actual ' +# Now test using system config by using a mocked up config file +# rather than inheriting "/etc/gitconfig". Here we do not use +# GIT_TR2* environment variables. + +unset GIT_TR2_BRIEF + +MOCK=./mock_system_config + +test_expect_success 'setup mocked /etc/gitconfig' ' + git config --file $MOCK trace2.normalTarget "$(pwd)/trace.normal" && + git config --file $MOCK trace2.normalBrief 1 +' + +test_expect_success 'using mock, normal stream, return code 0' ' + test_when_finished "rm trace.normal actual expect" && + GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 001return 0 && + perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + cat >expect <<-EOF && + version $V + start _EXE_ trace2 001return 0 + cmd_name trace2 (trace2) + exit elapsed:_TIME_ code:0 + atexit elapsed:_TIME_ code:0 + EOF + test_cmp expect actual +' + test_donet/t0211-trace2-perf.sh +36
-5@@ -1,5 +1,14 @@ #!/bin/sh +# Disable loading of Trace2 settings from the system config +# (usually "/etc/gitconfig") to eliminate system dependencies. +GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG + +# Turn off any inherited trace2 settings for this test. +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT +unset GIT_TR2_PERF_BRIEF +unset GIT_TR2_CONFIG_PARAMS + test_description='test trace2 facility (perf target)' . ./test-lib.sh@@ -15,11 +24,6 @@ PATH="$TTDIR:$PATH" && export PATH # Warning: So you may see extra lines in artifact files when # Warning: interactively debugging. -# Turn off any inherited trace2 settings for this test. -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT -unset GIT_TR2_PERF_BRIEF -unset GIT_TR2_CONFIG_PARAMS - V=$(git version | sed -e 's/^git version //') && export V # There are multiple trace2 targets: normal, perf, and event.@@ -150,4 +154,31 @@ test_expect_success 'perf stream, child processes' ' test_cmp expect actual ' +# Now test using system config by using a mocked up config file +# rather than inheriting "/etc/gitconfig". Here we do not use +# GIT_TR2* environment variables. + +unset GIT_TR2_PERF_BRIEF + +MOCK=./mock_system_config + +test_expect_success 'setup mocked /etc/gitconfig' ' + git config --file $MOCK trace2.perfTarget "$(pwd)/trace.perf" && + git config --file $MOCK trace2.perfBrief 1 +' + +test_expect_success 'using mock, perf stream, return code 0' ' + test_when_finished "rm trace.perf actual expect" && + GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 001return 0 && + perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && + cat >expect <<-EOF && + d0|main|version|||||$V + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 + d0|main|cmd_name|||||trace2 (trace2) + d0|main|exit||_T_ABS_|||code:0 + d0|main|atexit||_T_ABS_|||code:0 + EOF + test_cmp expect actual +' + test_donet/t0212-trace2-event.sh +47
-5@@ -1,5 +1,14 @@ #!/bin/sh +# Disable loading of Trace2 settings from the system config +# (usually "/etc/gitconfig") to eliminate system dependencies. +GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG + +# Turn off any inherited trace2 settings for this test. +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT +unset GIT_TR2_BARE +unset GIT_TR2_CONFIG_PARAMS + test_description='test trace2 facility' . ./test-lib.sh@@ -17,11 +26,6 @@ PATH="$TTDIR:$PATH" && export PATH # Warning: So you may see extra lines in artifact files when # Warning: interactively debugging. -# Turn off any inherited trace2 settings for this test. -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT -unset GIT_TR2_BARE -unset GIT_TR2_CONFIG_PARAMS - V=$(git version | sed -e 's/^git version //') && export V # There are multiple trace2 targets: normal, perf, and event.@@ -233,4 +237,42 @@ test_expect_success JSON_PP 'basic trace2_data' ' test_cmp expect actual ' +# Now test using system config by using a mocked up config file +# rather than inheriting "/etc/gitconfig". Here we do not use +# GIT_TR2* environment variables. + +MOCK=./mock_system_config + +test_expect_success 'setup mocked /etc/gitconfig' ' + git config --file $MOCK trace2.eventTarget "$(pwd)/trace.event" +' + +test_expect_success JSON_PP 'using mock, event stream, error event' ' + test_when_finished "rm trace.event actual expect" && + GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 003error "hello world" "this is a test" && + perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual && + sed -e "s/^|//" >expect <<-EOF && + |VAR1 = { + | "_SID0_":{ + | "argv":[ + | "_EXE_", + | "trace2", + | "003error", + | "hello world", + | "this is a test" + | ], + | "errors":[ + | "%s", + | "%s" + | ], + | "exit_code":0, + | "hierarchy":"trace2", + | "name":"trace2", + | "version":"$V" + | } + |}; + EOF + test_cmp expect actual +' + test_donetrace2.c +4
-0@@ -10,6 +10,7 @@#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" @@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)tr2_sid_release ();tr2_cmd_name_release ();tr2_cfg_free_patterns (); +tr2_sysenv_release (); trace2_enabled =0 ; }@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)if (trace2_enabled)return ; +tr2_sysenv_load (); +if (!tr2_tgt_want_builtins ())return ; trace2_enabled =1 ;trace2.h +4
-3@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine. @@ -125,8 +126,8 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: +* Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns +* configured important. For example: * * GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" * trace2/tr2_cfg.c +3
-4@@ -1,8 +1,7 @@#include "cache.h" #include "config.h" -#include "tr2_cfg.h" - -#define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS" +#include "trace2/tr2_cfg.h" +#include "trace2/tr2_sysenv.h" static struct strbuf **tr2_cfg_patterns;static int tr2_cfg_count_patterns;@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)return tr2_cfg_count_patterns; tr2_cfg_loaded =1 ; - envvar =getenv (TR2_ENVVAR_CFG_PARAM ); + envvar =tr2_sysenv_get (TR2_SYSENV_CFG_PARAM );if (!envvar || !*envvar)return tr2_cfg_count_patterns;trace2/tr2_dst.c +12
-12@@ -1,5 +1,6 @@#include "cache.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" /* * If a Trace2 target cannot be opened for writing, we should issue a @@ -7,17 +8,13 @@* or socket and beyond the user's control -- especially since every * git command (and sub-command) will print the message. So we silently * eat these warnings and just discard the trace data. -* -* Enable the following environment variable to see these warnings. */ -#define TR2_ENVVAR_DST_DEBUG "GIT_TR2_DST_DEBUG" -static int tr2_dst_want_warning (void ) {static int tr2env_dst_debug =-1 ;if (tr2env_dst_debug ==-1 ) { -const char *env_value =getenv (TR2_ENVVAR_DST_DEBUG ); +const char *env_value =tr2_sysenv_get (TR2_SYSENV_DST_DEBUG );if (!env_value || !*env_value) tr2env_dst_debug =0 ;else @@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)if (fd ==-1 ) {if (tr2_dst_want_warning ())warning ("trace2: could not open '%s' for '%s' tracing: %s" , - tgt_value, dst->env_var_name,strerror (errno)); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var), +strerror (errno));tr2_dst_trace_disable (dst);return 0 ;@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,if (!path || !*path) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX value '%s' for '%s' tracing" , - tgt_value, dst->env_var_name); + tgt_value,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX path '%s' for '%s' tracing" , - path, dst->env_var_name); + path,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, error:if (tr2_dst_want_warning ())warning ("trace2: could not connect to socket '%s' for '%s' tracing: %s" , - path, dst->env_var_name,strerror (e)); + path,tr2_sysenv_display_name (dst->sysenv_var),strerror (e));tr2_dst_trace_disable (dst);return 0 ;@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"trace2: unknown value for '%s': '%s'" , - dst->env_var_name, tgt_value); +tr2_sysenv_display_name (dst->sysenv_var), tgt_value);warning ("%s" , buf.buf);strbuf_release (&buf);@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst) dst->initialized =1 ; - tgt_value =getenv (dst->env_var_name); + tgt_value =tr2_sysenv_get (dst->sysenv_var);if (!tgt_value || !strcmp (tgt_value,"" ) || !strcmp (tgt_value,"0" ) || !strcasecmp (tgt_value,"false" )) {@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)return ;if (tr2_dst_want_warning ()) -warning ("unable to write trace to '%s': %s" , dst->env_var_name, +warning ("unable to write trace to '%s': %s" , +tr2_sysenv_display_name (dst->sysenv_var),strerror (errno));tr2_dst_trace_disable (dst); }trace2/tr2_dst.h +2
-1@@ -2,9 +2,10 @@#define TR2_DST_H struct strbuf ; +#include "trace2/tr2_sysenv.h" struct tr2_dst { -const char *const env_var_name; +enum tr2_sysenv_variable sysenv_var;int fd;unsigned int initialized :1 ;unsigned int need_close :1 ;trace2/tr2_sysenv.c new file +38
-0@@ -0,0 +1,125 @@ +#include "cache.h" +#include "config.h" +#include "dir.h" +#include "tr2_sysenv.h" + +/* +* Each entry represents a trace2 setting. +* See Documentation/technical/api-trace2.txt +*/ +struct tr2_sysenv_entry { +const char *env_var_name; +const char *git_config_name; + +char *value; +unsigned int getenv_called :1 ; +}; + +/* +* This table must match "enum tr2_sysenv_variable" in tr2_sysenv.h. +* These strings are constant and must match the published names as +* described in the documentation. +* +* We do not define entries for the GIT_TR2_PARENT_* environment +* variables because they are transient and used to pass information +* from parent to child git processes, rather than settings. +*/ +/* clang-format off */ +static struct tr2_sysenv_entry tr2_sysenv_settings[] = { + {"GIT_TR2_CONFIG_PARAMS" ,"trace2.configparams" }, + + {"GIT_TR2_DST_DEBUG" ,"trace2.destinationdebug" }, + + {"GIT_TR2" ,"trace2.normaltarget" }, + {"GIT_TR2_BRIEF" ,"trace2.normalbrief" }, + + {"GIT_TR2_EVENT" ,"trace2.eventtarget" }, + {"GIT_TR2_EVENT_BRIEF" ,"trace2.eventbrief" }, + {"GIT_TR2_EVENT_NESTING" ,"trace2.eventnesting" },
trace2/tr2_sysenv.c line 48
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+ + { "GIT_TR2_PERF", "trace2.perftarget" }, + { "GIT_TR2_PERF_BRIEF", "trace2.perfbrief" }, +}; +/* clang-format on */ + +static int tr2_sysenv_cb (const char *key,const char *value,void *d) +{ +int k; +
I added:
if (!starts_with(key, "trace2.")) return 0;
Here, and everything works as expected. I think that's a good idea. Makes this O(n) over N config keys instead of O(n*x) where x = num entries in tr2_sysenv_settings.
Quoted 25 lines
trace2/tr2_sysenv.c new file +25
-0+for (k =0 ; k <ARRAY_SIZE (tr2_sysenv_settings); k++) { +if (!strcmp (key, tr2_sysenv_settings[k].git_config_name)) { +free (tr2_sysenv_settings[k].value); + tr2_sysenv_settings[k].value =xstrdup (value); +return 0 ; + } + } + +return 0 ; +} + +/* +* Load Trace2 settings from the system config (usually "/etc/gitconfig" +* unless we were built with a runtime-prefix). These are intended to +* define the default values for Trace2 as requested by the administrator. +*/ +void tr2_sysenv_load (void ) +{ +const char *system_config_pathname; +const char *test_pathname; + + system_config_pathname =git_etc_gitconfig (); + + test_pathname =getenv ("GIT_TEST_TR2_SYSTEM_CONFIG" ); +if (test_pathname) {
trace2/tr2_sysenv.c line 83
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+if (!*test_pathname || !strcmp (test_pathname,"0" )) +return ;/* disable use of system config */ + +/* mock it with given test file */ + system_config_pathname = test_pathname; + } + +if (file_exists (system_config_pathname)) +git_config_from_file (tr2_sysenv_cb, system_config_pathname, +NULL );
Maybe this isn't worth it, but this "file_exists" thing is something we could abstract in the config machinery (or maybe passing via "config_options" makes more sense):
diff --git a/config.c b/config.c
index 0f0cdd8c0f..ea625a508f 100644
--- a/config.c
+++ b/config.c
@@ -1549,12 +1549,15 @@ static int git_config_from_stdin(config_fn_t fn, void *data)
int git_config_from_file_with_options(config_fn_t fn, const char *filename,
void *data,
- const struct config_options *opts)
+ const struct config_options *opts,
+ int or_warn)
{
int ret = -1;
FILE *f;
- f = fopen_or_warn(filename, "r");
+ f = or_warn
+ ? fopen_or_warn(filename, "r")
+ : fopen(filename, "r");
if (f) {
ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename,
filename, f, data, opts);
@@ -1565,7 +1568,7 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
{
- return git_config_from_file_with_options(fn, filename, data, NULL);
+ return git_config_from_file_with_options(fn, filename, data, NULL, 1);
}
int git_config_from_mem(config_fn_t fn,
@@ -2787,7 +2790,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
*/
if (git_config_from_file_with_options(store_aux,
config_filename,
- &store, &opts)) {
+ &store, &opts, 1)) {
error(_("invalid config file %s"), config_filename);
ret = CONFIG_INVALID_FILE;
goto out_free;
diff --git a/config.h b/config.h
index ee5d3fa7b4..52e93e6cdc 100644
--- a/config.h
+++ b/config.h
@@ -72,7 +72,8 @@ extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *, void *);
extern int git_config_from_file_with_options(config_fn_t fn, const char *,
void *,
- const struct config_options *);
+ const struct config_options *,
+ int);
extern int git_config_from_mem(config_fn_t fn,
const enum config_origin_type,
const char *name,
diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c
index 656613e371..25a9c19d20 100644
--- a/trace2/tr2_sysenv.c
+++ b/trace2/tr2_sysenv.c
@@ -78,9 +81,9 @@ void tr2_sysenv_load(void)
system_config_pathname = test_pathname;
}
- if (file_exists(system_config_pathname))
- git_config_from_file(tr2_sysenv_cb, system_config_pathname,
- NULL);
+ git_config_from_file_with_options(tr2_sysenv_cb,
+ system_config_pathname, NULL, NULL,
+ 0);
}
/*Quoted 133 lines
trace2/tr2_sysenv.c new file +42
-0+} + +/* +* Return the value for the requested setting. Start with the /etc/gitconfig +* value and allow the corresponding environment variable to override it. +*/ +const char *tr2_sysenv_get (enum tr2_sysenv_variable var) +{ +if (var >=TR2_SYSENV_MUST_BE_LAST ) +BUG ("tr2_sysenv_get invalid var '%d'" , var); + +if (!tr2_sysenv_settings[var].getenv_called) { +const char *v =getenv (tr2_sysenv_settings[var].env_var_name); +if (v && *v) { +free (tr2_sysenv_settings[var].value); + tr2_sysenv_settings[var].value =xstrdup (v); + } + tr2_sysenv_settings[var].getenv_called =1 ; + } + +return tr2_sysenv_settings[var].value; +} + +/* +* Return a friendly name for this setting that is suitable for printing +* in an error messages. +*/ +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var) +{ +if (var >=TR2_SYSENV_MUST_BE_LAST ) +BUG ("tr2_sysenv_get invalid var '%d'" , var); + +return tr2_sysenv_settings[var].env_var_name; +} + +void tr2_sysenv_release (void ) +{ +int k; + +for (k =0 ; k <ARRAY_SIZE (tr2_sysenv_settings); k++) +free (tr2_sysenv_settings[k].value); +}trace2/tr2_sysenv.h new file +36
-0@@ -0,0 +1,36 @@ +#ifndef TR2_SYSENV_H +#define TR2_SYSENV_H + +/* +* The Trace2 settings that can be loaded from /etc/gitconfig +* and/or user environment variables. +* +* Note that this set does not contain any of the transient +* environment variables used to pass information from parent +* to child git processes, such "GIT_TR2_PARENT_SID". +*/ +enum tr2_sysenv_variable { +TR2_SYSENV_CFG_PARAM =0 , + +TR2_SYSENV_DST_DEBUG , + +TR2_SYSENV_NORMAL , +TR2_SYSENV_NORMAL_BRIEF , + +TR2_SYSENV_EVENT , +TR2_SYSENV_EVENT_BRIEF , +TR2_SYSENV_EVENT_NESTING , + +TR2_SYSENV_PERF , +TR2_SYSENV_PERF_BRIEF , + +TR2_SYSENV_MUST_BE_LAST +}; + +void tr2_sysenv_load (void ); + +const char *tr2_sysenv_get (enum tr2_sysenv_variable ); +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var); +void tr2_sysenv_release (void ); + +#endif /* TR2_SYSENV_H */ trace2/tr2_tgt_event.c +7
-8@@ -6,10 +6,11 @@#include "trace2/tr2_dst.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_event = {"GIT_TR2_EVENT" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_event = {TR2_SYSENV_EVENT ,0 ,0 ,0 };/* * The version number of the JSON data generated by the EVENT target @@ -28,17 +29,15 @@ static struct tr2_dst tr2dst_event = { "GIT_TR2_EVENT", 0, 0, 0 };* are primarily intended for the performance target during debugging. * * Some of the outer-most messages, however, may be of interest to the -* event target. Set this environment variable to a larger integer for -* more detail in the event target. +* event target. Use the TR2_SYSENV_EVENT_NESTING setting to increase +* region details in the event target. */ -#define TR2_ENVVAR_EVENT_NESTING "GIT_TR2_EVENT_NESTING"static int tr2env_event_nesting_wanted =2 ;/* -* Set this environment variable to true to omit the <time>, <file>, and +* Use the TR2_SYSENV_EVENT_BRIEF to omit the <time>, <file>, and * <line> fields from most events. */ -#define TR2_ENVVAR_EVENT_BRIEF "GIT_TR2_EVENT_BRIEF"static int tr2env_event_brief;static int fn_init (void )@@ -46,17 +45,17 @@ static int fn_init(void)int want =tr2_dst_trace_want (&tr2dst_event);int want_nesting;int want_brief; -char *nesting; -char *brief; +const char *nesting; +const char *brief;if (!want)return want;
trace2/tr2_tgt_event.c static int fn_init(void) · line 60
Quoted 10 lines
trace2/tr2_tgt_event.c +2
-2- nesting =getenv (TR2_ENVVAR_EVENT_NESTING ); + nesting =tr2_sysenv_get (TR2_SYSENV_EVENT_NESTING );if (nesting && ((want_nesting =atoi (nesting)) >0 )) tr2env_event_nesting_wanted = want_nesting; - brief =getenv (TR2_ENVVAR_EVENT_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_EVENT_BRIEF );if (brief && ((want_brief =atoi (brief)) >0 )) tr2env_event_brief = want_brief;
A lot of this pre-dates this patch, but I wonder if the whole of trace2 couldn't make more use of config.c's bool parsing for things like these. Maybe by having a "cfg_type" enum & parsed_value void* in tr2_sysenv_entry?
Quoted 88 lines
trace2/tr2_tgt_normal.c +5
-5@@ -4,19 +4,19 @@#include "quote.h" #include "version.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = {"GIT_TR2" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_normal = {TR2_SYSENV_NORMAL ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>" * fields from each line written to the builtin normal target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF"static int tr2env_normal_brief;#define TR2FMT_NORMAL_FL_WIDTH (50)@@ -25,12 +25,12 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_normal);int want_brief; -char *brief; +const char *brief;if (!want)return want; - brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) tr2env_normal_brief = want_brief;trace2/tr2_tgt_perf.c +5
-5@@ -6,19 +6,19 @@#include "json-writer.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = {"GIT_TR2_PERF" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_perf = {TR2_SYSENV_PERF ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" * fields from each line written to the builtin performance target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF"static int tr2env_perf_brief;#define TR2FMT_PERF_FL_WIDTH (50)@@ -36,14 +36,14 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_perf);int want_brief; -char *brief; +const char *brief;if (!want)return want;strbuf_addchars (&dots,'.' ,TR2_DOTS_BUFFER_SIZE ); - brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) tr2env_perf_brief = want_brief;
Re: [PATCH 4/4] trace2: use system config for default trace2 settings
Quoted 13 lines · Ævar Arnfjörð Bjarmason
On Thu, Mar 28 2019, Jeff Hostetler via GitGitGadget wrote:
Thanks for working on this!
Haven't given this any deep testing. Just some observations:
Quoted 6 lines
From: Jeff Hostetler <[email protected]>
Teach git to read the system config (usually "
/etc/gitconfig") for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
[...]
Quoted 4 lines
Quoted 4 lines
trace2/tr2_sysenv.c new file +0
-1--- /dev/null
[...]
Quoted 25 lines
Quoted 12 lines
trace2/tr2_sysenv.c new file +12
-0+/* clang-format off */ +static struct tr2_sysenv_entry tr2_sysenv_settings[] = { + {"GIT_TR2_CONFIG_PARAMS" ,"trace2.configparams" }, + + {"GIT_TR2_DST_DEBUG" ,"trace2.destinationdebug" }, + + {"GIT_TR2" ,"trace2.normaltarget" }, + {"GIT_TR2_BRIEF" ,"trace2.normalbrief" }, + + {"GIT_TR2_EVENT" ,"trace2.eventtarget" }, + {"GIT_TR2_EVENT_BRIEF" ,"trace2.eventbrief" }, + {"GIT_TR2_EVENT_NESTING" ,"trace2.eventnesting" },trace2/tr2_sysenv.c line 48
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+ + { "GIT_TR2_PERF", "trace2.perftarget" }, + { "GIT_TR2_PERF_BRIEF", "trace2.perfbrief" }, +}; +/* clang-format on */ + +static int tr2_sysenv_cb (const char *key,const char *value,void *d) +{ +int k; +I added:
Quoted 6 lines
if (!starts_with(key, "trace2.")) return 0;Here, and everything works as expected. I think that's a good idea. Makes this O(n) over N config keys instead of
O(n*x)where x = num entries intr2_sysenv_settings.
Good idea. Thanks!
Quoted 32 lines
Quoted 32 lines
trace2/tr2_sysenv.c new file +31
-0+for (k =0 ; k <ARRAY_SIZE (tr2_sysenv_settings); k++) { +if (!strcmp (key, tr2_sysenv_settings[k].git_config_name)) { +free (tr2_sysenv_settings[k].value); + tr2_sysenv_settings[k].value =xstrdup (value); +return 0 ; + } + } + +return 0 ; +} + +/* +* Load Trace2 settings from the system config (usually "/etc/gitconfig" +* unless we were built with a runtime-prefix). These are intended to +* define the default values for Trace2 as requested by the administrator. +*/ +void tr2_sysenv_load (void ) +{ +const char *system_config_pathname; +const char *test_pathname; + + system_config_pathname =git_etc_gitconfig (); + + test_pathname =getenv ("GIT_TEST_TR2_SYSTEM_CONFIG" ); +if (test_pathname) { +if (!*test_pathname || !strcmp (test_pathname,"0" )) +return ;/* disable use of system config */ + +/* mock it with given test file */ + system_config_pathname = test_pathname; + }
Quoted 8 lines
trace2/tr2_sysenv.c line 83
Quoted 4 lines
trace2/tr2_sysenv.c new file +4
-0+ +if (file_exists (system_config_pathname)) +git_config_from_file (tr2_sysenv_cb, system_config_pathname, +NULL );Maybe this isn't worth it, but this "
file_exists" thing is something we could abstract in the config machinery (or maybe passing via "config_options" makes more sense):
[...]
This is a good idea, but I think I'll save this for a future effort rather than add it to the current patch series. It just seems outside of my scope right now and adds to the footprint of this series.
[...]
Quoted 6 lines
Quoted 6 lines
trace2/tr2_sysenv.c new file +1
-1- nesting =getenv (TR2_ENVVAR_EVENT_NESTING ); + nesting =tr2_sysenv_get (TR2_SYSENV_EVENT_NESTING );if (nesting && ((want_nesting =atoi (nesting)) >0 )) tr2env_event_nesting_wanted = want_nesting;
Quoted 9 lines
trace2/tr2_sysenv.c
Quoted 4 lines
trace2/tr2_sysenv.c new file +1
-1- brief =getenv (TR2_ENVVAR_EVENT_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_EVENT_BRIEF );if (brief && ((want_brief =atoi (brief)) >0 )) tr2env_event_brief = want_brief;A lot of this pre-dates this patch, but I wonder if the whole of trace2 couldn't make more use of config.c's bool parsing for things like these. Maybe by having a "
cfg_type" enum &parsed_valuevoid* intr2_sysenv_entry?
I converted the "brief" instances in the normal and perf targets to use git_parse_maybe_bool() already, but I missed this one.
The nesting one above is actually an integer value rather than a bool. I'll rename the variables in the re-roll to clarify that.
[...]
Quoted 5 lines
Quoted 5 lines
trace2/tr2_sysenv.c new file +1
-1- brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) tr2env_normal_brief = want_brief;
[...]
Quoted 5 lines
trace2/tr2_sysenv.c
Quoted 5 lines
trace2/tr2_sysenv.c new file +1
-1- brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) tr2env_perf_brief = want_brief;
Thanks for the review.
I'll push up another version shortly.
Jeff
Re: [PATCH 4/4] trace2: use system config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetOne quick comment:
On 2019.03.28 06:31, Jeff Hostetler via GitGitGadget wrote:
[...]
Quoted 15 lines
trace2.h +2
-1@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine.
trace2.h void trace2_cmd_alias_fl(const char *file, int line, const char *alias, · line 133
Quoted 10 lines
trace2.h +2
-2@@ -125,8 +126,8 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: +* Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns +* configured important. For example: * * GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" *
Looks like the example needs to be updated with the new var name as well.
v2 cover trace2: load trace2 settings from system config
In reply to Jeff Hostetler via GitGitGadgetHere is version 2. It addresses most the V1 comments WRT the system config changes.
It also addresses the format and uniqueness of the SID as discussed in [1]. The SID now containes: the UTC date/time, part of SHA1 of the hostname, and the PID and is formatted to make it safe for filenames.
It also contains (a somewhat unrelated platform-specific) commit to report total process memory usage at exit. This is helpful when looking for problematic commands that might have scaling problems.
[1]
https://public-inbox.org/git/[email protected]/T/#m6b4e6f2b0374d5ba88de8d0350ce6bf51b28d7da
----------------------------------------------------------------------------
Teach git to load default Trace2 settings from the system config (usually "/etc/gitconfig"). The existing GIT_TR2_* environment variables can be used to override the new system defaults. It also includes a little startup refactoring.
Note: I found interactive testing of this feature to be awkward on some platforms because of the use of prefix- or runtime-prefix-relative locations for the system configuration. It was easy to accidentally use an officially installed version of git to set a system config variable in the official system config directory; and then when testing with the test version of git, that value would not be seen because it was looking for the system config file in a different directory.
Jeff Hostetler (7):
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
trace2: use system config for default trace2 settings
trace2: report peak memory usage of the process
trace2: clarify UTC datetime formatting
trace2: make SIDs more unique
Documentation/technical/api-trace2.txt | 66 +++++++++--- Makefile | 1 + common-main.c | 8 +- compat/mingw.c | 2 + compat/win32/trace2_win32_process_info.c | 50 ++++++++- t/t0210-trace2-normal.sh | 41 +++++++- t/t0211-trace2-perf.sh | 53 ++++++++-- t/t0212-trace2-event.sh | 52 ++++++++- trace2.c | 21 +++- trace2.h | 43 ++++++-- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++--- trace2/tr2_dst.h | 3 +- trace2/tr2_sid.c | 39 ++++++- trace2/tr2_sysenv.c | 128 +++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++ trace2/tr2_tbuf.c | 20 +++- trace2/tr2_tbuf.h | 5 +- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 53 +++++----- trace2/tr2_tgt_normal.c | 19 ++-- trace2/tr2_tgt_perf.c | 23 ++-- trace2/tr2_tls.c | 38 ++++--- trace2/tr2_tls.h | 8 +- 24 files changed, 604 insertions(+), 137 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/169
Range-diff vs v1:
1: 7f1a347322 = 1: 7f1a347322 trace2: refactor setting process starting time
2: c15f783c26 = 2: c15f783c26 trace2: add absolute elapsed time to start event
3: d4023acde7 = 3: d4023acde7 trace2: find exec-dir before trace2 initialization
4: 7e0d4e20fb ! 4: d048f3ffb8 trace2: use system config for default trace2 settings
@@ -332,11 +332,16 @@
*
- * The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a
- * list of patterns considered important. For example:
-+ * Use the TR2_SYSENV_CFG_PARAM setting to register a list of patterns
-+ * configured important. For example:
- *
- * GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url"
+- *
+- * GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url"
++ * Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated
++ * list of patterns configured important. For example:
++ * git config --system trace2.configParams 'core.*,remote.*.url'
++ * or:
++ * GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url"
*
+ * Note: this routine does a read-only iteration on the config data
+ * (using read_early_config()), so it must not be called until enough
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
--- a/trace2/tr2_cfg.c
@@ -527,6 +532,9 @@
+{
+ int k;
+
++ if (!starts_with(key, "trace2."))
++ return 0;
++
+ for (k = 0; k < ARRAY_SIZE(tr2_sysenv_settings); k++) {
+ if (!strcmp(key, tr2_sysenv_settings[k].git_config_name)) {
+ free(tr2_sysenv_settings[k].value);
@@ -673,7 +681,8 @@
+ * region details in the event target.
*/
-#define TR2_ENVVAR_EVENT_NESTING "GIT_TR2_EVENT_NESTING"
- static int tr2env_event_nesting_wanted = 2;
+-static int tr2env_event_nesting_wanted = 2;
++static int tr2env_event_max_nesting_levels = 2;
/*
- * Set this environment variable to true to omit the <time>, <file>, and
@@ -681,12 +690,14 @@
* <line> fields from most events.
*/
-#define TR2_ENVVAR_EVENT_BRIEF "GIT_TR2_EVENT_BRIEF"
- static int tr2env_event_brief;
+-static int tr2env_event_brief;
++static int tr2env_event_be_brief;
static int fn_init(void)
-@@
+ {
int want = tr2_dst_trace_want(&tr2dst_event);
- int want_nesting;
+- int want_nesting;
++ int max_nesting;
int want_brief;
- char *nesting;
- char *brief;
@@ -697,15 +708,74 @@
return want;
- nesting = getenv(TR2_ENVVAR_EVENT_NESTING);
+- if (nesting && ((want_nesting = atoi(nesting)) > 0))
+- tr2env_event_nesting_wanted = want_nesting;
+ nesting = tr2_sysenv_get(TR2_SYSENV_EVENT_NESTING);
- if (nesting && ((want_nesting = atoi(nesting)) > 0))
- tr2env_event_nesting_wanted = want_nesting;
++ if (nesting && *nesting && ((max_nesting = atoi(nesting)) > 0))
++ tr2env_event_max_nesting_levels = max_nesting;
- brief = getenv(TR2_ENVVAR_EVENT_BRIEF);
+- if (brief && ((want_brief = atoi(brief)) > 0))
+- tr2env_event_brief = want_brief;
+ brief = tr2_sysenv_get(TR2_SYSENV_EVENT_BRIEF);
- if (brief && ((want_brief = atoi(brief)) > 0))
- tr2env_event_brief = want_brief;
++ if (brief && *brief &&
++ ((want_brief = git_parse_maybe_bool(brief)) != -1))
++ tr2env_event_be_brief = want_brief;
+ return want;
+ }
+@@
+ /*
+ * In brief mode, only emit <time> on these 2 event types.
+ */
+- if (!tr2env_event_brief || !strcmp(event_name, "version") ||
++ if (!tr2env_event_be_brief || !strcmp(event_name, "version") ||
+ !strcmp(event_name, "atexit")) {
+ tr2_tbuf_utc_time(&tb_now);
+ jw_object_string(jw, "time", tb_now.buf);
+ }
+
+- if (!tr2env_event_brief && file && *file) {
++ if (!tr2env_event_be_brief && file && *file) {
+ jw_object_string(jw, "file", file);
+ jw_object_intmax(jw, "line", line);
+ }
+@@
+ {
+ const char *event_name = "region_enter";
+ struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
+- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
++ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
+ struct json_writer jw = JSON_WRITER_INIT;
+
+ jw_object_begin(&jw, 0);
+@@
+ {
+ const char *event_name = "region_leave";
+ struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
+- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
++ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
+ struct json_writer jw = JSON_WRITER_INIT;
+ double t_rel = (double)us_elapsed_region / 1000000.0;
+
+@@
+ {
+ const char *event_name = "data";
+ struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
+- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
++ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
+ struct json_writer jw = JSON_WRITER_INIT;
+ double t_abs = (double)us_elapsed_absolute / 1000000.0;
+ double t_rel = (double)us_elapsed_region / 1000000.0;
+@@
+ {
+ const char *event_name = "data_json";
+ struct tr2tls_thread_ctx *ctx = tr2tls_get_self();
+- if (ctx->nr_open_regions <= tr2env_event_nesting_wanted) {
++ if (ctx->nr_open_regions <= tr2env_event_max_nesting_levels) {
+ struct json_writer jw = JSON_WRITER_INIT;
+ double t_abs = (double)us_elapsed_absolute / 1000000.0;
+ double t_rel = (double)us_elapsed_region / 1000000.0;
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
--- a/trace2/tr2_tgt_normal.c
@@ -730,9 +800,11 @@
* Unit tests may want to use this to help with testing.
*/
-#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF"
- static int tr2env_normal_brief;
+-static int tr2env_normal_brief;
++static int tr2env_normal_be_brief;
#define TR2FMT_NORMAL_FL_WIDTH (50)
+
@@
{
int want = tr2_dst_trace_want(&tr2dst_normal);
@@ -747,7 +819,20 @@
+ brief = tr2_sysenv_get(TR2_SYSENV_NORMAL_BRIEF);
if (brief && *brief &&
((want_brief = git_parse_maybe_bool(brief)) != -1))
- tr2env_normal_brief = want_brief;
+- tr2env_normal_brief = want_brief;
++ tr2env_normal_be_brief = want_brief;
+
+ return want;
+ }
+@@
+ {
+ strbuf_setlen(buf, 0);
+
+- if (!tr2env_normal_brief) {
++ if (!tr2env_normal_be_brief) {
+ struct tr2_tbuf tb_now;
+
+ tr2_tbuf_local_time(&tb_now);
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
--- a/trace2/tr2_tgt_perf.c
@@ -772,9 +857,11 @@
* Unit tests may want to use this to help with testing.
*/
-#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF"
- static int tr2env_perf_brief;
+-static int tr2env_perf_brief;
++static int tr2env_perf_be_brief;
#define TR2FMT_PERF_FL_WIDTH (50)
+ #define TR2FMT_PERF_MAX_EVENT_NAME (12)
@@
{
int want = tr2_dst_trace_want(&tr2dst_perf);
@@ -791,4 +878,17 @@
+ brief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);
if (brief && *brief &&
((want_brief = git_parse_maybe_bool(brief)) != -1))
- tr2env_perf_brief = want_brief;
+- tr2env_perf_brief = want_brief;
++ tr2env_perf_be_brief = want_brief;
+
+ return want;
+ }
+@@
+
+ strbuf_setlen(buf, 0);
+
+- if (!tr2env_perf_brief) {
++ if (!tr2env_perf_be_brief) {
+ struct tr2_tbuf tb_now;
+
+ tr2_tbuf_local_time(&tb_now);
-: ---------- > 5: 86d8fe28cf trace2: report peak memory usage of the process
-: ---------- > 6: ae11cc4186 trace2: clarify UTC datetime formatting
-: ---------- > 7: 4352952677 trace2: make SIDs more uniqueSignature · 1 line
gitgitgadget
PATCH v2 2/7 trace2: add absolute elapsed time to start event
From: Jeff Hostetler <[email protected]>
Add elapsed process time to "start" event to measure the performance of early process startup.
--- Documentation/technical/api-trace2.txt | 11 ++++++----- t/t0211-trace2-perf.sh | 12 ++++++------ trace2.c | 8 +++++++- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 5 ++++- trace2/tr2_tgt_normal.c | 3 ++- trace2/tr2_tgt_perf.c | 7 ++++--- 7 files changed, 30 insertions(+), 17 deletions(-)
Documentation/technical/api-trace2.txt +6 -5
@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.perf 12:28:42.620675 common-main.c:38 | d0 | main | version | | | | | 2.20.1.155.g426c96fcdb -12:28:42.621001 common-main.c:39 | d0 | main | start | | | | | git version +12:28:42.621001 common-main.c:39 | d0 | main | start | | 0.001173 | | | git version 12:28:42.621111 git.c:432 | d0 | main | cmd_name | | | | | version (version) 12:28:42.621225 git.c:662 | d0 | main | exit | | 0.001227 | | | code:0 12:28:42.621259 trace2/tr2_tgt_perf.c:211 | d0 | main | atexit | | 0.001265 | | | code:0
@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.event {"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"} -{"event":"start","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16 17:28:42.621027","file":"common-main.c","line":39,"argv":["git","version"]} +{"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"]} {"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"} {"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} {"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}
@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the "start" and { "event":"start", ... + "t_abs":0.001227, # elapsed time in seconds "argv":["git","version"] } ------------
@@ -1118,7 +1119,7 @@ $ git status $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.160.g5676107ecd.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1163,7 +1164,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.162.gb4ccea44db.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1219,7 +1220,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.156.gf9916ae094.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) d0 | main | region_enter | r1 | 0.001791 | | index | label:do_read_index .git/index
t/t0211-trace2-perf.sh +6 -6
@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:0 d0|main|atexit||_T_ABS_|||code:0
@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 1 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:1 d0|main|atexit||_T_ABS_|||code:1
@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' + d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' d0|main|cmd_name|||||trace2 (trace2) d0|main|error|||||hello world d0|main|error|||||this is a test
@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0 d1|main|version|||||$V - d1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0 + d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0 d1|main|cmd_name|||||trace2 (trace2/trace2) d1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0 d2|main|version|||||$V - d2|main|start|||||_EXE_ trace2 001return 0 + d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d2|main|cmd_name|||||trace2 (trace2/trace2/trace2) d2|main|exit||_T_ABS_|||code:0 d2|main|atexit||_T_ABS_|||code:0
trace2.c +7 -1
@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv) {struct tr2_tgt *tgt_j;int j; +uint64_t us_now; +uint64_t us_elapsed_absolute;if (!trace2_enabled)return ; + us_now =getnanotime () /1000 ; + us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); + for_each_wanted_builtin (j, tgt_j)if (tgt_j->pfn_start_fl) - tgt_j->pfn_start_fl (file, line, argv); + tgt_j->pfn_start_fl (file, line, us_elapsed_absolute, + argv); }int trace2_cmd_exit_fl (const char *file,int line,int code)
trace2/tr2_tgt.h +1 -0
@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);typedef void (tr2_tgt_evt_version_fl_t )(const char *file,int line);typedef void (tr2_tgt_evt_start_fl_t )(const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv);typedef void (tr2_tgt_evt_exit_fl_t )(const char *file,int line,uint64_t us_elapsed_absolute,int code);
trace2/tr2_tgt_event.c +4 -1
@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)jw_release (&jw); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct json_writer jw =JSON_WRITER_INIT ; +double t_abs = (double )us_elapsed_absolute /1000000.0 ;jw_object_begin (&jw,0 );event_fmt_prepare (event_name, file, line,NULL , &jw); +jw_object_double (&jw,"t_abs" ,6 , t_abs);jw_object_inline_begin_array (&jw,"argv" );jw_array_argv (&jw, argv);jw_end (&jw);
trace2/tr2_tgt_normal.c +2 -1
@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {struct strbuf buf_payload =STRBUF_INIT ;
trace2/tr2_tgt_perf.c +4 -3
@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct strbuf buf_payload =STRBUF_INIT ;sq_quote_argv_pretty (&buf_payload, argv); -perf_io_write_fl (file, line, event_name,NULL ,NULL ,NULL ,NULL , - &buf_payload); +perf_io_write_fl (file, line, event_name,NULL , &us_elapsed_absolute, +NULL ,NULL , &buf_payload);strbuf_release (&buf_payload); }
Signature · 1 line
gitgitgadget
PATCH v2 3/7 trace2: find exec-dir before trace2 initialization
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Git to resolve the executable directory before initializing Trace2. This allows the system configuration directory to be discovered earlier (because it is sometimes relative to the prefix or runtime-prefix).
This will be used by the next commit to allow trace2 settings to be loaded from the system config.
--- common-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common-main.c +2 -2
@@ -37,12 +37,12 @@ int main(int argc, const char **argv)sanitize_stdfds ();restore_sigpipe_to_default (); +git_resolve_executable_dir (argv[0 ]); +trace2_initialize ();trace2_cmd_start (argv);trace2_collect_process_info (); -git_resolve_executable_dir (argv[0 ]); -git_setup_gettext ();initialize_the_repository ();
Signature · 1 line
gitgitgadget
PATCH v2 5/7 trace2: report peak memory usage of the process
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Windows version of git to report peak memory usage during exit() processing.
--- common-main.c | 2 +- compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++-- trace2.c | 2 + trace2.h | 14 +++++-- 4 files changed, 60 insertions(+), 8 deletions(-)
common-main.c +1 -1
@@ -41,7 +41,7 @@ int main(int argc, const char **argv)trace2_initialize ();trace2_cmd_start (argv); -trace2_collect_process_info (); +trace2_collect_process_info (TRACE2_PROCESS_INFO_STARTUP );git_setup_gettext ();
compat/win32/trace2_win32_process_info.c +47 -3
63 lines not on this page · raw message
trace2.c +2 -0
@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)if (!trace2_enabled)return code; +trace2_collect_process_info (TRACE2_PROCESS_INFO_EXIT ); + tr2main_exit_code = code; us_now =getnanotime () /1000 ;
trace2.h +10 -4
@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);* Optional platform-specific code to dump information about the * current and any parent process(es). This is intended to allow * post-processors to know who spawned this git instance and anything -* else the platform may be able to tell us about the current process. +* else that the platform may be able to tell us about the current process. */ + +enum trace2_process_info_reason { +TRACE2_PROCESS_INFO_STARTUP , +TRACE2_PROCESS_INFO_EXIT , +}; +#if defined(GIT_WINDOWS_NATIVE ) -void trace2_collect_process_info (void ); +void trace2_collect_process_info (enum trace2_process_info_reason reason);#else -#define trace2_collect_process_info () \ - do { \ +#define trace2_collect_process_info (reason) \ + do { \ } while (0)#endif
Signature · 1 line
gitgitgadget
PATCH v2 6/7 trace2: clarify UTC datetime formatting
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update tr2_tbuf_utc_datetime to generate extended UTC format. Update tr2_tgt_event target to use extended format in 'time' columns.
--- Documentation/technical/api-trace2.txt | 12 ++++++------ trace2/tr2_tbuf.c | 4 ++-- trace2/tr2_tbuf.h | 4 ++-- trace2/tr2_tgt_event.c | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-)
Documentation/technical/api-trace2.txt +6 -6
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"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"} -{"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} -{"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} +{"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"} +{"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"]} +{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} +{"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} +{"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} ------------ == Enabling a Target
@@ -573,7 +573,7 @@ The following key/value pairs are common to all events: "event":"version", "sid":"1547659722619736-11614", "thread":"main", - "time":"2019-01-16 17:28:42.620713", + "time":"2019-01-16T17:28:42.620713Z", "file":"common-main.c", "line":38, ...
trace2/tr2_tbuf.c +2 -2
@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb) tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } -void tr2_tbuf_utc_time (struct tr2_tbuf *tb) +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb) {struct timeval tv;struct tm tm;
@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)gmtime_r (&secs, &tm);xsnprintf (tb->buf,sizeof (tb->buf), -"%4d-%02d-%02d %02d:%02d:%02d.%06ld" , tm.tm_year +1900 , +"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ" , tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long )tv.tv_usec); }
trace2/tr2_tbuf.h +2 -2
@@ -16,8 +16,8 @@ struct tr2_tbuf {void tr2_tbuf_local_time (struct tr2_tbuf *tb);/* -* Fill buffer with formatted UTC time string. +* Fill buffer with formatted UTC datatime string. */ -void tr2_tbuf_utc_time (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
trace2/tr2_tgt_event.c +1 -1
@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,*/ if (!tr2env_event_be_brief || !strcmp (event_name,"version" ) || !strcmp (event_name,"atexit" )) { -tr2_tbuf_utc_time (&tb_now); +tr2_tbuf_utc_datetime_extended (&tb_now);jw_object_string (jw,"time" , tb_now.buf); }
Signature · 1 line
gitgitgadget
PATCH v2 4/7 trace2: use system config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach git to read the system config (usually "/etc/gitconfig") for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system config file is used. Trace2 config values are ignored in local, global, and other config files. Likewise, the "-c" command line arguments are ignored for Trace2 values. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
Added the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing purposes to specify the pathname of a fake "system" config or disable use of the system config.
--- Documentation/technical/api-trace2.txt | 31 ++++++ Makefile | 1 + t/t0210-trace2-normal.sh | 41 +++++++- t/t0211-trace2-perf.sh | 41 +++++++- t/t0212-trace2-event.sh | 52 +++++++++- trace2.c | 4 + trace2.h | 12 ++- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++--- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 128 +++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++ trace2/tr2_tgt_event.c | 46 ++++----- trace2/tr2_tgt_normal.c | 16 ++-- trace2/tr2_tgt_perf.c | 16 ++-- 15 files changed, 382 insertions(+), 76 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
Documentation/technical/api-trace2.txt +31 -0
@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is omitted, Git will try both. +== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings. + +Trace2 will try to load the following system configuration settings +and then read the corresponding environment variables at startup. + +.... +--------------------------------------------------- +trace2.normalTarget GIT_TR2 +trace2.normalBrief GIT_TR2_BRIEF + +trace2.perfTarget GIT_TR2_PERF +trace2.perfBrief GIT_TR2_PERF_BRIEF + +trace2.eventTarget GIT_TR2_EVENT +trace2.eventBrief GIT_TR2_EVENT_BRIEF +trace2.eventNesting GIT_TR2_EVENT_NESTING + +trace2.configParams GIT_TR2_CONFIG_PARAMS + +trace2.destinationDebug GIT_TR2_DST_DEBUG +--------------------------------------------------- +.... + + == Trace2 API All public Trace2 functions and macros are defined in `trace2.h` and
Makefile +1 -0
@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o LIB_OBJS += trace2/tr2_cmd_name.o LIB_OBJS += trace2/tr2_dst.o LIB_OBJS += trace2/tr2_sid.o +LIB_OBJS += trace2/tr2_sysenv.o LIB_OBJS += trace2/tr2_tbuf.o LIB_OBJS += trace2/tr2_tgt_event.o LIB_OBJS += trace2/tr2_tgt_normal.o
t/t0210-trace2-normal.sh +36 -5
56 lines not on this page · raw message
t/t0211-trace2-perf.sh +36 -5
56 lines not on this page · raw message
t/t0212-trace2-event.sh +47 -5
67 lines not on this page · raw message
trace2.c +4 -0
@@ -10,6 +10,7 @@#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h"
@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)tr2_sid_release ();tr2_cmd_name_release ();tr2_cfg_free_patterns (); +tr2_sysenv_release (); trace2_enabled =0 ; }
@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)if (trace2_enabled)return ; +tr2_sysenv_load (); +if (!tr2_tgt_want_builtins ())return ; trace2_enabled =1 ;
trace2.h +7 -5
@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine.
@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: -* -* GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" +* Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated +* list of patterns configured important. For example: +* git config --system trace2.configParams 'core.*,remote.*.url' +* or: +* GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url" * * Note: this routine does a read-only iteration on the config data * (using read_early_config()), so it must not be called until enough
trace2/tr2_cfg.c +3 -4
@@ -1,8 +1,7 @@#include "cache.h" #include "config.h" -#include "tr2_cfg.h" - -#define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS" +#include "trace2/tr2_cfg.h" +#include "trace2/tr2_sysenv.h" static struct strbuf **tr2_cfg_patterns;static int tr2_cfg_count_patterns;
@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)return tr2_cfg_count_patterns; tr2_cfg_loaded =1 ; - envvar =getenv (TR2_ENVVAR_CFG_PARAM ); + envvar =tr2_sysenv_get (TR2_SYSENV_CFG_PARAM );if (!envvar || !*envvar)return tr2_cfg_count_patterns;
trace2/tr2_dst.c +12 -12
@@ -1,5 +1,6 @@#include "cache.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" /* * If a Trace2 target cannot be opened for writing, we should issue a
@@ -7,17 +8,13 @@* or socket and beyond the user's control -- especially since every * git command (and sub-command) will print the message. So we silently * eat these warnings and just discard the trace data. -* -* Enable the following environment variable to see these warnings. */ -#define TR2_ENVVAR_DST_DEBUG "GIT_TR2_DST_DEBUG" -static int tr2_dst_want_warning (void ) {static int tr2env_dst_debug =-1 ;if (tr2env_dst_debug ==-1 ) { -const char *env_value =getenv (TR2_ENVVAR_DST_DEBUG ); +const char *env_value =tr2_sysenv_get (TR2_SYSENV_DST_DEBUG );if (!env_value || !*env_value) tr2env_dst_debug =0 ;else
@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)if (fd ==-1 ) {if (tr2_dst_want_warning ())warning ("trace2: could not open '%s' for '%s' tracing: %s" , - tgt_value, dst->env_var_name,strerror (errno)); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var), +strerror (errno));tr2_dst_trace_disable (dst);return 0 ;
@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,if (!path || !*path) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX value '%s' for '%s' tracing" , - tgt_value, dst->env_var_name); + tgt_value,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX path '%s' for '%s' tracing" , - path, dst->env_var_name); + path,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, error:if (tr2_dst_want_warning ())warning ("trace2: could not connect to socket '%s' for '%s' tracing: %s" , - path, dst->env_var_name,strerror (e)); + path,tr2_sysenv_display_name (dst->sysenv_var),strerror (e));tr2_dst_trace_disable (dst);return 0 ;
@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"trace2: unknown value for '%s': '%s'" , - dst->env_var_name, tgt_value); +tr2_sysenv_display_name (dst->sysenv_var), tgt_value);warning ("%s" , buf.buf);strbuf_release (&buf);
@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst) dst->initialized =1 ; - tgt_value =getenv (dst->env_var_name); + tgt_value =tr2_sysenv_get (dst->sysenv_var);if (!tgt_value || !strcmp (tgt_value,"" ) || !strcmp (tgt_value,"0" ) || !strcasecmp (tgt_value,"false" )) {
@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)return ;if (tr2_dst_want_warning ()) -warning ("unable to write trace to '%s': %s" , dst->env_var_name, +warning ("unable to write trace to '%s': %s" , +tr2_sysenv_display_name (dst->sysenv_var),strerror (errno));tr2_dst_trace_disable (dst); }
trace2/tr2_dst.h +2 -1
@@ -2,9 +2,10 @@#define TR2_DST_H struct strbuf ; +#include "trace2/tr2_sysenv.h" struct tr2_dst { -const char *const env_var_name; +enum tr2_sysenv_variable sysenv_var;int fd;unsigned int initialized :1 ;unsigned int need_close :1 ;
trace2/tr2_sysenv.c new file +128 -0
128 lines not on this page · raw message
trace2/tr2_sysenv.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef TR2_SYSENV_H +#define TR2_SYSENV_H + +/* +* The Trace2 settings that can be loaded from /etc/gitconfig +* and/or user environment variables. +* +* Note that this set does not contain any of the transient +* environment variables used to pass information from parent +* to child git processes, such "GIT_TR2_PARENT_SID". +*/ +enum tr2_sysenv_variable { +TR2_SYSENV_CFG_PARAM =0 , + +TR2_SYSENV_DST_DEBUG , + +TR2_SYSENV_NORMAL , +TR2_SYSENV_NORMAL_BRIEF , + +TR2_SYSENV_EVENT , +TR2_SYSENV_EVENT_BRIEF , +TR2_SYSENV_EVENT_NESTING , + +TR2_SYSENV_PERF , +TR2_SYSENV_PERF_BRIEF , + +TR2_SYSENV_MUST_BE_LAST +}; + +void tr2_sysenv_load (void ); + +const char *tr2_sysenv_get (enum tr2_sysenv_variable ); +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var); +void tr2_sysenv_release (void ); + +#endif /* TR2_SYSENV_H */
trace2/tr2_tgt_event.c +23 -23
111 lines not on this page · raw message
trace2/tr2_tgt_normal.c +8 -8
@@ -4,20 +4,20 @@#include "quote.h" #include "version.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = {"GIT_TR2" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_normal = {TR2_SYSENV_NORMAL ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>" * fields from each line written to the builtin normal target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF" -static int tr2env_normal_brief; +static int tr2env_normal_be_brief;#define TR2FMT_NORMAL_FL_WIDTH (50)
@@ -25,15 +25,15 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_normal);int want_brief; -char *brief; +const char *brief;if (!want)return want; - brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_normal_brief = want_brief; + tr2env_normal_be_brief = want_brief;return want; }
@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf) {strbuf_setlen (buf,0 ); -if (!tr2env_normal_brief) { +if (!tr2env_normal_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
trace2/tr2_tgt_perf.c +8 -8
@@ -6,20 +6,20 @@#include "json-writer.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = {"GIT_TR2_PERF" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_perf = {TR2_SYSENV_PERF ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" * fields from each line written to the builtin performance target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF" -static int tr2env_perf_brief; +static int tr2env_perf_be_brief;#define TR2FMT_PERF_FL_WIDTH (50)#define TR2FMT_PERF_MAX_EVENT_NAME (12)
@@ -36,17 +36,17 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_perf);int want_brief; -char *brief; +const char *brief;if (!want)return want;strbuf_addchars (&dots,'.' ,TR2_DOTS_BUFFER_SIZE ); - brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_perf_brief = want_brief; + tr2env_perf_be_brief = want_brief;return want; }
@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,strbuf_setlen (buf,0 ); -if (!tr2env_perf_brief) { +if (!tr2env_perf_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
Signature · 1 line
gitgitgadget
PATCH v2 1/7 trace2: refactor setting process starting time
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Create trace2_initialize_clock() and call from main() to capture process start time in isolation and before other sub-systems are ready.
--- Documentation/technical/api-trace2.txt | 12 ++++++-- common-main.c | 2 ++ compat/mingw.c | 2 ++ trace2.c | 7 ++++- trace2.h | 17 ++++++++++++ trace2/tr2_tls.c | 38 ++++++++++++++++---------- trace2/tr2_tls.h | 8 +++++- 7 files changed, 67 insertions(+), 19 deletions(-)
Documentation/technical/api-trace2.txt +9 -3
@@ -160,17 +160,23 @@ purposes. These are concerned with the lifetime of the overall git process. +`void trace2_initialize_clock()`:: + + Initialize the Trace2 start clock and nothing else. This should + be called at the very top of main() to capture the process start + time and reduce startup order dependencies. + `void trace2_initialize()`:: Determines if any Trace2 Targets should be enabled and - initializes the Trace2 facility. This includes starting the - elapsed time clocks and thread local storage (TLS). + initializes the Trace2 facility. This includes setting up the + Trace2 thread local storage (TLS). + This function emits a "version" message containing the version of git and the Trace2 protocol. + This function should be called from `main()` as early as possible in -the life of the process. +the life of the process after essential process initialization. `int trace2_is_enabled()`::
common-main.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, const char **argv) {int result; +trace2_initialize_clock (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed
compat/mingw.c +2 -0
@@ -2569,6 +2569,8 @@ void mingw_startup(void)wchar_t **wenv, **wargv;_startupinfo si; +trace2_initialize_clock (); +maybe_redirect_std_handles ();/* get wide char arguments and environment */
trace2.c +6 -1
@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)raise (signo); } +void trace2_initialize_clock (void ) +{ +tr2tls_start_process_clock (); +} +void trace2_initialize_fl (const char *file,int line) {struct tr2_tgt *tgt_j;
@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name) us_now =getnanotime () /1000 ; us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); -tr2tls_create_self (thread_name); +tr2tls_create_self (thread_name, us_now);for_each_wanted_builtin (j, tgt_j) if (tgt_j->pfn_thread_start_fl)
trace2.h +17 -0
@@ -19,6 +19,23 @@ struct json_writer;* [] trace2_printf* -- legacy trace[1] messages. */ +/* +* Initialize the TRACE2 clock and do nothing else, in particular +* no mallocs, no system inspection, and no environment inspection. +* +* This should be called at the very top of main() to capture the +* process start time. This is intended to reduce chicken-n-egg +* bootstrap pressure. +* +* It is safe to call this more than once. This allows capturing +* absolute startup costs on Windows which uses a little trickery +* to do setup work before common-main.c:main() is called. +* +* The main trace2_initialize_fl() may be called a little later +* after more infrastructure is established. +*/ +void trace2_initialize_clock (void ); +/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 * targets are enabled in the environment. Emits a 'version' event.
trace2/tr2_tls.c +24 -14
@@ -10,16 +10,30 @@#define TR2_REGION_NESTING_INITIAL_SIZE (100)static struct tr2tls_thread_ctx *tr2tls_thread_main; -static uint64_t tr2tls_us_start_main; +static uint64_t tr2tls_us_start_process;static pthread_mutex_t tr2tls_mutex;static pthread_key_t tr2tls_key;static int tr2_next_thread_id;/* modify under lock */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name) +void tr2tls_start_process_clock (void ) +{ +if (tr2tls_us_start_process) +return ; + +/* +* Keep the absolute start time of the process (i.e. the main +* process) in a fixed variable since other threads need to +* access it. This allows them to do that without a lock on +* main thread's array data (because of reallocs). +*/ + tr2tls_us_start_process =getnanotime () /1000 ; +} + +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start) { -uint64_t us_now =getnanotime () /1000 ;struct tr2tls_thread_ctx *ctx =xcalloc (1 ,sizeof (*ctx));/*
@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)*/ ctx->alloc =TR2_REGION_NESTING_INITIAL_SIZE ; ctx->array_us_start = (uint64_t *)xcalloc (ctx->alloc,sizeof (uint64_t )); - ctx->array_us_start[ctx->nr_open_regions++] = us_now; + ctx->array_us_start[ctx->nr_open_regions++] = us_thread_start; ctx->thread_id =tr2tls_locked_increment (&tr2_next_thread_id);
@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)* here and silently continue. */ if (!ctx) - ctx =tr2tls_create_self ("unknown" ); + ctx =tr2tls_create_self ("unknown" ,getnanotime () /1000 );return ctx; }
@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)if (!tr2tls_thread_main)return 0 ; -return us - tr2tls_us_start_main; +return us - tr2tls_us_start_process; }void tr2tls_init (void ) { +tr2tls_start_process_clock (); +pthread_key_create (&tr2tls_key,NULL );init_recursive_mutex (&tr2tls_mutex); - tr2tls_thread_main =tr2tls_create_self ("main" ); -/* -* Keep a copy of the absolute start time of the main thread -* in a fixed variable since other threads need to access it. -* This also eliminates the need to lock accesses to the main -* thread's array (because of reallocs). -*/ - tr2tls_us_start_main = tr2tls_thread_main->array_us_start[0 ]; + tr2tls_thread_main =tr2tls_create_self ("main" , + tr2tls_us_start_process); }void tr2tls_release (void )
trace2/tr2_tls.h +7 -1
@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {* In this and all following functions the term "self" refers to the * current thread. */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name); +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start);/* * Get our TLS data.
@@ -94,4 +95,9 @@ void tr2tls_release(void);*/ int tr2tls_locked_increment (int *p); +/* +* Capture the process start time and do nothing else. +*/ +void tr2tls_start_process_clock (void ); +#endif /* TR2_TLS_H */
Signature · 1 line
gitgitgadget
PATCH v2 7/7 trace2: make SIDs more unique
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update SID component construction to use the current UTC datetime and a portion of the SHA1 of the hostname.
Use an simplified date/time format to make it easier to use the SID component as a logfile filename.
--- Documentation/technical/api-trace2.txt | 12 ++++---- trace2/tr2_sid.c | 39 +++++++++++++++++++++++--- trace2/tr2_tbuf.c | 16 +++++++++++ trace2/tr2_tbuf.h | 1 + 4 files changed, 58 insertions(+), 10 deletions(-)
Documentation/technical/api-trace2.txt +6 -6
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} -{"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} -{"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} +{"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"} +{"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"]} +{"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"} +{"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} +{"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} ------------ == Enabling a Target
@@ -571,7 +571,7 @@ The following key/value pairs are common to all events: ------------ { "event":"version", - "sid":"1547659722619736-11614", + "sid":"20190329-144314-319944-9b68c35f-012232", "thread":"main", "time":"2019-01-16T17:28:42.620713Z", "file":"common-main.c",
trace2/tr2_sid.c +35 -4
@@ -1,4 +1,5 @@#include "cache.h" +#include "trace2/tr2_tbuf.h" #include "trace2/tr2_sid.h" #define TR2_ENVVAR_PARENT_SID "GIT_TR2_PARENT_SID"
@@ -6,6 +7,39 @@static struct strbuf tr2sid_buf =STRBUF_INIT ;static int tr2sid_nr_git_parents; +/* +* Compute the final component of the SID representing the current process. +* This should uniquely identify the process and be a valid filename (to +* allow writing trace2 data to per-process files). +* +* <yyyymmdd> '-' <hhmmss> '-' <fraction> '-' <sha1-prefix> '-' <pid> +*/ +static void tr2_sid_append_my_sid_component (void ) +{ +const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1 ]; +struct tr2_tbuf tb_now; +git_hash_ctx ctx; +unsigned char hash[GIT_MAX_RAWSZ +1 ]; +char hex[GIT_MAX_HEXSZ +1 ]; +char hostname[HOST_NAME_MAX +1 ]; + +tr2_tbuf_utc_datetime_for_filename (&tb_now); +strbuf_addstr (&tr2sid_buf, tb_now.buf); +strbuf_addch (&tr2sid_buf,'-' ); + +if (xgethostname (hostname,sizeof (hostname))) +xsnprintf (hostname,sizeof (hostname),"localhost" ); + + algo->init_fn (&ctx); + algo->update_fn (&ctx, hostname,strlen (hostname)); + algo->final_fn (hash, &ctx); +hash_to_hex_algop_r (hex, hash, algo); +strbuf_add (&tr2sid_buf, hex,8 ); + +strbuf_addch (&tr2sid_buf,'-' ); +strbuf_addf (&tr2sid_buf,"%06" PRIuMAX, (uintmax_t )getpid ()); +} +/* * Compute a "unique" session id (SID) for the current process. This allows * all events from this process to have a single label (much like a PID).
@@ -20,7 +54,6 @@ static int tr2sid_nr_git_parents;*/ static void tr2_sid_compute (void ) { -uint64_t us_now;const char *parent_sid;if (tr2sid_buf.len)
@@ -38,9 +71,7 @@ static void tr2_sid_compute(void) tr2sid_nr_git_parents++; } - us_now =getnanotime () /1000 ; -strbuf_addf (&tr2sid_buf,"%" PRIuMAX"-%" PRIdMAX, (uintmax_t )us_now, - (intmax_t )getpid ()); +tr2_sid_append_my_sid_component ();setenv (TR2_ENVVAR_PARENT_SID , tr2sid_buf.buf,1 ); }
trace2/tr2_tbuf.c +16 -0
@@ -30,3 +30,19 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb) tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } + +void tr2_tbuf_utc_datetime_for_filename (struct tr2_tbuf *tb) +{ +struct timeval tv; +struct tm tm; +time_t secs; + +gettimeofday (&tv,NULL ); + secs = tv.tv_sec; +gmtime_r (&secs, &tm); + +xsnprintf (tb->buf,sizeof (tb->buf), +"%4d%02d%02d-%02d%02d%02d-%06ld" , tm.tm_year +1900 , + tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, + (long )tv.tv_usec); +}
trace2/tr2_tbuf.h +1 -0
@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);* Fill buffer with formatted UTC datatime string. */ void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime_for_filename (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
Signature · 1 line
gitgitgadget
Re: [PATCH v2 7/7] trace2: make SIDs more unique
Quoted 24 lines · Jeff Hostetler via GitGitGadget
From: Jeff Hostetler <[email protected]>
Update SID component construction to use the current UTC datetime and a portion of the SHA1 of the hostname.
Use an simplified date/time format to make it easier to use the SID component as a logfile filename.
[...]trace2/tr2_sid.c +16
-0+static void tr2_sid_append_my_sid_component (void ) +{ +const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1 ]; +struct tr2_tbuf tb_now; +git_hash_ctx ctx; +unsigned char hash[GIT_MAX_RAWSZ +1 ]; +char hex[GIT_MAX_HEXSZ +1 ]; +char hostname[HOST_NAME_MAX +1 ]; + +tr2_tbuf_utc_datetime_for_filename (&tb_now); +strbuf_addstr (&tr2sid_buf, tb_now.buf); +strbuf_addch (&tr2sid_buf,'-' ); + +if (xgethostname (hostname,sizeof (hostname))) +xsnprintf (hostname,sizeof (hostname),"localhost" ); +
trace2/tr2_sid.c line 42
Quoted 10 lines
trace2/tr2_sid.c +10
-0+ algo->init_fn (&ctx); + algo->update_fn (&ctx, hostname,strlen (hostname)); + algo->final_fn (hash, &ctx); +hash_to_hex_algop_r (hex, hash, algo); +strbuf_add (&tr2sid_buf, hex,8 ); + +strbuf_addch (&tr2sid_buf,'-' ); +strbuf_addf (&tr2sid_buf,"%06" PRIuMAX, (uintmax_t )getpid ()); +} +
Thanks for turning my shitty half-formed idea into a patch :)
I wrote this on top to bikeshed this a bit further, wonder what you think:
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
So e.g.:
Before: 20190329-220413-446441-c2f5b994-018702
After: 20190329T220431.244562Z-Hc2f5b994-P19812FI.e:
* Using <date>T<time> as is ISO 8601 convention/easier to read
* <dateime>.<microseconds>Z, so seperating with "." to indicate it's the same value + add "Z" for "it's UTC". I'm least sure about the ".". Is that going to cause issues on Windows these days (the rest being the "extension"...).
* I changed the hostname discovery so if gethostbyname() fails we'll print "-H00000000-" for that part, instead of "-H<first 8 chars of the sha1 for 'localhost'>-". Also prefix with "H" for "Host".
* Wrap pids to 0xffff, prefix with "P" (Pid)" and trail with either "F" = Full or "W" = Wrapped (not the real PID).
* I didn't add "T<datetime>" like "H" and "P" for the rest, since it's obvious what sort of value it is.
Maybe this is going a bit overboard, but I think it's easier to read at a glance for humans, and since it's meant to be opaque to machines anyway and the length is simliar enough not to matter I figure it's worth it.
Re: [PATCH v2 5/7] trace2: report peak memory usage of the process
In reply to Jeff Hostetler via GitGitGadgetQuoted 125 lines · Jeff Hostetler via GitGitGadget
From: Jeff Hostetler <[email protected]>
Teach Windows version of git to report peak memory usage during
exit()processing.Signed-off-by Jeff Hostetler <[email protected]>--- common-main.c | 2 +- compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++-- trace2.c | 2 + trace2.h | 14 +++++-- 4 files changed, 60 insertions(+), 8 deletions(-)common-main.c +1
-1@@ -41,7 +41,7 @@ int main(int argc, const char **argv)trace2_initialize ();trace2_cmd_start (argv); -trace2_collect_process_info (); +trace2_collect_process_info (TRACE2_PROCESS_INFO_STARTUP );git_setup_gettext ();compat/win32/trace2_win32_process_info.c +47
-3@@ -1,5 +1,6 @@#include "../../cache.h" #include "../../json-writer.h" +#include "lazyload.h" #include <Psapi.h> #include <tlHelp32.h> @@ -137,11 +138,54 @@ static void get_is_being_debugged(void) "windows/debugger_present", 1); } -void trace2_collect_process_info (void ) +/* +* Emit JSON data with the peak memory usage of the current process. +*/ +static void get_peak_memory_info (void ) +{ +DECLARE_PROC_ADDR (psapi.dll,BOOL , GetProcessMemoryInfo, +HANDLE ,PPROCESS_MEMORY_COUNTERS ,DWORD ); + +if (INIT_PROC_ADDR (GetProcessMemoryInfo)) { +PROCESS_MEMORY_COUNTERS pmc; + +if (GetProcessMemoryInfo (GetCurrentProcess (), &pmc, +sizeof (pmc))) { +struct json_writer jw =JSON_WRITER_INIT ; + +jw_object_begin (&jw,0 ); + +#define KV (kv) #kv, (intmax_t)pmc.kv + +jw_object_intmax (&jw,KV (PageFaultCount)); +jw_object_intmax (&jw,KV (PeakWorkingSetSize)); +jw_object_intmax (&jw,KV (PeakPagefileUsage)); + +jw_end (&jw); + +trace2_data_json ("process" , the_repository, +"windows/memory" , &jw); +jw_release (&jw); + } + } +} + +void trace2_collect_process_info (enum trace2_process_info_reason reason) {if (!trace2_is_enabled ())return ; -get_is_being_debugged (); -get_ancestry (); +switch (reason) { +case TRACE2_PROCESS_INFO_STARTUP : +get_is_being_debugged (); +get_ancestry (); +return ; + +case TRACE2_PROCESS_INFO_EXIT : +get_peak_memory_info (); +return ; + +default : +BUG ("trace2_collect_process_info: unknown reason '%d'" , reason); + } }trace2.c +2
-0@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)if (!trace2_enabled)return code; +trace2_collect_process_info (TRACE2_PROCESS_INFO_EXIT ); + tr2main_exit_code = code; us_now =getnanotime () /1000 ;trace2.h +7
-1@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);* Optional platform-specific code to dump information about the * current and any parent process(es). This is intended to allow * post-processors to know who spawned this git instance and anything -* else the platform may be able to tell us about the current process. +* else that the platform may be able to tell us about the current process. */ + +enum trace2_process_info_reason { +TRACE2_PROCESS_INFO_STARTUP , +TRACE2_PROCESS_INFO_EXIT , +}; +
trace2.h void trace2_printf(const char *fmt, ...); · line 408
Quoted 10 lines
trace2.h +3
-3#if defined(GIT_WINDOWS_NATIVE ) -void trace2_collect_process_info (void ); +void trace2_collect_process_info (enum trace2_process_info_reason reason);#else -#define trace2_collect_process_info () \ - do { \ +#define trace2_collect_process_info (reason) \ + do { \ } while (0)#endif
FWIW this is the "VmPeak" line in /proc/$$/status on Linux. I don't know if we can/should parse that in practice (I've been bitten in the past by things in /proc having high cost on some kernel versions in the past, notably smaps).
Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetOn 2019.03.29 10:04, Jeff Hostetler via GitGitGadget wrote:
[...]
Quoted 29 lines
Documentation/technical/api-trace2.txt +21
-0@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is omitted, Git will try both. +== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings. + +Trace2 will try to load the following system configuration settings +and then read the corresponding environment variables at startup. + +.... +--------------------------------------------------- +trace2.normalTarget GIT_TR2 +trace2.normalBrief GIT_TR2_BRIEF + +trace2.perfTarget GIT_TR2_PERF +trace2.perfBrief GIT_TR2_PERF_BRIEF + +trace2.eventTarget GIT_TR2_EVENT
Documentation/technical/api-trace2.txt values are recognized. · line 150
Quoted 10 lines
Documentation/technical/api-trace2.txt +10
-0+trace2.eventBrief GIT_TR2_EVENT_BRIEF +trace2.eventNesting GIT_TR2_EVENT_NESTING + +trace2.configParams GIT_TR2_CONFIG_PARAMS + +trace2.destinationDebug GIT_TR2_DST_DEBUG +--------------------------------------------------- +.... + +
A question for the list: should these new config vars also be documented in the git-config manpage, or is it better to keep these separate since they are only read from the system config?
Quoted 68 lines · Jeff Hostetler via GitGitGadget
Here is version 2. It addresses most the V1 comments WRT the system config changes.
It also addresses the format and uniqueness of the SID as discussed in [1]. The SID now containes: the UTC date/time, part of SHA1 of the hostname, and the PID and is formatted to make it safe for filenames.
It also contains (a somewhat unrelated platform-specific) commit to report total process memory usage at exit. This is helpful when looking for problematic commands that might have scaling problems.
[1]
https://public-inbox.org/git/[email protected]/T/#m6b4e6f2b0374d5ba88de8d0350ce6bf51b28d7da----------------------------------------------------------------------------
Teach git to load default Trace2 settings from the system config (usually "
/etc/gitconfig"). The existing GIT_TR2_* environment variables can be used to override the new system defaults. It also includes a little startup refactoring.Note: I found interactive testing of this feature to be awkward on some platforms because of the use of prefix- or runtime-prefix-relative locations for the system configuration. It was easy to accidentally use an officially installed version of git to set a system config variable in the official system config directory; and then when testing with the test version of git, that value would not be seen because it was looking for the system config file in a different directory.
Jeff Hostetler (7):
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
trace2: use system config for default trace2 settings
trace2: report peak memory usage of the process
trace2: clarify UTC datetime formatting
trace2: make SIDs more uniqueDocumentation/technical/api-trace2.txt | 66 +++++++++--- Makefile | 1 + common-main.c | 8 +- compat/mingw.c | 2 + compat/win32/trace2_win32_process_info.c | 50 ++++++++- t/t0210-trace2-normal.sh | 41 +++++++- t/t0211-trace2-perf.sh | 53 ++++++++-- t/t0212-trace2-event.sh | 52 ++++++++- trace2.c | 21 +++- trace2.h | 43 ++++++-- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++--- trace2/tr2_dst.h | 3 +- trace2/tr2_sid.c | 39 ++++++- trace2/tr2_sysenv.c | 128 +++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++ trace2/tr2_tbuf.c | 20 +++- trace2/tr2_tbuf.h | 5 +- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 53 +++++----- trace2/tr2_tgt_normal.c | 19 ++-- trace2/tr2_tgt_perf.c | 23 ++-- trace2/tr2_tls.c | 38 ++++--- trace2/tr2_tls.h | 8 +- 24 files changed, 604 insertions(+), 137 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
Quoted 4 lines
base-commit:
041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/169
This series looks good to me, apart from the open question about documentation. Thanks!
Re: [PATCH v2 5/7] trace2: report peak memory usage of the process
In reply to Ævar Arnfjörð BjarmasonQuoted 135 lines · Ævar Arnfjörð Bjarmason
Quoted 132 lines · Jeff Hostetler via GitGitGadget
From: Jeff Hostetler <[email protected]>
Teach Windows version of git to report peak memory usage during
exit()processing.Signed-off-by Jeff Hostetler <[email protected]>--- common-main.c | 2 +- compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++-- trace2.c | 2 + trace2.h | 14 +++++-- 4 files changed, 60 insertions(+), 8 deletions(-)common-main.c +1
-1@@ -41,7 +41,7 @@ int main(int argc, const char **argv)trace2_initialize ();trace2_cmd_start (argv); -trace2_collect_process_info (); +trace2_collect_process_info (TRACE2_PROCESS_INFO_STARTUP );git_setup_gettext ();compat/win32/trace2_win32_process_info.c +47
-3@@ -1,5 +1,6 @@#include "../../cache.h" #include "../../json-writer.h" +#include "lazyload.h" #include <Psapi.h> #include <tlHelp32.h> @@ -137,11 +138,54 @@ static void get_is_being_debugged(void) "windows/debugger_present", 1); } -void trace2_collect_process_info (void ) +/* +* Emit JSON data with the peak memory usage of the current process. +*/ +static void get_peak_memory_info (void ) +{ +DECLARE_PROC_ADDR (psapi.dll,BOOL , GetProcessMemoryInfo, +HANDLE ,PPROCESS_MEMORY_COUNTERS ,DWORD ); + +if (INIT_PROC_ADDR (GetProcessMemoryInfo)) { +PROCESS_MEMORY_COUNTERS pmc; + +if (GetProcessMemoryInfo (GetCurrentProcess (), &pmc, +sizeof (pmc))) { +struct json_writer jw =JSON_WRITER_INIT ; + +jw_object_begin (&jw,0 ); + +#define KV (kv) #kv, (intmax_t)pmc.kv + +jw_object_intmax (&jw,KV (PageFaultCount)); +jw_object_intmax (&jw,KV (PeakWorkingSetSize)); +jw_object_intmax (&jw,KV (PeakPagefileUsage)); + +jw_end (&jw); + +trace2_data_json ("process" , the_repository, +"windows/memory" , &jw); +jw_release (&jw); + } + } +} + +void trace2_collect_process_info (enum trace2_process_info_reason reason) {if (!trace2_is_enabled ())return ; -get_is_being_debugged (); -get_ancestry (); +switch (reason) { +case TRACE2_PROCESS_INFO_STARTUP : +get_is_being_debugged (); +get_ancestry (); +return ; + +case TRACE2_PROCESS_INFO_EXIT : +get_peak_memory_info (); +return ; + +default : +BUG ("trace2_collect_process_info: unknown reason '%d'" , reason); + } }trace2.c +2
-0@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)if (!trace2_enabled)return code; +trace2_collect_process_info (TRACE2_PROCESS_INFO_EXIT ); + tr2main_exit_code = code; us_now =getnanotime () /1000 ;trace2.h +9
-4@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);* Optional platform-specific code to dump information about the * current and any parent process(es). This is intended to allow * post-processors to know who spawned this git instance and anything -* else the platform may be able to tell us about the current process. +* else that the platform may be able to tell us about the current process. */ + +enum trace2_process_info_reason { +TRACE2_PROCESS_INFO_STARTUP , +TRACE2_PROCESS_INFO_EXIT , +}; +#if defined(GIT_WINDOWS_NATIVE ) -void trace2_collect_process_info (void ); +void trace2_collect_process_info (enum trace2_process_info_reason reason);#else -#define trace2_collect_process_info () \ - do { \ +#define trace2_collect_process_info (reason) \
Quoted 9 lines
trace2.h void trace2_printf(const char *fmt, ...); · line 408
Quoted 3 lines
trace2.h +1
-0+do { \ } while (0)#endif FWIW this is the "VmPeak" line in
/proc/$$/statuson Linux. I don't know if we can/should parse that in practice (I've been bitten in the past by things in /proc having high cost on some kernel versions in the past, notably smaps).
Thanks,
Yeah, I've avoided adding the corresponding platform-specific changes in for non-Windows versions because I didn't want to venture off into the weeds and introduce a perf or functional problem (for something that I'm not going to make use of in the short term). Whereas, we're seeing occasional perf problems with our Windows users on the OS repo where some (yet to be determined) commands will just go out to lunch.
I suspect we'll have similar problems with out Mac users in the near future, but I didn't want to jump in there just yet.
Jeff
Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings
In reply to Josh SteadmonQuoted 37 lines · Josh Steadmon
On 2019.03.29 10:04, Jeff Hostetler via GitGitGadget wrote:
[...]Quoted 35 lines
Documentation/technical/api-trace2.txt +27
-0@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is omitted, Git will try both. +== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings. + +Trace2 will try to load the following system configuration settings +and then read the corresponding environment variables at startup. + +.... +--------------------------------------------------- +trace2.normalTarget GIT_TR2 +trace2.normalBrief GIT_TR2_BRIEF + +trace2.perfTarget GIT_TR2_PERF +trace2.perfBrief GIT_TR2_PERF_BRIEF + +trace2.eventTarget GIT_TR2_EVENT +trace2.eventBrief GIT_TR2_EVENT_BRIEF +trace2.eventNesting GIT_TR2_EVENT_NESTING + +trace2.configParams GIT_TR2_CONFIG_PARAMS + +trace2.destinationDebug GIT_TR2_DST_DEBUG
Quoted 9 lines
Documentation/technical/api-trace2.txt values are recognized. · line 150
Quoted 4 lines
Documentation/technical/api-trace2.txt +4
-0+--------------------------------------------------- +.... + +A question for the list: should these new config vars also be documented in the git-config manpage, or is it better to keep these separate since they are only read from the system config?
I wasn't sure either, so I just kept them in the trace2 api doc for now. Jeff
Re: [PATCH v2 7/7] trace2: make SIDs more unique
In reply to Ævar Arnfjörð BjarmasonQuoted 49 lines · Ævar Arnfjörð Bjarmason
Quoted 24 lines · Jeff Hostetler via GitGitGadget
From: Jeff Hostetler <[email protected]>
Update SID component construction to use the current UTC datetime and a portion of the SHA1 of the hostname.
Use an simplified date/time format to make it easier to use the SID component as a logfile filename.
[...]trace2/tr2_sid.c +16
-0+static void tr2_sid_append_my_sid_component (void ) +{ +const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1 ]; +struct tr2_tbuf tb_now; +git_hash_ctx ctx; +unsigned char hash[GIT_MAX_RAWSZ +1 ]; +char hex[GIT_MAX_HEXSZ +1 ]; +char hostname[HOST_NAME_MAX +1 ]; + +tr2_tbuf_utc_datetime_for_filename (&tb_now); +strbuf_addstr (&tr2sid_buf, tb_now.buf); +strbuf_addch (&tr2sid_buf,'-' ); + +if (xgethostname (hostname,sizeof (hostname))) +xsnprintf (hostname,sizeof (hostname),"localhost" ); +trace2/tr2_sid.c line 42
Quoted 10 lines
trace2/tr2_sid.c +10
-0+ algo->init_fn (&ctx); + algo->update_fn (&ctx, hostname,strlen (hostname)); + algo->final_fn (hash, &ctx); +hash_to_hex_algop_r (hex, hash, algo); +strbuf_add (&tr2sid_buf, hex,8 ); + +strbuf_addch (&tr2sid_buf,'-' ); +strbuf_addf (&tr2sid_buf,"%06" PRIuMAX, (uintmax_t )getpid ()); +} +Thanks for turning my shitty half-formed idea into a patch :)
I wrote this on top to bikeshed this a bit further, wonder what you think:
https://github.com/gitgitgadget/git/compare/pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2...avar:pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v2So e.g.:
Before: 20190329-220413-446441-c2f5b994-018702 After: 20190329T220431.244562Z-Hc2f5b994-P19812F
Quoted 8 lines
I.e:
* Using <date>T<time> as is ISO 8601 convention/easier to read
* <dateime>.<microseconds>Z, so seperating with "." to indicate it's the same value + add "Z" for "it's UTC". I'm least sure about the ".". Is that going to cause issues on Windows these days (the rest being the "extension"...).
I had a version that did just that. I checked the various ISO and RFCs and it seems like the fractional seconds is usually allowed between the whole seconds and the "Z".
I've not seen any problems with that format.
I think I got spooked by your original suggestion to put the fraction in a term after the whole "<date>T<time>Z" term.
I'll convert it back to match your suggestion.
Quoted 4 lines
* I changed the hostname discovery so if
gethostbyname()fails we'll print "-H00000000-" for that part, instead of "-H<first 8 chars of the sha1 for 'localhost'>-". Also prefix with "H" for "Host".
I like that.
Quoted 3 lines
* Wrap pids to
0xffff, prefix with "P" (Pid)" and trail with either "F" = Full or "W" = Wrapped (not the real PID).
I could see the "P". I'm not sure about the hex -- I sometimes want to do a "ps" or watch the processes go by in TaskManager and friends and they all print the pid in decimal. But it's not that big a deal.
Quoted 9 lines
* I didn't add "T<datetime>" like "H" and "P" for the rest, since it's obvious what sort of value it is.
Maybe this is going a bit overboard, but I think it's easier to read at a glance for humans, and since it's meant to be opaque to machines anyway and the length is simliar enough not to matter I figure it's worth it.
I'll re-roll.
Thanks
Jeff
Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetHi,
Quoted 4 lines · Jeff Hostetler via GitGitGadget
Teach git to read the system config (usually "
/etc/gitconfig") for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
Yay! Thanks for writing this, and sorry for the slow review.
[...]
Quoted 4 lines
Only the system config file is used. Trace2 config values are ignored in local, global, and other config files. Likewise, the "-c" command line arguments are ignored for Trace2 values. These limits are for performance reasons.
Can you say a bit more about this? If I'm willing to pay the performance cost, is there a way for me to turn on respecting other config files? What is that performance cost?
[...]
Quoted 4 lines
Documentation/technical/api-trace2.txt +0
-0@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is
Documentation/technical/api-trace2.txt values are recognized. · line 127
Quoted 10 lines
Documentation/technical/api-trace2.txt +8
-0omitted, Git will try both. +== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings.
An additional limitation is that this doesn't appear to support include.* directives. Intended?
[...]
Quoted 2 lines
t/t0210-trace2-normal.sh +0
-0
[...]
t/t0210-trace2-normal.sh test_expect_success 'normal stream, error event' ' · line 154
Quoted 10 lines
t/t0210-trace2-normal.sh +10
-0+MOCK=./mock_system_config + +test_expect_success 'setup mocked /etc/gitconfig' ' + git config --file $MOCK trace2.normalTarget "$(pwd)/trace.normal" && + git config --file $MOCK trace2.normalBrief 1 +' + +test_expect_success 'using mock, normal stream, return code 0' ' + test_when_finished "rm trace.normal actual expect" && + GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 001return 0 &&
Tests run with GIT_CONFIG_NOSYSTEM=1 to protect themselves from any system config the user has.
So this would be easier to test if we can use user-level config for it.
[...]
Quoted 12 lines
trace2/tr2_sysenv.c new file +9
-0@@ -0,0 +1,128 @@ +#include "cache.h" +#include "config.h" +#include "dir.h" +#include "tr2_sysenv.h" + +/* +* Each entry represents a trace2 setting. +* See Documentation/technical/api-trace2.txt +*/
trace2/tr2_sysenv.c line 19
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+struct tr2_sysenv_entry { +const char *env_var_name; +const char *git_config_name; + +char *value; +unsigned int getenv_called :1 ; +}; + +/* +* This table must match "enum tr2_sysenv_variable" in tr2_sysenv.h.
Can we deduplicate to avoid the need to match?
Perhaps using C99 array initializers would help:
[TR2_SYSENV_CFG_PARAM] = { ... },[...]
Quoted 14 lines
trace2/tr2_sysenv.c new file +14
-0+/* +* Load Trace2 settings from the system config (usually "/etc/gitconfig" +* unless we were built with a runtime-prefix). These are intended to +* define the default values for Trace2 as requested by the administrator. +*/ +void tr2_sysenv_load (void ) +{ +const char *system_config_pathname; +const char *test_pathname; + + system_config_pathname =git_etc_gitconfig (); + + test_pathname =getenv ("GIT_TEST_TR2_SYSTEM_CONFIG" ); +if (test_pathname) {
trace2/tr2_sysenv.c line 86
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+if (!*test_pathname || !strcmp (test_pathname,"0" )) +return ;/* disable use of system config */ + +/* mock it with given test file */ + system_config_pathname = test_pathname; + } + +if (file_exists (system_config_pathname)) +git_config_from_file (tr2_sysenv_cb, system_config_pathname, +NULL );
This duplicates functionality from config.c and misses some features along the way (e.g. support for include.*).
Would read_early_config work? If we want a variant that doesn't discover_git_directory, we can change that function to handle it.
For our needs at Google, it would be very helpful to have support for include.* and reading settings from at least $HOME/.gitconfig in addition to /etc/gitconfig (even better if it supports per-repo config as well). I believe it would simplify the code and tests, too. If there's anything I can to help, please don't hesitate to ask.
Thanks,
Jonathan
Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings
In reply to Josh SteadmonQuoted 3 lines · Josh Steadmon
A question for the list: should these new config vars also be documented in the git-config manpage, or is it better to keep these separate since they are only read from the system config?
Yes, they should be in the git-config manpage.
*If* they are read only from the system config, the documentation there should say so.
Thanks,
Jonathan
Re: [PATCH v2 4/7] trace2: use system config for default trace2 settings
In reply to Jonathan NiederQuoted 12 lines · Jonathan Nieder
Hi,
Quoted 4 lines · Jeff Hostetler via GitGitGadget
Teach git to read the system config (usually "
/etc/gitconfig") for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.Yay! Thanks for writing this, and sorry for the slow review.
[...]
Quoted 8 lines
Quoted 4 lines
Only the system config file is used. Trace2 config values are ignored in local, global, and other config files. Likewise, the "-c" command line arguments are ignored for Trace2 values. These limits are for performance reasons.
Can you say a bit more about this? If I'm willing to pay the performance cost, is there a way for me to turn on respecting other config files? What is that performance cost?
Several thoughts here. Some are performance-related and some are startup chicken-n-egg problems. I tried to add trace2 to the code base in the least disruptive way possible and hopefully with minimal side-effects on existing behaviors. And also minimum impact on overall performance when not in use.
So, with that in mind:
[] Trace2 should be initialized as early as and lightly as possible
so that timers are started and it can capture events from other startup activities. And so that we can tell as early as possible if trace2 should NOT be enabled and short-cut those calls and not waste time collecting unnecessary data.
[] Trace2 is initialized by calls from common-main.c:main(). This
happens before cmd_main() is called, so we are very early in the startup process and very few things have been initialized. For example, I had to let git_resolve_executable_dir() run so that we could find the location of the system config, but that's about it. We have not even initialized "the_repository" yet.
[] WRT "-c var=val", this is processed by git.c:handle_options() and
called from git.c:cmd_main() and git.c:handle_alias(). So the "-c" args won't be respected until after that point.
Adding trace2 initialization after that point is a bit of a mess. Teaching trace2 to scan the argv for "-c" is just duplicating effort. And moving the "-c" processing earlier in the startup, changes the behavior of the "git-*" commands (which don't currently recognize the "-c" option).
So that's why I'm suggesting we not respect "-c" for this.
[] By initializing trace2 inside main() we guarantee that it will get
started. If we wait to initialize it until after handle_options() returns, we miss events for commands that it handles itself (such as "git --exec-path" where it just prints and exits or syntax errors where it directly calls usage() and exits).
[] WRT to per-repo config values:
In common-main.c:main() we have not yet discovered the .git dir, so repo-local config files are questionable at a very early point in the process startup. Again, it comes down to whether we wait for gitdir discovery (and whatever file system scanning, --gitdir, or -C processing is required) before deciding whether to start trace2 or not.
Also, per-repo trace2 config settings aren't available at the time of the clone, so just relying on them will leave our telemetry incomplete. It's better to have a system (or maybe a user) setting and not a per-repo setting.
Longer term, with submodules and plans to support them in-proc rather than via sub-processes, I don't think there should be any expectation that trace2 settings would adapt during recursive operations. So for example, a top-level command might see different trace2 settings than a command run inside a submodule. If submodule operations become in-proc, then to maintain that expected behavior we'd need to have per-repo trace2 settings. (Granted, not impossible, but by saying no to that now, we can eliminate a possible pain point in the future.)
[] i'll add more on this topic at the bottom of this note in response to
your per-user and includes questions.
Quoted 7 lines
[...]
Quoted 6 lines
Documentation/technical/api-trace2.txt +0
-0@@ -117,6 +117,37 @@ values are recognized. Socket type can be either `stream` or `dgram`. If the socket type is omitted, Git will try both.
Quoted 11 lines
Documentation/technical/api-trace2.txt values are recognized. · line 127
Quoted 8 lines
Documentation/technical/api-trace2.txt +8
-0+== Trace2 Settings in System Config + +Trace2 also reads configuration information from the system config. +This is intended to help adminstrators to gather system-wide Git +performance data. + +Trace2 only reads the system configuration, it does not read global, +local, worktree, or `-c` config settings.An additional limitation is that this doesn't appear to support include.* directives. Intended?
I didn't specifically intend to support or not-support include files here. Frankly, the complexity of the config code makes my eyes bleed. I'll investigate adding it.
Quoted 5 lines
[...]
Quoted 2 lines
t/t0210-trace2-normal.sh +0
-0[...]
Quoted 13 lines
t/t0210-trace2-normal.sh test_expect_success 'normal stream, error event' ' · line 154
Quoted 10 lines
t/t0210-trace2-normal.sh +10
-0+MOCK=./mock_system_config + +test_expect_success 'setup mocked /etc/gitconfig' ' + git config --file $MOCK trace2.normalTarget "$(pwd)/trace.normal" && + git config --file $MOCK trace2.normalBrief 1 +' + +test_expect_success 'using mock, normal stream, return code 0' ' + test_when_finished "rm trace.normal actual expect" && + GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 001return 0 &&Tests run with GIT_CONFIG_NOSYSTEM=1 to protect themselves from any system config the user has.
Thanks for the pointer. I'll update the tr2_sysenv_load() to check git_system_config() before trying to use the system config file.
Quoted 3 lines
So this would be easier to test if we can use user-level config for it.
I suppose. I think it just moves the testing problem to a trick using $HOME, right? But it does get rid of that GIT_TEST_TR2_SYSTEM_CONFIG symbol, so yeah a net win. I'll investigate. Thanks.
Quoted 26 lines
[...]
Quoted 12 lines
trace2/tr2_sysenv.c new file +9
-0@@ -0,0 +1,128 @@ +#include "cache.h" +#include "config.h" +#include "dir.h" +#include "tr2_sysenv.h" + +/* +* Each entry represents a trace2 setting. +* See Documentation/technical/api-trace2.txt +*/ trace2/tr2_sysenv.c line 19
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+struct tr2_sysenv_entry { +const char *env_var_name; +const char *git_config_name; + +char *value; +unsigned int getenv_called :1 ; +}; + +/* +* This table must match "enum tr2_sysenv_variable" in tr2_sysenv.h. Can we deduplicate to avoid the need to match?
Quoted 3 lines
Perhaps using C99 array initializers would help:
[TR2_SYSENV_CFG_PARAM] = { ... },
Cool. I hadn't seen that syntax before.
Quoted 30 lines
[...]
Quoted 14 lines
trace2/tr2_sysenv.c new file +14
-0+/* +* Load Trace2 settings from the system config (usually "/etc/gitconfig" +* unless we were built with a runtime-prefix). These are intended to +* define the default values for Trace2 as requested by the administrator. +*/ +void tr2_sysenv_load (void ) +{ +const char *system_config_pathname; +const char *test_pathname; + + system_config_pathname =git_etc_gitconfig (); + + test_pathname =getenv ("GIT_TEST_TR2_SYSTEM_CONFIG" ); +if (test_pathname) {trace2/tr2_sysenv.c line 86
Quoted 10 lines
trace2/tr2_sysenv.c new file +10
-0+if (!*test_pathname || !strcmp (test_pathname,"0" )) +return ;/* disable use of system config */ + +/* mock it with given test file */ + system_config_pathname = test_pathname; + } + +if (file_exists (system_config_pathname)) +git_config_from_file (tr2_sysenv_cb, system_config_pathname, +NULL );This duplicates functionality from
config.cand misses some features along the way (e.g. support for include.*).
Quoted 8 lines
Would
read_early_configwork? If we want a variant that doesn'tdiscover_git_directory, we can change that function to handle it.For our needs at Google, it would be very helpful to have support for include.* and reading settings from at least $HOME/.gitconfig in addition to
/etc/gitconfig(even better if it supports per-repo config as well). I believe it would simplify the code and tests, too. If there's anything I can to help, please don't hesitate to ask.
read_early_config() might work, but it is pretty heavy and doesn't address my above comments.
Perhaps a compromise would be to have it read just the system and user config files (w/ includes turned on). It shouldn't take too much time and it shouldn't have the startup-order dependencies, I think.
Thoughts??
Quoted 4 lines
Thanks,
Jonathan
Thanks,
Jeff
PATCH v3 1/10 config: initialize opts structure in repo_read_config()
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Initialize opts structure in repo_read_config().
This change fixes a crash in later commit after a new field is added to the structure.
In commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config() was added. It only initializes 3 fields in the opts structure. It is passed to config_with_options() and then to do_git_config_sequence(). However, do_git_config_sequence() drops the opts on the floor and calls git_config_from_file() rather than git_config_from_file_with_options(), so that may be why this hasn't been a problem in the past.
--- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
config.c +1 -1
@@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha/* Functions use to read configuration from a repository */ static void repo_read_config (struct repository *repo) { -struct config_options opts; +struct config_options opts = {0 }; opts.respect_includes =1 ; opts.commondir = repo->commondir;
Signature · 1 line
gitgitgadget
v3 cover trace2: load trace2 settings from system config
In reply to Jeff Hostetler via GitGitGadgetHere is version 3.
[] It incorporates Ævar's suggestions WRT the format and uniqueness of the SID. [] It now reads both system and global config for trace2 settings and handles includes as Jonathan suggested.
I added a read_very_early_config() function that is similar to read_early_config()but omits repo local, worktree, and -c command line settings. This felt like a little bit of a hack, but it made the intent clear. And it avoided asserting the various global variables were in a certain known state before calling the read_early_config().
In doing so, I uncovered an uninitialized opts variable in read_repo_config(). The first patch in this series addresses it in isolation. As the commit message suggests, this went undetected because opts variable doesn't get passed all the way down, but I'm not familiar enough with that code to know whether that's an accident or by design. Callers of config_with_options() all setopts.respect_includes and that changes the args that config_with_options()passes to the functions that it calls. What makes this a little more troubling is theopts.event_fn field added in 8032cc4462b8af268fe457c2a0431473334dfd18 that might not be initialized. Again, I'm not familiar enough with this code and the actually observable control flows thru it to know if that could cause an issue.
Jeff Hostetler (10):
config: initialize opts structure in repo_read_config()
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
config: add read_very_early_config()
trace2: use system/global config for default trace2 settings
trace2: report peak memory usage of the process
trace2: clarify UTC datetime formatting
trace2: make SIDs more unique
trace2: update docs to describe system/global config settings
Documentation/config.txt | 2 + Documentation/config/trace2.txt | 56 ++++++++ Documentation/technical/api-trace2.txt | 176 +++++++++++++---------- Documentation/trace2-target-values.txt | 10 ++ Makefile | 1 + common-main.c | 8 +- compat/mingw.c | 2 + compat/win32/trace2_win32_process_info.c | 50 ++++++- config.c | 27 +++- config.h | 4 + t/t0210-trace2-normal.sh | 49 ++++++- t/t0211-trace2-perf.sh | 43 ++++-- t/t0212-trace2-event.sh | 42 +++++- trace2.c | 21 ++- trace2.h | 43 ++++-- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 24 ++-- trace2/tr2_dst.h | 3 +- trace2/tr2_sid.c | 55 ++++++- trace2/tr2_sysenv.c | 127 ++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++ trace2/tr2_tbuf.c | 20 ++- trace2/tr2_tbuf.h | 5 +- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 53 +++---- trace2/tr2_tgt_normal.c | 19 +-- trace2/tr2_tgt_perf.c | 23 +-- trace2/tr2_tls.c | 38 +++-- trace2/tr2_tls.h | 8 +- 29 files changed, 750 insertions(+), 203 deletions(-) create mode 100644 Documentation/config/trace2.txt create mode 100644 Documentation/trace2-target-values.txt create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/169
Range-diff vs v2:
-: ---------- > 1: ea8c199f91 config: initialize opts structure in repo_read_config()
1: 7f1a347322 = 2: 3dbcfc6a8d trace2: refactor setting process starting time
2: c15f783c26 = 3: 8b00025af5 trace2: add absolute elapsed time to start event
3: d4023acde7 = 4: c3c5f6a96b trace2: find exec-dir before trace2 initialization
-: ---------- > 5: d15be7b63a config: add read_very_early_config()
4: d048f3ffb8 ! 6: c085a482dd trace2: use system config for default trace2 settings
@@ -1,8 +1,8 @@
Author: Jeff Hostetler <[email protected]>
- trace2: use system config for default trace2 settings
+ trace2: use system/global config for default trace2 settings
- Teach git to read the system config (usually "/etc/gitconfig") for
+ Teach git to read the system and global config files for
default Trace2 settings. This allows system-wide Trace2 settings to
be installed and inherited to make it easier to manage a collection of
systems.
@@ -10,10 +10,9 @@
The original GIT_TR2* environment variables are loaded afterwards and
can be used to override the system settings.
- Only the system config file is used. Trace2 config values are ignored
- in local, global, and other config files. Likewise, the "-c" command
- line arguments are ignored for Trace2 values. These limits are for
- performance reasons.
+ Only the system and global config files are used. Repo and worktree
+ local config files are ignored. Likewise, the "-c" command line
+ arguments are also ignored. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to
detect that Trace2 is not enabled. In particular, Trace2 should not
@@ -24,54 +23,8 @@
git process initialization (which involves discovering the .git directory
and reading a hierarchy of config files).
- Added the GIT_TEST_TR2_SYSTEM_CONFIG environment variable for testing
- purposes to specify the pathname of a fake "system" config or disable
- use of the system config.
-
Signed-off-by: Jeff Hostetler <[email protected]>
- diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
- --- a/Documentation/technical/api-trace2.txt
- +++ b/Documentation/technical/api-trace2.txt
-@@
- Socket type can be either `stream` or `dgram`. If the socket type is
- omitted, Git will try both.
-
-+== Trace2 Settings in System Config
-+
-+Trace2 also reads configuration information from the system config.
-+This is intended to help adminstrators to gather system-wide Git
-+performance data.
-+
-+Trace2 only reads the system configuration, it does not read global,
-+local, worktree, or `-c` config settings.
-+
-+Trace2 will try to load the following system configuration settings
-+and then read the corresponding environment variables at startup.
-+
-+....
-+---------------------------------------------------
-+trace2.normalTarget GIT_TR2
-+trace2.normalBrief GIT_TR2_BRIEF
-+
-+trace2.perfTarget GIT_TR2_PERF
-+trace2.perfBrief GIT_TR2_PERF_BRIEF
-+
-+trace2.eventTarget GIT_TR2_EVENT
-+trace2.eventBrief GIT_TR2_EVENT_BRIEF
-+trace2.eventNesting GIT_TR2_EVENT_NESTING
-+
-+trace2.configParams GIT_TR2_CONFIG_PARAMS
-+
-+trace2.destinationDebug GIT_TR2_DST_DEBUG
-+---------------------------------------------------
-+....
-+
-+
- == Trace2 API
-
- All public Trace2 functions and macros are defined in `trace2.h` and
-
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -90,10 +43,6 @@
@@
#!/bin/sh
-+# Disable loading of Trace2 settings from the system config
-+# (usually "/etc/gitconfig") to eliminate system dependencies.
-+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG
-+
+# Turn off any inherited trace2 settings for this test.
+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
+unset GIT_TR2_BRIEF
@@ -118,22 +67,34 @@
test_cmp expect actual
'
-+# Now test using system config by using a mocked up config file
-+# rather than inheriting "/etc/gitconfig". Here we do not use
-+# GIT_TR2* environment variables.
-+
+unset GIT_TR2_BRIEF
+
-+MOCK=./mock_system_config
++# Now test without environment variables and get all Trace2 settings
++# from the global config.
+
-+test_expect_success 'setup mocked /etc/gitconfig' '
-+ git config --file $MOCK trace2.normalTarget "$(pwd)/trace.normal" &&
-+ git config --file $MOCK trace2.normalBrief 1
++test_expect_success 'using global config, normal stream, return code 0' '
++ test_when_finished "rm trace.normal actual expect" &&
++ test_config_global trace2.normalBrief 1 &&
++ test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
++ test-tool trace2 001return 0 &&
++ perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
++ cat >expect <<-EOF &&
++ version $V
++ start _EXE_ trace2 001return 0
++ cmd_name trace2 (trace2)
++ exit elapsed:_TIME_ code:0
++ atexit elapsed:_TIME_ code:0
++ EOF
++ test_cmp expect actual
+'
+
-+test_expect_success 'using mock, normal stream, return code 0' '
-+ test_when_finished "rm trace.normal actual expect" &&
-+ GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 001return 0 &&
++test_expect_success 'using global config with include' '
++ test_when_finished "rm trace.normal actual expect real.gitconfig" &&
++ test_config_global trace2.normalBrief 1 &&
++ test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
++ mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" &&
++ test_config_global include.path "$(pwd)/real.gitconfig" &&
++ test-tool trace2 001return 0 &&
+ perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ cat >expect <<-EOF &&
+ version $V
@@ -153,10 +114,6 @@
@@
#!/bin/sh
-+# Disable loading of Trace2 settings from the system config
-+# (usually "/etc/gitconfig") to eliminate system dependencies.
-+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG
-+
+# Turn off any inherited trace2 settings for this test.
+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
+unset GIT_TR2_PERF_BRIEF
@@ -181,22 +138,16 @@
test_cmp expect actual
'
-+# Now test using system config by using a mocked up config file
-+# rather than inheriting "/etc/gitconfig". Here we do not use
-+# GIT_TR2* environment variables.
-+
+unset GIT_TR2_PERF_BRIEF
+
-+MOCK=./mock_system_config
-+
-+test_expect_success 'setup mocked /etc/gitconfig' '
-+ git config --file $MOCK trace2.perfTarget "$(pwd)/trace.perf" &&
-+ git config --file $MOCK trace2.perfBrief 1
-+'
++# Now test without environment variables and get all Trace2 settings
++# from the global config.
+
-+test_expect_success 'using mock, perf stream, return code 0' '
++test_expect_success 'using global config, perf stream, return code 0' '
+ test_when_finished "rm trace.perf actual expect" &&
-+ GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 001return 0 &&
++ test_config_global trace2.perfBrief 1 &&
++ test_config_global trace2.perfTarget "$(pwd)/trace.perf" &&
++ test-tool trace2 001return 0 &&
+ perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual &&
+ cat >expect <<-EOF &&
+ d0|main|version|||||$V
@@ -216,10 +167,6 @@
@@
#!/bin/sh
-+# Disable loading of Trace2 settings from the system config
-+# (usually "/etc/gitconfig") to eliminate system dependencies.
-+GIT_TEST_TR2_SYSTEM_CONFIG=0 && export GIT_TEST_TR2_SYSTEM_CONFIG
-+
+# Turn off any inherited trace2 settings for this test.
+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
+unset GIT_TR2_BARE
@@ -244,19 +191,13 @@
test_cmp expect actual
'
-+# Now test using system config by using a mocked up config file
-+# rather than inheriting "/etc/gitconfig". Here we do not use
-+# GIT_TR2* environment variables.
-+
-+MOCK=./mock_system_config
++# Now test without environment variables and get all Trace2 settings
++# from the global config.
+
-+test_expect_success 'setup mocked /etc/gitconfig' '
-+ git config --file $MOCK trace2.eventTarget "$(pwd)/trace.event"
-+'
-+
-+test_expect_success JSON_PP 'using mock, event stream, error event' '
++test_expect_success JSON_PP 'using global config, event stream, error event' '
+ test_when_finished "rm trace.event actual expect" &&
-+ GIT_TEST_TR2_SYSTEM_CONFIG="$MOCK" test-tool trace2 003error "hello world" "this is a test" &&
++ test_config_global trace2.eventTarget "$(pwd)/trace.event" &&
++ test-tool trace2 003error "hello world" "this is a test" &&
+ perl "$TEST_DIRECTORY/t0212/parse_events.perl" <trace.event >actual &&
+ sed -e "s/^|//" >expect <<-EOF &&
+ |VAR1 = {
@@ -503,8 +444,9 @@
+
+/*
+ * This table must match "enum tr2_sysenv_variable" in tr2_sysenv.h.
-+ * These strings are constant and must match the published names as
-+ * described in the documentation.
++ *
++ * The strings in this table are constant and must match the published
++ * config and environment variable names as described in the documentation.
+ *
+ * We do not define entries for the GIT_TR2_PARENT_* environment
+ * variables because they are transient and used to pass information
@@ -512,19 +454,28 @@
+ */
+/* clang-format off */
+static struct tr2_sysenv_entry tr2_sysenv_settings[] = {
-+ { "GIT_TR2_CONFIG_PARAMS", "trace2.configparams" },
-+
-+ { "GIT_TR2_DST_DEBUG", "trace2.destinationdebug" },
-+
-+ { "GIT_TR2", "trace2.normaltarget" },
-+ { "GIT_TR2_BRIEF", "trace2.normalbrief" },
-+
-+ { "GIT_TR2_EVENT", "trace2.eventtarget" },
-+ { "GIT_TR2_EVENT_BRIEF", "trace2.eventbrief" },
-+ { "GIT_TR2_EVENT_NESTING", "trace2.eventnesting" },
-+
-+ { "GIT_TR2_PERF", "trace2.perftarget" },
-+ { "GIT_TR2_PERF_BRIEF", "trace2.perfbrief" },
++ [TR2_SYSENV_CFG_PARAM] = { "GIT_TR2_CONFIG_PARAMS",
++ "trace2.configparams" },
++
++ [TR2_SYSENV_DST_DEBUG] = { "GIT_TR2_DST_DEBUG",
++ "trace2.destinationdebug" },
++
++ [TR2_SYSENV_NORMAL] = { "GIT_TR2",
++ "trace2.normaltarget" },
++ [TR2_SYSENV_NORMAL_BRIEF] = { "GIT_TR2_BRIEF",
++ "trace2.normalbrief" },
++
++ [TR2_SYSENV_EVENT] = { "GIT_TR2_EVENT",
++ "trace2.eventtarget" },
++ [TR2_SYSENV_EVENT_BRIEF] = { "GIT_TR2_EVENT_BRIEF",
++ "trace2.eventbrief" },
++ [TR2_SYSENV_EVENT_NESTING] = { "GIT_TR2_EVENT_NESTING",
++ "trace2.eventnesting" },
++
++ [TR2_SYSENV_PERF] = { "GIT_TR2_PERF",
++ "trace2.perftarget" },
++ [TR2_SYSENV_PERF_BRIEF] = { "GIT_TR2_PERF_BRIEF",
++ "trace2.perfbrief" },
+};
+/* clang-format on */
+
@@ -550,31 +501,20 @@
+ * Load Trace2 settings from the system config (usually "/etc/gitconfig"
+ * unless we were built with a runtime-prefix). These are intended to
+ * define the default values for Trace2 as requested by the administrator.
++ *
++ * Then override with the Trace2 settings from the global config.
+ */
+void tr2_sysenv_load(void)
+{
-+ const char *system_config_pathname;
-+ const char *test_pathname;
-+
-+ system_config_pathname = git_etc_gitconfig();
-+
-+ test_pathname = getenv("GIT_TEST_TR2_SYSTEM_CONFIG");
-+ if (test_pathname) {
-+ if (!*test_pathname || !strcmp(test_pathname, "0"))
-+ return; /* disable use of system config */
-+
-+ /* mock it with given test file */
-+ system_config_pathname = test_pathname;
-+ }
++ if (ARRAY_SIZE(tr2_sysenv_settings) != TR2_SYSENV_MUST_BE_LAST)
++ BUG("tr2_sysenv_settings size is wrong");
+
-+ if (file_exists(system_config_pathname))
-+ git_config_from_file(tr2_sysenv_cb, system_config_pathname,
-+ NULL);
++ read_very_early_config(tr2_sysenv_cb, NULL);
+}
+
+/*
-+ * Return the value for the requested setting. Start with the /etc/gitconfig
-+ * value and allow the corresponding environment variable to override it.
++ * Return the value for the requested Trace2 setting from these sources:
++ * the system config, the global config, and the environment.
+ */
+const char *tr2_sysenv_get(enum tr2_sysenv_variable var)
+{
5: 86d8fe28cf = 7: 2a7a933875 trace2: report peak memory usage of the process
6: ae11cc4186 = 8: 56f357dc7b trace2: clarify UTC datetime formatting
7: 4352952677 ! 9: 156ffde489 trace2: make SIDs more unique
@@ -22,11 +22,11 @@
-{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"}
-{"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}
-{"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}
-+{"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"}
-+{"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"]}
-+{"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"}
-+{"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}
-+{"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}
++{"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"}
++{"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"]}
++{"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"}
++{"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}
++{"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}
------------
== Enabling a Target
@@ -35,10 +35,16 @@
{
"event":"version",
- "sid":"1547659722619736-11614",
-+ "sid":"20190329-144314-319944-9b68c35f-012232",
++ "sid":"20190408T191827.272759Z-H9b68c35f-P011764",
"thread":"main",
- "time":"2019-01-16T17:28:42.620713Z",
+- "time":"2019-01-16T17:28:42.620713Z",
++ "time":"2019-04-08T19:18:27.282761Z",
"file":"common-main.c",
+- "line":38,
++ "line":42,
+ ...
+ }
+ ------------
diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c
--- a/trace2/tr2_sid.c
@@ -56,34 +62,50 @@
+/*
+ * Compute the final component of the SID representing the current process.
+ * This should uniquely identify the process and be a valid filename (to
-+ * allow writing trace2 data to per-process files).
++ * allow writing trace2 data to per-process files). It should also be fixed
++ * possible length for use as a database key.
++ *
++ * "<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>"
++ *
++ * where <host> is a 9 character string:
++ * "H<first_8_chars_of_sha1_of_hostname>"
++ * "Localhost" when no hostname.
+ *
-+ * <yyyymmdd> '-' <hhmmss> '-' <fraction> '-' <sha1-prefix> '-' <pid>
++ * where <process> is a possibly wrapped PID:
++ * "P<6-digit-pid>"
++ * "W<wrapped-6-digit-pid>" when PID too big.
++ *
+ */
+static void tr2_sid_append_my_sid_component(void)
+{
+ const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];
+ struct tr2_tbuf tb_now;
+ git_hash_ctx ctx;
++ uintmax_t pid = getpid();
+ unsigned char hash[GIT_MAX_RAWSZ + 1];
+ char hex[GIT_MAX_HEXSZ + 1];
+ char hostname[HOST_NAME_MAX + 1];
+
-+ tr2_tbuf_utc_datetime_for_filename(&tb_now);
++ tr2_tbuf_utc_datetime(&tb_now);
+ strbuf_addstr(&tr2sid_buf, tb_now.buf);
-+ strbuf_addch(&tr2sid_buf, '-');
+
++ strbuf_addch(&tr2sid_buf, '-');
+ if (xgethostname(hostname, sizeof(hostname)))
-+ xsnprintf(hostname, sizeof(hostname), "localhost");
-+
-+ algo->init_fn(&ctx);
-+ algo->update_fn(&ctx, hostname, strlen(hostname));
-+ algo->final_fn(hash, &ctx);
-+ hash_to_hex_algop_r(hex, hash, algo);
-+ strbuf_add(&tr2sid_buf, hex, 8);
++ strbuf_add(&tr2sid_buf, "Localhost", 9);
++ else {
++ algo->init_fn(&ctx);
++ algo->update_fn(&ctx, hostname, strlen(hostname));
++ algo->final_fn(hash, &ctx);
++ hash_to_hex_algop_r(hex, hash, algo);
++ strbuf_addch(&tr2sid_buf, 'H');
++ strbuf_add(&tr2sid_buf, hex, 8);
++ }
+
+ strbuf_addch(&tr2sid_buf, '-');
-+ strbuf_addf(&tr2sid_buf, "%06"PRIuMAX, (uintmax_t)getpid());
++ if (pid > 999999)
++ strbuf_addf(&tr2sid_buf, "W%06d", (int)(pid % 1000000));
++ else
++ strbuf_addf(&tr2sid_buf, "P%06d", (int)pid);
+}
+
/*
@@ -117,7 +139,7 @@
(long)tv.tv_usec);
}
+
-+void tr2_tbuf_utc_datetime_for_filename(struct tr2_tbuf *tb)
++void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)
+{
+ struct timeval tv;
+ struct tm tm;
@@ -128,7 +150,7 @@
+ gmtime_r(&secs, &tm);
+
+ xsnprintf(tb->buf, sizeof(tb->buf),
-+ "%4d%02d%02d-%02d%02d%02d-%06ld", tm.tm_year + 1900,
++ "%4d%02d%02dT%02d%02d%02d.%06ldZ", tm.tm_year + 1900,
+ tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
+ (long)tv.tv_usec);
+}
@@ -140,6 +162,6 @@
* Fill buffer with formatted UTC datatime string.
*/
void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb);
-+void tr2_tbuf_utc_datetime_for_filename(struct tr2_tbuf *tb);
++void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb);
#endif /* TR2_TBUF_H */ -: ---------- > 10: 285beb2b2d trace2: update docs to describe system/global config settings
Signature · 1 line
gitgitgadget
PATCH v3 3/10 trace2: add absolute elapsed time to start event
From: Jeff Hostetler <[email protected]>
Add elapsed process time to "start" event to measure the performance of early process startup.
--- Documentation/technical/api-trace2.txt | 11 ++++++----- t/t0211-trace2-perf.sh | 12 ++++++------ trace2.c | 8 +++++++- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 5 ++++- trace2/tr2_tgt_normal.c | 3 ++- trace2/tr2_tgt_perf.c | 7 ++++--- 7 files changed, 30 insertions(+), 17 deletions(-)
Documentation/technical/api-trace2.txt +6 -5
@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.perf 12:28:42.620675 common-main.c:38 | d0 | main | version | | | | | 2.20.1.155.g426c96fcdb -12:28:42.621001 common-main.c:39 | d0 | main | start | | | | | git version +12:28:42.621001 common-main.c:39 | d0 | main | start | | 0.001173 | | | git version 12:28:42.621111 git.c:432 | d0 | main | cmd_name | | | | | version (version) 12:28:42.621225 git.c:662 | d0 | main | exit | | 0.001227 | | | code:0 12:28:42.621259 trace2/tr2_tgt_perf.c:211 | d0 | main | atexit | | 0.001265 | | | code:0
@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.event {"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"} -{"event":"start","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16 17:28:42.621027","file":"common-main.c","line":39,"argv":["git","version"]} +{"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"]} {"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"} {"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} {"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}
@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the "start" and { "event":"start", ... + "t_abs":0.001227, # elapsed time in seconds "argv":["git","version"] } ------------
@@ -1118,7 +1119,7 @@ $ git status $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.160.g5676107ecd.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1163,7 +1164,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.162.gb4ccea44db.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1219,7 +1220,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.156.gf9916ae094.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) d0 | main | region_enter | r1 | 0.001791 | | index | label:do_read_index .git/index
t/t0211-trace2-perf.sh +6 -6
@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:0 d0|main|atexit||_T_ABS_|||code:0
@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 1 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:1 d0|main|atexit||_T_ABS_|||code:1
@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' + d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' d0|main|cmd_name|||||trace2 (trace2) d0|main|error|||||hello world d0|main|error|||||this is a test
@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0 d1|main|version|||||$V - d1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0 + d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0 d1|main|cmd_name|||||trace2 (trace2/trace2) d1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0 d2|main|version|||||$V - d2|main|start|||||_EXE_ trace2 001return 0 + d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d2|main|cmd_name|||||trace2 (trace2/trace2/trace2) d2|main|exit||_T_ABS_|||code:0 d2|main|atexit||_T_ABS_|||code:0
trace2.c +7 -1
@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv) {struct tr2_tgt *tgt_j;int j; +uint64_t us_now; +uint64_t us_elapsed_absolute;if (!trace2_enabled)return ; + us_now =getnanotime () /1000 ; + us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); + for_each_wanted_builtin (j, tgt_j)if (tgt_j->pfn_start_fl) - tgt_j->pfn_start_fl (file, line, argv); + tgt_j->pfn_start_fl (file, line, us_elapsed_absolute, + argv); }int trace2_cmd_exit_fl (const char *file,int line,int code)
trace2/tr2_tgt.h +1 -0
@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);typedef void (tr2_tgt_evt_version_fl_t )(const char *file,int line);typedef void (tr2_tgt_evt_start_fl_t )(const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv);typedef void (tr2_tgt_evt_exit_fl_t )(const char *file,int line,uint64_t us_elapsed_absolute,int code);
trace2/tr2_tgt_event.c +4 -1
@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)jw_release (&jw); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct json_writer jw =JSON_WRITER_INIT ; +double t_abs = (double )us_elapsed_absolute /1000000.0 ;jw_object_begin (&jw,0 );event_fmt_prepare (event_name, file, line,NULL , &jw); +jw_object_double (&jw,"t_abs" ,6 , t_abs);jw_object_inline_begin_array (&jw,"argv" );jw_array_argv (&jw, argv);jw_end (&jw);
trace2/tr2_tgt_normal.c +2 -1
@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {struct strbuf buf_payload =STRBUF_INIT ;
trace2/tr2_tgt_perf.c +4 -3
@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct strbuf buf_payload =STRBUF_INIT ;sq_quote_argv_pretty (&buf_payload, argv); -perf_io_write_fl (file, line, event_name,NULL ,NULL ,NULL ,NULL , - &buf_payload); +perf_io_write_fl (file, line, event_name,NULL , &us_elapsed_absolute, +NULL ,NULL , &buf_payload);strbuf_release (&buf_payload); }
Signature · 1 line
gitgitgadget
PATCH v3 5/10 config: add read_very_early_config()
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Created an even lighter version of read_early_config() that only looks at system and global config settings. It omits repo-local, worktree-local, and command-line settings.
--- config.c | 25 ++++++++++++++++++++++--- config.h | 4 ++++ 2 files changed, 26 insertions(+), 3 deletions(-)
config.c +22 -3
@@ -1688,14 +1688,16 @@ static int do_git_config_sequence(const struct config_options *opts, ret +=git_config_from_file (fn, user_config, data); current_parsing_scope =CONFIG_SCOPE_REPO ; -if (repo_config && !access_or_die (repo_config,R_OK ,0 )) +if (!opts->ignore_repo && + repo_config && !access_or_die (repo_config,R_OK ,0 )) ret +=git_config_from_file (fn, repo_config, data);/* * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. * But let's not complicate things before it's actually needed. */ -if (repository_format_worktree_config) { +if (!opts->ignore_worktree && + repository_format_worktree_config) {char *path =git_pathdup ("config.worktree" );if (!access_or_die (path,R_OK ,0 )) ret +=git_config_from_file (fn, path, data);
@@ -1703,7 +1705,8 @@ static int do_git_config_sequence(const struct config_options *opts, } current_parsing_scope =CONFIG_SCOPE_CMDLINE ; -if (git_config_from_parameters (fn, data) <0 ) +if (!opts->ignore_cmdline && +git_config_from_parameters (fn, data) <0 )die (_ ("unable to parse command-line config" )); current_parsing_scope =CONFIG_SCOPE_UNKNOWN ;
@@ -1794,6 +1797,22 @@ void read_early_config(config_fn_t cb, void *data)strbuf_release (&gitdir); } +/* +* Read config but only enumerate system and global settings. +* Omit any repo-local, worktree-local, or command-line settings. +*/ +void read_very_early_config (config_fn_t cb,void *data) +{ +struct config_options opts = {0 }; + + opts.respect_includes =1 ; + opts.ignore_repo =1 ; + opts.ignore_worktree =1 ; + opts.ignore_cmdline =1 ; + +config_with_options (cb, data,NULL , &opts); +} +static struct config_set_element *configset_find_element (struct config_set *cs,const char *key) {struct config_set_element k;
config.h +4 -0
@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,struct config_options {unsigned int respect_includes :1 ; +unsigned int ignore_repo :1 ; +unsigned int ignore_worktree :1 ; +unsigned int ignore_cmdline :1 ;const char *commondir;const char *git_dir;config_parser_event_fn_t event_fn;
@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,extern void git_config_push_parameter (const char *text);extern int git_config_from_parameters (config_fn_t fn,void *data);extern void read_early_config (config_fn_t cb,void *data); +extern void read_very_early_config (config_fn_t cb,void *data);extern void git_config (config_fn_t fn,void *); extern int config_with_options(config_fn_t fn, void *, struct git_config_source *config_source,
Signature · 1 line
gitgitgadget
PATCH v3 8/10 trace2: clarify UTC datetime formatting
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update tr2_tbuf_utc_datetime to generate extended UTC format. Update tr2_tgt_event target to use extended format in 'time' columns.
--- Documentation/technical/api-trace2.txt | 12 ++++++------ trace2/tr2_tbuf.c | 4 ++-- trace2/tr2_tbuf.h | 4 ++-- trace2/tr2_tgt_event.c | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-)
Documentation/technical/api-trace2.txt +6 -6
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"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"} -{"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} -{"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} +{"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"} +{"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"]} +{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} +{"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} +{"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} ------------ == Enabling a Target
@@ -542,7 +542,7 @@ The following key/value pairs are common to all events: "event":"version", "sid":"1547659722619736-11614", "thread":"main", - "time":"2019-01-16 17:28:42.620713", + "time":"2019-01-16T17:28:42.620713Z", "file":"common-main.c", "line":38, ...
trace2/tr2_tbuf.c +2 -2
@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb) tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } -void tr2_tbuf_utc_time (struct tr2_tbuf *tb) +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb) {struct timeval tv;struct tm tm;
@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)gmtime_r (&secs, &tm);xsnprintf (tb->buf,sizeof (tb->buf), -"%4d-%02d-%02d %02d:%02d:%02d.%06ld" , tm.tm_year +1900 , +"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ" , tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long )tv.tv_usec); }
trace2/tr2_tbuf.h +2 -2
@@ -16,8 +16,8 @@ struct tr2_tbuf {void tr2_tbuf_local_time (struct tr2_tbuf *tb);/* -* Fill buffer with formatted UTC time string. +* Fill buffer with formatted UTC datatime string. */ -void tr2_tbuf_utc_time (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
trace2/tr2_tgt_event.c +1 -1
@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,*/ if (!tr2env_event_be_brief || !strcmp (event_name,"version" ) || !strcmp (event_name,"atexit" )) { -tr2_tbuf_utc_time (&tb_now); +tr2_tbuf_utc_datetime_extended (&tb_now);jw_object_string (jw,"time" , tb_now.buf); }
Signature · 1 line
gitgitgadget
PATCH v3 7/10 trace2: report peak memory usage of the process
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Windows version of git to report peak memory usage during exit() processing.
--- common-main.c | 2 +- compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++-- trace2.c | 2 + trace2.h | 14 +++++-- 4 files changed, 60 insertions(+), 8 deletions(-)
common-main.c +1 -1
@@ -41,7 +41,7 @@ int main(int argc, const char **argv)trace2_initialize ();trace2_cmd_start (argv); -trace2_collect_process_info (); +trace2_collect_process_info (TRACE2_PROCESS_INFO_STARTUP );git_setup_gettext ();
compat/win32/trace2_win32_process_info.c +47 -3
63 lines not on this page · raw message
trace2.c +2 -0
@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)if (!trace2_enabled)return code; +trace2_collect_process_info (TRACE2_PROCESS_INFO_EXIT ); + tr2main_exit_code = code; us_now =getnanotime () /1000 ;
trace2.h +10 -4
@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);* Optional platform-specific code to dump information about the * current and any parent process(es). This is intended to allow * post-processors to know who spawned this git instance and anything -* else the platform may be able to tell us about the current process. +* else that the platform may be able to tell us about the current process. */ + +enum trace2_process_info_reason { +TRACE2_PROCESS_INFO_STARTUP , +TRACE2_PROCESS_INFO_EXIT , +}; +#if defined(GIT_WINDOWS_NATIVE ) -void trace2_collect_process_info (void ); +void trace2_collect_process_info (enum trace2_process_info_reason reason);#else -#define trace2_collect_process_info () \ - do { \ +#define trace2_collect_process_info (reason) \ + do { \ } while (0)#endif
Signature · 1 line
gitgitgadget
PATCH v3 10/10 trace2: update docs to describe system/global config settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
--- Documentation/config.txt | 2 + Documentation/config/trace2.txt | 56 ++++++++++ Documentation/technical/api-trace2.txt | 141 ++++++++++++++----------- Documentation/trace2-target-values.txt | 10 ++ 4 files changed, 147 insertions(+), 62 deletions(-) create mode 100644 Documentation/config/trace2.txt create mode 100644 Documentation/trace2-target-values.txt
Documentation/config.txt +2 -0
@@ -422,6 +422,8 @@ include::config/submodule.txt[] include::config/tag.txt[] +include::config/trace2.txt[] + include::config/transfer.txt[] include::config/uploadarchive.txt[]
Documentation/config/trace2.txt new file +56 -0
56 lines not on this page · raw message
Documentation/technical/api-trace2.txt +79 -62
244 lines not on this page · raw message
Documentation/trace2-target-values.txt new file +10 -0
@@ -0,0 +1,10 @@ +-- +* `0` or `false` - Disables the target. +* `1` or `true` - Writes to `STDERR`. +* `[2-9]` - Writes to the already opened file descriptor. +* `<absolute-pathname>` - Writes to the file in append mode. +* `af_unix:[<socket_type>:]<absolute-pathname>` - Write to a +Unix DomainSocket (on platforms that support them). Socket +type can be either `stream` or `dgram`; if omitted Git will +try both. +--
Signature · 1 line
gitgitgadget
PATCH v3 9/10 trace2: make SIDs more unique
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update SID component construction to use the current UTC datetime and a portion of the SHA1 of the hostname.
Use an simplified date/time format to make it easier to use the SID component as a logfile filename.
--- Documentation/technical/api-trace2.txt | 16 ++++---- trace2/tr2_sid.c | 55 ++++++++++++++++++++++++-- trace2/tr2_tbuf.c | 16 ++++++++ trace2/tr2_tbuf.h | 1 + 4 files changed, 76 insertions(+), 12 deletions(-)
Documentation/technical/api-trace2.txt +8 -8
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} -{"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} -{"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} +{"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"} +{"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"]} +{"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"} +{"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} +{"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} ------------ == Enabling a Target
@@ -540,11 +540,11 @@ The following key/value pairs are common to all events: ------------ { "event":"version", - "sid":"1547659722619736-11614", + "sid":"20190408T191827.272759Z-H9b68c35f-P011764", "thread":"main", - "time":"2019-01-16T17:28:42.620713Z", + "time":"2019-04-08T19:18:27.282761Z", "file":"common-main.c", - "line":38, + "line":42, ... } ------------
trace2/tr2_sid.c +51 -4
77 lines not on this page · raw message
trace2/tr2_tbuf.c +16 -0
@@ -30,3 +30,19 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb) tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } + +void tr2_tbuf_utc_datetime (struct tr2_tbuf *tb) +{ +struct timeval tv; +struct tm tm; +time_t secs; + +gettimeofday (&tv,NULL ); + secs = tv.tv_sec; +gmtime_r (&secs, &tm); + +xsnprintf (tb->buf,sizeof (tb->buf), +"%4d%02d%02dT%02d%02d%02d.%06ldZ" , tm.tm_year +1900 , + tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, + (long )tv.tv_usec); +}
trace2/tr2_tbuf.h +1 -0
@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);* Fill buffer with formatted UTC datatime string. */ void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
Signature · 1 line
gitgitgadget
PATCH v3 2/10 trace2: refactor setting process starting time
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Create trace2_initialize_clock() and call from main() to capture process start time in isolation and before other sub-systems are ready.
--- Documentation/technical/api-trace2.txt | 12 ++++++-- common-main.c | 2 ++ compat/mingw.c | 2 ++ trace2.c | 7 ++++- trace2.h | 17 ++++++++++++ trace2/tr2_tls.c | 38 ++++++++++++++++---------- trace2/tr2_tls.h | 8 +++++- 7 files changed, 67 insertions(+), 19 deletions(-)
Documentation/technical/api-trace2.txt +9 -3
@@ -160,17 +160,23 @@ purposes. These are concerned with the lifetime of the overall git process. +`void trace2_initialize_clock()`:: + + Initialize the Trace2 start clock and nothing else. This should + be called at the very top of main() to capture the process start + time and reduce startup order dependencies. + `void trace2_initialize()`:: Determines if any Trace2 Targets should be enabled and - initializes the Trace2 facility. This includes starting the - elapsed time clocks and thread local storage (TLS). + initializes the Trace2 facility. This includes setting up the + Trace2 thread local storage (TLS). + This function emits a "version" message containing the version of git and the Trace2 protocol. + This function should be called from `main()` as early as possible in -the life of the process. +the life of the process after essential process initialization. `int trace2_is_enabled()`::
common-main.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, const char **argv) {int result; +trace2_initialize_clock (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed
compat/mingw.c +2 -0
@@ -2569,6 +2569,8 @@ void mingw_startup(void)wchar_t **wenv, **wargv;_startupinfo si; +trace2_initialize_clock (); +maybe_redirect_std_handles ();/* get wide char arguments and environment */
trace2.c +6 -1
@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)raise (signo); } +void trace2_initialize_clock (void ) +{ +tr2tls_start_process_clock (); +} +void trace2_initialize_fl (const char *file,int line) {struct tr2_tgt *tgt_j;
@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name) us_now =getnanotime () /1000 ; us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); -tr2tls_create_self (thread_name); +tr2tls_create_self (thread_name, us_now);for_each_wanted_builtin (j, tgt_j) if (tgt_j->pfn_thread_start_fl)
trace2.h +17 -0
@@ -19,6 +19,23 @@ struct json_writer;* [] trace2_printf* -- legacy trace[1] messages. */ +/* +* Initialize the TRACE2 clock and do nothing else, in particular +* no mallocs, no system inspection, and no environment inspection. +* +* This should be called at the very top of main() to capture the +* process start time. This is intended to reduce chicken-n-egg +* bootstrap pressure. +* +* It is safe to call this more than once. This allows capturing +* absolute startup costs on Windows which uses a little trickery +* to do setup work before common-main.c:main() is called. +* +* The main trace2_initialize_fl() may be called a little later +* after more infrastructure is established. +*/ +void trace2_initialize_clock (void ); +/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 * targets are enabled in the environment. Emits a 'version' event.
trace2/tr2_tls.c +24 -14
@@ -10,16 +10,30 @@#define TR2_REGION_NESTING_INITIAL_SIZE (100)static struct tr2tls_thread_ctx *tr2tls_thread_main; -static uint64_t tr2tls_us_start_main; +static uint64_t tr2tls_us_start_process;static pthread_mutex_t tr2tls_mutex;static pthread_key_t tr2tls_key;static int tr2_next_thread_id;/* modify under lock */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name) +void tr2tls_start_process_clock (void ) +{ +if (tr2tls_us_start_process) +return ; + +/* +* Keep the absolute start time of the process (i.e. the main +* process) in a fixed variable since other threads need to +* access it. This allows them to do that without a lock on +* main thread's array data (because of reallocs). +*/ + tr2tls_us_start_process =getnanotime () /1000 ; +} + +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start) { -uint64_t us_now =getnanotime () /1000 ;struct tr2tls_thread_ctx *ctx =xcalloc (1 ,sizeof (*ctx));/*
@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)*/ ctx->alloc =TR2_REGION_NESTING_INITIAL_SIZE ; ctx->array_us_start = (uint64_t *)xcalloc (ctx->alloc,sizeof (uint64_t )); - ctx->array_us_start[ctx->nr_open_regions++] = us_now; + ctx->array_us_start[ctx->nr_open_regions++] = us_thread_start; ctx->thread_id =tr2tls_locked_increment (&tr2_next_thread_id);
@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)* here and silently continue. */ if (!ctx) - ctx =tr2tls_create_self ("unknown" ); + ctx =tr2tls_create_self ("unknown" ,getnanotime () /1000 );return ctx; }
@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)if (!tr2tls_thread_main)return 0 ; -return us - tr2tls_us_start_main; +return us - tr2tls_us_start_process; }void tr2tls_init (void ) { +tr2tls_start_process_clock (); +pthread_key_create (&tr2tls_key,NULL );init_recursive_mutex (&tr2tls_mutex); - tr2tls_thread_main =tr2tls_create_self ("main" ); -/* -* Keep a copy of the absolute start time of the main thread -* in a fixed variable since other threads need to access it. -* This also eliminates the need to lock accesses to the main -* thread's array (because of reallocs). -*/ - tr2tls_us_start_main = tr2tls_thread_main->array_us_start[0 ]; + tr2tls_thread_main =tr2tls_create_self ("main" , + tr2tls_us_start_process); }void tr2tls_release (void )
trace2/tr2_tls.h +7 -1
@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {* In this and all following functions the term "self" refers to the * current thread. */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name); +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start);/* * Get our TLS data.
@@ -94,4 +95,9 @@ void tr2tls_release(void);*/ int tr2tls_locked_increment (int *p); +/* +* Capture the process start time and do nothing else. +*/ +void tr2tls_start_process_clock (void ); +#endif /* TR2_TLS_H */
Signature · 1 line
gitgitgadget
PATCH v3 4/10 trace2: find exec-dir before trace2 initialization
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Git to resolve the executable directory before initializing Trace2. This allows the system configuration directory to be discovered earlier (because it is sometimes relative to the prefix or runtime-prefix).
This will be used by the next commit to allow trace2 settings to be loaded from the system config.
--- common-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common-main.c +2 -2
@@ -37,12 +37,12 @@ int main(int argc, const char **argv)sanitize_stdfds ();restore_sigpipe_to_default (); +git_resolve_executable_dir (argv[0 ]); +trace2_initialize ();trace2_cmd_start (argv);trace2_collect_process_info (); -git_resolve_executable_dir (argv[0 ]); -git_setup_gettext ();initialize_the_repository ();
Signature · 1 line
gitgitgadget
PATCH v3 6/10 trace2: use system/global config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach git to read the system and global config files for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system and global config files are used. Repo and worktree local config files are ignored. Likewise, the "-c" command line arguments are also ignored. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
--- Makefile | 1 + t/t0210-trace2-normal.sh | 49 +++++++++++++-- t/t0211-trace2-perf.sh | 31 ++++++++-- t/t0212-trace2-event.sh | 42 +++++++++++-- trace2.c | 4 ++ trace2.h | 12 ++-- trace2/tr2_cfg.c | 7 +-- trace2/tr2_dst.c | 24 ++++---- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 127 +++++++++++++++++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++++++ trace2/tr2_tgt_event.c | 46 +++++++------- trace2/tr2_tgt_normal.c | 16 ++--- trace2/tr2_tgt_perf.c | 16 ++--- 14 files changed, 338 insertions(+), 76 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
Makefile +1 -0
@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o LIB_OBJS += trace2/tr2_cmd_name.o LIB_OBJS += trace2/tr2_dst.o LIB_OBJS += trace2/tr2_sid.o +LIB_OBJS += trace2/tr2_sysenv.o LIB_OBJS += trace2/tr2_tbuf.o LIB_OBJS += trace2/tr2_tgt_event.o LIB_OBJS += trace2/tr2_tgt_normal.o
t/t0210-trace2-normal.sh +44 -5
64 lines not on this page · raw message
t/t0211-trace2-perf.sh +26 -5
@@ -1,5 +1,10 @@ #!/bin/sh +# Turn off any inherited trace2 settings for this test. +unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT +unset GIT_TR2_PERF_BRIEF +unset GIT_TR2_CONFIG_PARAMS + test_description='test trace2 facility (perf target)' . ./test-lib.sh
@@ -15,11 +20,6 @@ PATH="$TTDIR:$PATH" && export PATH # Warning: So you may see extra lines in artifact files when # Warning: interactively debugging. -# Turn off any inherited trace2 settings for this test. -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT -unset GIT_TR2_PERF_BRIEF -unset GIT_TR2_CONFIG_PARAMS - V=$(git version | sed -e 's/^git version //') && export V # There are multiple trace2 targets: normal, perf, and event.
@@ -150,4 +150,25 @@ test_expect_success 'perf stream, child processes' ' test_cmp expect actual ' +unset GIT_TR2_PERF_BRIEF + +# Now test without environment variables and get all Trace2 settings +# from the global config. + +test_expect_success 'using global config, perf stream, return code 0' ' + test_when_finished "rm trace.perf actual expect" && + test_config_global trace2.perfBrief 1 && + test_config_global trace2.perfTarget "$(pwd)/trace.perf" && + test-tool trace2 001return 0 && + perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && + cat >expect <<-EOF && + d0|main|version|||||$V + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 + d0|main|cmd_name|||||trace2 (trace2) + d0|main|exit||_T_ABS_|||code:0 + d0|main|atexit||_T_ABS_|||code:0 + EOF + test_cmp expect actual +' + test_done
t/t0212-trace2-event.sh +37 -5
57 lines not on this page · raw message
trace2.c +4 -0
@@ -10,6 +10,7 @@#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h"
@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)tr2_sid_release ();tr2_cmd_name_release ();tr2_cfg_free_patterns (); +tr2_sysenv_release (); trace2_enabled =0 ; }
@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)if (trace2_enabled)return ; +tr2_sysenv_load (); +if (!tr2_tgt_want_builtins ())return ; trace2_enabled =1 ;
trace2.h +7 -5
@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine.
@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: -* -* GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" +* Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated +* list of patterns configured important. For example: +* git config --system trace2.configParams 'core.*,remote.*.url' +* or: +* GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url" * * Note: this routine does a read-only iteration on the config data * (using read_early_config()), so it must not be called until enough
trace2/tr2_cfg.c +3 -4
@@ -1,8 +1,7 @@#include "cache.h" #include "config.h" -#include "tr2_cfg.h" - -#define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS" +#include "trace2/tr2_cfg.h" +#include "trace2/tr2_sysenv.h" static struct strbuf **tr2_cfg_patterns;static int tr2_cfg_count_patterns;
@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)return tr2_cfg_count_patterns; tr2_cfg_loaded =1 ; - envvar =getenv (TR2_ENVVAR_CFG_PARAM ); + envvar =tr2_sysenv_get (TR2_SYSENV_CFG_PARAM );if (!envvar || !*envvar)return tr2_cfg_count_patterns;
trace2/tr2_dst.c +12 -12
@@ -1,5 +1,6 @@#include "cache.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" /* * If a Trace2 target cannot be opened for writing, we should issue a
@@ -7,17 +8,13 @@* or socket and beyond the user's control -- especially since every * git command (and sub-command) will print the message. So we silently * eat these warnings and just discard the trace data. -* -* Enable the following environment variable to see these warnings. */ -#define TR2_ENVVAR_DST_DEBUG "GIT_TR2_DST_DEBUG" -static int tr2_dst_want_warning (void ) {static int tr2env_dst_debug =-1 ;if (tr2env_dst_debug ==-1 ) { -const char *env_value =getenv (TR2_ENVVAR_DST_DEBUG ); +const char *env_value =tr2_sysenv_get (TR2_SYSENV_DST_DEBUG );if (!env_value || !*env_value) tr2env_dst_debug =0 ;else
@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)if (fd ==-1 ) {if (tr2_dst_want_warning ())warning ("trace2: could not open '%s' for '%s' tracing: %s" , - tgt_value, dst->env_var_name,strerror (errno)); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var), +strerror (errno));tr2_dst_trace_disable (dst);return 0 ;
@@ -116,7 +115,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,if (!path || !*path) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX value '%s' for '%s' tracing" , - tgt_value, dst->env_var_name); + tgt_value,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -126,7 +125,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX path '%s' for '%s' tracing" , - path, dst->env_var_name); + path,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -148,7 +147,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, error:if (tr2_dst_want_warning ())warning ("trace2: could not connect to socket '%s' for '%s' tracing: %s" , - path, dst->env_var_name,strerror (e)); + path,tr2_sysenv_display_name (dst->sysenv_var),strerror (e));tr2_dst_trace_disable (dst);return 0 ;
@@ -168,7 +167,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"trace2: unknown value for '%s': '%s'" , - dst->env_var_name, tgt_value); +tr2_sysenv_display_name (dst->sysenv_var), tgt_value);warning ("%s" , buf.buf);strbuf_release (&buf);
@@ -184,7 +183,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst) dst->initialized =1 ; - tgt_value =getenv (dst->env_var_name); + tgt_value =tr2_sysenv_get (dst->sysenv_var);if (!tgt_value || !strcmp (tgt_value,"" ) || !strcmp (tgt_value,"0" ) || !strcasecmp (tgt_value,"false" )) {
@@ -246,7 +245,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)return ;if (tr2_dst_want_warning ()) -warning ("unable to write trace to '%s': %s" , dst->env_var_name, +warning ("unable to write trace to '%s': %s" , +tr2_sysenv_display_name (dst->sysenv_var),strerror (errno));tr2_dst_trace_disable (dst); }
trace2/tr2_dst.h +2 -1
@@ -2,9 +2,10 @@#define TR2_DST_H struct strbuf ; +#include "trace2/tr2_sysenv.h" struct tr2_dst { -const char *const env_var_name; +enum tr2_sysenv_variable sysenv_var;int fd;unsigned int initialized :1 ;unsigned int need_close :1 ;
trace2/tr2_sysenv.c new file +127 -0
127 lines not on this page · raw message
trace2/tr2_sysenv.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef TR2_SYSENV_H +#define TR2_SYSENV_H + +/* +* The Trace2 settings that can be loaded from /etc/gitconfig +* and/or user environment variables. +* +* Note that this set does not contain any of the transient +* environment variables used to pass information from parent +* to child git processes, such "GIT_TR2_PARENT_SID". +*/ +enum tr2_sysenv_variable { +TR2_SYSENV_CFG_PARAM =0 , + +TR2_SYSENV_DST_DEBUG , + +TR2_SYSENV_NORMAL , +TR2_SYSENV_NORMAL_BRIEF , + +TR2_SYSENV_EVENT , +TR2_SYSENV_EVENT_BRIEF , +TR2_SYSENV_EVENT_NESTING , + +TR2_SYSENV_PERF , +TR2_SYSENV_PERF_BRIEF , + +TR2_SYSENV_MUST_BE_LAST +}; + +void tr2_sysenv_load (void ); + +const char *tr2_sysenv_get (enum tr2_sysenv_variable ); +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var); +void tr2_sysenv_release (void ); + +#endif /* TR2_SYSENV_H */
trace2/tr2_tgt_event.c +23 -23
111 lines not on this page · raw message
trace2/tr2_tgt_normal.c +8 -8
@@ -4,20 +4,20 @@#include "quote.h" #include "version.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = {"GIT_TR2" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_normal = {TR2_SYSENV_NORMAL ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>" * fields from each line written to the builtin normal target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF" -static int tr2env_normal_brief; +static int tr2env_normal_be_brief;#define TR2FMT_NORMAL_FL_WIDTH (50)
@@ -25,15 +25,15 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_normal);int want_brief; -char *brief; +const char *brief;if (!want)return want; - brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_normal_brief = want_brief; + tr2env_normal_be_brief = want_brief;return want; }
@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf) {strbuf_setlen (buf,0 ); -if (!tr2env_normal_brief) { +if (!tr2env_normal_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
trace2/tr2_tgt_perf.c +8 -8
@@ -6,20 +6,20 @@#include "json-writer.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = {"GIT_TR2_PERF" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_perf = {TR2_SYSENV_PERF ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" * fields from each line written to the builtin performance target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF" -static int tr2env_perf_brief; +static int tr2env_perf_be_brief;#define TR2FMT_PERF_FL_WIDTH (50)#define TR2FMT_PERF_MAX_EVENT_NAME (12)
@@ -36,17 +36,17 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_perf);int want_brief; -char *brief; +const char *brief;if (!want)return want;strbuf_addchars (&dots,'.' ,TR2_DOTS_BUFFER_SIZE ); - brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_perf_brief = want_brief; + tr2env_perf_be_brief = want_brief;return want; }
@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,strbuf_setlen (buf,0 ); -if (!tr2env_perf_brief) { +if (!tr2env_perf_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
Signature · 1 line
gitgitgadget
Quoted 4 lines · Jeff Hostetler via GitGitGadget
Here is version 3.
[] It incorporates Ævar's suggestions WRT the format and uniqueness of the SID. [] It now reads both system and global config for trace2 settings and handles includes as Jonathan suggested.
Following the ISO more closely with Ts and Zs in the format looks like a good idea (i.e. it gives a more familiar-looking result). I have no string opinions on the per-user config or inclusion, but I think it probably is an essential ingredient to give an opt-out escape hatch to make this appear less big-brotherly [*1*].
Side note *1*: and hence less scary. An otherwise useful mechanism can have an appearance that it can also be misused for bad purposes, and at that point, to those with fear, it does not matter how useful an application the mechanism has.
I think "by default you are opting in due to your belonging to this organization in the first place (hence we give you /etc/gitconfig that lets us collect your usage patterns) but you could easily opt-out by overriding in $HOME/.gitconfig" strikes a good balance.
Quoted 4 lines
I added a
read_very_early_config()function that is similar to read_early_config()but omits repo local, worktree, and -c command line settings. This felt like a little bit of a hack, but it made the intent clear.
I am not yet judging if the "very early config" itself is a good thing to have (and if it is good, then it is not a "hack" ;-)), but I very much agree that it is a very good change to have a helper that makes the intent clear.
Quoted 5 lines
-+# Now test using system config by using a mocked up config file -+# rather than inheriting "
/etc/gitconfig". Here we do not use -+# GIT_TR2* environment variables.
-+
+unsetGIT_TR2_BRIEF
This does not have to be sane_unset, as we are not aiming for making our tests "set -e" clean. But in tXXXX-*.sh scripts, it may not be a bad idea to stick to sane_unset regardless, as people tend to cut and paste without thinking enough.
Quoted 18 lines
@@ -512,19 +454,28 @@
+ */
+/* clang-format off */
++ [TR2_SYSENV_CFG_PARAM] = { "GIT_TR2_CONFIG_PARAMS",
++ "trace2.configparams" },
++
++ [TR2_SYSENV_DST_DEBUG] = { "GIT_TR2_DST_DEBUG",
++ "trace2.destinationdebug" },
++
++ [TR2_SYSENV_NORMAL] = { "GIT_TR2",
++ "trace2.normaltarget" },
++ [TR2_SYSENV_NORMAL_BRIEF] = { "GIT_TR2_BRIEF",
++ "trace2.normalbrief" },
++
++ [TR2_SYSENV_EVENT] = { "GIT_TR2_EVENT",
++ "trace2.eventtarget" },
++ [TR2_SYSENV_EVENT_BRIEF] = { "GIT_TR2_EVENT_BRIEF",Quoted 8 lines
++ "trace2.eventbrief" },
++ [TR2_SYSENV_EVENT_NESTING] = { "GIT_TR2_EVENT_NESTING",
++ "trace2.eventnesting" },
++
++ [TR2_SYSENV_PERF] = { "GIT_TR2_PERF",
++ "trace2.perftarget" },
++ [TR2_SYSENV_PERF_BRIEF] = { "GIT_TR2_PERF_BRIEF",
++ "trace2.perfbrief" },With use of designated initializers, the table got a lot cleaner to read. Is the above "format off" still needed (I am a bit curious how clang-format wants these entries to look like)?
Quoted 4 lines
++ if (pid > 999999)
++ strbuf_addf(&tr2sid_buf, "W%06d", (int)(pid % 1000000));
++ else
++ strbuf_addf(&tr2sid_buf, "P%06d", (int)pid);I do not think it matters too much, but this is kind-of curious.
How would the users of the log utilize the distinction between W and P? Do they discard the ones with W when they care about the exact process that left the trace entries, or something? If it's not a plausibly useful use pattern (and I do not think it is), I wonder if we want to go with only W (i.e. truncated to the lower N digits) entries, if you are shooting for a fixed-width output from this function. If you want less chance of collisions, you obviously could use hexadecimal to gain back a few more bits.
After all, if the application does care the PID, that could be in the log data itself (i.e. an "start" event can say "my pid is blah").
Thanks. I'll wait until learning what others think.
Re: [PATCH v3 01/10] config: initialize opts structure in repo_read_config()
In reply to Jeff Hostetler via GitGitGadgetHi,
Quoted 1 line · Jeff Hostetler
Initialize opts structure in
repo_read_config().
Good find. I wonder if there are some flags we can turn on with DEVELOPER=1 to prevent this kind of issue going undetected in the future (or maybe this means we need to get the valgrind or ASan testing modes to be fast enough for people to consistently run them).
[...]
Quoted 2 lines
config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks.
Quoted 2 lines · Junio C Hamano
"Jeff Hostetler via GitGitGadget" <[email protected]> writes:
[...]
Quoted 28 lines
Quoted 18 lines
@@ -512,19 +454,28 @@ + */ +/* clang-format off */ ++ [TR2_SYSENV_CFG_PARAM] = { "GIT_TR2_CONFIG_PARAMS", ++ "trace2.configparams" }, ++ ++ [TR2_SYSENV_DST_DEBUG] = { "GIT_TR2_DST_DEBUG", ++ "trace2.destinationdebug" }, ++ ++ [TR2_SYSENV_NORMAL] = { "GIT_TR2", ++ "trace2.normaltarget" }, ++ [TR2_SYSENV_NORMAL_BRIEF] = { "GIT_TR2_BRIEF", ++ "trace2.normalbrief" }, ++ ++ [TR2_SYSENV_EVENT] = { "GIT_TR2_EVENT", ++ "trace2.eventtarget" }, ++ [TR2_SYSENV_EVENT_BRIEF] = { "GIT_TR2_EVENT_BRIEF",Quoted 8 lines
++ "trace2.eventbrief" }, ++ [TR2_SYSENV_EVENT_NESTING] = { "GIT_TR2_EVENT_NESTING", ++ "trace2.eventnesting" }, ++ ++ [TR2_SYSENV_PERF] = { "GIT_TR2_PERF", ++ "trace2.perftarget" }, ++ [TR2_SYSENV_PERF_BRIEF] = { "GIT_TR2_PERF_BRIEF", ++ "trace2.perfbrief" },
Quoted 3 lines
With use of designated initializers, the table got a lot cleaner to read. Is the above "format off" still needed (I am a bit curious how clang-format wants these entries to look like)?
clang-format suggests getting rid of the extra whitespace on the lines, so we lose all of the column alignment. Then it wants to line-wrap some but not all of the lines. So it is a bit of a mess to look at.
Quoted 17 lines
Quoted 5 lines
++ if (pid > 999999) ++ strbuf_addf(&tr2sid_buf, "W%06d", (int)(pid % 1000000)); ++ else ++ strbuf_addf(&tr2sid_buf, "P%06d", (int)pid);I do not think it matters too much, but this is kind-of curious.
How would the users of the log utilize the distinction between W and P? Do they discard the ones with W when they care about the exact process that left the trace entries, or something? If it's not a plausibly useful use pattern (and I do not think it is), I wonder if we want to go with only W (i.e. truncated to the lower N digits) entries, if you are shooting for a fixed-width output from this function. If you want less chance of collisions, you obviously could use hexadecimal to gain back a few more bits.
Quoted 2 lines
After all, if the application does care the PID, that could be in the log data itself (i.e. an "start" event can say "my pid is blah").
Right. Ævar suggested adding the full or wrapped PID so that the SID would be a fixed length. I stuck with decimal rather than hex because it's easier to match up a running command with '/usr/bin/ps' output, but that's no big deal either way. It might be simpler to just %08lx it and be done with it.
Jeff
Re: [PATCH v3 01/10] config: initialize opts structure in repo_read_config()
In reply to Jonathan NiederHi Jonathan,
Quoted 5 lines · Jonathan Nieder
Quoted 1 line · Jeff Hostetler
Initialize opts structure in
repo_read_config().Good find.
Heh, it really was our CI that found it, and it was I (with valgrind's help) who identified the problem and proposed the fix. So: thank you!
Quoted 4 lines
I wonder if there are some flags we can turn on with DEVELOPER=1 to prevent this kind of issue going undetected in the future (or maybe this means we need to get the valgrind or ASan testing modes to be fast enough for people to consistently run them).
Sadly, I do not think that either is an option. Such uninitialized memory is really hard to catch without in-depth analysis, so DEVELOPER=1 is out. And valgrind (or the faster alternative, DrMemory) have to spend quite a bit of time to do what they do, and it is unlikely that that could ever be made faster.
A better approach might be static analysis (and I do not mean the diet coke of static analysis that we run as part of our CI, but something as powerful as Coverity).
Sadly, Coverity makes it super hard to switch off false positives regarding e.g. our use of FLEX_ARRAY or strbuf's strbuf_slopbuf.
For quite a while, I wanted to play with [infer](https://fbinfer.com/), in the hopes that it would be possible to do customize what cannot be customized with Coverity. Alas, their use of OCaml (why do they make it so hard?) puts quite the bit of a road block ahead of me in that endeavor.
Ciao,
Dscho
v4 cover trace2: load trace2 settings from system config
In reply to Jeff Hostetler via GitGitGadgetVersion 4 fixes a few clang-format warnings and simplifies the PID field in the SID.
Jeff Hostetler (10):
config: initialize opts structure in repo_read_config()
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
config: add read_very_early_config()
trace2: use system/global config for default trace2 settings
trace2: report peak memory usage of the process
trace2: clarify UTC datetime formatting
trace2: make SIDs more unique
trace2: update docs to describe system/global config settings
Documentation/config.txt | 2 + Documentation/config/trace2.txt | 56 ++++++++ Documentation/technical/api-trace2.txt | 176 +++++++++++++---------- Documentation/trace2-target-values.txt | 10 ++ Makefile | 1 + common-main.c | 8 +- compat/mingw.c | 2 + compat/win32/trace2_win32_process_info.c | 50 ++++++- config.c | 25 +++- config.h | 4 + t/t0210-trace2-normal.sh | 49 ++++++- t/t0211-trace2-perf.sh | 43 ++++-- t/t0212-trace2-event.sh | 42 +++++- trace2.c | 21 ++- trace2.h | 43 ++++-- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 26 ++-- trace2/tr2_dst.h | 3 +- trace2/tr2_sid.c | 53 ++++++- trace2/tr2_sysenv.c | 127 ++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++ trace2/tr2_tbuf.c | 19 ++- trace2/tr2_tbuf.h | 5 +- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 53 +++---- trace2/tr2_tgt_normal.c | 19 +-- trace2/tr2_tgt_perf.c | 23 +-- trace2/tr2_tls.c | 38 +++-- trace2/tr2_tls.h | 8 +- 29 files changed, 747 insertions(+), 203 deletions(-) create mode 100644 Documentation/config/trace2.txt create mode 100644 Documentation/trace2-target-values.txt create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/169
Range-diff vs v3:
1: ea8c199f91 ! 1: f6653f1c59 config: initialize opts structure in repo_read_config()
@@ -25,7 +25,7 @@
static void repo_read_config(struct repository *repo)
{
- struct config_options opts;
-+ struct config_options opts = {0};
++ struct config_options opts = { 0 }; opts.respect_includes = 1;
opts.commondir = repo->commondir;
2: 3dbcfc6a8d ! 2: 48e34834b6 trace2: refactor setting process starting time
@@ -196,8 +196,8 @@
- * thread's array (because of reallocs).
- */
- tr2tls_us_start_main = tr2tls_thread_main->array_us_start[0];
-+ tr2tls_thread_main = tr2tls_create_self("main",
-+ tr2tls_us_start_process);
++ tr2tls_thread_main =
++ tr2tls_create_self("main", tr2tls_us_start_process);
}
void tr2tls_release(void)
3: 8b00025af5 = 3: 175371fb54 trace2: add absolute elapsed time to start event
4: c3c5f6a96b = 4: 94729b284c trace2: find exec-dir before trace2 initialization
5: d15be7b63a ! 5: b0fe1385f1 config: add read_very_early_config()
@@ -16,8 +16,8 @@
current_parsing_scope = CONFIG_SCOPE_REPO;
- if (repo_config && !access_or_die(repo_config, R_OK, 0))
-+ if (!opts->ignore_repo &&
-+ repo_config && !access_or_die(repo_config, R_OK, 0))
++ if (!opts->ignore_repo && repo_config &&
++ !access_or_die(repo_config, R_OK, 0))
ret += git_config_from_file(fn, repo_config, data);
/*
@@ -25,8 +25,7 @@
* But let's not complicate things before it's actually needed.
*/
- if (repository_format_worktree_config) {
-+ if (!opts->ignore_worktree &&
-+ repository_format_worktree_config) {
++ if (!opts->ignore_worktree && repository_format_worktree_config) {
char *path = git_pathdup("config.worktree");
if (!access_or_die(path, R_OK, 0))
ret += git_config_from_file(fn, path, data);
@@ -35,8 +34,7 @@
current_parsing_scope = CONFIG_SCOPE_CMDLINE;
- if (git_config_from_parameters(fn, data) < 0)
-+ if (!opts->ignore_cmdline &&
-+ git_config_from_parameters(fn, data) < 0)
++ if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
die(_("unable to parse command-line config"));
current_parsing_scope = CONFIG_SCOPE_UNKNOWN;
@@ -50,7 +48,7 @@
+ */
+void read_very_early_config(config_fn_t cb, void *data)
+{
-+ struct config_options opts = {0};
++ struct config_options opts = { 0 };
+
+ opts.respect_includes = 1;
+ opts.ignore_repo = 1;
6: c085a482dd ! 6: 550cad6189 trace2: use system/global config for default trace2 settings
@@ -41,16 +41,17 @@
--- a/t/t0210-trace2-normal.sh
+++ b/t/t0210-trace2-normal.sh
@@
- #!/bin/sh
-
-+# Turn off any inherited trace2 settings for this test.
-+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
-+unset GIT_TR2_BRIEF
-+unset GIT_TR2_CONFIG_PARAMS
-+
test_description='test trace2 facility (normal target)'
. ./test-lib.sh
++# Turn off any inherited trace2 settings for this test.
++sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
++sane_unset GIT_TR2_BRIEF
++sane_unset GIT_TR2_CONFIG_PARAMS
++
+ # Add t/helper directory to PATH so that we can use a relative
+ # path to run nested instances of test-tool.exe (see 004child).
+ # This helps with HEREDOC comparisons later.
@@
# Warning: So you may see extra lines in artifact files when
# Warning: interactively debugging.
@@ -67,7 +68,7 @@
test_cmp expect actual
'
-+unset GIT_TR2_BRIEF
++sane_unset GIT_TR2_BRIEF
+
+# Now test without environment variables and get all Trace2 settings
+# from the global config.
@@ -112,16 +113,17 @@
--- a/t/t0211-trace2-perf.sh
+++ b/t/t0211-trace2-perf.sh
@@
- #!/bin/sh
-
-+# Turn off any inherited trace2 settings for this test.
-+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
-+unset GIT_TR2_PERF_BRIEF
-+unset GIT_TR2_CONFIG_PARAMS
-+
test_description='test trace2 facility (perf target)'
. ./test-lib.sh
++# Turn off any inherited trace2 settings for this test.
++sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
++sane_unset GIT_TR2_PERF_BRIEF
++sane_unset GIT_TR2_CONFIG_PARAMS
++
+ # Add t/helper directory to PATH so that we can use a relative
+ # path to run nested instances of test-tool.exe (see 004child).
+ # This helps with HEREDOC comparisons later.
@@
# Warning: So you may see extra lines in artifact files when
# Warning: interactively debugging.
@@ -138,7 +140,7 @@
test_cmp expect actual
'
-+unset GIT_TR2_PERF_BRIEF
++sane_unset GIT_TR2_PERF_BRIEF
+
+# Now test without environment variables and get all Trace2 settings
+# from the global config.
@@ -165,16 +167,17 @@
--- a/t/t0212-trace2-event.sh
+++ b/t/t0212-trace2-event.sh
@@
- #!/bin/sh
+ test_description='test trace2 facility'
+ . ./test-lib.sh
+# Turn off any inherited trace2 settings for this test.
-+unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
-+unset GIT_TR2_BARE
-+unset GIT_TR2_CONFIG_PARAMS
++sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
++sane_unset GIT_TR2_BARE
++sane_unset GIT_TR2_CONFIG_PARAMS
+
- test_description='test trace2 facility'
- . ./test-lib.sh
+ perl -MJSON::PP -e 0 >/dev/null 2>&1 && test_set_prereq JSON_PP
+ # Add t/helper directory to PATH so that we can use a relative
@@
# Warning: So you may see extra lines in artifact files when
# Warning: interactively debugging.
@@ -353,7 +356,8 @@
if (tr2_dst_want_warning())
warning("trace2: invalid AF_UNIX value '%s' for '%s' tracing",
- tgt_value, dst->env_var_name);
-+ tgt_value, tr2_sysenv_display_name(dst->sysenv_var));
++ tgt_value,
++ tr2_sysenv_display_name(dst->sysenv_var));
tr2_dst_trace_disable(dst);
return 0;
@@ -371,7 +375,8 @@
if (tr2_dst_want_warning())
warning("trace2: could not connect to socket '%s' for '%s' tracing: %s",
- path, dst->env_var_name, strerror(e));
-+ path, tr2_sysenv_display_name(dst->sysenv_var), strerror(e));
++ path, tr2_sysenv_display_name(dst->sysenv_var),
++ strerror(e));
tr2_dst_trace_disable(dst);
return 0;
7: 2a7a933875 ! 7: 56d8ce3fd6 trace2: report peak memory usage of the process
@@ -40,8 +40,8 @@
+ */
+static void get_peak_memory_info(void)
+{
-+ DECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo,
-+ HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
++ DECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE,
++ PPROCESS_MEMORY_COUNTERS, DWORD);
+
+ if (INIT_PROC_ADDR(GetProcessMemoryInfo)) {
+ PROCESS_MEMORY_COUNTERS pmc;
8: 56f357dc7b = 8: 196a9d2c85 trace2: clarify UTC datetime formatting
9: 156ffde489 ! 9: 9fdcb50140 trace2: make SIDs more unique
@@ -63,7 +63,7 @@
+ * Compute the final component of the SID representing the current process.
+ * This should uniquely identify the process and be a valid filename (to
+ * allow writing trace2 data to per-process files). It should also be fixed
-+ * possible length for use as a database key.
++ * length for possible use as a database key.
+ *
+ * "<yyyymmdd>T<hhmmss>.<fraction>Z-<host>-<process>"
+ *
@@ -71,17 +71,19 @@
+ * "H<first_8_chars_of_sha1_of_hostname>"
+ * "Localhost" when no hostname.
+ *
-+ * where <process> is a possibly wrapped PID:
-+ * "P<6-digit-pid>"
-+ * "W<wrapped-6-digit-pid>" when PID too big.
-+ *
++ * where <process> is a 9 character string containing the least signifcant
++ * 32 bits in the process-id.
++ * "P<pid>"
++ * (This is an abribrary choice. On most systems pid_t is a 32 bit value,
++ * so limit doesn't matter. On larger systems, a truncated value is fine
++ * for our purposes here.)
+ */
+static void tr2_sid_append_my_sid_component(void)
+{
+ const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1];
+ struct tr2_tbuf tb_now;
+ git_hash_ctx ctx;
-+ uintmax_t pid = getpid();
++ pid_t pid = getpid();
+ unsigned char hash[GIT_MAX_RAWSZ + 1];
+ char hex[GIT_MAX_HEXSZ + 1];
+ char hostname[HOST_NAME_MAX + 1];
@@ -101,11 +103,7 @@
+ strbuf_add(&tr2sid_buf, hex, 8);
+ }
+
-+ strbuf_addch(&tr2sid_buf, '-');
-+ if (pid > 999999)
-+ strbuf_addf(&tr2sid_buf, "W%06d", (int)(pid % 1000000));
-+ else
-+ strbuf_addf(&tr2sid_buf, "P%06d", (int)pid);
++ strbuf_addf(&tr2sid_buf, "-P%08"PRIx32, (uint32_t)pid);
+}
+
/*
@@ -149,10 +147,9 @@
+ secs = tv.tv_sec;
+ gmtime_r(&secs, &tm);
+
-+ xsnprintf(tb->buf, sizeof(tb->buf),
-+ "%4d%02d%02dT%02d%02d%02d.%06ldZ", tm.tm_year + 1900,
-+ tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
-+ (long)tv.tv_usec);
++ xsnprintf(tb->buf, sizeof(tb->buf), "%4d%02d%02dT%02d%02d%02d.%06ldZ",
++ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
++ tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
+}
diff --git a/trace2/tr2_tbuf.h b/trace2/tr2_tbuf.h
10: 285beb2b2d ! 10: 3414016d04 trace2: update docs to describe system/global config settings
@@ -188,53 +188,59 @@
git version 2.20.1.155.g426c96fcdb
------------
-+
-+
-+or
-+
-+------------
-+$ git config --global trace2.eventTarget ~/log.event
-+$ git version
-+git version 2.20.1.155.g426c96fcdb
-+------------
-+
-+yields
-+
- ------------
- $ cat ~/log.event
- {"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"}
-@@
- {"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}
- ------------
-
+-------------
+-$ cat ~/log.event
+-{"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"}
+-{"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"]}
+-{"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"}
+-{"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}
+-{"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}
+-------------
+-
-== Enabling a Target
-
-A Trace2 Target is enabled when the corresponding environment variable
-(`GIT_TR2`, `GIT_TR2_PERF`, or `GIT_TR2_EVENT`) is set. The following
-values are recognized.
-+=== Enabling a Target
-
+-
-`0`::
-`false`::
-+To enable a target, set the corresponding environment variable or
-+system or global config value to one of the following:
-
-- Disables the target.
-
+- Disables the target.
+
-`1`::
-`true`::
--
++or
+
- Enables the target and writes stream to `STDERR`.
-
-`[2-9]`::
--
++------------
++$ git config --global trace2.eventTarget ~/log.event
++$ git version
++git version 2.20.1.155.g426c96fcdb
++------------
+
- Enables the target and writes to the already opened file descriptor.
--
++yields
+
-`<absolute-pathname>`::
--
++------------
++$ cat ~/log.event
++{"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"}
++{"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"]}
++{"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"}
++{"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}
++{"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}
++------------
+
- Enables the target, opens and writes to the file in append mode.
--
++=== Enabling a Target
+
-`af_unix:[<socket_type>:]<absolute-pathname>`::
--
++To enable a target, set the corresponding environment variable or
++system or global config value to one of the following:
+
- Enables the target, opens and writes to a Unix Domain Socket
- (on platforms that support them).
-+
@@ -316,6 +322,15 @@
Each event is a JSON-object containing multiple key/value pairs
written as a single line and followed by a LF.
+@@
+ ------------
+ {
+ "event":"version",
+- "sid":"20190408T191827.272759Z-H9b68c35f-P011764",
++ "sid":"20190408T191827.272759Z-H9b68c35f-P00003510",
+ "thread":"main",
+ "time":"2019-04-08T19:18:27.282761Z",
+ "file":"common-main.c",
@@
`"repo":<repo-id>`::
when present, is the integer repo-id as described previously.Signature · 1 line
gitgitgadget
PATCH v4 1/10 config: initialize opts structure in repo_read_config()
From: Jeff Hostetler <[email protected]>
Initialize opts structure in repo_read_config().
This change fixes a crash in later commit after a new field is added to the structure.
In commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config() was added. It only initializes 3 fields in the opts structure. It is passed to config_with_options() and then to do_git_config_sequence(). However, do_git_config_sequence() drops the opts on the floor and calls git_config_from_file() rather than git_config_from_file_with_options(), so that may be why this hasn't been a problem in the past.
--- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
config.c +1 -1
@@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha/* Functions use to read configuration from a repository */ static void repo_read_config (struct repository *repo) { -struct config_options opts; +struct config_options opts = {0 }; opts.respect_includes =1 ; opts.commondir = repo->commondir;
Signature · 1 line
gitgitgadget
PATCH v4 2/10 trace2: refactor setting process starting time
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Create trace2_initialize_clock() and call from main() to capture process start time in isolation and before other sub-systems are ready.
--- Documentation/technical/api-trace2.txt | 12 ++++++-- common-main.c | 2 ++ compat/mingw.c | 2 ++ trace2.c | 7 ++++- trace2.h | 17 ++++++++++++ trace2/tr2_tls.c | 38 ++++++++++++++++---------- trace2/tr2_tls.h | 8 +++++- 7 files changed, 67 insertions(+), 19 deletions(-)
Documentation/technical/api-trace2.txt +9 -3
@@ -160,17 +160,23 @@ purposes. These are concerned with the lifetime of the overall git process. +`void trace2_initialize_clock()`:: + + Initialize the Trace2 start clock and nothing else. This should + be called at the very top of main() to capture the process start + time and reduce startup order dependencies. + `void trace2_initialize()`:: Determines if any Trace2 Targets should be enabled and - initializes the Trace2 facility. This includes starting the - elapsed time clocks and thread local storage (TLS). + initializes the Trace2 facility. This includes setting up the + Trace2 thread local storage (TLS). + This function emits a "version" message containing the version of git and the Trace2 protocol. + This function should be called from `main()` as early as possible in -the life of the process. +the life of the process after essential process initialization. `int trace2_is_enabled()`::
common-main.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, const char **argv) {int result; +trace2_initialize_clock (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed
compat/mingw.c +2 -0
@@ -2569,6 +2569,8 @@ void mingw_startup(void)wchar_t **wenv, **wargv;_startupinfo si; +trace2_initialize_clock (); +maybe_redirect_std_handles ();/* get wide char arguments and environment */
trace2.c +6 -1
@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)raise (signo); } +void trace2_initialize_clock (void ) +{ +tr2tls_start_process_clock (); +} +void trace2_initialize_fl (const char *file,int line) {struct tr2_tgt *tgt_j;
@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name) us_now =getnanotime () /1000 ; us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); -tr2tls_create_self (thread_name); +tr2tls_create_self (thread_name, us_now);for_each_wanted_builtin (j, tgt_j) if (tgt_j->pfn_thread_start_fl)
trace2.h +17 -0
@@ -19,6 +19,23 @@ struct json_writer;* [] trace2_printf* -- legacy trace[1] messages. */ +/* +* Initialize the TRACE2 clock and do nothing else, in particular +* no mallocs, no system inspection, and no environment inspection. +* +* This should be called at the very top of main() to capture the +* process start time. This is intended to reduce chicken-n-egg +* bootstrap pressure. +* +* It is safe to call this more than once. This allows capturing +* absolute startup costs on Windows which uses a little trickery +* to do setup work before common-main.c:main() is called. +* +* The main trace2_initialize_fl() may be called a little later +* after more infrastructure is established. +*/ +void trace2_initialize_clock (void ); +/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 * targets are enabled in the environment. Emits a 'version' event.
trace2/tr2_tls.c +24 -14
@@ -10,16 +10,30 @@#define TR2_REGION_NESTING_INITIAL_SIZE (100)static struct tr2tls_thread_ctx *tr2tls_thread_main; -static uint64_t tr2tls_us_start_main; +static uint64_t tr2tls_us_start_process;static pthread_mutex_t tr2tls_mutex;static pthread_key_t tr2tls_key;static int tr2_next_thread_id;/* modify under lock */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name) +void tr2tls_start_process_clock (void ) +{ +if (tr2tls_us_start_process) +return ; + +/* +* Keep the absolute start time of the process (i.e. the main +* process) in a fixed variable since other threads need to +* access it. This allows them to do that without a lock on +* main thread's array data (because of reallocs). +*/ + tr2tls_us_start_process =getnanotime () /1000 ; +} + +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start) { -uint64_t us_now =getnanotime () /1000 ;struct tr2tls_thread_ctx *ctx =xcalloc (1 ,sizeof (*ctx));/*
@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)*/ ctx->alloc =TR2_REGION_NESTING_INITIAL_SIZE ; ctx->array_us_start = (uint64_t *)xcalloc (ctx->alloc,sizeof (uint64_t )); - ctx->array_us_start[ctx->nr_open_regions++] = us_now; + ctx->array_us_start[ctx->nr_open_regions++] = us_thread_start; ctx->thread_id =tr2tls_locked_increment (&tr2_next_thread_id);
@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)* here and silently continue. */ if (!ctx) - ctx =tr2tls_create_self ("unknown" ); + ctx =tr2tls_create_self ("unknown" ,getnanotime () /1000 );return ctx; }
@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)if (!tr2tls_thread_main)return 0 ; -return us - tr2tls_us_start_main; +return us - tr2tls_us_start_process; }void tr2tls_init (void ) { +tr2tls_start_process_clock (); +pthread_key_create (&tr2tls_key,NULL );init_recursive_mutex (&tr2tls_mutex); - tr2tls_thread_main =tr2tls_create_self ("main" ); -/* -* Keep a copy of the absolute start time of the main thread -* in a fixed variable since other threads need to access it. -* This also eliminates the need to lock accesses to the main -* thread's array (because of reallocs). -*/ - tr2tls_us_start_main = tr2tls_thread_main->array_us_start[0 ]; + tr2tls_thread_main = +tr2tls_create_self ("main" , tr2tls_us_start_process); }void tr2tls_release (void )
trace2/tr2_tls.h +7 -1
@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {* In this and all following functions the term "self" refers to the * current thread. */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name); +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start);/* * Get our TLS data.
@@ -94,4 +95,9 @@ void tr2tls_release(void);*/ int tr2tls_locked_increment (int *p); +/* +* Capture the process start time and do nothing else. +*/ +void tr2tls_start_process_clock (void ); +#endif /* TR2_TLS_H */
Signature · 1 line
gitgitgadget
PATCH v4 3/10 trace2: add absolute elapsed time to start event
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Add elapsed process time to "start" event to measure the performance of early process startup.
--- Documentation/technical/api-trace2.txt | 11 ++++++----- t/t0211-trace2-perf.sh | 12 ++++++------ trace2.c | 8 +++++++- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 5 ++++- trace2/tr2_tgt_normal.c | 3 ++- trace2/tr2_tgt_perf.c | 7 ++++--- 7 files changed, 30 insertions(+), 17 deletions(-)
Documentation/technical/api-trace2.txt +6 -5
@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.perf 12:28:42.620675 common-main.c:38 | d0 | main | version | | | | | 2.20.1.155.g426c96fcdb -12:28:42.621001 common-main.c:39 | d0 | main | start | | | | | git version +12:28:42.621001 common-main.c:39 | d0 | main | start | | 0.001173 | | | git version 12:28:42.621111 git.c:432 | d0 | main | cmd_name | | | | | version (version) 12:28:42.621225 git.c:662 | d0 | main | exit | | 0.001227 | | | code:0 12:28:42.621259 trace2/tr2_tgt_perf.c:211 | d0 | main | atexit | | 0.001265 | | | code:0
@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.event {"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"} -{"event":"start","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16 17:28:42.621027","file":"common-main.c","line":39,"argv":["git","version"]} +{"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"]} {"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"} {"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} {"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}
@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the "start" and { "event":"start", ... + "t_abs":0.001227, # elapsed time in seconds "argv":["git","version"] } ------------
@@ -1118,7 +1119,7 @@ $ git status $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.160.g5676107ecd.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1163,7 +1164,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.162.gb4ccea44db.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1219,7 +1220,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.156.gf9916ae094.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) d0 | main | region_enter | r1 | 0.001791 | | index | label:do_read_index .git/index
t/t0211-trace2-perf.sh +6 -6
@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:0 d0|main|atexit||_T_ABS_|||code:0
@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 1 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:1 d0|main|atexit||_T_ABS_|||code:1
@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' + d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' d0|main|cmd_name|||||trace2 (trace2) d0|main|error|||||hello world d0|main|error|||||this is a test
@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0 d1|main|version|||||$V - d1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0 + d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0 d1|main|cmd_name|||||trace2 (trace2/trace2) d1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0 d2|main|version|||||$V - d2|main|start|||||_EXE_ trace2 001return 0 + d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d2|main|cmd_name|||||trace2 (trace2/trace2/trace2) d2|main|exit||_T_ABS_|||code:0 d2|main|atexit||_T_ABS_|||code:0
trace2.c +7 -1
@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv) {struct tr2_tgt *tgt_j;int j; +uint64_t us_now; +uint64_t us_elapsed_absolute;if (!trace2_enabled)return ; + us_now =getnanotime () /1000 ; + us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); + for_each_wanted_builtin (j, tgt_j)if (tgt_j->pfn_start_fl) - tgt_j->pfn_start_fl (file, line, argv); + tgt_j->pfn_start_fl (file, line, us_elapsed_absolute, + argv); }int trace2_cmd_exit_fl (const char *file,int line,int code)
trace2/tr2_tgt.h +1 -0
@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);typedef void (tr2_tgt_evt_version_fl_t )(const char *file,int line);typedef void (tr2_tgt_evt_start_fl_t )(const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv);typedef void (tr2_tgt_evt_exit_fl_t )(const char *file,int line,uint64_t us_elapsed_absolute,int code);
trace2/tr2_tgt_event.c +4 -1
@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)jw_release (&jw); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct json_writer jw =JSON_WRITER_INIT ; +double t_abs = (double )us_elapsed_absolute /1000000.0 ;jw_object_begin (&jw,0 );event_fmt_prepare (event_name, file, line,NULL , &jw); +jw_object_double (&jw,"t_abs" ,6 , t_abs);jw_object_inline_begin_array (&jw,"argv" );jw_array_argv (&jw, argv);jw_end (&jw);
trace2/tr2_tgt_normal.c +2 -1
@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {struct strbuf buf_payload =STRBUF_INIT ;
trace2/tr2_tgt_perf.c +4 -3
@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct strbuf buf_payload =STRBUF_INIT ;sq_quote_argv_pretty (&buf_payload, argv); -perf_io_write_fl (file, line, event_name,NULL ,NULL ,NULL ,NULL , - &buf_payload); +perf_io_write_fl (file, line, event_name,NULL , &us_elapsed_absolute, +NULL ,NULL , &buf_payload);strbuf_release (&buf_payload); }
Signature · 1 line
gitgitgadget
PATCH v4 5/10 config: add read_very_early_config()
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Created an even lighter version of read_early_config() that only looks at system and global config settings. It omits repo-local, worktree-local, and command-line settings.
--- config.c | 23 ++++++++++++++++++++--- config.h | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-)
config.c +20 -3
@@ -1688,14 +1688,15 @@ static int do_git_config_sequence(const struct config_options *opts, ret +=git_config_from_file (fn, user_config, data); current_parsing_scope =CONFIG_SCOPE_REPO ; -if (repo_config && !access_or_die (repo_config,R_OK ,0 )) +if (!opts->ignore_repo && repo_config && + !access_or_die (repo_config,R_OK ,0 )) ret +=git_config_from_file (fn, repo_config, data);/* * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. * But let's not complicate things before it's actually needed. */ -if (repository_format_worktree_config) { +if (!opts->ignore_worktree && repository_format_worktree_config) {char *path =git_pathdup ("config.worktree" );if (!access_or_die (path,R_OK ,0 )) ret +=git_config_from_file (fn, path, data);
@@ -1703,7 +1704,7 @@ static int do_git_config_sequence(const struct config_options *opts, } current_parsing_scope =CONFIG_SCOPE_CMDLINE ; -if (git_config_from_parameters (fn, data) <0 ) +if (!opts->ignore_cmdline &&git_config_from_parameters (fn, data) <0 )die (_ ("unable to parse command-line config" )); current_parsing_scope =CONFIG_SCOPE_UNKNOWN ;
@@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data)strbuf_release (&gitdir); } +/* +* Read config but only enumerate system and global settings. +* Omit any repo-local, worktree-local, or command-line settings. +*/ +void read_very_early_config (config_fn_t cb,void *data) +{ +struct config_options opts = {0 }; + + opts.respect_includes =1 ; + opts.ignore_repo =1 ; + opts.ignore_worktree =1 ; + opts.ignore_cmdline =1 ; + +config_with_options (cb, data,NULL , &opts); +} +static struct config_set_element *configset_find_element (struct config_set *cs,const char *key) {struct config_set_element k;
config.h +4 -0
@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,struct config_options {unsigned int respect_includes :1 ; +unsigned int ignore_repo :1 ; +unsigned int ignore_worktree :1 ; +unsigned int ignore_cmdline :1 ;const char *commondir;const char *git_dir;config_parser_event_fn_t event_fn;
@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,extern void git_config_push_parameter (const char *text);extern int git_config_from_parameters (config_fn_t fn,void *data);extern void read_early_config (config_fn_t cb,void *data); +extern void read_very_early_config (config_fn_t cb,void *data);extern void git_config (config_fn_t fn,void *); extern int config_with_options(config_fn_t fn, void *, struct git_config_source *config_source,
Signature · 1 line
gitgitgadget
PATCH v4 6/10 trace2: use system/global config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach git to read the system and global config files for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system and global config files are used. Repo and worktree local config files are ignored. Likewise, the "-c" command line arguments are also ignored. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
--- Makefile | 1 + t/t0210-trace2-normal.sh | 49 +++++++++++++-- t/t0211-trace2-perf.sh | 31 ++++++++-- t/t0212-trace2-event.sh | 42 +++++++++++-- trace2.c | 4 ++ trace2.h | 12 ++-- trace2/tr2_cfg.c | 7 +-- trace2/tr2_dst.c | 26 ++++---- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 127 +++++++++++++++++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++++++ trace2/tr2_tgt_event.c | 46 +++++++------- trace2/tr2_tgt_normal.c | 16 ++--- trace2/tr2_tgt_perf.c | 16 ++--- 14 files changed, 340 insertions(+), 76 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
Makefile +1 -0
@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o LIB_OBJS += trace2/tr2_cmd_name.o LIB_OBJS += trace2/tr2_dst.o LIB_OBJS += trace2/tr2_sid.o +LIB_OBJS += trace2/tr2_sysenv.o LIB_OBJS += trace2/tr2_tbuf.o LIB_OBJS += trace2/tr2_tgt_event.o LIB_OBJS += trace2/tr2_tgt_normal.o
t/t0210-trace2-normal.sh +44 -5
65 lines not on this page · raw message
t/t0211-trace2-perf.sh +26 -5
@@ -3,6 +3,11 @@ test_description='test trace2 facility (perf target)' . ./test-lib.sh +# Turn off any inherited trace2 settings for this test. +sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT +sane_unset GIT_TR2_PERF_BRIEF +sane_unset GIT_TR2_CONFIG_PARAMS + # Add t/helper directory to PATH so that we can use a relative # path to run nested instances of test-tool.exe (see 004child). # This helps with HEREDOC comparisons later.
@@ -15,11 +20,6 @@ PATH="$TTDIR:$PATH" && export PATH # Warning: So you may see extra lines in artifact files when # Warning: interactively debugging. -# Turn off any inherited trace2 settings for this test. -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT -unset GIT_TR2_PERF_BRIEF -unset GIT_TR2_CONFIG_PARAMS - V=$(git version | sed -e 's/^git version //') && export V # There are multiple trace2 targets: normal, perf, and event.
@@ -150,4 +150,25 @@ test_expect_success 'perf stream, child processes' ' test_cmp expect actual ' +sane_unset GIT_TR2_PERF_BRIEF + +# Now test without environment variables and get all Trace2 settings +# from the global config. + +test_expect_success 'using global config, perf stream, return code 0' ' + test_when_finished "rm trace.perf actual expect" && + test_config_global trace2.perfBrief 1 && + test_config_global trace2.perfTarget "$(pwd)/trace.perf" && + test-tool trace2 001return 0 && + perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && + cat >expect <<-EOF && + d0|main|version|||||$V + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 + d0|main|cmd_name|||||trace2 (trace2) + d0|main|exit||_T_ABS_|||code:0 + d0|main|atexit||_T_ABS_|||code:0 + EOF + test_cmp expect actual +' + test_done
t/t0212-trace2-event.sh +37 -5
58 lines not on this page · raw message
trace2.c +4 -0
@@ -10,6 +10,7 @@#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h"
@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)tr2_sid_release ();tr2_cmd_name_release ();tr2_cfg_free_patterns (); +tr2_sysenv_release (); trace2_enabled =0 ; }
@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)if (trace2_enabled)return ; +tr2_sysenv_load (); +if (!tr2_tgt_want_builtins ())return ; trace2_enabled =1 ;
trace2.h +7 -5
@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine.
@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: -* -* GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" +* Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated +* list of patterns configured important. For example: +* git config --system trace2.configParams 'core.*,remote.*.url' +* or: +* GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url" * * Note: this routine does a read-only iteration on the config data * (using read_early_config()), so it must not be called until enough
trace2/tr2_cfg.c +3 -4
@@ -1,8 +1,7 @@#include "cache.h" #include "config.h" -#include "tr2_cfg.h" - -#define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS" +#include "trace2/tr2_cfg.h" +#include "trace2/tr2_sysenv.h" static struct strbuf **tr2_cfg_patterns;static int tr2_cfg_count_patterns;
@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)return tr2_cfg_count_patterns; tr2_cfg_loaded =1 ; - envvar =getenv (TR2_ENVVAR_CFG_PARAM ); + envvar =tr2_sysenv_get (TR2_SYSENV_CFG_PARAM );if (!envvar || !*envvar)return tr2_cfg_count_patterns;
trace2/tr2_dst.c +14 -12
@@ -1,5 +1,6 @@#include "cache.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" /* * If a Trace2 target cannot be opened for writing, we should issue a
@@ -7,17 +8,13 @@* or socket and beyond the user's control -- especially since every * git command (and sub-command) will print the message. So we silently * eat these warnings and just discard the trace data. -* -* Enable the following environment variable to see these warnings. */ -#define TR2_ENVVAR_DST_DEBUG "GIT_TR2_DST_DEBUG" -static int tr2_dst_want_warning (void ) {static int tr2env_dst_debug =-1 ;if (tr2env_dst_debug ==-1 ) { -const char *env_value =getenv (TR2_ENVVAR_DST_DEBUG ); +const char *env_value =tr2_sysenv_get (TR2_SYSENV_DST_DEBUG );if (!env_value || !*env_value) tr2env_dst_debug =0 ;else
@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)if (fd ==-1 ) {if (tr2_dst_want_warning ())warning ("trace2: could not open '%s' for '%s' tracing: %s" , - tgt_value, dst->env_var_name,strerror (errno)); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var), +strerror (errno));tr2_dst_trace_disable (dst);return 0 ;
@@ -116,7 +115,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,if (!path || !*path) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX value '%s' for '%s' tracing" , - tgt_value, dst->env_var_name); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -126,7 +126,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX path '%s' for '%s' tracing" , - path, dst->env_var_name); + path,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -148,7 +148,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, error:if (tr2_dst_want_warning ())warning ("trace2: could not connect to socket '%s' for '%s' tracing: %s" , - path, dst->env_var_name,strerror (e)); + path,tr2_sysenv_display_name (dst->sysenv_var), +strerror (e));tr2_dst_trace_disable (dst);return 0 ;
@@ -168,7 +169,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"trace2: unknown value for '%s': '%s'" , - dst->env_var_name, tgt_value); +tr2_sysenv_display_name (dst->sysenv_var), tgt_value);warning ("%s" , buf.buf);strbuf_release (&buf);
@@ -184,7 +185,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst) dst->initialized =1 ; - tgt_value =getenv (dst->env_var_name); + tgt_value =tr2_sysenv_get (dst->sysenv_var);if (!tgt_value || !strcmp (tgt_value,"" ) || !strcmp (tgt_value,"0" ) || !strcasecmp (tgt_value,"false" )) {
@@ -246,7 +247,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)return ;if (tr2_dst_want_warning ()) -warning ("unable to write trace to '%s': %s" , dst->env_var_name, +warning ("unable to write trace to '%s': %s" , +tr2_sysenv_display_name (dst->sysenv_var),strerror (errno));tr2_dst_trace_disable (dst); }
trace2/tr2_dst.h +2 -1
@@ -2,9 +2,10 @@#define TR2_DST_H struct strbuf ; +#include "trace2/tr2_sysenv.h" struct tr2_dst { -const char *const env_var_name; +enum tr2_sysenv_variable sysenv_var;int fd;unsigned int initialized :1 ;unsigned int need_close :1 ;
trace2/tr2_sysenv.c new file +127 -0
127 lines not on this page · raw message
trace2/tr2_sysenv.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef TR2_SYSENV_H +#define TR2_SYSENV_H + +/* +* The Trace2 settings that can be loaded from /etc/gitconfig +* and/or user environment variables. +* +* Note that this set does not contain any of the transient +* environment variables used to pass information from parent +* to child git processes, such "GIT_TR2_PARENT_SID". +*/ +enum tr2_sysenv_variable { +TR2_SYSENV_CFG_PARAM =0 , + +TR2_SYSENV_DST_DEBUG , + +TR2_SYSENV_NORMAL , +TR2_SYSENV_NORMAL_BRIEF , + +TR2_SYSENV_EVENT , +TR2_SYSENV_EVENT_BRIEF , +TR2_SYSENV_EVENT_NESTING , + +TR2_SYSENV_PERF , +TR2_SYSENV_PERF_BRIEF , + +TR2_SYSENV_MUST_BE_LAST +}; + +void tr2_sysenv_load (void ); + +const char *tr2_sysenv_get (enum tr2_sysenv_variable ); +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var); +void tr2_sysenv_release (void ); + +#endif /* TR2_SYSENV_H */
trace2/tr2_tgt_event.c +23 -23
111 lines not on this page · raw message
trace2/tr2_tgt_normal.c +8 -8
@@ -4,20 +4,20 @@#include "quote.h" #include "version.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = {"GIT_TR2" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_normal = {TR2_SYSENV_NORMAL ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>" * fields from each line written to the builtin normal target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF" -static int tr2env_normal_brief; +static int tr2env_normal_be_brief;#define TR2FMT_NORMAL_FL_WIDTH (50)
@@ -25,15 +25,15 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_normal);int want_brief; -char *brief; +const char *brief;if (!want)return want; - brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_normal_brief = want_brief; + tr2env_normal_be_brief = want_brief;return want; }
@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf) {strbuf_setlen (buf,0 ); -if (!tr2env_normal_brief) { +if (!tr2env_normal_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
trace2/tr2_tgt_perf.c +8 -8
@@ -6,20 +6,20 @@#include "json-writer.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = {"GIT_TR2_PERF" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_perf = {TR2_SYSENV_PERF ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" * fields from each line written to the builtin performance target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF" -static int tr2env_perf_brief; +static int tr2env_perf_be_brief;#define TR2FMT_PERF_FL_WIDTH (50)#define TR2FMT_PERF_MAX_EVENT_NAME (12)
@@ -36,17 +36,17 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_perf);int want_brief; -char *brief; +const char *brief;if (!want)return want;strbuf_addchars (&dots,'.' ,TR2_DOTS_BUFFER_SIZE ); - brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_perf_brief = want_brief; + tr2env_perf_be_brief = want_brief;return want; }
@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,strbuf_setlen (buf,0 ); -if (!tr2env_perf_brief) { +if (!tr2env_perf_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
Signature · 1 line
gitgitgadget
PATCH v4 7/10 trace2: report peak memory usage of the process
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Windows version of git to report peak memory usage during exit() processing.
--- common-main.c | 2 +- compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++-- trace2.c | 2 + trace2.h | 14 +++++-- 4 files changed, 60 insertions(+), 8 deletions(-)
common-main.c +1 -1
@@ -41,7 +41,7 @@ int main(int argc, const char **argv)trace2_initialize ();trace2_cmd_start (argv); -trace2_collect_process_info (); +trace2_collect_process_info (TRACE2_PROCESS_INFO_STARTUP );git_setup_gettext ();
compat/win32/trace2_win32_process_info.c +47 -3
63 lines not on this page · raw message
trace2.c +2 -0
@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)if (!trace2_enabled)return code; +trace2_collect_process_info (TRACE2_PROCESS_INFO_EXIT ); + tr2main_exit_code = code; us_now =getnanotime () /1000 ;
trace2.h +10 -4
@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);* Optional platform-specific code to dump information about the * current and any parent process(es). This is intended to allow * post-processors to know who spawned this git instance and anything -* else the platform may be able to tell us about the current process. +* else that the platform may be able to tell us about the current process. */ + +enum trace2_process_info_reason { +TRACE2_PROCESS_INFO_STARTUP , +TRACE2_PROCESS_INFO_EXIT , +}; +#if defined(GIT_WINDOWS_NATIVE ) -void trace2_collect_process_info (void ); +void trace2_collect_process_info (enum trace2_process_info_reason reason);#else -#define trace2_collect_process_info () \ - do { \ +#define trace2_collect_process_info (reason) \ + do { \ } while (0)#endif
Signature · 1 line
gitgitgadget
PATCH v4 10/10 trace2: update docs to describe system/global config settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
--- Documentation/config.txt | 2 + Documentation/config/trace2.txt | 56 +++++++++ Documentation/technical/api-trace2.txt | 151 ++++++++++++++----------- Documentation/trace2-target-values.txt | 10 ++ 4 files changed, 152 insertions(+), 67 deletions(-) create mode 100644 Documentation/config/trace2.txt create mode 100644 Documentation/trace2-target-values.txt
Documentation/config.txt +2 -0
@@ -422,6 +422,8 @@ include::config/submodule.txt[] include::config/tag.txt[] +include::config/trace2.txt[] + include::config/transfer.txt[] include::config/uploadarchive.txt[]
Documentation/config/trace2.txt new file +56 -0
56 lines not on this page · raw message
Documentation/technical/api-trace2.txt +84 -67
259 lines not on this page · raw message
Documentation/trace2-target-values.txt new file +10 -0
@@ -0,0 +1,10 @@ +-- +* `0` or `false` - Disables the target. +* `1` or `true` - Writes to `STDERR`. +* `[2-9]` - Writes to the already opened file descriptor. +* `<absolute-pathname>` - Writes to the file in append mode. +* `af_unix:[<socket_type>:]<absolute-pathname>` - Write to a +Unix DomainSocket (on platforms that support them). Socket +type can be either `stream` or `dgram`; if omitted Git will +try both. +--
Signature · 1 line
gitgitgadget
PATCH v4 4/10 trace2: find exec-dir before trace2 initialization
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Git to resolve the executable directory before initializing Trace2. This allows the system configuration directory to be discovered earlier (because it is sometimes relative to the prefix or runtime-prefix).
This will be used by the next commit to allow trace2 settings to be loaded from the system config.
--- common-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common-main.c +2 -2
@@ -37,12 +37,12 @@ int main(int argc, const char **argv)sanitize_stdfds ();restore_sigpipe_to_default (); +git_resolve_executable_dir (argv[0 ]); +trace2_initialize ();trace2_cmd_start (argv);trace2_collect_process_info (); -git_resolve_executable_dir (argv[0 ]); -git_setup_gettext ();initialize_the_repository ();
Signature · 1 line
gitgitgadget
PATCH v4 9/10 trace2: make SIDs more unique
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update SID component construction to use the current UTC datetime and a portion of the SHA1 of the hostname.
Use an simplified date/time format to make it easier to use the SID component as a logfile filename.
--- Documentation/technical/api-trace2.txt | 16 ++++---- trace2/tr2_sid.c | 53 ++++++++++++++++++++++++-- trace2/tr2_tbuf.c | 15 ++++++++ trace2/tr2_tbuf.h | 1 + 4 files changed, 73 insertions(+), 12 deletions(-)
Documentation/technical/api-trace2.txt +8 -8
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} -{"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} -{"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} +{"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"} +{"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"]} +{"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"} +{"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} +{"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} ------------ == Enabling a Target
@@ -540,11 +540,11 @@ The following key/value pairs are common to all events: ------------ { "event":"version", - "sid":"1547659722619736-11614", + "sid":"20190408T191827.272759Z-H9b68c35f-P011764", "thread":"main", - "time":"2019-01-16T17:28:42.620713Z", + "time":"2019-04-08T19:18:27.282761Z", "file":"common-main.c", - "line":38, + "line":42, ... } ------------
trace2/tr2_sid.c +49 -4
75 lines not on this page · raw message
trace2/tr2_tbuf.c +15 -0
@@ -30,3 +30,18 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb) tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } + +void tr2_tbuf_utc_datetime (struct tr2_tbuf *tb) +{ +struct timeval tv; +struct tm tm; +time_t secs; + +gettimeofday (&tv,NULL ); + secs = tv.tv_sec; +gmtime_r (&secs, &tm); + +xsnprintf (tb->buf,sizeof (tb->buf),"%4d%02d%02dT%02d%02d%02d.%06ldZ" , + tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, + tm.tm_min, tm.tm_sec, (long )tv.tv_usec); +}
trace2/tr2_tbuf.h +1 -0
@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);* Fill buffer with formatted UTC datatime string. */ void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
Signature · 1 line
gitgitgadget
PATCH v4 8/10 trace2: clarify UTC datetime formatting
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update tr2_tbuf_utc_datetime to generate extended UTC format. Update tr2_tgt_event target to use extended format in 'time' columns.
--- Documentation/technical/api-trace2.txt | 12 ++++++------ trace2/tr2_tbuf.c | 4 ++-- trace2/tr2_tbuf.h | 4 ++-- trace2/tr2_tgt_event.c | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-)
Documentation/technical/api-trace2.txt +6 -6
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"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"} -{"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} -{"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} +{"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"} +{"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"]} +{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} +{"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} +{"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} ------------ == Enabling a Target
@@ -542,7 +542,7 @@ The following key/value pairs are common to all events: "event":"version", "sid":"1547659722619736-11614", "thread":"main", - "time":"2019-01-16 17:28:42.620713", + "time":"2019-01-16T17:28:42.620713Z", "file":"common-main.c", "line":38, ...
trace2/tr2_tbuf.c +2 -2
@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb) tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } -void tr2_tbuf_utc_time (struct tr2_tbuf *tb) +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb) {struct timeval tv;struct tm tm;
@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)gmtime_r (&secs, &tm);xsnprintf (tb->buf,sizeof (tb->buf), -"%4d-%02d-%02d %02d:%02d:%02d.%06ld" , tm.tm_year +1900 , +"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ" , tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long )tv.tv_usec); }
trace2/tr2_tbuf.h +2 -2
@@ -16,8 +16,8 @@ struct tr2_tbuf {void tr2_tbuf_local_time (struct tr2_tbuf *tb);/* -* Fill buffer with formatted UTC time string. +* Fill buffer with formatted UTC datatime string. */ -void tr2_tbuf_utc_time (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
trace2/tr2_tgt_event.c +1 -1
@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,*/ if (!tr2env_event_be_brief || !strcmp (event_name,"version" ) || !strcmp (event_name,"atexit" )) { -tr2_tbuf_utc_time (&tb_now); +tr2_tbuf_utc_datetime_extended (&tb_now);jw_object_string (jw,"time" , tb_now.buf); }
Signature · 1 line
gitgitgadget
Re: [PATCH v4 06/10] trace2: use system/global config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetQuoted 14 lines · Jeff Hostetler via GitGitGadget
From: Jeff Hostetler <[email protected]>
Teach git to read the system and global config files for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system and global config files are used. Repo and worktree local config files are ignored. Likewise, the "-c" command line arguments are also ignored. These limits are for performance reasons.
Quoted 8 lines
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
Reading the configuration that early causes unexpected and undesired behavior change:
$ sudo chmod a-rwx /usr/local/etc/gitconfig $ ./BUILDS/v2.21.0/bin/git usage: git [--version] [--help] [-C <path>] [-c <name>=<value>] <... snip rest of usage ...> $ strace ./BUILDS/v2.21.0/bin/git 2>&1 |grep config -c 0 $ ./git fatal: unable to access '/usr/local/etc/gitconfig': Permission denied $ ./git --version fatal: unable to access '/usr/local/etc/gitconfig': Permission denied
I think at least 'git', 'git --help', and 'git --version' should Just Work, no matter what.
This breaks the 32 bit Linux build job on Travis CI, because:
- In the 32 bit Docker image we change UID from root to regular user while preserving the environment, including $HOME.
- Since $HOME is the default build prefix, Git will look for the system-wide configuration under '/root/etc/gitconfig', which fails as a regular user.
- Our test harness checks early (i.e. earlier than setting GIT_CONFIG_NOSYSTEM=1) whether Git has been built successfully by attempting to run '$GIT_BUILD_DIR}/git', which fails because of the inaccessible system-wide config file, and in turn the harness assumes that Git hasn't been built and aborts.
Re: [PATCH v4 06/10] trace2: use system/global config for default trace2 settings
Quoted 51 lines · SZEDER Gábor
Quoted 14 lines · Jeff Hostetler via GitGitGadget
From: Jeff Hostetler <[email protected]>
Teach git to read the system and global config files for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system and global config files are used. Repo and worktree local config files are ignored. Likewise, the "-c" command line arguments are also ignored. These limits are for performance reasons.
Quoted 8 lines
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
Reading the configuration that early causes unexpected and undesired behavior change:
$ sudo chmod a-rwx /usr/local/etc/gitconfig $ ./BUILDS/v2.21.0/bin/git usage: git [--version] [--help] [-C <path>] [-c <name>=<value>] <... snip rest of usage ...> $ strace ./BUILDS/v2.21.0/bin/git 2>&1 |grep config -c 0 $ ./git fatal: unable to access '/usr/local/etc/gitconfig': Permission denied $ ./git --version fatal: unable to access '/usr/local/etc/gitconfig': Permission deniedI think at least 'git', 'git --help', and 'git --version' should Just Work, no matter what.
This breaks the 32 bit Linux build job on Travis CI, because:
- In the 32 bit Docker image we change UID from root to regular user while preserving the environment, including $HOME.
- Since $HOME is the default build prefix, Git will look for the system-wide configuration under '
/root/etc/gitconfig', which fails as a regular user.
Quoted 8 lines
- Our test harness checks early (i.e. earlier than setting GIT_CONFIG_NOSYSTEM=1) whether Git has been built successfully by attempting to run '$GIT_BUILD_DIR}/git', which fails because of the inaccessible system-wide config file, and in turn the harness assumes that Git hasn't been built and aborts.
https://travis-ci.org/git/git/jobs/524403682#L1258
It appears that config.c:do_git_config_sequence() passes flags = 0 to access_or_die() rather than ACCESS_EACCES_OK as it does for the other scopes. This causes the fatal error, rather than ignoring the problem.
Reasons for this were discussed in:
4698c8feb1 config: allow inaccessible configuration under $HOME
I'll push a fix shortly.
Thanks
Jeff
v5 cover trace2: load trace2 settings from system config
In reply to Jeff Hostetler via GitGitGadgetVersion 4 fixes a few clang-format warnings and simplifies the PID field in the SID.
Jeff Hostetler (11):
config: initialize opts structure in repo_read_config()
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
config: add read_very_early_config()
trace2: use system/global config for default trace2 settings
trace2: report peak memory usage of the process
trace2: clarify UTC datetime formatting
trace2: make SIDs more unique
trace2: update docs to describe system/global config settings
trace2: fixup access problem on /etc/gitconfig in
read_very_early_config
Documentation/config.txt | 2 + Documentation/config/trace2.txt | 56 ++++++++ Documentation/technical/api-trace2.txt | 176 +++++++++++++---------- Documentation/trace2-target-values.txt | 10 ++ Makefile | 1 + common-main.c | 8 +- compat/mingw.c | 2 + compat/win32/trace2_win32_process_info.c | 50 ++++++- config.c | 30 +++- config.h | 5 + t/t0210-trace2-normal.sh | 49 ++++++- t/t0211-trace2-perf.sh | 43 ++++-- t/t0212-trace2-event.sh | 42 +++++- trace2.c | 21 ++- trace2.h | 43 ++++-- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 26 ++-- trace2/tr2_dst.h | 3 +- trace2/tr2_sid.c | 53 ++++++- trace2/tr2_sysenv.c | 127 ++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++ trace2/tr2_tbuf.c | 19 ++- trace2/tr2_tbuf.h | 5 +- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 53 +++---- trace2/tr2_tgt_normal.c | 19 +-- trace2/tr2_tgt_perf.c | 23 +-- trace2/tr2_tls.c | 38 +++-- trace2/tr2_tls.h | 8 +- 29 files changed, 752 insertions(+), 204 deletions(-) create mode 100644 Documentation/config/trace2.txt create mode 100644 Documentation/trace2-target-values.txt create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
base-commit: 041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/169
Range-diff vs v4:
1: f6653f1c59 = 1: f6653f1c59 config: initialize opts structure in repo_read_config() 2: 48e34834b6 = 2: 48e34834b6 trace2: refactor setting process starting time 3: 175371fb54 = 3: 175371fb54 trace2: add absolute elapsed time to start event 4: 94729b284c = 4: 94729b284c trace2: find exec-dir before trace2 initialization 5: b0fe1385f1 = 5: b0fe1385f1 config: add read_very_early_config() 6: 550cad6189 = 6: 550cad6189 trace2: use system/global config for default trace2 settings 7: 56d8ce3fd6 = 7: 56d8ce3fd6 trace2: report peak memory usage of the process 8: 196a9d2c85 = 8: 196a9d2c85 trace2: clarify UTC datetime formatting 9: 9fdcb50140 = 9: 9fdcb50140 trace2: make SIDs more unique 10: 3414016d04 = 10: 3414016d04 trace2: update docs to describe system/global config settings -: ---------- > 11: 18ce795360 trace2: fixup access problem on /etc/gitconfig in read_very_early_config
Signature · 1 line
gitgitgadget
PATCH v5 1/11 config: initialize opts structure in repo_read_config()
From: Jeff Hostetler <[email protected]>
Initialize opts structure in repo_read_config().
This change fixes a crash in later commit after a new field is added to the structure.
In commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config() was added. It only initializes 3 fields in the opts structure. It is passed to config_with_options() and then to do_git_config_sequence(). However, do_git_config_sequence() drops the opts on the floor and calls git_config_from_file() rather than git_config_from_file_with_options(), so that may be why this hasn't been a problem in the past.
--- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
config.c +1 -1
@@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha/* Functions use to read configuration from a repository */ static void repo_read_config (struct repository *repo) { -struct config_options opts; +struct config_options opts = {0 }; opts.respect_includes =1 ; opts.commondir = repo->commondir;
Signature · 1 line
gitgitgadget
PATCH v5 3/11 trace2: add absolute elapsed time to start event
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Add elapsed process time to "start" event to measure the performance of early process startup.
--- Documentation/technical/api-trace2.txt | 11 ++++++----- t/t0211-trace2-perf.sh | 12 ++++++------ trace2.c | 8 +++++++- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 5 ++++- trace2/tr2_tgt_normal.c | 3 ++- trace2/tr2_tgt_perf.c | 7 ++++--- 7 files changed, 30 insertions(+), 17 deletions(-)
Documentation/technical/api-trace2.txt +6 -5
@@ -60,7 +60,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.perf 12:28:42.620675 common-main.c:38 | d0 | main | version | | | | | 2.20.1.155.g426c96fcdb -12:28:42.621001 common-main.c:39 | d0 | main | start | | | | | git version +12:28:42.621001 common-main.c:39 | d0 | main | start | | 0.001173 | | | git version 12:28:42.621111 git.c:432 | d0 | main | cmd_name | | | | | version (version) 12:28:42.621225 git.c:662 | d0 | main | exit | | 0.001227 | | | code:0 12:28:42.621259 trace2/tr2_tgt_perf.c:211 | d0 | main | atexit | | 0.001265 | | | code:0
@@ -79,7 +79,7 @@ git version 2.20.1.155.g426c96fcdb ------------ $ cat ~/log.event {"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"} -{"event":"start","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16 17:28:42.621027","file":"common-main.c","line":39,"argv":["git","version"]} +{"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"]} {"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"} {"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} {"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}
@@ -601,6 +601,7 @@ from all events and the `time` field is only present on the "start" and { "event":"start", ... + "t_abs":0.001227, # elapsed time in seconds "argv":["git","version"] } ------------
@@ -1118,7 +1119,7 @@ $ git status $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.160.g5676107ecd.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1163,7 +1164,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.162.gb4ccea44db.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) ...
@@ -1219,7 +1220,7 @@ $ git status ... $ cat ~/log.perf d0 | main | version | | | | | 2.20.1.156.gf9916ae094.dirty -d0 | main | start | | | | | git status +d0 | main | start | | 0.001173 | | | git status d0 | main | def_repo | r1 | | | | worktree:/Users/jeffhost/work/gfw d0 | main | cmd_name | | | | | status (status) d0 | main | region_enter | r1 | 0.001791 | | index | label:do_read_index .git/index
t/t0211-trace2-perf.sh +6 -6
@@ -50,7 +50,7 @@ test_expect_success 'perf stream, return code 0' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:0 d0|main|atexit||_T_ABS_|||code:0
@@ -64,7 +64,7 @@ test_expect_success 'perf stream, return code 1' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 001return 1 + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 1 d0|main|cmd_name|||||trace2 (trace2) d0|main|exit||_T_ABS_|||code:1 d0|main|atexit||_T_ABS_|||code:1
@@ -82,7 +82,7 @@ test_expect_success 'perf stream, error event' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' + d0|main|start||_T_ABS_|||_EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' d0|main|cmd_name|||||trace2 (trace2) d0|main|error|||||hello world d0|main|error|||||this is a test
@@ -128,15 +128,15 @@ test_expect_success 'perf stream, child processes' ' perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && cat >expect <<-EOF && d0|main|version|||||$V - d0|main|start|||||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 + d0|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 004child test-tool trace2 001return 0 d0|main|cmd_name|||||trace2 (trace2) d0|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 004child test-tool trace2 001return 0 d1|main|version|||||$V - d1|main|start|||||_EXE_ trace2 004child test-tool trace2 001return 0 + d1|main|start||_T_ABS_|||_EXE_ trace2 004child test-tool trace2 001return 0 d1|main|cmd_name|||||trace2 (trace2/trace2) d1|main|child_start||_T_ABS_|||[ch0] class:? argv: test-tool trace2 001return 0 d2|main|version|||||$V - d2|main|start|||||_EXE_ trace2 001return 0 + d2|main|start||_T_ABS_|||_EXE_ trace2 001return 0 d2|main|cmd_name|||||trace2 (trace2/trace2/trace2) d2|main|exit||_T_ABS_|||code:0 d2|main|atexit||_T_ABS_|||code:0
trace2.c +7 -1
@@ -182,13 +182,19 @@ void trace2_cmd_start_fl(const char *file, int line, const char **argv) {struct tr2_tgt *tgt_j;int j; +uint64_t us_now; +uint64_t us_elapsed_absolute;if (!trace2_enabled)return ; + us_now =getnanotime () /1000 ; + us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); + for_each_wanted_builtin (j, tgt_j)if (tgt_j->pfn_start_fl) - tgt_j->pfn_start_fl (file, line, argv); + tgt_j->pfn_start_fl (file, line, us_elapsed_absolute, + argv); }int trace2_cmd_exit_fl (const char *file,int line,int code)
trace2/tr2_tgt.h +1 -0
@@ -15,6 +15,7 @@ typedef void(tr2_tgt_term_t)(void);typedef void (tr2_tgt_evt_version_fl_t )(const char *file,int line);typedef void (tr2_tgt_evt_start_fl_t )(const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv);typedef void (tr2_tgt_evt_exit_fl_t )(const char *file,int line,uint64_t us_elapsed_absolute,int code);
trace2/tr2_tgt_event.c +4 -1
@@ -122,13 +122,16 @@ static void fn_version_fl(const char *file, int line)jw_release (&jw); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct json_writer jw =JSON_WRITER_INIT ; +double t_abs = (double )us_elapsed_absolute /1000000.0 ;jw_object_begin (&jw,0 );event_fmt_prepare (event_name, file, line,NULL , &jw); +jw_object_double (&jw,"t_abs" ,6 , t_abs);jw_object_inline_begin_array (&jw,"argv" );jw_array_argv (&jw, argv);jw_end (&jw);
trace2/tr2_tgt_normal.c +2 -1
@@ -81,7 +81,8 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {struct strbuf buf_payload =STRBUF_INIT ;
trace2/tr2_tgt_perf.c +4 -3
@@ -159,15 +159,16 @@ static void fn_version_fl(const char *file, int line)strbuf_release (&buf_payload); } -static void fn_start_fl (const char *file,int line,const char **argv) +static void fn_start_fl (const char *file,int line, +uint64_t us_elapsed_absolute,const char **argv) {const char *event_name ="start" ;struct strbuf buf_payload =STRBUF_INIT ;sq_quote_argv_pretty (&buf_payload, argv); -perf_io_write_fl (file, line, event_name,NULL ,NULL ,NULL ,NULL , - &buf_payload); +perf_io_write_fl (file, line, event_name,NULL , &us_elapsed_absolute, +NULL ,NULL , &buf_payload);strbuf_release (&buf_payload); }
Signature · 1 line
gitgitgadget
PATCH v5 2/11 trace2: refactor setting process starting time
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Create trace2_initialize_clock() and call from main() to capture process start time in isolation and before other sub-systems are ready.
--- Documentation/technical/api-trace2.txt | 12 ++++++-- common-main.c | 2 ++ compat/mingw.c | 2 ++ trace2.c | 7 ++++- trace2.h | 17 ++++++++++++ trace2/tr2_tls.c | 38 ++++++++++++++++---------- trace2/tr2_tls.h | 8 +++++- 7 files changed, 67 insertions(+), 19 deletions(-)
Documentation/technical/api-trace2.txt +9 -3
@@ -160,17 +160,23 @@ purposes. These are concerned with the lifetime of the overall git process. +`void trace2_initialize_clock()`:: + + Initialize the Trace2 start clock and nothing else. This should + be called at the very top of main() to capture the process start + time and reduce startup order dependencies. + `void trace2_initialize()`:: Determines if any Trace2 Targets should be enabled and - initializes the Trace2 facility. This includes starting the - elapsed time clocks and thread local storage (TLS). + initializes the Trace2 facility. This includes setting up the + Trace2 thread local storage (TLS). + This function emits a "version" message containing the version of git and the Trace2 protocol. + This function should be called from `main()` as early as possible in -the life of the process. +the life of the process after essential process initialization. `int trace2_is_enabled()`::
common-main.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, const char **argv) {int result; +trace2_initialize_clock (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed
compat/mingw.c +2 -0
@@ -2569,6 +2569,8 @@ void mingw_startup(void)wchar_t **wenv, **wargv;_startupinfo si; +trace2_initialize_clock (); +maybe_redirect_std_handles ();/* get wide char arguments and environment */
trace2.c +6 -1
@@ -142,6 +142,11 @@ static void tr2main_signal_handler(int signo)raise (signo); } +void trace2_initialize_clock (void ) +{ +tr2tls_start_process_clock (); +} +void trace2_initialize_fl (const char *file,int line) {struct tr2_tgt *tgt_j;
@@ -428,7 +433,7 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name) us_now =getnanotime () /1000 ; us_elapsed_absolute =tr2tls_absolute_elapsed (us_now); -tr2tls_create_self (thread_name); +tr2tls_create_self (thread_name, us_now);for_each_wanted_builtin (j, tgt_j) if (tgt_j->pfn_thread_start_fl)
trace2.h +17 -0
@@ -19,6 +19,23 @@ struct json_writer;* [] trace2_printf* -- legacy trace[1] messages. */ +/* +* Initialize the TRACE2 clock and do nothing else, in particular +* no mallocs, no system inspection, and no environment inspection. +* +* This should be called at the very top of main() to capture the +* process start time. This is intended to reduce chicken-n-egg +* bootstrap pressure. +* +* It is safe to call this more than once. This allows capturing +* absolute startup costs on Windows which uses a little trickery +* to do setup work before common-main.c:main() is called. +* +* The main trace2_initialize_fl() may be called a little later +* after more infrastructure is established. +*/ +void trace2_initialize_clock (void ); +/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 * targets are enabled in the environment. Emits a 'version' event.
trace2/tr2_tls.c +24 -14
@@ -10,16 +10,30 @@#define TR2_REGION_NESTING_INITIAL_SIZE (100)static struct tr2tls_thread_ctx *tr2tls_thread_main; -static uint64_t tr2tls_us_start_main; +static uint64_t tr2tls_us_start_process;static pthread_mutex_t tr2tls_mutex;static pthread_key_t tr2tls_key;static int tr2_next_thread_id;/* modify under lock */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name) +void tr2tls_start_process_clock (void ) +{ +if (tr2tls_us_start_process) +return ; + +/* +* Keep the absolute start time of the process (i.e. the main +* process) in a fixed variable since other threads need to +* access it. This allows them to do that without a lock on +* main thread's array data (because of reallocs). +*/ + tr2tls_us_start_process =getnanotime () /1000 ; +} + +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start) { -uint64_t us_now =getnanotime () /1000 ;struct tr2tls_thread_ctx *ctx =xcalloc (1 ,sizeof (*ctx));/*
@@ -29,7 +43,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name)*/ ctx->alloc =TR2_REGION_NESTING_INITIAL_SIZE ; ctx->array_us_start = (uint64_t *)xcalloc (ctx->alloc,sizeof (uint64_t )); - ctx->array_us_start[ctx->nr_open_regions++] = us_now; + ctx->array_us_start[ctx->nr_open_regions++] = us_thread_start; ctx->thread_id =tr2tls_locked_increment (&tr2_next_thread_id);
@@ -55,7 +69,7 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)* here and silently continue. */ if (!ctx) - ctx =tr2tls_create_self ("unknown" ); + ctx =tr2tls_create_self ("unknown" ,getnanotime () /1000 );return ctx; }
@@ -124,22 +138,18 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)if (!tr2tls_thread_main)return 0 ; -return us - tr2tls_us_start_main; +return us - tr2tls_us_start_process; }void tr2tls_init (void ) { +tr2tls_start_process_clock (); +pthread_key_create (&tr2tls_key,NULL );init_recursive_mutex (&tr2tls_mutex); - tr2tls_thread_main =tr2tls_create_self ("main" ); -/* -* Keep a copy of the absolute start time of the main thread -* in a fixed variable since other threads need to access it. -* This also eliminates the need to lock accesses to the main -* thread's array (because of reallocs). -*/ - tr2tls_us_start_main = tr2tls_thread_main->array_us_start[0 ]; + tr2tls_thread_main = +tr2tls_create_self ("main" , tr2tls_us_start_process); }void tr2tls_release (void )
trace2/tr2_tls.h +7 -1
@@ -31,7 +31,8 @@ struct tr2tls_thread_ctx {* In this and all following functions the term "self" refers to the * current thread. */ -struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name); +struct tr2tls_thread_ctx *tr2tls_create_self (const char *thread_name, +uint64_t us_thread_start);/* * Get our TLS data.
@@ -94,4 +95,9 @@ void tr2tls_release(void);*/ int tr2tls_locked_increment (int *p); +/* +* Capture the process start time and do nothing else. +*/ +void tr2tls_start_process_clock (void ); +#endif /* TR2_TLS_H */
Signature · 1 line
gitgitgadget
PATCH v5 7/11 trace2: report peak memory usage of the process
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Windows version of git to report peak memory usage during exit() processing.
--- common-main.c | 2 +- compat/win32/trace2_win32_process_info.c | 50 ++++++++++++++++++++++-- trace2.c | 2 + trace2.h | 14 +++++-- 4 files changed, 60 insertions(+), 8 deletions(-)
common-main.c +1 -1
@@ -41,7 +41,7 @@ int main(int argc, const char **argv)trace2_initialize ();trace2_cmd_start (argv); -trace2_collect_process_info (); +trace2_collect_process_info (TRACE2_PROCESS_INFO_STARTUP );git_setup_gettext ();
compat/win32/trace2_win32_process_info.c +47 -3
63 lines not on this page · raw message
trace2.c +2 -0
@@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)if (!trace2_enabled)return code; +trace2_collect_process_info (TRACE2_PROCESS_INFO_EXIT ); + tr2main_exit_code = code; us_now =getnanotime () /1000 ;
trace2.h +10 -4
@@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);* Optional platform-specific code to dump information about the * current and any parent process(es). This is intended to allow * post-processors to know who spawned this git instance and anything -* else the platform may be able to tell us about the current process. +* else that the platform may be able to tell us about the current process. */ + +enum trace2_process_info_reason { +TRACE2_PROCESS_INFO_STARTUP , +TRACE2_PROCESS_INFO_EXIT , +}; +#if defined(GIT_WINDOWS_NATIVE ) -void trace2_collect_process_info (void ); +void trace2_collect_process_info (enum trace2_process_info_reason reason);#else -#define trace2_collect_process_info () \ - do { \ +#define trace2_collect_process_info (reason) \ + do { \ } while (0)#endif
Signature · 1 line
gitgitgadget
PATCH v5 8/11 trace2: clarify UTC datetime formatting
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update tr2_tbuf_utc_datetime to generate extended UTC format. Update tr2_tgt_event target to use extended format in 'time' columns.
--- Documentation/technical/api-trace2.txt | 12 ++++++------ trace2/tr2_tbuf.c | 4 ++-- trace2/tr2_tbuf.h | 4 ++-- trace2/tr2_tgt_event.c | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-)
Documentation/technical/api-trace2.txt +6 -6
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"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"} -{"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} -{"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} +{"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"} +{"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"]} +{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} +{"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} +{"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} ------------ == Enabling a Target
@@ -542,7 +542,7 @@ The following key/value pairs are common to all events: "event":"version", "sid":"1547659722619736-11614", "thread":"main", - "time":"2019-01-16 17:28:42.620713", + "time":"2019-01-16T17:28:42.620713Z", "file":"common-main.c", "line":38, ...
trace2/tr2_tbuf.c +2 -2
@@ -15,7 +15,7 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb) tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } -void tr2_tbuf_utc_time (struct tr2_tbuf *tb) +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb) {struct timeval tv;struct tm tm;
@@ -26,7 +26,7 @@ void tr2_tbuf_utc_time(struct tr2_tbuf *tb)gmtime_r (&secs, &tm);xsnprintf (tb->buf,sizeof (tb->buf), -"%4d-%02d-%02d %02d:%02d:%02d.%06ld" , tm.tm_year +1900 , +"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ" , tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long )tv.tv_usec); }
trace2/tr2_tbuf.h +2 -2
@@ -16,8 +16,8 @@ struct tr2_tbuf {void tr2_tbuf_local_time (struct tr2_tbuf *tb);/* -* Fill buffer with formatted UTC time string. +* Fill buffer with formatted UTC datatime string. */ -void tr2_tbuf_utc_time (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
trace2/tr2_tgt_event.c +1 -1
@@ -94,7 +94,7 @@ static void event_fmt_prepare(const char *event_name, const char *file,*/ if (!tr2env_event_be_brief || !strcmp (event_name,"version" ) || !strcmp (event_name,"atexit" )) { -tr2_tbuf_utc_time (&tb_now); +tr2_tbuf_utc_datetime_extended (&tb_now);jw_object_string (jw,"time" , tb_now.buf); }
Signature · 1 line
gitgitgadget
PATCH v5 9/11 trace2: make SIDs more unique
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Update SID component construction to use the current UTC datetime and a portion of the SHA1 of the hostname.
Use an simplified date/time format to make it easier to use the SID component as a logfile filename.
--- Documentation/technical/api-trace2.txt | 16 ++++---- trace2/tr2_sid.c | 53 ++++++++++++++++++++++++-- trace2/tr2_tbuf.c | 15 ++++++++ trace2/tr2_tbuf.h | 1 + 4 files changed, 73 insertions(+), 12 deletions(-)
Documentation/technical/api-trace2.txt +8 -8
@@ -78,11 +78,11 @@ git version 2.20.1.155.g426c96fcdb + ------------ $ cat ~/log.event -{"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"} -{"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"]} -{"event":"cmd_name","sid":"1547659722619736-11614","thread":"main","time":"2019-01-16T17:28:42.621122Z","file":"git.c","line":432,"name":"version","hierarchy":"version"} -{"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} -{"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} +{"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"} +{"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"]} +{"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"} +{"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} +{"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} ------------ == Enabling a Target
@@ -540,11 +540,11 @@ The following key/value pairs are common to all events: ------------ { "event":"version", - "sid":"1547659722619736-11614", + "sid":"20190408T191827.272759Z-H9b68c35f-P011764", "thread":"main", - "time":"2019-01-16T17:28:42.620713Z", + "time":"2019-04-08T19:18:27.282761Z", "file":"common-main.c", - "line":38, + "line":42, ... } ------------
trace2/tr2_sid.c +49 -4
75 lines not on this page · raw message
trace2/tr2_tbuf.c +15 -0
@@ -30,3 +30,18 @@ void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb) tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec); } + +void tr2_tbuf_utc_datetime (struct tr2_tbuf *tb) +{ +struct timeval tv; +struct tm tm; +time_t secs; + +gettimeofday (&tv,NULL ); + secs = tv.tv_sec; +gmtime_r (&secs, &tm); + +xsnprintf (tb->buf,sizeof (tb->buf),"%4d%02d%02dT%02d%02d%02d.%06ldZ" , + tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, + tm.tm_min, tm.tm_sec, (long )tv.tv_usec); +}
trace2/tr2_tbuf.h +1 -0
@@ -19,5 +19,6 @@ void tr2_tbuf_local_time(struct tr2_tbuf *tb);* Fill buffer with formatted UTC datatime string. */ void tr2_tbuf_utc_datetime_extended (struct tr2_tbuf *tb); +void tr2_tbuf_utc_datetime (struct tr2_tbuf *tb);#endif /* TR2_TBUF_H */
Signature · 1 line
gitgitgadget
PATCH v5 6/11 trace2: use system/global config for default trace2 settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach git to read the system and global config files for default Trace2 settings. This allows system-wide Trace2 settings to be installed and inherited to make it easier to manage a collection of systems.
The original GIT_TR2* environment variables are loaded afterwards and can be used to override the system settings.
Only the system and global config files are used. Repo and worktree local config files are ignored. Likewise, the "-c" command line arguments are also ignored. These limits are for performance reasons.
(1) For users not using Trace2, there should be minimal overhead to detect that Trace2 is not enabled. In particular, Trace2 should not allocate lots of otherwise unused data strucutres.
(2) For accurate performance measurements, Trace2 should be initialized as early in the git process as possible, and before most of the normal git process initialization (which involves discovering the .git directory and reading a hierarchy of config files).
--- Makefile | 1 + t/t0210-trace2-normal.sh | 49 +++++++++++++-- t/t0211-trace2-perf.sh | 31 ++++++++-- t/t0212-trace2-event.sh | 42 +++++++++++-- trace2.c | 4 ++ trace2.h | 12 ++-- trace2/tr2_cfg.c | 7 +-- trace2/tr2_dst.c | 26 ++++---- trace2/tr2_dst.h | 3 +- trace2/tr2_sysenv.c | 127 +++++++++++++++++++++++++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++++++++ trace2/tr2_tgt_event.c | 46 +++++++------- trace2/tr2_tgt_normal.c | 16 ++--- trace2/tr2_tgt_perf.c | 16 ++--- 14 files changed, 340 insertions(+), 76 deletions(-) create mode 100644 trace2/tr2_sysenv.c create mode 100644 trace2/tr2_sysenv.h
Makefile +1 -0
@@ -1005,6 +1005,7 @@ LIB_OBJS += trace2/tr2_cfg.o LIB_OBJS += trace2/tr2_cmd_name.o LIB_OBJS += trace2/tr2_dst.o LIB_OBJS += trace2/tr2_sid.o +LIB_OBJS += trace2/tr2_sysenv.o LIB_OBJS += trace2/tr2_tbuf.o LIB_OBJS += trace2/tr2_tgt_event.o LIB_OBJS += trace2/tr2_tgt_normal.o
t/t0210-trace2-normal.sh +44 -5
65 lines not on this page · raw message
t/t0211-trace2-perf.sh +26 -5
@@ -3,6 +3,11 @@ test_description='test trace2 facility (perf target)' . ./test-lib.sh +# Turn off any inherited trace2 settings for this test. +sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT +sane_unset GIT_TR2_PERF_BRIEF +sane_unset GIT_TR2_CONFIG_PARAMS + # Add t/helper directory to PATH so that we can use a relative # path to run nested instances of test-tool.exe (see 004child). # This helps with HEREDOC comparisons later.
@@ -15,11 +20,6 @@ PATH="$TTDIR:$PATH" && export PATH # Warning: So you may see extra lines in artifact files when # Warning: interactively debugging. -# Turn off any inherited trace2 settings for this test. -unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT -unset GIT_TR2_PERF_BRIEF -unset GIT_TR2_CONFIG_PARAMS - V=$(git version | sed -e 's/^git version //') && export V # There are multiple trace2 targets: normal, perf, and event.
@@ -150,4 +150,25 @@ test_expect_success 'perf stream, child processes' ' test_cmp expect actual ' +sane_unset GIT_TR2_PERF_BRIEF + +# Now test without environment variables and get all Trace2 settings +# from the global config. + +test_expect_success 'using global config, perf stream, return code 0' ' + test_when_finished "rm trace.perf actual expect" && + test_config_global trace2.perfBrief 1 && + test_config_global trace2.perfTarget "$(pwd)/trace.perf" && + test-tool trace2 001return 0 && + perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <trace.perf >actual && + cat >expect <<-EOF && + d0|main|version|||||$V + d0|main|start||_T_ABS_|||_EXE_ trace2 001return 0 + d0|main|cmd_name|||||trace2 (trace2) + d0|main|exit||_T_ABS_|||code:0 + d0|main|atexit||_T_ABS_|||code:0 + EOF + test_cmp expect actual +' + test_done
t/t0212-trace2-event.sh +37 -5
58 lines not on this page · raw message
trace2.c +4 -0
@@ -10,6 +10,7 @@#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h"
@@ -120,6 +121,7 @@ static void tr2main_atexit_handler(void)tr2_sid_release ();tr2_cmd_name_release ();tr2_cfg_free_patterns (); +tr2_sysenv_release (); trace2_enabled =0 ; }
@@ -155,6 +157,8 @@ void trace2_initialize_fl(const char *file, int line)if (trace2_enabled)return ; +tr2_sysenv_load (); +if (!tr2_tgt_want_builtins ())return ; trace2_enabled =1 ;
trace2.h +7 -5
@@ -38,7 +38,8 @@ void trace2_initialize_clock(void);/* * Initialize TRACE2 tracing facility if any of the builtin TRACE2 -* targets are enabled in the environment. Emits a 'version' event. +* targets are enabled in the system config or the environment. +* Emits a 'version' event. * * Cleanup/Termination is handled automatically by a registered * atexit() routine.
@@ -125,10 +126,11 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,* Emit one or more 'def_param' events for "interesting" configuration * settings. * -* The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a -* list of patterns considered important. For example: -* -* GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url" +* Use the TR2_SYSENV_CFG_PARAM setting to register a comma-separated +* list of patterns configured important. For example: +* git config --system trace2.configParams 'core.*,remote.*.url' +* or: +* GIT_TR2_CONFIG_PARAMS=core.*,remote.*.url" * * Note: this routine does a read-only iteration on the config data * (using read_early_config()), so it must not be called until enough
trace2/tr2_cfg.c +3 -4
@@ -1,8 +1,7 @@#include "cache.h" #include "config.h" -#include "tr2_cfg.h" - -#define TR2_ENVVAR_CFG_PARAM "GIT_TR2_CONFIG_PARAMS" +#include "trace2/tr2_cfg.h" +#include "trace2/tr2_sysenv.h" static struct strbuf **tr2_cfg_patterns;static int tr2_cfg_count_patterns;
@@ -21,7 +20,7 @@ static int tr2_cfg_load_patterns(void)return tr2_cfg_count_patterns; tr2_cfg_loaded =1 ; - envvar =getenv (TR2_ENVVAR_CFG_PARAM ); + envvar =tr2_sysenv_get (TR2_SYSENV_CFG_PARAM );if (!envvar || !*envvar)return tr2_cfg_count_patterns;
trace2/tr2_dst.c +14 -12
@@ -1,5 +1,6 @@#include "cache.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" /* * If a Trace2 target cannot be opened for writing, we should issue a
@@ -7,17 +8,13 @@* or socket and beyond the user's control -- especially since every * git command (and sub-command) will print the message. So we silently * eat these warnings and just discard the trace data. -* -* Enable the following environment variable to see these warnings. */ -#define TR2_ENVVAR_DST_DEBUG "GIT_TR2_DST_DEBUG" -static int tr2_dst_want_warning (void ) {static int tr2env_dst_debug =-1 ;if (tr2env_dst_debug ==-1 ) { -const char *env_value =getenv (TR2_ENVVAR_DST_DEBUG ); +const char *env_value =tr2_sysenv_get (TR2_SYSENV_DST_DEBUG );if (!env_value || !*env_value) tr2env_dst_debug =0 ;else
@@ -42,7 +39,9 @@ static int tr2_dst_try_path(struct tr2_dst *dst, const char *tgt_value)if (fd ==-1 ) {if (tr2_dst_want_warning ())warning ("trace2: could not open '%s' for '%s' tracing: %s" , - tgt_value, dst->env_var_name,strerror (errno)); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var), +strerror (errno));tr2_dst_trace_disable (dst);return 0 ;
@@ -116,7 +115,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst,if (!path || !*path) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX value '%s' for '%s' tracing" , - tgt_value, dst->env_var_name); + tgt_value, +tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -126,7 +126,7 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, strlen(path) >= sizeof(((struct sockaddr_un *)0)->sun_path)) {if (tr2_dst_want_warning ())warning ("trace2: invalid AF_UNIX path '%s' for '%s' tracing" , - path, dst->env_var_name); + path,tr2_sysenv_display_name (dst->sysenv_var));tr2_dst_trace_disable (dst);return 0 ;
@@ -148,7 +148,8 @@ static int tr2_dst_try_unix_domain_socket(struct tr2_dst *dst, error:if (tr2_dst_want_warning ())warning ("trace2: could not connect to socket '%s' for '%s' tracing: %s" , - path, dst->env_var_name,strerror (e)); + path,tr2_sysenv_display_name (dst->sysenv_var), +strerror (e));tr2_dst_trace_disable (dst);return 0 ;
@@ -168,7 +169,7 @@ static void tr2_dst_malformed_warning(struct tr2_dst *dst,struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"trace2: unknown value for '%s': '%s'" , - dst->env_var_name, tgt_value); +tr2_sysenv_display_name (dst->sysenv_var), tgt_value);warning ("%s" , buf.buf);strbuf_release (&buf);
@@ -184,7 +185,7 @@ int tr2_dst_get_trace_fd(struct tr2_dst *dst) dst->initialized =1 ; - tgt_value =getenv (dst->env_var_name); + tgt_value =tr2_sysenv_get (dst->sysenv_var);if (!tgt_value || !strcmp (tgt_value,"" ) || !strcmp (tgt_value,"0" ) || !strcasecmp (tgt_value,"false" )) {
@@ -246,7 +247,8 @@ void tr2_dst_write_line(struct tr2_dst *dst, struct strbuf *buf_line)return ;if (tr2_dst_want_warning ()) -warning ("unable to write trace to '%s': %s" , dst->env_var_name, +warning ("unable to write trace to '%s': %s" , +tr2_sysenv_display_name (dst->sysenv_var),strerror (errno));tr2_dst_trace_disable (dst); }
trace2/tr2_dst.h +2 -1
@@ -2,9 +2,10 @@#define TR2_DST_H struct strbuf ; +#include "trace2/tr2_sysenv.h" struct tr2_dst { -const char *const env_var_name; +enum tr2_sysenv_variable sysenv_var;int fd;unsigned int initialized :1 ;unsigned int need_close :1 ;
trace2/tr2_sysenv.c new file +127 -0
127 lines not on this page · raw message
trace2/tr2_sysenv.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef TR2_SYSENV_H +#define TR2_SYSENV_H + +/* +* The Trace2 settings that can be loaded from /etc/gitconfig +* and/or user environment variables. +* +* Note that this set does not contain any of the transient +* environment variables used to pass information from parent +* to child git processes, such "GIT_TR2_PARENT_SID". +*/ +enum tr2_sysenv_variable { +TR2_SYSENV_CFG_PARAM =0 , + +TR2_SYSENV_DST_DEBUG , + +TR2_SYSENV_NORMAL , +TR2_SYSENV_NORMAL_BRIEF , + +TR2_SYSENV_EVENT , +TR2_SYSENV_EVENT_BRIEF , +TR2_SYSENV_EVENT_NESTING , + +TR2_SYSENV_PERF , +TR2_SYSENV_PERF_BRIEF , + +TR2_SYSENV_MUST_BE_LAST +}; + +void tr2_sysenv_load (void ); + +const char *tr2_sysenv_get (enum tr2_sysenv_variable ); +const char *tr2_sysenv_display_name (enum tr2_sysenv_variable var); +void tr2_sysenv_release (void ); + +#endif /* TR2_SYSENV_H */
trace2/tr2_tgt_event.c +23 -23
111 lines not on this page · raw message
trace2/tr2_tgt_normal.c +8 -8
@@ -4,20 +4,20 @@#include "quote.h" #include "version.h" #include "trace2/tr2_dst.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = {"GIT_TR2" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_normal = {TR2_SYSENV_NORMAL ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>" * fields from each line written to the builtin normal target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_NORMAL_BRIEF "GIT_TR2_BRIEF" -static int tr2env_normal_brief; +static int tr2env_normal_be_brief;#define TR2FMT_NORMAL_FL_WIDTH (50)
@@ -25,15 +25,15 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_normal);int want_brief; -char *brief; +const char *brief;if (!want)return want; - brief =getenv (TR2_ENVVAR_NORMAL_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_NORMAL_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_normal_brief = want_brief; + tr2env_normal_be_brief = want_brief;return want; }
@@ -47,7 +47,7 @@ static void normal_fmt_prepare(const char *file, int line, struct strbuf *buf) {strbuf_setlen (buf,0 ); -if (!tr2env_normal_brief) { +if (!tr2env_normal_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
trace2/tr2_tgt_perf.c +8 -8
@@ -6,20 +6,20 @@#include "json-writer.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" +#include "trace2/tr2_sysenv.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = {"GIT_TR2_PERF" ,0 ,0 ,0 }; +static struct tr2_dst tr2dst_perf = {TR2_SYSENV_PERF ,0 ,0 ,0 };/* -* Set this environment variable to true to omit the "<time> <file>:<line>" +* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" * fields from each line written to the builtin performance target. * * Unit tests may want to use this to help with testing. */ -#define TR2_ENVVAR_PERF_BRIEF "GIT_TR2_PERF_BRIEF" -static int tr2env_perf_brief; +static int tr2env_perf_be_brief;#define TR2FMT_PERF_FL_WIDTH (50)#define TR2FMT_PERF_MAX_EVENT_NAME (12)
@@ -36,17 +36,17 @@ static int fn_init(void) {int want =tr2_dst_trace_want (&tr2dst_perf);int want_brief; -char *brief; +const char *brief;if (!want)return want;strbuf_addchars (&dots,'.' ,TR2_DOTS_BUFFER_SIZE ); - brief =getenv (TR2_ENVVAR_PERF_BRIEF ); + brief =tr2_sysenv_get (TR2_SYSENV_PERF_BRIEF );if (brief && *brief && ((want_brief =git_parse_maybe_bool (brief)) !=-1 )) - tr2env_perf_brief = want_brief; + tr2env_perf_be_brief = want_brief;return want; }
@@ -77,7 +77,7 @@ static void perf_fmt_prepare(const char *event_name,strbuf_setlen (buf,0 ); -if (!tr2env_perf_brief) { +if (!tr2env_perf_be_brief) {struct tr2_tbuf tb_now;tr2_tbuf_local_time (&tb_now);
Signature · 1 line
gitgitgadget
PATCH v5 10/11 trace2: update docs to describe system/global config settings
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
--- Documentation/config.txt | 2 + Documentation/config/trace2.txt | 56 +++++++++ Documentation/technical/api-trace2.txt | 151 ++++++++++++++----------- Documentation/trace2-target-values.txt | 10 ++ 4 files changed, 152 insertions(+), 67 deletions(-) create mode 100644 Documentation/config/trace2.txt create mode 100644 Documentation/trace2-target-values.txt
Documentation/config.txt +2 -0
@@ -422,6 +422,8 @@ include::config/submodule.txt[] include::config/tag.txt[] +include::config/trace2.txt[] + include::config/transfer.txt[] include::config/uploadarchive.txt[]
Documentation/config/trace2.txt new file +56 -0
56 lines not on this page · raw message
Documentation/technical/api-trace2.txt +84 -67
259 lines not on this page · raw message
Documentation/trace2-target-values.txt new file +10 -0
@@ -0,0 +1,10 @@ +-- +* `0` or `false` - Disables the target. +* `1` or `true` - Writes to `STDERR`. +* `[2-9]` - Writes to the already opened file descriptor. +* `<absolute-pathname>` - Writes to the file in append mode. +* `af_unix:[<socket_type>:]<absolute-pathname>` - Write to a +Unix DomainSocket (on platforms that support them). Socket +type can be either `stream` or `dgram`; if omitted Git will +try both. +--
Signature · 1 line
gitgitgadget
PATCH v5 11/11 trace2: fixup access problem on /etc/gitconfig in read_very_early_config
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach do_git_config_sequence() to optionally gently check for access to the system config. Use this option in read_very_early_config() when initializing trace2.
In [1] SZEDER Gábor reported that my changes in [2] introduced a regression when the user does not have permission to read the system config.
This commit addresses that problem by optionally ignoring that error.
[1] https://public-inbox.org/git/285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com/T/#m342e839289aec515523a98b5e34d7f42d3f1fd79
[2] https://public-inbox.org/git/285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com/T/#m11b59c9228c698442f750ee8f9b10c629399ae48
--- config.c | 5 ++++- config.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
config.c +4 -1
@@ -1676,7 +1676,9 @@ static int do_git_config_sequence(const struct config_options *opts, repo_config =NULL ; current_parsing_scope =CONFIG_SCOPE_SYSTEM ; -if (git_config_system () && !access_or_die (git_etc_gitconfig (),R_OK ,0 )) +if (git_config_system () && !access_or_die (git_etc_gitconfig (),R_OK , + opts->system_gently ? +ACCESS_EACCES_OK :0 )) ret +=git_config_from_file (fn,git_etc_gitconfig (), data);
@@ -1807,6 +1809,7 @@ void read_very_early_config(config_fn_t cb, void *data) opts.ignore_repo =1 ; opts.ignore_worktree =1 ; opts.ignore_cmdline =1 ; + opts.system_gently =1 ;config_with_options (cb, data,NULL , &opts); }
config.h +1 -0
@@ -58,6 +58,7 @@ struct config_options { unsigned int ignore_repo : 1; unsigned int ignore_worktree : 1; unsigned int ignore_cmdline : 1; + unsigned int system_gently : 1;const char *commondir;const char *git_dir;config_parser_event_fn_t event_fn;
Signature · 1 line
gitgitgadget
PATCH v5 5/11 config: add read_very_early_config()
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Created an even lighter version of read_early_config() that only looks at system and global config settings. It omits repo-local, worktree-local, and command-line settings.
--- config.c | 23 ++++++++++++++++++++--- config.h | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-)
config.c +20 -3
@@ -1688,14 +1688,15 @@ static int do_git_config_sequence(const struct config_options *opts, ret +=git_config_from_file (fn, user_config, data); current_parsing_scope =CONFIG_SCOPE_REPO ; -if (repo_config && !access_or_die (repo_config,R_OK ,0 )) +if (!opts->ignore_repo && repo_config && + !access_or_die (repo_config,R_OK ,0 )) ret +=git_config_from_file (fn, repo_config, data);/* * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. * But let's not complicate things before it's actually needed. */ -if (repository_format_worktree_config) { +if (!opts->ignore_worktree && repository_format_worktree_config) {char *path =git_pathdup ("config.worktree" );if (!access_or_die (path,R_OK ,0 )) ret +=git_config_from_file (fn, path, data);
@@ -1703,7 +1704,7 @@ static int do_git_config_sequence(const struct config_options *opts, } current_parsing_scope =CONFIG_SCOPE_CMDLINE ; -if (git_config_from_parameters (fn, data) <0 ) +if (!opts->ignore_cmdline &&git_config_from_parameters (fn, data) <0 )die (_ ("unable to parse command-line config" )); current_parsing_scope =CONFIG_SCOPE_UNKNOWN ;
@@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data)strbuf_release (&gitdir); } +/* +* Read config but only enumerate system and global settings. +* Omit any repo-local, worktree-local, or command-line settings. +*/ +void read_very_early_config (config_fn_t cb,void *data) +{ +struct config_options opts = {0 }; + + opts.respect_includes =1 ; + opts.ignore_repo =1 ; + opts.ignore_worktree =1 ; + opts.ignore_cmdline =1 ; + +config_with_options (cb, data,NULL , &opts); +} +static struct config_set_element *configset_find_element (struct config_set *cs,const char *key) {struct config_set_element k;
config.h +4 -0
@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,struct config_options {unsigned int respect_includes :1 ; +unsigned int ignore_repo :1 ; +unsigned int ignore_worktree :1 ; +unsigned int ignore_cmdline :1 ;const char *commondir;const char *git_dir;config_parser_event_fn_t event_fn;
@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,extern void git_config_push_parameter (const char *text);extern int git_config_from_parameters (config_fn_t fn,void *data);extern void read_early_config (config_fn_t cb,void *data); +extern void read_very_early_config (config_fn_t cb,void *data);extern void git_config (config_fn_t fn,void *); extern int config_with_options(config_fn_t fn, void *, struct git_config_source *config_source,
Signature · 1 line
gitgitgadget
PATCH v5 4/11 trace2: find exec-dir before trace2 initialization
In reply to Jeff Hostetler via GitGitGadgetFrom: Jeff Hostetler <[email protected]>
Teach Git to resolve the executable directory before initializing Trace2. This allows the system configuration directory to be discovered earlier (because it is sometimes relative to the prefix or runtime-prefix).
This will be used by the next commit to allow trace2 settings to be loaded from the system config.
--- common-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common-main.c +2 -2
@@ -37,12 +37,12 @@ int main(int argc, const char **argv)sanitize_stdfds ();restore_sigpipe_to_default (); +git_resolve_executable_dir (argv[0 ]); +trace2_initialize ();trace2_cmd_start (argv);trace2_collect_process_info (); -git_resolve_executable_dir (argv[0 ]); -git_setup_gettext ();initialize_the_repository ();
Signature · 1 line
gitgitgadget
I forgot to update the cover letter for V5.
V5 adds a commit to fix the permission problem in /etc/gitconfig reported by SZEDER.
This commit could/should be squashed into commit 5 if wanted. I left it on top for review purposes.
Jeff
Quoted 72 lines · Jeff Hostetler via GitGitGadget
Version 4 fixes a few clang-format warnings and simplifies the PID field in the SID.
Jeff Hostetler (11):
config: initialize opts structure inrepo_read_config()
trace2: refactor setting process starting time
trace2: add absolute elapsed time to start event
trace2: find exec-dir before trace2 initialization
config: addread_very_early_config()
trace2: use system/global config for default trace2 settings
trace2: report peak memory usage of the process
trace2: clarify UTC datetime formatting
trace2: make SIDs more unique
trace2: update docs to describe system/global config settings
trace2: fixup access problem on/etc/gitconfigin
read_very_early_configDocumentation/config.txt | 2 + Documentation/config/trace2.txt | 56 ++++++++ Documentation/technical/api-trace2.txt | 176 +++++++++++++---------- Documentation/trace2-target-values.txt | 10 ++ Makefile | 1 + common-main.c | 8 +- compat/mingw.c | 2 + compat/win32/trace2_win32_process_info.c | 50 ++++++- config.c | 30 +++- config.h | 5 + t/t0210-trace2-normal.sh | 49 ++++++- t/t0211-trace2-perf.sh | 43 ++++-- t/t0212-trace2-event.sh | 42 +++++- trace2.c | 21 ++- trace2.h | 43 ++++-- trace2/tr2_cfg.c | 7 +- trace2/tr2_dst.c | 26 ++-- trace2/tr2_dst.h | 3 +- trace2/tr2_sid.c | 53 ++++++- trace2/tr2_sysenv.c | 127 ++++++++++++++++ trace2/tr2_sysenv.h | 36 +++++ trace2/tr2_tbuf.c | 19 ++- trace2/tr2_tbuf.h | 5 +- trace2/tr2_tgt.h | 1 + trace2/tr2_tgt_event.c | 53 +++---- trace2/tr2_tgt_normal.c | 19 +-- trace2/tr2_tgt_perf.c | 23 +-- trace2/tr2_tls.c | 38 +++-- trace2/tr2_tls.h | 8 +- 29 files changed, 752 insertions(+), 204 deletions(-)create mode 100644
Documentation/config/trace2.txtcreate mode 100644Documentation/trace2-target-values.txtcreate mode 100644trace2/tr2_sysenv.c
create mode 100644trace2/tr2_sysenv.hbase-commit:
041f5ea1cf987a4068ef5f39ba0a09be85952064
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-169%2Fjeffhostetler%2Fcore-tr2-startup-and-sysenv-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-169/jeffhostetler/core-tr2-startup-and-sysenv-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/169Range-diff vs v4:
1: f6653f1c59 = 1: f6653f1c59 config: initialize opts structure in repo_read_config() 2: 48e34834b6 = 2: 48e34834b6 trace2: refactor setting process starting time 3: 175371fb54 = 3: 175371fb54 trace2: add absolute elapsed time to start event 4: 94729b284c = 4: 94729b284c trace2: find exec-dir before trace2 initialization 5: b0fe1385f1 = 5: b0fe1385f1 config: add read_very_early_config() 6: 550cad6189 = 6: 550cad6189 trace2: use system/global config for default trace2 settings 7: 56d8ce3fd6 = 7: 56d8ce3fd6 trace2: report peak memory usage of the process 8: 196a9d2c85 = 8: 196a9d2c85 trace2: clarify UTC datetime formatting 9: 9fdcb50140 = 9: 9fdcb50140 trace2: make SIDs more unique 10: 3414016d04 = 10: 3414016d04 trace2: update docs to describe system/global config settings -: ---------- > 11: 18ce795360 trace2: fixup access problem on /etc/gitconfig in read_very_early_config
Quoted 6 lines · Jeff Hostetler
I forgot to update the cover letter for V5.
V5 adds a commit to fix the permission problem in/etc/gitconfigreported by SZEDER.This commit could/should be squashed into commit 5 if wanted. I left it on top for review purposes.
I think v4 has been in 'next' for several days already, so an incremental update like PATCH 11/11 is good. The first 10 patches are identical to the previous round, so all is good ;-)