Skip to contentSkip to conversation

perf, tools: Fix adding multiple event groups

PATCH In review Andi Kleen 3 participants 3 messages Sep 14, 2017 – Sep 22, 2017 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 perf, tools: Fix adding multiple event groups

From: Andi Kleen <[email protected]>

The -M metric group parser threw away the events of earlier groups when multiple groups were specified. Fix this here by not overwriting the string incorrectly.

Now this works correctly:

% perf stat -M Summary,SMT --metric-only -a sleep 1

Performance counter stats for 'system wide':

Instructions CPI CLKS CPU_Utilization GFLOPs SMT_2T_Utilization SMT_2T_Utilization Kernel_Utilization CoreIPC CORE_CLKS
900907376.0 2.7 2398954144.0 0.1 0.0 0.2 0.2 0.1 0.4 2080822855.5

while previously it would only show the SMT metrics.

---
 tools/perf/util/metricgroup.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/metricgroup.c +4 -3
index 0794f02cbb8f..ce18474adc12 100644
@@ -373,9 +373,6 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
 	int ret = -EINVAL;
 	int i, j;
 
-	strbuf_init(events, 100);
-	strbuf_addf(events, "%s", "");
-
 	if (!map)
 		return 0;
 
@@ -433,6 +430,10 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
 	if (!nlist)
 		return -ENOMEM;
 	llist = nlist;
+
+	strbuf_init(events, 100);
+	strbuf_addf(events, "%s", "");
+
 	while ((p = strsep(&llist, ",")) != NULL) {
 		ret = metricgroup__add_metric(p, events, group_list);
 		if (ret == -EINVAL) {
Signature · 1 line
2.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andi Kleen

From: Andi Kleen <[email protected]>

The -M metric group parser threw away the events of earlier groups when multiple groups were specified. Fix this here by not overwriting the string incorrectly.

Now this works correctly:

% perf stat -M Summary,SMT --metric-only -a sleep 1

Quoted 8 lines

Performance counter stats for 'system wide':

Instructions CPI CLKS CPU_Utilization GFLOPs SMT_2T_Utilization SMT_2T_Utilization Kernel_Utilization CoreIPC CORE_CLKS
900907376.0 2.7 2398954144.0 0.1 0.0 0.2 0.2 0.1 0.4 2080822855.5

while previously it would only show the SMT metrics.

thanks,
jirka

#2 lore raw

[tip:perf/core] perf stat: Fix adding multiple event groups

In reply to Andi Kleen
perf stat: Fix adding multiple event groups
Commit-ID:  411bc316f3365363959c2c895af2618389534583
Gitweb:     http://git.kernel.org/tip/411bc316f3365363959c2c895af2618389534583
Author:     Andi Kleen <[email protected]>
AuthorDate: Thu, 14 Sep 2017 13:57:35 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 21 Sep 2017 13:12:58 -0300

perf stat: Fix adding multiple event groups

The -M metric group parser threw away the events of earlier groups when multiple groups were specified. Fix this here by not overwriting the string incorrectly.

Now this works correctly:

% perf stat -M Summary,SMT --metric-only -a sleep 1

Performance counter stats for 'system wide':

Instructions CPI CLKS CPU_Utilization GFLOPs SMT_2T_Utilization SMT_2T_Utilization Kernel_Utilization CoreIPC CORE_CLKS
900907376.0 2.7 2398954144.0 0.1 0.0 0.2 0.2 0.1 0.4 2080822855.5

while previously it would only show the SMT metrics.

---
 tools/perf/util/metricgroup.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/metricgroup.c +4 -3
index fa37ef7..0ddd9c1 100644
@@ -373,9 +373,6 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
 	int ret = -EINVAL;
 	int i, j;
 
-	strbuf_init(events, 100);
-	strbuf_addf(events, "%s", "");
-
 	if (!map)
 		return 0;
 
@@ -433,6 +430,10 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
 	if (!nlist)
 		return -ENOMEM;
 	llist = nlist;
+
+	strbuf_init(events, 100);
+	strbuf_addf(events, "%s", "");
+
 	while ((p = strsep(&llist, ",")) != NULL) {
 		ret = metricgroup__add_metric(p, events, group_list);
 		if (ret == -EINVAL) {