Skip to content

Commit 3369871

Browse files
committed
trace2: documentation
Document how users can set up and utilize the Trace2 API.
1 parent 3b47ed4 commit 3369871

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

docs/development.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ Git to be the one launching us.
9898

9999
### Collect trace output
100100

101+
GCM has two tracing systems - one that is distinctly GCM's and one that
102+
implements certain features of [Git's Trace2 API][trace2]. Below are
103+
instructions for how to use each.
104+
105+
#### `GCM_TRACE`
106+
101107
If you want to debug a release build or installation of GCM, you can set the
102108
`GCM_TRACE` environment variable to `1` to print trace information to standard
103109
error, or to an absolute file path to write trace information to a file.
@@ -110,6 +116,80 @@ $ GCM_TRACE=1 git-credential-manager version
110116
> Git Credential Manager version 2.0.124-beta+e1ebbe1517 (macOS, .NET 5.0)
111117
```
112118

119+
#### Git's Trace2 API
120+
121+
This API can also be used to print debug, performance, and telemetry information
122+
to stderr or a file in various formats.
123+
124+
##### Supported format targets
125+
126+
1. The Normal Format Target: Similar to `GCM_TRACE`, this target writes
127+
human-readable output and is best suited for debugging. It can be enabled via
128+
environment variable or config, for example:
129+
130+
```shell
131+
export GIT_TRACE2=1
132+
```
133+
134+
or
135+
136+
```shell
137+
git config --global trace2.normalTarget ~/log.normal
138+
```
139+
140+
0. The Performance Format Target: This format is column-based and geared toward
141+
analyzing performance during development and testing. It can be enabled via
142+
environment variable or config, for example:
143+
144+
```shell
145+
export GIT_TRACE2_PERF=1
146+
```
147+
148+
or
149+
150+
```shell
151+
git config --global trace2.perfTarget ~/log.perf
152+
```
153+
154+
0. The Event Format Target: This format is json-based and is geared toward
155+
collection of large quantities of data for advanced analysis. It can be enabled
156+
via environment variable or config, for example:
157+
158+
```shell
159+
export GIT_TRACE2_EVENT=1
160+
```
161+
162+
or
163+
164+
```shell
165+
git config --global trace2.eventTarget ~/log.event
166+
```
167+
168+
You can read more about each of these format targets in the [corresponding
169+
section][trace2-targets] of Git's Trace2 API documentation.
170+
171+
##### Supported events
172+
173+
The below describes, at a high level, the Trace2 API events that are currently
174+
supported in GCM and the information they provide:
175+
176+
1. `version`: contains the version of the current executable (e.g. GCM or a
177+
helper exe)
178+
0. `start`: contains the complete argv received by current executable's `Main()`
179+
method
180+
0. `exit`: contains current executable's exit code
181+
0. `child_start`: describes a child process that is about to be spawned
182+
0. `child_exit`: describes a child process at exit
183+
0. `region_enter`: describes a region (e.g. a timer for a section of code that
184+
is interesting) on entry
185+
0. `region_leave`: describes a region on leaving
186+
187+
You can read more about each of these format targets in the [corresponding
188+
section][trace2-events] of Git's Trace2 API documentation.
189+
190+
Want to see more events? Consider contributing! We'd :love: to see your
191+
awesome work in support of building out this API.
192+
113193
### Code coverage metrics
114194

115195
If you want code coverage metrics these can be generated either from the command
@@ -169,4 +249,7 @@ Some URLs are ignored by lychee, per the [lycheeignore][lycheeignore].
169249
[lycheeignore]: ../.lycheeignore
170250
[markdownlint]: https://github.com/DavidAnson/markdownlint-cli2
171251
[markdownlint-config]: ../.markdownlint.jsonc
252+
[trace2]: https://git-scm.com/docs/api-trace2
253+
[trace2-events]: https://git-scm.com/docs/api-trace2#_event_specific_keyvalue_pairs
254+
[trace2-targets]: https://git-scm.com/docs/api-trace2#_trace2_targets
172255
[vscode-markdownlint]: https://github.com/DavidAnson/vscode-markdownlint

0 commit comments

Comments
 (0)