All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] tr2: shows the scope unconditionally with config
@ 2022-07-21 13:27 tenglong.tl
  2022-07-21 13:27 ` [PATCH 1/2] api-trace2.txt: print config key-value pair tenglong.tl
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-21 13:27 UTC (permalink / raw)
  To: git; +Cc: gitster, --cc=avarab, git, tenglong.tl, Teng Long

From: Teng Long <dyroneteng@gmail.com>

This series is separated from :

  https://public-inbox.org/git/a01ae8478d3a8545241c5b064b6d369a330ee59f.1658159746.git.dyroneteng@gmail.com/

and now move to a independent topic now.

Thanks.


Teng Long (2):
  api-trace2.txt: print config key-value pair
  tr2: shows scope unconditionally in addition to key-value pair

 Documentation/technical/api-trace2.txt | 41 ++++++++++++++++++++++++++
 trace2/tr2_tgt_event.c                 |  3 ++
 trace2/tr2_tgt_normal.c                |  5 +++-
 trace2/tr2_tgt_perf.c                  |  9 ++++--
 4 files changed, 55 insertions(+), 3 deletions(-)

-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 1/2] api-trace2.txt: print config key-value pair
  2022-07-21 13:27 [PATCH 0/2] tr2: shows the scope unconditionally with config tenglong.tl
@ 2022-07-21 13:27 ` tenglong.tl
  2022-07-21 13:27 ` [PATCH 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
  2022-07-22  8:19 ` [PATCH v1 0/2] tr2: shows the scope unconditionally with config tenglong.tl
  2 siblings, 0 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-21 13:27 UTC (permalink / raw)
  To: git; +Cc: gitster, --cc=avarab, git, tenglong.tl, Teng Long

From: Teng Long <dyroneteng@gmail.com>

It's supported to print "interesting" config key-value paire
to tr2 log by setting "GIT_TRACE2_CONFIG_PARAMS" environment
variable and the "trace2.configparam" config, let's add the
related docs in Documentaion/technical/api-trace2.txt.

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 Documentation/technical/api-trace2.txt | 31 ++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index 77a150b30e..dcd0429037 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -1207,6 +1207,37 @@ at offset 508.
 This example also shows that thread names are assigned in a racy manner
 as each thread starts and allocates TLS storage.
 
+Print Configs::
+
+	  Dump "interesting" config values to trace2 log.
++
+The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
+`trace2.configparams` can be used to output config values which you care
+about(see linkgit:git-config[1). For example:
++
+----------------
+$ git config color.ui auto
+----------------
++
+Then, mark the config `color.ui` as "interesting" config with
+`GIT_TRACE2_CONFIG_PARAMS`:
++
+----------------
+$ export GIT_TRACE2_PERF_BRIEF=1
+$ export GIT_TRACE2_PERF=~/log.perf
+$ export GIT_TRACE2_CONFIG_PARAMS=color.ui
+$ git version
+...
+$ cat ~/log.perf
+d0 | main                     | version      |     |           |           |              | ...
+d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
+d0 | main                     | cmd_name     |     |           |           |              | version (version)
+d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
+d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
+d0 | main                     | exit         |     |  0.002142 |           |              | code:0
+d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+----------------
 == Future Work
 
 === Relationship to the Existing Trace Api (api-trace.txt)
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2/2] tr2: shows scope unconditionally in addition to key-value pair
  2022-07-21 13:27 [PATCH 0/2] tr2: shows the scope unconditionally with config tenglong.tl
  2022-07-21 13:27 ` [PATCH 1/2] api-trace2.txt: print config key-value pair tenglong.tl
@ 2022-07-21 13:27 ` tenglong.tl
  2022-07-21 16:57   ` Junio C Hamano
  2022-07-22  8:19 ` [PATCH v1 0/2] tr2: shows the scope unconditionally with config tenglong.tl
  2 siblings, 1 reply; 22+ messages in thread
From: tenglong.tl @ 2022-07-21 13:27 UTC (permalink / raw)
  To: git; +Cc: gitster, --cc=avarab, git, tenglong.tl, Teng Long

From: Teng Long <dyroneteng@gmail.com>

When we specify GIT_TRACE2_CONFIG_PARAMS or trace2.configparams,
trace2 will prints "interesting" config values to log. Sometimes,
when a config set in multiple scope files, the following output
looks like (the irrelevant fields are omitted here as "..."):

...| def_param    |  ...  | core.multipackindex:false
...| def_param    |  ...  | core.multipackindex:false
...| def_param    |  ...  | core.multipackindex:false

As the log shows, even each config in different scope is dumped, but
we don't know which scope it comes from. Therefore, it's better to
add the scope names as well to make them be more recognizable. For
example, when execute:

    $ GIT_TRACE2_PERF=1 \
    > GIT_TRACE2_CONFIG_PARAMS=core.multipackIndex \
    > git rev-list --test-bitmap HEAD"

The following is the ouput (the irrelevant fields are omitted here
as "..."):

Format normal:
... git.c:461 ... def_param scope:system core.multipackindex=false
... git.c:461 ... def_param scope:global core.multipackindex=false
... git.c:461 ... def_param scope:local core.multipackindex=false

Format perf:

... | def_param    | ... | scope:system | core.multipackindex:false
... | def_param    | ... | scope:global | core.multipackindex:false
... | def_param    | ... | scope:local  | core.multipackindex:false

Format event:

{"event":"def_param", ... ,"scope":"system","param":"core.multipackindex","value":"false"}
{"event":"def_param", ... ,"scope":"global","param":"core.multipackindex","value":"false"}
{"event":"def_param", ... ,"scope":"local","param":"core.multipackindex","value":"false"}

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 Documentation/technical/api-trace2.txt | 20 +++++++++++++++-----
 trace2/tr2_tgt_event.c                 |  3 +++
 trace2/tr2_tgt_normal.c                |  5 ++++-
 trace2/tr2_tgt_perf.c                  |  9 +++++++--
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index dcd0429037..229f31ab31 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
 {
 	"event":"def_param",
 	...
+	scope: <a string that 'git config --show-scope' would return>
 	"param":"core.abbrev",
 	"value":"7"
 }
@@ -1213,10 +1214,17 @@ Print Configs::
 +
 The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
 `trace2.configparams` can be used to output config values which you care
-about(see linkgit:git-config[1). For example:
+about(see linkgit:git-config[1). For example assume that we want to config
+different `color.ui` values in multiple scopes, such as:
 +
 ----------------
-$ git config color.ui auto
+$ git config --system color.ui never
+$ git config --global color.ui always
+$ git config --local color.ui auto
+$ git config --list --show-scope | grep 'color.ui'
+system  color.ui=never
+global  color.ui=always
+local   color.ui=auto
 ----------------
 +
 Then, mark the config `color.ui` as "interesting" config with
@@ -1232,11 +1240,13 @@ $ cat ~/log.perf
 d0 | main                     | version      |     |           |           |              | ...
 d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
 d0 | main                     | cmd_name     |     |           |           |              | version (version)
-d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | def_param    |     |           |           | scope:system | color.ui:never
+d0 | main                     | def_param    |     |           |           | scope:global | color.ui:always
+d0 | main                     | def_param    |     |           |           | scope:local  | color.ui:auto
 d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
 d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
-d0 | main                     | exit         |     |  0.002142 |           |              | code:0
-d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+d0 | main                     | exit         |     |  0.000470 |           |              | code:0
+d0 | main                     | atexit       |     |  0.000477 |           |              | code:0
 ----------------
 == Future Work
 
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index c5c8cfbbaa..37a3163be1 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -479,9 +479,12 @@ static void fn_param_fl(const char *file, int line, const char *param,
 {
 	const char *event_name = "def_param";
 	struct json_writer jw = JSON_WRITER_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
 	jw_object_begin(&jw, 0);
 	event_fmt_prepare(event_name, file, line, NULL, &jw);
+	jw_object_string(&jw, "scope", scope_name);
 	jw_object_string(&jw, "param", param);
 	jw_object_string(&jw, "value", value);
 	jw_end(&jw);
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index c42fbade7f..69f8033077 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -298,8 +298,11 @@ static void fn_param_fl(const char *file, int line, const char *param,
 			const char *value)
 {
 	struct strbuf buf_payload = STRBUF_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
-	strbuf_addf(&buf_payload, "def_param %s=%s", param, value);
+	strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
+		    value);
 	normal_io_write_fl(file, line, &buf_payload);
 	strbuf_release(&buf_payload);
 }
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index a1eff8bea3..8cb792488c 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -441,12 +441,17 @@ static void fn_param_fl(const char *file, int line, const char *param,
 {
 	const char *event_name = "def_param";
 	struct strbuf buf_payload = STRBUF_INIT;
+	struct strbuf scope_payload = STRBUF_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
 	strbuf_addf(&buf_payload, "%s:%s", param, value);
+	strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
 
-	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
-			 &buf_payload);
+	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
+			 scope_payload.buf, &buf_payload);
 	strbuf_release(&buf_payload);
+	strbuf_release(&scope_payload);
 }
 
 static void fn_repo_fl(const char *file, int line,
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 2/2] tr2: shows scope unconditionally in addition to key-value pair
  2022-07-21 13:27 ` [PATCH 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
@ 2022-07-21 16:57   ` Junio C Hamano
  2022-07-22  6:12     ` tenglong.tl
  0 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2022-07-21 16:57 UTC (permalink / raw)
  To: tenglong.tl; +Cc: git, avarab, git, tenglong.tl

"tenglong.tl" <dyroneteng@gmail.com> writes:

> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
> index dcd0429037..229f31ab31 100644
> --- a/Documentation/technical/api-trace2.txt
> +++ b/Documentation/technical/api-trace2.txt
> @@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
>  {
>  	"event":"def_param",
>  	...
> +	scope: <a string that 'git config --show-scope' would return>
>  	"param":"core.abbrev",
>  	"value":"7"
>  }

Everything in these examples use concrete values and follow the real
syntax (e.g. param is enclosed in double-quotes and so is its value
core.abbrev; even though core.abbrev is not the only param that can
be reported by a def-param event, it is used as a concrete example.
The same story goes for value).  The new "scope" thing stands out
like a sore thumb.  I think the above should read more like

	"event":"def_param",
	...
	"scope":"global",
	"param":"core.abbrev",
	"value":"7"

or something.  Pick your favourite value for scope.

Other than that, these two patches make quite a lot of sense.

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2/2] tr2: shows scope unconditionally in addition to key-value pair
  2022-07-21 16:57   ` Junio C Hamano
@ 2022-07-22  6:12     ` tenglong.tl
  0 siblings, 0 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-22  6:12 UTC (permalink / raw)
  To: gitster; +Cc: avarab, dyroneteng, git, git, tenglong.tl

Junio C Hamano <gitster@pobox.com> writes:

> Everything in these examples use concrete values and follow the real
> syntax (e.g. param is enclosed in double-quotes and so is its value
> core.abbrev; even though core.abbrev is not the only param that can
> be reported by a def-param event, it is used as a concrete example.
> The same story goes for value).  The new "scope" thing stands out
> like a sore thumb.  I think the above should read more like
>
> 	"event":"def_param",
> 	...
> 	"scope":"global",
> 	"param":"core.abbrev",
> 	"value":"7"
>
> or something.  Pick your favourite value for scope.
>
> Other than that, these two patches make quite a lot of sense.

Yes. I think you are right, in this context, we should obey the same syntax
and will fix in next patch.

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v1 0/2] tr2: shows the scope unconditionally with config
  2022-07-21 13:27 [PATCH 0/2] tr2: shows the scope unconditionally with config tenglong.tl
  2022-07-21 13:27 ` [PATCH 1/2] api-trace2.txt: print config key-value pair tenglong.tl
  2022-07-21 13:27 ` [PATCH 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
@ 2022-07-22  8:19 ` tenglong.tl
  2022-07-22  8:19   ` [PATCH v1 1/2] api-trace2.txt: print config key-value pair tenglong.tl
                     ` (2 more replies)
  2 siblings, 3 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-22  8:19 UTC (permalink / raw)
  To: dyroneteng; +Cc: avarab, git, git, gitster, tenglong.tl

From: Teng Long <dyroneteng@gmail.com>

Changes since the initial patch:

1. [1/2] optimize the "scope" field representation with real syntax and
concrete value.

Thanks.

Teng Long (2):
  api-trace2.txt: print config key-value pair
  tr2: shows scope unconditionally in addition to key-value pair

 Documentation/technical/api-trace2.txt | 41 ++++++++++++++++++++++++++
 trace2/tr2_tgt_event.c                 |  3 ++
 trace2/tr2_tgt_normal.c                |  5 +++-
 trace2/tr2_tgt_perf.c                  |  9 ++++--
 4 files changed, 55 insertions(+), 3 deletions(-)

Range-diff against v0:
1:  bebd97c832 ! 1:  32f8b9ae6b api-trace2.txt: print config key-value pair
    @@ Commit message
         Signed-off-by: Teng Long <dyroneteng@gmail.com>
     
      ## Documentation/technical/api-trace2.txt ##
    +@@ Documentation/technical/api-trace2.txt: The "exec_id" field is a command-unique id and is only useful if the
    + {
    + 	"event":"def_param",
    + 	...
    ++	"scope":"global",
    + 	"param":"core.abbrev",
    + 	"value":"7"
    + }
     @@ Documentation/technical/api-trace2.txt: at offset 508.
      This example also shows that thread names are assigned in a racy manner
      as each thread starts and allocates TLS storage.
2:  2f8fce6599 ! 2:  78575cca0b tr2: shows scope unconditionally in addition to key-value pair
    @@ Commit message
         Signed-off-by: Teng Long <dyroneteng@gmail.com>
     
      ## Documentation/technical/api-trace2.txt ##
    -@@ Documentation/technical/api-trace2.txt: The "exec_id" field is a command-unique id and is only useful if the
    - {
    - 	"event":"def_param",
    - 	...
    -+	scope: <a string that 'git config --show-scope' would return>
    - 	"param":"core.abbrev",
    - 	"value":"7"
    - }
     @@ Documentation/technical/api-trace2.txt: Print Configs::
      +
      The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-22  8:19 ` [PATCH v1 0/2] tr2: shows the scope unconditionally with config tenglong.tl
@ 2022-07-22  8:19   ` tenglong.tl
  2022-07-22 10:59     ` Ævar Arnfjörð Bjarmason
  2022-07-22 21:05     ` Junio C Hamano
  2022-07-22  8:19   ` [PATCH v1 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
  2022-08-12  2:56   ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Teng Long
  2 siblings, 2 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-22  8:19 UTC (permalink / raw)
  To: dyroneteng; +Cc: avarab, git, git, gitster, tenglong.tl

From: Teng Long <dyroneteng@gmail.com>

It's supported to print "interesting" config key-value paire
to tr2 log by setting "GIT_TRACE2_CONFIG_PARAMS" environment
variable and the "trace2.configparam" config, let's add the
related docs in Documentaion/technical/api-trace2.txt.

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 Documentation/technical/api-trace2.txt | 32 ++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index 77a150b30e..ddc0bfb9c9 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
 {
 	"event":"def_param",
 	...
+	"scope":"global",
 	"param":"core.abbrev",
 	"value":"7"
 }
@@ -1207,6 +1208,37 @@ at offset 508.
 This example also shows that thread names are assigned in a racy manner
 as each thread starts and allocates TLS storage.
 
+Print Configs::
+
+	  Dump "interesting" config values to trace2 log.
++
+The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
+`trace2.configparams` can be used to output config values which you care
+about(see linkgit:git-config[1). For example:
++
+----------------
+$ git config color.ui auto
+----------------
++
+Then, mark the config `color.ui` as "interesting" config with
+`GIT_TRACE2_CONFIG_PARAMS`:
++
+----------------
+$ export GIT_TRACE2_PERF_BRIEF=1
+$ export GIT_TRACE2_PERF=~/log.perf
+$ export GIT_TRACE2_CONFIG_PARAMS=color.ui
+$ git version
+...
+$ cat ~/log.perf
+d0 | main                     | version      |     |           |           |              | ...
+d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
+d0 | main                     | cmd_name     |     |           |           |              | version (version)
+d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
+d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
+d0 | main                     | exit         |     |  0.002142 |           |              | code:0
+d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+----------------
 == Future Work
 
 === Relationship to the Existing Trace Api (api-trace.txt)
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v1 2/2] tr2: shows scope unconditionally in addition to key-value pair
  2022-07-22  8:19 ` [PATCH v1 0/2] tr2: shows the scope unconditionally with config tenglong.tl
  2022-07-22  8:19   ` [PATCH v1 1/2] api-trace2.txt: print config key-value pair tenglong.tl
@ 2022-07-22  8:19   ` tenglong.tl
  2022-08-12  2:56   ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Teng Long
  2 siblings, 0 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-22  8:19 UTC (permalink / raw)
  To: dyroneteng; +Cc: avarab, git, git, gitster, tenglong.tl

From: Teng Long <dyroneteng@gmail.com>

When we specify GIT_TRACE2_CONFIG_PARAMS or trace2.configparams,
trace2 will prints "interesting" config values to log. Sometimes,
when a config set in multiple scope files, the following output
looks like (the irrelevant fields are omitted here as "..."):

...| def_param    |  ...  | core.multipackindex:false
...| def_param    |  ...  | core.multipackindex:false
...| def_param    |  ...  | core.multipackindex:false

As the log shows, even each config in different scope is dumped, but
we don't know which scope it comes from. Therefore, it's better to
add the scope names as well to make them be more recognizable. For
example, when execute:

    $ GIT_TRACE2_PERF=1 \
    > GIT_TRACE2_CONFIG_PARAMS=core.multipackIndex \
    > git rev-list --test-bitmap HEAD"

The following is the ouput (the irrelevant fields are omitted here
as "..."):

Format normal:
... git.c:461 ... def_param scope:system core.multipackindex=false
... git.c:461 ... def_param scope:global core.multipackindex=false
... git.c:461 ... def_param scope:local core.multipackindex=false

Format perf:

... | def_param    | ... | scope:system | core.multipackindex:false
... | def_param    | ... | scope:global | core.multipackindex:false
... | def_param    | ... | scope:local  | core.multipackindex:false

Format event:

{"event":"def_param", ... ,"scope":"system","param":"core.multipackindex","value":"false"}
{"event":"def_param", ... ,"scope":"global","param":"core.multipackindex","value":"false"}
{"event":"def_param", ... ,"scope":"local","param":"core.multipackindex","value":"false"}

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 Documentation/technical/api-trace2.txt | 19 ++++++++++++++-----
 trace2/tr2_tgt_event.c                 |  3 +++
 trace2/tr2_tgt_normal.c                |  5 ++++-
 trace2/tr2_tgt_perf.c                  |  9 +++++++--
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index ddc0bfb9c9..534cfa98fa 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -1214,10 +1214,17 @@ Print Configs::
 +
 The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
 `trace2.configparams` can be used to output config values which you care
-about(see linkgit:git-config[1). For example:
+about(see linkgit:git-config[1). For example assume that we want to config
+different `color.ui` values in multiple scopes, such as:
 +
 ----------------
-$ git config color.ui auto
+$ git config --system color.ui never
+$ git config --global color.ui always
+$ git config --local color.ui auto
+$ git config --list --show-scope | grep 'color.ui'
+system  color.ui=never
+global  color.ui=always
+local   color.ui=auto
 ----------------
 +
 Then, mark the config `color.ui` as "interesting" config with
@@ -1233,11 +1240,13 @@ $ cat ~/log.perf
 d0 | main                     | version      |     |           |           |              | ...
 d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
 d0 | main                     | cmd_name     |     |           |           |              | version (version)
-d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | def_param    |     |           |           | scope:system | color.ui:never
+d0 | main                     | def_param    |     |           |           | scope:global | color.ui:always
+d0 | main                     | def_param    |     |           |           | scope:local  | color.ui:auto
 d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
 d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
-d0 | main                     | exit         |     |  0.002142 |           |              | code:0
-d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+d0 | main                     | exit         |     |  0.000470 |           |              | code:0
+d0 | main                     | atexit       |     |  0.000477 |           |              | code:0
 ----------------
 == Future Work
 
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index c5c8cfbbaa..37a3163be1 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -479,9 +479,12 @@ static void fn_param_fl(const char *file, int line, const char *param,
 {
 	const char *event_name = "def_param";
 	struct json_writer jw = JSON_WRITER_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
 	jw_object_begin(&jw, 0);
 	event_fmt_prepare(event_name, file, line, NULL, &jw);
+	jw_object_string(&jw, "scope", scope_name);
 	jw_object_string(&jw, "param", param);
 	jw_object_string(&jw, "value", value);
 	jw_end(&jw);
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index c42fbade7f..69f8033077 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -298,8 +298,11 @@ static void fn_param_fl(const char *file, int line, const char *param,
 			const char *value)
 {
 	struct strbuf buf_payload = STRBUF_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
-	strbuf_addf(&buf_payload, "def_param %s=%s", param, value);
+	strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
+		    value);
 	normal_io_write_fl(file, line, &buf_payload);
 	strbuf_release(&buf_payload);
 }
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index a1eff8bea3..8cb792488c 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -441,12 +441,17 @@ static void fn_param_fl(const char *file, int line, const char *param,
 {
 	const char *event_name = "def_param";
 	struct strbuf buf_payload = STRBUF_INIT;
+	struct strbuf scope_payload = STRBUF_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
 	strbuf_addf(&buf_payload, "%s:%s", param, value);
+	strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
 
-	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
-			 &buf_payload);
+	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
+			 scope_payload.buf, &buf_payload);
 	strbuf_release(&buf_payload);
+	strbuf_release(&scope_payload);
 }
 
 static void fn_repo_fl(const char *file, int line,
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-22  8:19   ` [PATCH v1 1/2] api-trace2.txt: print config key-value pair tenglong.tl
@ 2022-07-22 10:59     ` Ævar Arnfjörð Bjarmason
  2022-07-25 19:07       ` Junio C Hamano
  2022-08-01 12:25       ` tenglong.tl
  2022-07-22 21:05     ` Junio C Hamano
  1 sibling, 2 replies; 22+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-07-22 10:59 UTC (permalink / raw)
  To: tenglong.tl; +Cc: git, git, gitster, tenglong.tl


On Fri, Jul 22 2022, tenglong.tl wrote:

> From: Teng Long <dyroneteng@gmail.com>
>
> It's supported to print "interesting" config key-value paire
> to tr2 log by setting "GIT_TRACE2_CONFIG_PARAMS" environment
> variable and the "trace2.configparam" config, let's add the
> related docs in Documentaion/technical/api-trace2.txt.
>
> Signed-off-by: Teng Long <dyroneteng@gmail.com>
> ---
>  Documentation/technical/api-trace2.txt | 32 ++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
> index 77a150b30e..ddc0bfb9c9 100644
> --- a/Documentation/technical/api-trace2.txt
> +++ b/Documentation/technical/api-trace2.txt
> @@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
>  {
>  	"event":"def_param",
>  	...
> +	"scope":"global",
>  	"param":"core.abbrev",
>  	"value":"7"
>  }
> @@ -1207,6 +1208,37 @@ at offset 508.
>  This example also shows that thread names are assigned in a racy manner
>  as each thread starts and allocates TLS storage.
>  
> +Print Configs::
> +
> +	  Dump "interesting" config values to trace2 log.
> ++
> +The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
> +`trace2.configparams` can be used to output config values which you care
> +about(see linkgit:git-config[1). For example:

I didn't notice this before, but this is an addition to a long section
where the examples are ------- delimited, starting with "in this
example.." usually.

So this "print configs" seems like on odd continuation. Shouldn't this
copy the template of "Thread Events::" above. I.e. something like (I
have not tried to asciidoc render this):
	
	Config (def param) Events::
		We can optionally emit configuration events, see
		`trace2.configParams` in linkgit:git-config[1] for how to enable
		it.
	+
	< your example below would follow this>

I.e. re my earlier mention of git-config we it explains
GIT_TRACE2_CONFIG_PARAMS, so perhaps it suffices to just link to
linkgit:git-config[1] for that.

Also a nit: trace2.configParams, not trace2.configparams.
	
> ++
> +----------------
> +$ git config color.ui auto
> +----------------
> ++
> +Then, mark the config `color.ui` as "interesting" config with
> +`GIT_TRACE2_CONFIG_PARAMS`:
> ++
> +----------------
> +$ export GIT_TRACE2_PERF_BRIEF=1
> +$ export GIT_TRACE2_PERF=~/log.perf
> +$ export GIT_TRACE2_CONFIG_PARAMS=color.ui
> +$ git version
> +...
> +$ cat ~/log.perf
> +d0 | main                     | version      |     |           |           |              | ...
> +d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
> +d0 | main                     | cmd_name     |     |           |           |              | version (version)
> +d0 | main                     | def_param    |     |           |           |              | color.ui:auto
> +d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
> +d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
> +d0 | main                     | exit         |     |  0.002142 |           |              | code:0
> +d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
> +----------------
>  == Future Work
>  
>  === Relationship to the Existing Trace Api (api-trace.txt)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-22  8:19   ` [PATCH v1 1/2] api-trace2.txt: print config key-value pair tenglong.tl
  2022-07-22 10:59     ` Ævar Arnfjörð Bjarmason
@ 2022-07-22 21:05     ` Junio C Hamano
  2022-07-23  6:06       ` tenglong.tl
  1 sibling, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2022-07-22 21:05 UTC (permalink / raw)
  To: tenglong.tl; +Cc: avarab, git, git, tenglong.tl

"tenglong.tl" <dyroneteng@gmail.com> writes:

> From: Teng Long <dyroneteng@gmail.com>
>
> It's supported to print "interesting" config key-value paire
> to tr2 log by setting "GIT_TRACE2_CONFIG_PARAMS" environment
> variable and the "trace2.configparam" config, let's add the
> related docs in Documentaion/technical/api-trace2.txt.
>
> Signed-off-by: Teng Long <dyroneteng@gmail.com>
> ---
>  Documentation/technical/api-trace2.txt | 32 ++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
> index 77a150b30e..ddc0bfb9c9 100644
> --- a/Documentation/technical/api-trace2.txt
> +++ b/Documentation/technical/api-trace2.txt
> @@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
>  {
>  	"event":"def_param",
>  	...
> +	"scope":"global",
>  	"param":"core.abbrev",
>  	"value":"7"
>  }

Isn't this a bit premature to do in [PATCH 1/2]?

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-22 21:05     ` Junio C Hamano
@ 2022-07-23  6:06       ` tenglong.tl
  2022-07-23 17:47         ` Junio C Hamano
  0 siblings, 1 reply; 22+ messages in thread
From: tenglong.tl @ 2022-07-23  6:06 UTC (permalink / raw)
  To: gitster; +Cc: avarab, dyroneteng, git, git, tenglong.tl

> Isn't this a bit premature to do in [PATCH 1/2]?

Yes, one oversight, sorry for that and will fix.

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-23  6:06       ` tenglong.tl
@ 2022-07-23 17:47         ` Junio C Hamano
  2022-07-25  9:18           ` tenglong.tl
  0 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2022-07-23 17:47 UTC (permalink / raw)
  To: tenglong.tl; +Cc: avarab, git, git, tenglong.tl

"tenglong.tl" <dyroneteng@gmail.com> writes:

>> Isn't this a bit premature to do in [PATCH 1/2]?
>
> Yes, one oversight, sorry for that and will fix.

I've tweaked with "rebase -i" after queuing and before pushing the
integration result out, so if you can double check the result to
make sure I didn't screw up, there is no need to resend.

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-23 17:47         ` Junio C Hamano
@ 2022-07-25  9:18           ` tenglong.tl
  0 siblings, 0 replies; 22+ messages in thread
From: tenglong.tl @ 2022-07-25  9:18 UTC (permalink / raw)
  To: gitster; +Cc: avarab, dyroneteng, git, git, tenglong.tl

Junio C Hamano <gitster@pobox.com> writes:

> I've tweaked with "rebase -i" after queuing and before pushing the
> integration result out, so if you can double check the result to
> make sure I didn't screw up, there is no need to resend.

OK, got it. There is no inconsistency in understanding, I agree with
your suggestion.

Thanks for explanation.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-22 10:59     ` Ævar Arnfjörð Bjarmason
@ 2022-07-25 19:07       ` Junio C Hamano
  2022-08-01 12:25       ` tenglong.tl
  1 sibling, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2022-07-25 19:07 UTC (permalink / raw)
  To: tenglong.tl; +Cc: Ævar Arnfjörð Bjarmason, git, git

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> On Fri, Jul 22 2022, tenglong.tl wrote:
> ...
>> +Print Configs::
>> +
>> +	  Dump "interesting" config values to trace2 log.
>> ++
>> +The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
>> +`trace2.configparams` can be used to output config values which you care
>> +about(see linkgit:git-config[1). For example:
>
> I didn't notice this before, but this is an addition to a long section
> where the examples are ------- delimited, starting with "in this
> example.." usually.
>
> So this "print configs" seems like on odd continuation. Shouldn't this
> copy the template of "Thread Events::" above. I.e. something like (I
> have not tried to asciidoc render this):
> 	
> 	Config (def param) Events::
> 		We can optionally emit configuration events, see
> 		`trace2.configParams` in linkgit:git-config[1] for how to enable
> 		it.
> 	+
> 	< your example below would follow this>
>
> I.e. re my earlier mention of git-config we it explains
> GIT_TRACE2_CONFIG_PARAMS, so perhaps it suffices to just link to
> linkgit:git-config[1] for that.
>
> Also a nit: trace2.configParams, not trace2.configparams.

These may be worth fixing, regardless of the "adding scope in the
example needs to wait until 2/2" I pointed out separately.

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-07-22 10:59     ` Ævar Arnfjörð Bjarmason
  2022-07-25 19:07       ` Junio C Hamano
@ 2022-08-01 12:25       ` tenglong.tl
  2022-08-05 22:21         ` Junio C Hamano
  1 sibling, 1 reply; 22+ messages in thread
From: tenglong.tl @ 2022-08-01 12:25 UTC (permalink / raw)
  To: avarab; +Cc: dyroneteng, git, git, gitster, tenglong.tl

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> I didn't notice this before, but this is an addition to a long section
> where the examples are ------- delimited, starting with "in this
> example.." usually.

A little puzzled. About "------- delimited", do you mean the "block" syntax?

> So this "print configs" seems like on odd continuation. Shouldn't this
> copy the template of "Thread Events::" above. I.e. something like (I
> have not tried to asciidoc render this):

I think "Events" in "Thread Events" means the thread start and end events,
maybe not a template here. So I think it might be better to keep this namingi
if I'm right, but I will use this candidate naming to show diff in the end.

I'm not good at naming so I'm glad to accept the suggestion about it.

>	Config (def param) Events::
>		We can optionally emit configuration events, see
>		`trace2.configParams` in linkgit:git-config[1] for how to enable
>		it.
>	+
>	< your example below would follow this>

I refer to the previous sections, it's like the template is :

<title>

        <brief one-line description>

<detailed multi-lines description>

So, how about this like:

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index 77a150b30e..38d0878d85 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -1207,6 +1207,37 @@ at offset 508.
 This example also shows that thread names are assigned in a racy manner
 as each thread starts and allocates TLS storage.

+Config (def param) Events::
+
+         Dump "interesting" config values to trace2 log.
++
+We can optionally emit configuration events, see
+`trace2.configparams` in linkgit:git-config[1] for how to enable
+it.
++
+----------------
+$ git config color.ui auto
+----------------
++
+Then, mark the config `color.ui` as "interesting" config with
+`GIT_TRACE2_CONFIG_PARAMS`:
++
+----------------
+$ export GIT_TRACE2_PERF_BRIEF=1
+$ export GIT_TRACE2_PERF=~/log.perf
+$ export GIT_TRACE2_CONFIG_PARAMS=color.ui
+$ git version
+...
+$ cat ~/log.perf
+d0 | main                     | version      |     |           |           |              | ...
+d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
+d0 | main                     | cmd_name     |     |           |           |              | version (version)
+d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
+d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
+d0 | main                     | exit         |     |  0.002142 |           |              | code:0
+d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+----------------
 == Future Work

 === Relationship to the Existing Trace Api (api-trace.txt)

Thanks.

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-08-01 12:25       ` tenglong.tl
@ 2022-08-05 22:21         ` Junio C Hamano
  2022-08-08  6:16           ` Teng Long
  0 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2022-08-05 22:21 UTC (permalink / raw)
  To: avarab, tenglong.tl; +Cc: git, git, tenglong.tl

"tenglong.tl" <dyroneteng@gmail.com> writes:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> I didn't notice this before, but this is an addition to a long section
> ...
> I refer to the previous sections, it's like the template is :
>
> <title>
>
>         <brief one-line description>
>
> <detailed multi-lines description>
>
> So, how about this like:
>
> diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
> index 77a150b30e..38d0878d85 100644
> --- a/Documentation/technical/api-trace2.txt
> +++ b/Documentation/technical/api-trace2.txt
> @@ -1207,6 +1207,37 @@ at offset 508.

So, what is the outcome from this discussion?  It seems that this
subthread on [1/2] is blocking the two-patch series?

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] api-trace2.txt: print config key-value pair
  2022-08-05 22:21         ` Junio C Hamano
@ 2022-08-08  6:16           ` Teng Long
  0 siblings, 0 replies; 22+ messages in thread
From: Teng Long @ 2022-08-08  6:16 UTC (permalink / raw)
  To: gitster; +Cc: avarab, dyroneteng, git, git, tenglong.tl


Junio C Hamano <gitster@pobox.com> writes:

> So, what is the outcome from this discussion?  It seems that this
> subthread on [1/2] is blocking the two-patch series?

I think it's blocking. I replied a comment to comfirm that I understand Ævar
Arnfjörð Bjarmason's suggestion and also there is an improvement change in it:

  https://public-inbox.org/git/20220801122515.23146-1-tenglong.tl@alibaba-inc.com/

Thanks.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v2 0/2] tr2: shows the scope unconditionally with config
  2022-07-22  8:19 ` [PATCH v1 0/2] tr2: shows the scope unconditionally with config tenglong.tl
  2022-07-22  8:19   ` [PATCH v1 1/2] api-trace2.txt: print config key-value pair tenglong.tl
  2022-07-22  8:19   ` [PATCH v1 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
@ 2022-08-12  2:56   ` Teng Long
  2022-08-12  2:56     ` [PATCH v2 1/2] api-trace2.txt: print config key-value pair Teng Long
                       ` (2 more replies)
  2 siblings, 3 replies; 22+ messages in thread
From: Teng Long @ 2022-08-12  2:56 UTC (permalink / raw)
  To: dyroneteng; +Cc: avarab, git, git, gitster, tenglong.tl

From: Teng Long <dyroneteng@gmail.com>

Diff from v1:

* Fix the premature code in [1/2] by Junio's comment in:

  https://public-inbox.org/git/xmqqy1wkc0yw.fsf@gitster.g/

* Optimize the documentaion in [1/2] by Ævar's comment in:

  https://public-inbox.org/git/220722.86fsits91m.gmgdl@evledraar.gmail.com/

I send this patch version a little earlier maybe because some context not fully
discussed or solved, intend to avoid context signal disappearance because it's
been lasted a while now. 

Thanks.

Teng Long (2):
  api-trace2.txt: print config key-value pair
  tr2: shows scope unconditionally in addition to key-value pair

 Documentation/technical/api-trace2.txt | 40 ++++++++++++++++++++++++++
 trace2/tr2_tgt_event.c                 |  3 ++
 trace2/tr2_tgt_normal.c                |  5 +++-
 trace2/tr2_tgt_perf.c                  |  9 ++++--
 4 files changed, 54 insertions(+), 3 deletions(-)

Range-diff against v1:
1:  bebd97c832 ! 1:  84bd8a71d7 api-trace2.txt: print config key-value pair
    @@ Documentation/technical/api-trace2.txt: at offset 508.
      This example also shows that thread names are assigned in a racy manner
      as each thread starts and allocates TLS storage.
      
    -+Print Configs::
    ++Config (def param) Events::
     +
     +	  Dump "interesting" config values to trace2 log.
     ++
    -+The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
    -+`trace2.configparams` can be used to output config values which you care
    -+about(see linkgit:git-config[1). For example:
    ++We can optionally emit configuration events, see
    ++`trace2.configparams` in linkgit:git-config[1] for how to enable
    ++it.
     ++
     +----------------
     +$ git config color.ui auto
2:  2f8fce6599 ! 2:  9856058df6 tr2: shows scope unconditionally in addition to key-value pair
    @@ Documentation/technical/api-trace2.txt: The "exec_id" field is a command-unique
      {
      	"event":"def_param",
      	...
    -+	scope: <a string that 'git config --show-scope' would return>
    ++	"scope":"global",
      	"param":"core.abbrev",
      	"value":"7"
      }
    -@@ Documentation/technical/api-trace2.txt: Print Configs::
    - +
    - The environment variable `GIT_TRACE2_CONFIG_PARAMS` and configuration
    - `trace2.configparams` can be used to output config values which you care
    --about(see linkgit:git-config[1). For example:
    -+about(see linkgit:git-config[1). For example assume that we want to config
    -+different `color.ui` values in multiple scopes, such as:
    +@@ Documentation/technical/api-trace2.txt: We can optionally emit configuration events, see
    + it.
      +
      ----------------
     -$ git config color.ui auto
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v2 1/2] api-trace2.txt: print config key-value pair
  2022-08-12  2:56   ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Teng Long
@ 2022-08-12  2:56     ` Teng Long
  2022-08-12  2:56     ` [PATCH v2 2/2] tr2: shows scope unconditionally in addition to " Teng Long
  2022-08-19 21:18     ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Junio C Hamano
  2 siblings, 0 replies; 22+ messages in thread
From: Teng Long @ 2022-08-12  2:56 UTC (permalink / raw)
  To: dyroneteng; +Cc: avarab, git, git, gitster, tenglong.tl

From: Teng Long <dyroneteng@gmail.com>

It's supported to print "interesting" config key-value paire
to tr2 log by setting "GIT_TRACE2_CONFIG_PARAMS" environment
variable and the "trace2.configparam" config, let's add the
related docs in Documentaion/technical/api-trace2.txt.

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 Documentation/technical/api-trace2.txt | 31 ++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index 77a150b30e..38d0878d85 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -1207,6 +1207,37 @@ at offset 508.
 This example also shows that thread names are assigned in a racy manner
 as each thread starts and allocates TLS storage.
 
+Config (def param) Events::
+
+	  Dump "interesting" config values to trace2 log.
++
+We can optionally emit configuration events, see
+`trace2.configparams` in linkgit:git-config[1] for how to enable
+it.
++
+----------------
+$ git config color.ui auto
+----------------
++
+Then, mark the config `color.ui` as "interesting" config with
+`GIT_TRACE2_CONFIG_PARAMS`:
++
+----------------
+$ export GIT_TRACE2_PERF_BRIEF=1
+$ export GIT_TRACE2_PERF=~/log.perf
+$ export GIT_TRACE2_CONFIG_PARAMS=color.ui
+$ git version
+...
+$ cat ~/log.perf
+d0 | main                     | version      |     |           |           |              | ...
+d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
+d0 | main                     | cmd_name     |     |           |           |              | version (version)
+d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
+d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
+d0 | main                     | exit         |     |  0.002142 |           |              | code:0
+d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+----------------
 == Future Work
 
 === Relationship to the Existing Trace Api (api-trace.txt)
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 2/2] tr2: shows scope unconditionally in addition to key-value pair
  2022-08-12  2:56   ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Teng Long
  2022-08-12  2:56     ` [PATCH v2 1/2] api-trace2.txt: print config key-value pair Teng Long
@ 2022-08-12  2:56     ` Teng Long
  2022-08-12 21:16       ` Junio C Hamano
  2022-08-19 21:18     ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Junio C Hamano
  2 siblings, 1 reply; 22+ messages in thread
From: Teng Long @ 2022-08-12  2:56 UTC (permalink / raw)
  To: dyroneteng; +Cc: avarab, git, git, gitster, tenglong.tl

From: Teng Long <dyroneteng@gmail.com>

When we specify GIT_TRACE2_CONFIG_PARAMS or trace2.configparams,
trace2 will prints "interesting" config values to log. Sometimes,
when a config set in multiple scope files, the following output
looks like (the irrelevant fields are omitted here as "..."):

...| def_param    |  ...  | core.multipackindex:false
...| def_param    |  ...  | core.multipackindex:false
...| def_param    |  ...  | core.multipackindex:false

As the log shows, even each config in different scope is dumped, but
we don't know which scope it comes from. Therefore, it's better to
add the scope names as well to make them be more recognizable. For
example, when execute:

    $ GIT_TRACE2_PERF=1 \
    > GIT_TRACE2_CONFIG_PARAMS=core.multipackIndex \
    > git rev-list --test-bitmap HEAD"

The following is the ouput (the irrelevant fields are omitted here
as "..."):

Format normal:
... git.c:461 ... def_param scope:system core.multipackindex=false
... git.c:461 ... def_param scope:global core.multipackindex=false
... git.c:461 ... def_param scope:local core.multipackindex=false

Format perf:

... | def_param    | ... | scope:system | core.multipackindex:false
... | def_param    | ... | scope:global | core.multipackindex:false
... | def_param    | ... | scope:local  | core.multipackindex:false

Format event:

{"event":"def_param", ... ,"scope":"system","param":"core.multipackindex","value":"false"}
{"event":"def_param", ... ,"scope":"global","param":"core.multipackindex","value":"false"}
{"event":"def_param", ... ,"scope":"local","param":"core.multipackindex","value":"false"}

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 Documentation/technical/api-trace2.txt | 17 +++++++++++++----
 trace2/tr2_tgt_event.c                 |  3 +++
 trace2/tr2_tgt_normal.c                |  5 ++++-
 trace2/tr2_tgt_perf.c                  |  9 +++++++--
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/Documentation/technical/api-trace2.txt b/Documentation/technical/api-trace2.txt
index 38d0878d85..2afa28bb5a 100644
--- a/Documentation/technical/api-trace2.txt
+++ b/Documentation/technical/api-trace2.txt
@@ -717,6 +717,7 @@ The "exec_id" field is a command-unique id and is only useful if the
 {
 	"event":"def_param",
 	...
+	"scope":"global",
 	"param":"core.abbrev",
 	"value":"7"
 }
@@ -1216,7 +1217,13 @@ We can optionally emit configuration events, see
 it.
 +
 ----------------
-$ git config color.ui auto
+$ git config --system color.ui never
+$ git config --global color.ui always
+$ git config --local color.ui auto
+$ git config --list --show-scope | grep 'color.ui'
+system  color.ui=never
+global  color.ui=always
+local   color.ui=auto
 ----------------
 +
 Then, mark the config `color.ui` as "interesting" config with
@@ -1232,11 +1239,13 @@ $ cat ~/log.perf
 d0 | main                     | version      |     |           |           |              | ...
 d0 | main                     | start        |     |  0.001642 |           |              | /usr/local/bin/git version
 d0 | main                     | cmd_name     |     |           |           |              | version (version)
-d0 | main                     | def_param    |     |           |           |              | color.ui:auto
+d0 | main                     | def_param    |     |           |           | scope:system | color.ui:never
+d0 | main                     | def_param    |     |           |           | scope:global | color.ui:always
+d0 | main                     | def_param    |     |           |           | scope:local  | color.ui:auto
 d0 | main                     | data         | r0  |  0.002100 |  0.002100 | fsync        | fsync/writeout-only:0
 d0 | main                     | data         | r0  |  0.002126 |  0.002126 | fsync        | fsync/hardware-flush:0
-d0 | main                     | exit         |     |  0.002142 |           |              | code:0
-d0 | main                     | atexit       |     |  0.002161 |           |              | code:0
+d0 | main                     | exit         |     |  0.000470 |           |              | code:0
+d0 | main                     | atexit       |     |  0.000477 |           |              | code:0
 ----------------
 == Future Work
 
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index c5c8cfbbaa..37a3163be1 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -479,9 +479,12 @@ static void fn_param_fl(const char *file, int line, const char *param,
 {
 	const char *event_name = "def_param";
 	struct json_writer jw = JSON_WRITER_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
 	jw_object_begin(&jw, 0);
 	event_fmt_prepare(event_name, file, line, NULL, &jw);
+	jw_object_string(&jw, "scope", scope_name);
 	jw_object_string(&jw, "param", param);
 	jw_object_string(&jw, "value", value);
 	jw_end(&jw);
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index c42fbade7f..69f8033077 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -298,8 +298,11 @@ static void fn_param_fl(const char *file, int line, const char *param,
 			const char *value)
 {
 	struct strbuf buf_payload = STRBUF_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
-	strbuf_addf(&buf_payload, "def_param %s=%s", param, value);
+	strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
+		    value);
 	normal_io_write_fl(file, line, &buf_payload);
 	strbuf_release(&buf_payload);
 }
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index a1eff8bea3..8cb792488c 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -441,12 +441,17 @@ static void fn_param_fl(const char *file, int line, const char *param,
 {
 	const char *event_name = "def_param";
 	struct strbuf buf_payload = STRBUF_INIT;
+	struct strbuf scope_payload = STRBUF_INIT;
+	enum config_scope scope = current_config_scope();
+	const char *scope_name = config_scope_name(scope);
 
 	strbuf_addf(&buf_payload, "%s:%s", param, value);
+	strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
 
-	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
-			 &buf_payload);
+	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
+			 scope_payload.buf, &buf_payload);
 	strbuf_release(&buf_payload);
+	strbuf_release(&scope_payload);
 }
 
 static void fn_repo_fl(const char *file, int line,
-- 
2.37.1.1.g8cbb44ffc4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 2/2] tr2: shows scope unconditionally in addition to key-value pair
  2022-08-12  2:56     ` [PATCH v2 2/2] tr2: shows scope unconditionally in addition to " Teng Long
@ 2022-08-12 21:16       ` Junio C Hamano
  0 siblings, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2022-08-12 21:16 UTC (permalink / raw)
  To: Teng Long; +Cc: avarab, git, git, tenglong.tl

Teng Long <dyroneteng@gmail.com> writes:

> diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
> index c5c8cfbbaa..37a3163be1 100644
> --- a/trace2/tr2_tgt_event.c
> +++ b/trace2/tr2_tgt_event.c
> @@ -479,9 +479,12 @@ static void fn_param_fl(const char *file, int line, const char *param,
>  {
>  	const char *event_name = "def_param";
>  	struct json_writer jw = JSON_WRITER_INIT;
> +	enum config_scope scope = current_config_scope();
> +	const char *scope_name = config_scope_name(scope);
>  
>  	jw_object_begin(&jw, 0);
>  	event_fmt_prepare(event_name, file, line, NULL, &jw);
> +	jw_object_string(&jw, "scope", scope_name);
>  	jw_object_string(&jw, "param", param);
>  	jw_object_string(&jw, "value", value);
>  	jw_end(&jw);

OK, that is quite straight-forward.

> diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
> index c42fbade7f..69f8033077 100644
> --- a/trace2/tr2_tgt_normal.c
> +++ b/trace2/tr2_tgt_normal.c
> @@ -298,8 +298,11 @@ static void fn_param_fl(const char *file, int line, const char *param,
>  			const char *value)
>  {
>  	struct strbuf buf_payload = STRBUF_INIT;
> +	enum config_scope scope = current_config_scope();
> +	const char *scope_name = config_scope_name(scope);
>  
> -	strbuf_addf(&buf_payload, "def_param %s=%s", param, value);
> +	strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
> +		    value);
>  	normal_io_write_fl(file, line, &buf_payload);
>  	strbuf_release(&buf_payload);
>  }

So is this one.  Quite nice.

Is everybody happy with the choice of ":" colon here, though?  The
one in tgt_perf below uses the same delimiter that is used between
<param, value> to delimit <"scope", scome_name>.  I am wondering if
this one should use "=", the delimiter used between <param, value>
in this output stream, to match.  I do not care at all either way,
but I am mentioning it because I happened have noticed it, and
because somebody else may care.

Thanks, will queue.


> diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
> index a1eff8bea3..8cb792488c 100644
> --- a/trace2/tr2_tgt_perf.c
> +++ b/trace2/tr2_tgt_perf.c
> @@ -441,12 +441,17 @@ static void fn_param_fl(const char *file, int line, const char *param,
>  {
>  	const char *event_name = "def_param";
>  	struct strbuf buf_payload = STRBUF_INIT;
> +	struct strbuf scope_payload = STRBUF_INIT;
> +	enum config_scope scope = current_config_scope();
> +	const char *scope_name = config_scope_name(scope);
>  
>  	strbuf_addf(&buf_payload, "%s:%s", param, value);
> +	strbuf_addf(&scope_payload, "%s:%s", "scope", scope_name);
>  
> -	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
> -			 &buf_payload);
> +	perf_io_write_fl(file, line, event_name, NULL, NULL, NULL,
> +			 scope_payload.buf, &buf_payload);
>  	strbuf_release(&buf_payload);
> +	strbuf_release(&scope_payload);
>  }
>  
>  static void fn_repo_fl(const char *file, int line,

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 0/2] tr2: shows the scope unconditionally with config
  2022-08-12  2:56   ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Teng Long
  2022-08-12  2:56     ` [PATCH v2 1/2] api-trace2.txt: print config key-value pair Teng Long
  2022-08-12  2:56     ` [PATCH v2 2/2] tr2: shows scope unconditionally in addition to " Teng Long
@ 2022-08-19 21:18     ` Junio C Hamano
  2 siblings, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2022-08-19 21:18 UTC (permalink / raw)
  To: Teng Long; +Cc: avarab, git, git, tenglong.tl

Teng Long <dyroneteng@gmail.com> writes:

> From: Teng Long <dyroneteng@gmail.com>
>
> Diff from v1:
>
> * Fix the premature code in [1/2] by Junio's comment in:
>
>   https://public-inbox.org/git/xmqqy1wkc0yw.fsf@gitster.g/
>
> * Optimize the documentaion in [1/2] by Ævar's comment in:
>
>   https://public-inbox.org/git/220722.86fsits91m.gmgdl@evledraar.gmail.com/
>
> I send this patch version a little earlier maybe because some context not fully
> discussed or solved, intend to avoid context signal disappearance because it's
> been lasted a while now. 

We haven't seen any comments (other than mine) for a full week, and
am wondering if everybody is happy with it.  Let me mark it for
'next' in the draft of "What's cooking" and merge it down.

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-08-19 21:18 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 13:27 [PATCH 0/2] tr2: shows the scope unconditionally with config tenglong.tl
2022-07-21 13:27 ` [PATCH 1/2] api-trace2.txt: print config key-value pair tenglong.tl
2022-07-21 13:27 ` [PATCH 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
2022-07-21 16:57   ` Junio C Hamano
2022-07-22  6:12     ` tenglong.tl
2022-07-22  8:19 ` [PATCH v1 0/2] tr2: shows the scope unconditionally with config tenglong.tl
2022-07-22  8:19   ` [PATCH v1 1/2] api-trace2.txt: print config key-value pair tenglong.tl
2022-07-22 10:59     ` Ævar Arnfjörð Bjarmason
2022-07-25 19:07       ` Junio C Hamano
2022-08-01 12:25       ` tenglong.tl
2022-08-05 22:21         ` Junio C Hamano
2022-08-08  6:16           ` Teng Long
2022-07-22 21:05     ` Junio C Hamano
2022-07-23  6:06       ` tenglong.tl
2022-07-23 17:47         ` Junio C Hamano
2022-07-25  9:18           ` tenglong.tl
2022-07-22  8:19   ` [PATCH v1 2/2] tr2: shows scope unconditionally in addition to " tenglong.tl
2022-08-12  2:56   ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Teng Long
2022-08-12  2:56     ` [PATCH v2 1/2] api-trace2.txt: print config key-value pair Teng Long
2022-08-12  2:56     ` [PATCH v2 2/2] tr2: shows scope unconditionally in addition to " Teng Long
2022-08-12 21:16       ` Junio C Hamano
2022-08-19 21:18     ` [PATCH v2 0/2] tr2: shows the scope unconditionally with config Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.