git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 5/6] test-lib: add run_and_check_trace2

From
Derrick Stolee <stolee@gmail.com>
Date
Sep 6, 2018, 15:13 UTC
Message-ID
<20180906151309.66712-6-dstolee@microsoft.com>
In-Reply-To
<20180906151309.66712-1-dstolee@microsoft.com>

The trace2 facility allows tracing category-key-value triples that we can use to communicate runtime information to a side channel. One use is to track the number of commits that are walked by a graph algorithm.

Add run_and_check_trace2 test function to run a given command with GIT_TR2_PERFORMANCE running. Then, check the output for the expected category-key-value triple.

Use this function in t6600-test-reach.sh to verify can_all_from_reach only visits 11 commits in the example.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 t/t6600-test-reach.sh |  6 ++++++
 t/test-lib.sh         | 14 ++++++++++++++
 2 files changed, 20 insertions(+)
diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
index d139a00d1d..98ad25bb45 100755
--- a/t/t6600-test-reach.sh
+++ b/t/t6600-test-reach.sh
@@ -183,6 +183,12 @@ test_expect_success 'can_all_from_reach:hit' '
 	test_three_modes can_all_from_reach
 '
 
+test_expect_success 'can_all_from_reach:perf' '
+	cp commit-graph-full .git/objects/info/commit-graph &&
+	run_and_check_trace2 can_all_from_reach_with_flag num_walked 40 input \
+		"test-tool reach can_all_from_reach"
+'
+
 test_expect_success 'can_all_from_reach:miss' '
 	cat >input <<-\EOF &&
 	X:commit-2-10
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 8bb0f4348e..9b9f68f324 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1231,3 +1231,17 @@ test_lazy_prereq CURL '
 test_lazy_prereq SHA1 '
 	test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
 '
+
+# Useage: run_and_check_trace2 <category> <key> <value> <file> <command>
+# Run "command <file" with GIT_TR2_PERFORMANCE logging to a file and
+# check that file for a data output matching category.key = value.
+run_and_check_trace2 () {
+	CATEGORY=$1
+	KEY=$2
+	VALUE=$3
+	INPUT=$4
+	COMMAND=$5
+	# GIT_TR2_PERFORMANCE="$(pwd)/perf-log.txt"
+	GIT_TR2_PERFORMANCE="$(pwd)/perf-log.txt" $COMMAND <$INPUT &&
+	cat perf-log.txt | grep "category:$CATEGORY key:$KEY value:$VALUE"
+}
-- 
2.19.0.rc2
Previous: Derrick StoleeNext: Derrick Stolee
Message 21 of 26 in “WIP: trace2: a new trace facility”
  1. 0/8 WIP: trace2: a new trace facilityJeff Hostetler via GitGitGadget, Aug 31, 2018
  2. 2/8 trace2: add trace2 to mainJeff Hostetler via GitGitGadget, Aug 31, 2018
  3. 1/8 trace2: create new combined trace facilityJeff Hostetler via GitGitGadget, Aug 31, 2018
  4. Derrick StoleeAug 31, 2018
  5. Stefan BellerSep 4, 2018
  6. Junio C HamanoSep 4, 2018
  7. Jeff HostetlerSep 5, 2018
  8. Jeff HostetlerSep 5, 2018
  9. 4/8 trace2: demonstrate trace2 child process classificationJeff Hostetler via GitGitGadget, Aug 31, 2018
  10. 5/8 trace2: demonstrate instrumenting do_read_indexJeff Hostetler via GitGitGadget, Aug 31, 2018
  11. 3/8 trace2: demonstrate trace2 regions in wt-statusJeff Hostetler via GitGitGadget, Aug 31, 2018
  12. 7/8 trace2: demonstrate setting sub-command parameter in checkoutJeff Hostetler via GitGitGadget, Aug 31, 2018
  13. 8/8 trace2: demonstrate use of regions in read_directory_recursiveJeff Hostetler via GitGitGadget, Aug 31, 2018
  14. 6/8 trace2: demonstrate instrumenting threaded preload_indexJeff Hostetler via GitGitGadget, Aug 31, 2018
  15. Derrick StoleeAug 31, 2018
  16. 0/6 Use trace2 in commit-reachDerrick Stolee, Sep 6, 2018
  17. 1/6 commit-reach: add trace2 telemetry and walk countDerrick Stolee, Sep 6, 2018
  18. 3/6 commit-reach: use trace2 in can_all_from_reachDerrick Stolee, Sep 6, 2018
  19. 2/6 comit-reach: use trace2 for commit_contains_tag_algoDerrick Stolee, Sep 6, 2018
  20. 4/6 test-tool: start trace2 environmentDerrick Stolee, Sep 6, 2018
  21. 5/6 test-lib: add run_and_check_trace2Derrick Stolee, Sep 6, 2018
  22. 6/6 commit-reach: fix first-parent heuristicDerrick Stolee, Sep 6, 2018
  23. Jonathan NiederOct 11, 2018
  24. Derrick StoleeOct 11, 2018
  25. Jonathan NiederJan 15, 2019
  26. Jeff HostetlerJan 15, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.