From: Jeff Hostetler Date: Wed, 05 Sep 2018 15:01:37 GMT Subject: Re: [PATCH 1/8] trace2: create new combined trace facility Message-ID: In-Reply-To: On 9/4/2018 6:12 PM, Stefan Beller wrote: >> Create GIT_TR2 trace-key to replace GIT_TRACE, GIT_TR2_PERFORMANCE to >> replace GIT_TRACE_PERFORMANCE, and a new trace-key GIT_TR2_EVENT to >> generate JSON data for telemetry purposes. Other structured formats >> can easily be added later using this new existing model. > > So the idea is to use the GIT_TR2 instead of GIT_TRACE and we > get the same output as well as a new form of structured logging here? > (Then GIT_TRACE could be retired, and we'd use the new API to add > more events, which are also more structured as the API allows for more > than just a string printed?) > >> Define a higher-level event API that selectively writes to all of the >> new GIT_TR2_* targets (depending on event type) without needing to call >> different trace_printf*() or trace_performance_*() routines. >> >> The API defines both fixed-field and printf-style functions. >> >> The trace2 performance tracing includes thread-specific function >> nesting and timings. > > So this only adds the new API, and we need to merge the TRACE > into the TRACE2 later? > >> +++ b/trace2.c >> @@ -0,0 +1,1592 @@ > [...] >> + >> +/***************************************************************** >> + * TODO remove this section header >> + *****************************************************************/ > > Yes, please. > >> +/* >> + * Compute a "unique" session id (SID) for the current process. All events >> + * from this process will have this label. If we were started by another >> + * git instance, use our parent's SID as a prefix and count the number of >> + * nested git processes. (This lets us track parent/child relationships >> + * even if there is an intermediate shell process.) > > How does this work with threading. From this description we can have > two threads starting new child processes and they have the same ID > (-2) Threads are not involved here. A git process computes its own unique session id. It is constructed from { [], , }. So in the following example, fetch spawned rev-list and gc. (I've stripped out fields irrelevant to this discussion.) "sid":"1536153920286494-12592", "argv":["C:\\work\\gfw\\git.exe","--exec-path=.","fetch","gh"] "sid":"1536153920286494-12592/1536153925520530-23024", "argv":["git","rev-list","--objects","--stdin", ...] "sid":"1536153920286494-12592/1536153926081533-23992", "argv":["git","gc","--auto"] So 2 child processes simultaneously spawned from 2 threads in the top-level git command, would still have unique SIDs since their PIDs are unique over the time interval of their execution. In the above example, if rev-list spawned a child git process, that child's SID would have 3 components (the prefix that it inherited plus its own time and pid): 1536153920286494-12592/1536153925520530-23024/