public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Tom Zanussi <zanussi@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 5/5] tracing: Show hitcount value only when specified
Date: Sat, 27 Aug 2022 13:03:52 +0900	[thread overview]
Message-ID: <166157303240.348924.7493529171143320258.stgit@devnote2> (raw)
In-Reply-To: <166157298537.348924.2537162090505397377.stgit@devnote2>

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Show the hitcount value only when it is specified explicitly or
no value is specified.

  # cd /sys/kernel/debug/tracing/
  # echo hist:keys=pid:vals=runtime.percent,runtime.graph:sort=pid > \
        events/sched/sched_stat_runtime/trigger
  # sleep 10
  # cat events/sched/sched_stat_runtime/hist
 # event histogram
 #
 # trigger info: hist:keys=pid:vals=runtime.percent,runtime.graph:sort=pid:size=2048 [active]
 #

 { pid:         14 }  runtime (%):   0.97  runtime:
 { pid:         16 }  runtime (%):   1.74  runtime:
 { pid:         26 }  runtime (%):   0.13  runtime:
 { pid:         57 }  runtime (%):   7.06  runtime: ###
 { pid:         61 }  runtime (%):  11.06  runtime: #####
 { pid:         65 }  runtime (%):   0.75  runtime:
 { pid:         70 }  runtime (%):   0.98  runtime:
 { pid:         77 }  runtime (%):   0.10  runtime:
 { pid:        125 }  runtime (%):   0.56  runtime:
 { pid:        146 }  runtime (%):  37.53  runtime: ####################
 { pid:        152 }  runtime (%):  23.67  runtime: ############
 { pid:        153 }  runtime (%):  15.39  runtime: ########


Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_events_hist.c |   33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index fceea784fded..35feeea84a38 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -508,6 +508,7 @@ enum hist_field_flags {
 	HIST_FIELD_FL_CONST		= 1 << 18,
 	HIST_FIELD_FL_PERCENT		= 1 << 19,
 	HIST_FIELD_FL_GRAPH		= 1 << 20,
+	HIST_FIELD_FL_VAL		= 1 << 21,
 };
 
 struct var_defs {
@@ -4204,7 +4205,8 @@ static int create_val_field(struct hist_trigger_data *hist_data,
 	if (WARN_ON(val_idx >= TRACING_MAP_VALS_MAX))
 		return -EINVAL;
 
-	return __create_val_field(hist_data, val_idx, file, NULL, field_str, 0);
+	return __create_val_field(hist_data, val_idx, file, NULL, field_str,
+				  HIST_FIELD_FL_VAL);
 }
 
 static const char no_comm[] = "(no comm)";
@@ -4355,8 +4357,11 @@ static int create_val_fields(struct hist_trigger_data *hist_data,
 		goto out;
 
 	fields_str = hist_data->attrs->vals_str;
-	if (!fields_str)
+	if (!fields_str) {
+		/* If there is no value, use hitcount as a value */
+		hist_data->fields[HITCOUNT_IDX]->flags |= HIST_FIELD_FL_VAL;
 		goto out;
+	}
 
 	for (i = 0, j = 1; i < TRACING_MAP_VALS_MAX &&
 		     j < TRACING_MAP_VALS_MAX; i++) {
@@ -4372,6 +4377,8 @@ static int create_val_fields(struct hist_trigger_data *hist_data,
 			if (strncmp(field_str + 8, ".graph", 8) == 0)
 				hist_data->fields[HITCOUNT_IDX]->flags |=
 					HIST_FIELD_FL_GRAPH;
+			hist_data->fields[HITCOUNT_IDX]->flags |=
+				HIST_FIELD_FL_VAL;
 			continue;
 		}
 
@@ -5392,13 +5399,13 @@ static void hist_trigger_entry_print(struct seq_file *m,
 	hist_trigger_print_key(m, hist_data, key, elt);
 
 	flags = hist_data->fields[i]->flags;
-	hist_trigger_print_val(m, i, "hitcount", flags, stats, elt);
+	if (flags & HIST_FIELD_FL_VAL)
+		hist_trigger_print_val(m, i, "hitcount", flags, stats, elt);
 
 	for (i = 1; i < hist_data->n_vals; i++) {
 		field_name = hist_field_name(hist_data->fields[i], 0);
 		flags = hist_data->fields[i]->flags;
-
-		if (flags & HIST_FIELD_FL_VAR || flags & HIST_FIELD_FL_EXPR)
+		if (!(flags & HIST_FIELD_FL_VAL))
 			continue;
 
 		seq_puts(m, " ");
@@ -5842,6 +5849,7 @@ static int event_hist_trigger_print(struct seq_file *m,
 	struct hist_trigger_data *hist_data = data->private_data;
 	struct hist_field *field;
 	bool have_var = false;
+	bool show_val = false;
 	unsigned int i;
 
 	seq_puts(m, HIST_PREFIX);
@@ -5872,16 +5880,13 @@ static int event_hist_trigger_print(struct seq_file *m,
 			continue;
 		}
 
-		if (i == HITCOUNT_IDX) {
-			seq_puts(m, "hitcount");
-			if (field->flags & HIST_FIELD_FL_PERCENT)
-				seq_puts(m, ".percent");
-			else if (field->flags & HIST_FIELD_FL_GRAPH)
-				seq_puts(m, ".graph");
-		} else {
+		if (!(field->flags & HIST_FIELD_FL_VAL))
+			continue;
+
+		if (show_val)
 			seq_puts(m, ",");
-			hist_field_print(m, field);
-		}
+		hist_field_print(m, field);
+		show_val = true;
 	}
 
 	if (have_var) {


  parent reply	other threads:[~2022-08-27  4:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-27  4:03 [PATCH v4 0/5] tracing/hist: Add percentage histogram suffixes Masami Hiramatsu (Google)
2022-08-27  4:03 ` [PATCH v4 1/5] tracing: Allow multiple hitcount values in histograms Masami Hiramatsu (Google)
2022-08-27  4:03 ` [PATCH v4 2/5] tracing: Fix to check event_mutex is held while accessing trigger list Masami Hiramatsu (Google)
2022-08-27  4:03 ` [PATCH v4 3/5] tracing: Add .percent suffix option to histogram values Masami Hiramatsu (Google)
2022-08-27  4:03 ` [PATCH v4 4/5] tracing: Add .graph suffix option to histogram value Masami Hiramatsu (Google)
2022-08-27  4:03 ` Masami Hiramatsu (Google) [this message]
2022-08-31 21:35 ` [PATCH v4 0/5] tracing/hist: Add percentage histogram suffixes Tom Zanussi
2022-08-31 23:02   ` Masami Hiramatsu
2022-09-01 20:59     ` Tom Zanussi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=166157303240.348924.7493529171143320258.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox