Skip to contentSkip to conversation

trace2: completely compiling out trace2 subsystem

RFC PATCH New Junio C Hamano 1 participant 1 message May 15, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 trace2: completely compiling out trace2 subsystem

This patch is primarily for fun value to see how much overhead we are incurring when trace2 is compiled in but not activated with GIT_TRACE2_* environment variables. You can build with

	$ make NO_TRACE2=NoThanks

In the following "hyperfine" output, invocations of "git" are running "git" built from the tip of 'master', and invocations of "./git" are running one built with this patch.

Obviously the overhead is more prominent for trivial commands, like cat-file of a single object:

Benchmark 1: git cat-file commit HEAD

  Time (mean ± σ):       9.6 ms ±   0.3 ms    [User: 0.9 ms, System: 9.3 ms]
  Range (min … max):     9.1 ms …  11.5 ms    256 runs

Benchmark 1: ./git cat-file commit HEAD
Time (mean ± σ): 9.0 ms ± 0.2 ms [User: 0.8 ms, System: 9.0 ms]
Range (min … max): 8.6 ms … 9.9 ms 264 runs

or asking the name of a single rev:

Benchmark 1: git rev-parse HEAD
Time (mean ± σ): 6.4 ms ± 0.3 ms [User: 0.7 ms, System: 6.5 ms]
Range (min … max): 6.0 ms … 8.4 ms 367 runs

Benchmark 1: ./git rev-parse HEAD
Time (mean ± σ): 6.0 ms ± 0.2 ms [User: 0.6 ms, System: 6.4 ms]
Range (min … max): 5.6 ms … 7.8 ms 381 runs

And the main operation of anything more involved, like showing the topmost few commits, would dwarf the overhead out, but the difference is still visible (about 0.6 ms, which is consistent with the above two comparisons):

Benchmark 1: git log -5

  Time (mean ± σ):      16.9 ms ±   0.4 ms    [User: 1.6 ms, System: 15.8 ms]
  Range (min … max):    16.2 ms …  18.6 ms    159 runs

Benchmark 1: ./git log -5

  Time (mean ± σ):      16.3 ms ±   0.4 ms    [User: 1.4 ms, System: 15.5 ms]
  Range (min … max):    15.8 ms …  17.6 ms    165 runs

Because quite a lot of parts of our test suite, besides the obvious ones like t0210 that are about testing trace2 output, depend on reading and parsing output from trace2, this patch will break quite a many of them. If people feel that an option to completely compile out the trace2 subsystem is worth adding, these test breakages would need to be fixed before this main change can be merged.

This patch invents a prerequisite "TRACE2" to help these tests that rely on the availability of trace2 subsystem and marks just one such tests that depends on it as an example.

Also, I have no confidence in stubbing out the compat/stub and compat/win32 versions of procinfo stuff done by this patch. Again, if people are interested in this option, those with access to Win32 and !HAVE_PLATFORM_PROCINFO platforms need to tip into the effort.

---
 Makefile                                 |  10 +
 compat/linux/procinfo.c                  |   2 +
 compat/stub/procinfo.c                   |   2 +
 compat/win32/trace2_win32_process_info.c |   2 +
 t/t0017-env-helper.sh                    |   2 +-
 t/test-lib.sh                            |   1 +
 trace2.c                                 |   4 +
 trace2.h                                 | 311 ++++++++++++++++++++---
 8 files changed, 294 insertions(+), 40 deletions(-)
Makefile +10 -0
index cf504963c2..71f78a5854 100644
@@ -553,6 +553,11 @@ include shared.mak
 # If don't enable any of the *_SHA256 settings in this section, Git
 # will default to its built-in sha256 implementation.
 #
+# == Privacy? ==
+#
+# Define NO_TRACE2 to completely compile out the trace2 subsystem
+# to avoid leaking trace log to anywhere.
+#
 # == DEVELOPER defines ==
 #
 # Define DEVELOPER to enable more compiler warnings. Compiler version
@@ -1539,6 +1544,10 @@ ifneq (,$(INLINE))
 	BASIC_CFLAGS += -Dinline=$(INLINE)
 endif
 
+ifneq (,$(NO_TRACE2))
+	BASIC_CFLAGS += -DNO_TRACE2
+endif
+
 ifneq (,$(SOCKLEN_T))
 	BASIC_CFLAGS += -Dsocklen_t=$(SOCKLEN_T)
 endif
@@ -3134,6 +3143,7 @@ GIT-BUILD-OPTIONS: FORCE
 	@echo NO_PTHREADS=\''$(subst ','\'',$(subst ','\'',$(NO_PTHREADS)))'\' >>$@+
 	@echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+
 	@echo NO_REGEX=\''$(subst ','\'',$(subst ','\'',$(NO_REGEX)))'\' >>$@+
+	@echo NO_TRACE2=\''$(subst ','\'',$(subst ','\'',$(NO_TRACE2)))'\' >>$@+
 	@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
 	@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
 	@echo SANITIZE_LEAK=\''$(subst ','\'',$(subst ','\'',$(SANITIZE_LEAK)))'\' >>$@+
compat/linux/procinfo.c +2 -0
index 4bb2d66227..c30080fc59 100644
@@ -42,6 +42,7 @@
  */
 #define STAT_PARENT_PID_READ_N 64
 
+#ifndef NO_TRACE2
 static int parse_proc_stat(struct strbuf *sb, struct strbuf *name,
 			    int *statppid)
 {
@@ -174,3 +175,4 @@ void trace2_collect_process_info(enum trace2_process_info_reason reason)
 
 	return;
 }
+#endif
compat/stub/procinfo.c +2 -0
index 12c0a23c9e..933f20c628 100644
@@ -2,6 +2,7 @@
 
 #include "trace2.h"
 
+#ifndef NO_TRACE2
 /*
  * Stub. See sample implementations in compat/linux/procinfo.c and
  * compat/win32/trace2_win32_process_info.c.
@@ -9,3 +10,4 @@
 void trace2_collect_process_info(enum trace2_process_info_reason reason)
 {
 }
+#endif
compat/win32/trace2_win32_process_info.c +2 -0
index 3ef0936f6f..d73cb71b08 100644
@@ -6,6 +6,7 @@
 #include <psapi.h>
 #include <tlhelp32.h>
 
+#ifndef NO_TRACE2
 /*
  * An arbitrarily chosen value to limit the size of the ancestor
  * array built in git_processes().
@@ -191,3 +192,4 @@ void trace2_collect_process_info(enum trace2_process_info_reason reason)
 		BUG("trace2_collect_process_info: unknown reason '%d'", reason);
 	}
 }
+#endif
t/t0017-env-helper.sh +1 -1
index fc14ba091c..13780b376e 100755
@@ -81,7 +81,7 @@ test_expect_success 'test-tool env-helper --type=ulong' '
 	test_must_be_empty actual.err
 '
 
-test_expect_success 'test-tool env-helper reads config thanks to trace2' '
+test_expect_success TRACE2 'test-tool env-helper reads config thanks to trace2' '
 	mkdir home &&
 	git config -f home/.gitconfig include.path cycle &&
 	git config -f home/cycle include.path .gitconfig &&
t/test-lib.sh +1 -0
index 79d3e0e7d9..ab314049e0 100644
@@ -1773,6 +1773,7 @@ test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
 test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK
 test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND
+test -z "$NO_TRACE2" && test_set_prereq TRACE2
 
 if test -z "$GIT_TEST_CHECK_CACHE_TREE"
 then
trace2.c +4 -0
index f894532d05..08537cea01 100644
@@ -16,6 +16,8 @@
 #include "trace2/tr2_tls.h"
 #include "trace2/tr2_tmr.h"
 
+#ifndef NO_TRACE2
+
 static int trace2_enabled;
 static int trace2_redact = 1;
 
@@ -1040,3 +1042,5 @@ const char *trace2_session_id(void)
 {
 	return tr2_sid_get();
 }
+
+#endif
trace2.h +272 -39

534 lines not on this page · raw message

Signature · 1 line
2.45.1-190-g19fe900cfc