Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/technical/api-trace2.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / technical / api-trace2.adoc` 1352 lines ยท 44494 bytes Raw Blame History 1 = Trace2 API 2 3 The Trace2 API can be used to print debug, performance, and telemetry 4 information to stderr or a file. The Trace2 feature is inactive unless 5 explicitly enabled by enabling one or more Trace2 Targets. 6 7 The Trace2 API is intended to replace the existing (Trace1) 8 `printf()`-style tracing provided by the existing `GIT_TRACE` and 9 `GIT_TRACE_PERFORMANCE` facilities. During initial implementation, 10 Trace2 and Trace1 may operate in parallel. 11 12 The Trace2 API defines a set of high-level messages with known fields, 13 such as (`start`: `argv`) and (`exit`: {`exit-code`, `elapsed-time`}). 14 15 Trace2 instrumentation throughout the Git code base sends Trace2 16 messages to the enabled Trace2 Targets. Targets transform these 17 messages content into purpose-specific formats and write events to 18 their data streams. In this manner, the Trace2 API can drive 19 many different types of analysis. 20 21 Targets are defined using a VTable allowing easy extension to other 22 formats in the future. This might be used to define a binary format, 23 for example. 24 25 Trace2 is controlled using `trace2.*` config values in the system and 26 global config files and `GIT_TRACE2*` environment variables. Trace2 does 27 not read from repo local or worktree config files, nor does it respect 28 `-c` command line config settings. 29 30 == Trace2 Targets 31 32 Trace2 defines the following set of Trace2 Targets. 33 Format details are given in a later section. 34 35 === The Normal Format Target 36 37 The normal format target is a traditional `printf()` format and similar 38 to the `GIT_TRACE` format. This format is enabled with the `GIT_TRACE2` 39 environment variable or the `trace2.normalTarget` system or global 40 config setting. 41 42 For example 43 44 ------------ 45 $ export GIT_TRACE2=~/log.normal 46 $ git version 47 git version 2.20.1.155.g426c96fcdb 48 ------------ 49 50 or 51 52 ------------ 53 $ git config --global trace2.normalTarget ~/log.normal 54 $ git version 55 git version 2.20.1.155.g426c96fcdb 56 ------------ 57 58 yields 59 60 ------------ 61 $ cat ~/log.normal 62 12:28:42.620009 common-main.c:38 version 2.20.1.155.g426c96fcdb 63 12:28:42.620989 common-main.c:39 start git version 64 12:28:42.621101 git.c:432 cmd_name version (version) 65 12:28:42.621215 git.c:662 exit elapsed:0.001227 code:0 66 12:28:42.621250 trace2/tr2_tgt_normal.c:124 atexit elapsed:0.001265 code:0 67 ------------ 68 69 === The Performance Format Target 70 71 The performance format target (PERF) is a column-based format to 72 replace `GIT_TRACE_PERFORMANCE` and is suitable for development and 73 testing, possibly to complement tools like `gprof`. This format is 74 enabled with the `GIT_TRACE2_PERF` environment variable or the 75 `trace2.perfTarget` system or global config setting. 76 77 For example 78 79 ------------ 80 $ export GIT_TRACE2_PERF=~/log.perf 81 $ git version 82 git version 2.20.1.155.g426c96fcdb 83 ------------ 84 85 or 86 87 ------------ 88 $ git config --global trace2.perfTarget ~/log.perf 89 $ git version 90 git version 2.20.1.155.g426c96fcdb 91 ------------ 92 93 yields 94 95 ------------ 96 $ cat ~/log.perf 97 12:28:42.620675 common-main.c:38 | d0 | main | version | | | | | 2.20.1.155.g426c96fcdb 98 12:28:42.621001 common-main.c:39 | d0 | main | start | | 0.001173 | | | git version 99 12:28:42.621111 git.c:432 | d0 | main | cmd_name | | | | | version (version) 100 12:28:42.621225 git.c:662 | d0 | main | exit | | 0.001227 | | | code:0 101 12:28:42.621259 trace2/tr2_tgt_perf.c:211 | d0 | main | atexit | | 0.001265 | | | code:0 102 ------------ 103 104 === The Event Format Target 105 106 The event format target is a JSON-based format of event data suitable 107 for telemetry analysis. This format is enabled with the `GIT_TRACE2_EVENT` 108 environment variable or the `trace2.eventTarget` system or global config 109 setting. 110 111 For example 112 113 ------------ 114 $ export GIT_TRACE2_EVENT=~/log.event 115 $ git version 116 git version 2.20.1.155.g426c96fcdb 117 ------------ 118 119 or 120 121 ------------ 122 $ git config --global trace2.eventTarget ~/log.event 123 $ git version 124 git version 2.20.1.155.g426c96fcdb 125 ------------ 126 127 yields 128 129 ------------ 130 $ cat ~/log.event 131 {"event":"version","sid":"20190408T191610.507018Z-H9b68c35f-P000059a8","thread":"main","time":"2019-01-16T17:28:42.620713Z","file":"common-main.c","line":38,"evt":"4","exe":"2.20.1.155.g426c96fcdb"} 132 {"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"]} 133 {"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"} 134 {"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} 135 {"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} 136 ------------ 137 138 === Enabling a Target 139 140 To enable a target, set the corresponding environment variable or 141 system or global config value to one of the following: 142 143 include::../trace2-target-values.adoc[] 144 145 When trace files are written to a target directory, they will be named according 146 to the last component of the SID (optionally followed by a counter to avoid 147 filename collisions). 148 149 == Trace2 API 150 151 The Trace2 public API is defined and documented in `trace2.h`; refer to it for 152 more information. All public functions and macros are prefixed 153 with `trace2_` and are implemented in `trace2.c`. 154 155 There are no public Trace2 data structures. 156 157 The Trace2 code also defines a set of private functions and data types 158 in the `trace2/` directory. These symbols are prefixed with `tr2_` 159 and should only be used by functions in `trace2.c` (or other private 160 source files in `trace2/`). 161 162 === Conventions for Public Functions and Macros 163 164 Some functions have a `_fl()` suffix to indicate that they take `file` 165 and `line-number` arguments. 166 167 Some functions have a `_va_fl()` suffix to indicate that they also 168 take a `va_list` argument. 169 170 Some functions have a `_printf_fl()` suffix to indicate that they also 171 take a `printf()` style format with a variable number of arguments. 172 173 CPP wrapper macros are defined to hide most of these details. 174 175 == Trace2 Target Formats 176 177 === NORMAL Format 178 179 Events are written as lines of the form: 180 181 ------------ 182 [