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

Re: [PATCH 3/4] trace2: refactor Windows process ancestry trace2 event

From
Derrick Stolee <stolee@gmail.com>
Date
Feb 9, 2026, 14:41 UTC
Message-ID
<1a282a1c-866e-49fc-b396-014921135cc4@gmail.com>
In-Reply-To
<7ccd0a9a6d89decaa5856494a184c71bc0d678e9.1770307510.git.gitgitgadget@gmail.com>
On 2/5/2026 11:05 AM, Matthew John Cheetham via GitGitGadget wrote:
> diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
...
>  #include "../../json-writer.h"
Are we able to delete this after your change?
Show 21 quoted lines
>  	pid = GetCurrentProcessId();
>  	while (find_pid(pid, hSnapshot, &pe32)) {
> -		/* Only report parents. Omit self from the JSON output. */
> +		/* Only report parents. Omit self from the output. */
>  		if (nr_pids)
> -			jw_array_string(jw, pe32.szExeFile);
> +			strvec_push(names, pe32.szExeFile);
>  
>  		/* Check for cycle in snapshot. (Yes, it happened.) */
>  		for (k = 0; k < nr_pids; k++)
>  			if (pid == pid_list[k]) {
> -				jw_array_string(jw, "(cycle)");
> +				strvec_push(names, "(cycle)");
>  				return;
>  			}
>  
>  		if (nr_pids == NR_PIDS_LIMIT) {
> -			jw_array_string(jw, "(truncated)");
> +			strvec_push(names, "(truncated)");
>  			return;
>  		}
Nice replacement of JSON with strvec logic.
Show 26 quoted lines
> @@ -105,24 +101,14 @@ static void get_processes(struct json_writer *jw, HANDLE hSnapshot)
>  }
>  
>  /*
> - * Emit JSON data for the current and parent processes.  Individual
> - * trace2 targets can decide how to actually print it.
> + * Collect the list of parent process names.
>   */
> -static void get_ancestry(void)
> +static void get_ancestry(struct strvec *names)
>  {
>  	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
>  
>  	if (hSnapshot != INVALID_HANDLE_VALUE) {
> -		struct json_writer jw = JSON_WRITER_INIT;
> -
> -		jw_array_begin(&jw, 0);
> -		get_processes(&jw, hSnapshot);
> -		jw_end(&jw);
> -
> -		trace2_data_json("process", the_repository, "windows/ancestry",
> -				 &jw);
> -
> -		jw_release(&jw);
> +		get_processes(names, hSnapshot);
>  		CloseHandle(hSnapshot);
Nice simplification!
Show 21 quoted lines
>  void trace2_collect_process_info(enum trace2_process_info_reason reason)
>  {
> +	struct strvec names = STRVEC_INIT;
> +
>  	if (!trace2_is_enabled())
>  		return;
>  
>  	switch (reason) {
>  	case TRACE2_PROCESS_INFO_STARTUP:
>  		get_is_being_debugged();
> -		get_ancestry();
> +		get_ancestry(&names);
> +		if (names.nr) {
> +			struct json_writer jw = JSON_WRITER_INIT;
> +			jw_array_begin(&jw, 0);
> +			for (size_t i = 0; i < names.nr; i++)
> +				jw_array_string(&jw, names.v[i]);
> +			jw_end(&jw);
> +			trace2_data_json("process", the_repository,
> +					 "windows/ancestry", &jw);
> +			jw_release(&jw);
Ah, you still have JSON logic at this point.

I see that in your next patch you export the names vector itself _and_ this older JSON version. We should consider a future where we drop this JSON altogether, but it's nice to have both for a few versions so tool makers have time to respond.

Thanks, -Stolee

Previous: Matthew John Cheetham via GitGitGadgetNext: Matthew John Cheetham via GitGitGadget
Message 9 of 25 in “trace2: add macOS and Windows process ancestry tracing”
  1. 0/4 trace2: add macOS and Windows process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  2. 2/4 build: include procinfo.c impl for macOSMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  3. Derrick StoleeFeb 9, 2026
  4. 1/4 trace2: add macOS process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  5. Derrick StoleeFeb 9, 2026
  6. Matthew John CheethamFeb 9, 2026
  7. Derrick StoleeFeb 10, 2026
  8. 3/4 trace2: refactor Windows process ancestry trace2 eventMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  9. Derrick StoleeFeb 9, 2026
  10. 4/4 trace2: emit cmd_ancestry data for WindowsMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  11. Kristoffer HaugsbakkFeb 5, 2026
  12. Derrick StoleeFeb 9, 2026
  13. Derrick StoleeFeb 9, 2026
  14. Junio C HamanoFeb 9, 2026
  15. 0/6 trace2: add macOS and Windows process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  16. 1/6 trace2: add macOS process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  17. 2/6 build: include procinfo.c impl for macOSMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  18. Junio C HamanoFeb 13, 2026
  19. 3/6 trace2: refactor Windows process ancestry trace2 eventMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  20. Junio C HamanoFeb 13, 2026
  21. 4/6 trace2: emit cmd_ancestry data for WindowsMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  22. Junio C HamanoFeb 13, 2026
  23. 5/6 test-tool: extend trace2 helper with 400ancestryMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  24. 6/6 t0213: add trace2 cmd_ancestry testsMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  25. Derrick StoleeFeb 14, 2026

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.