Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp287158lqo; Thu, 9 May 2024 22:38:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWGzN44L2jNG3oHLBp4sP5lPs0+ebYOQXFVhvAJ7Jx2Us/xJkNNqS7D0p/WfJ+SojPNYW4hxS422ptQERqPW6cvwZMj4CBP8ymnRq1msQ== X-Google-Smtp-Source: AGHT+IEYaz6+auF32F1DABhfbJFX75nADANrKDJYK8JEoKmZ+NmE8+Psvo2KcLChDr9QRzQjBagb X-Received: by 2002:a05:620a:84f:b0:790:fd04:5a1b with SMTP id af79cd13be357-792c7574a7fmr171222085a.9.1715319517438; Thu, 09 May 2024 22:38:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715319517; cv=pass; d=google.com; s=arc-20160816; b=jx4eWZCqV46JnPSrLkxvwunGxddoLcneCIhYpN2T+bDj2p1fyVI3fwxufob5VuXlQ7 Z/dDazJ0l2+2b/ySRu2mjsPxJOSRADyjaBkNMizUOjXAemSCudYauTqsr4mB5/0zxzGz ZNU4h71mfDyMggu17KFejcZ2+0hoQb2m8+37eRMsNMVXAMDzEK+32a/oObkJYQltBa8N Pu0OdsgpA5rwNUbYlZQBOKTyaIClJbemlnvo9ckIdMOzD3RluiwWA4DDpXhBzAg5oCGY 80npMinZiJBKhJ2msVQhmgdjEQuTNzlHvS04UL58LFOxelUxNAN+HfpvyE5uGVakbsVm t5yA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=U81cdFZOryTWzARq4P9O2qKcBTbob0BFWgpG3EYHhxM=; fh=nwGiDGs0yi1u5ZhrzHmWIlKcYeR1/UCnxOdS7ieLEY0=; b=CNhP0dN3dmwIQUtRvCB7dTUzCwlG8BYxfSmtdEQtwTkFXX9G1jmOScfVMO1wUNLHbu 675cnNXanmQ6XBPOojhFsyMh/tLy1l7wTidao3B4yRDC2hd4ZFkR64+skoAHiYwq64BD VMAUziFm283ckfqtEcdz+Iafb/16AqCXvuFbenUtDwIp+rI/tQVKdvdbUjqVgzYBG8M+ 5LPNVLg5oW0MUQA/NOAQW6jV4gjifCPiT5YQq9iA3t8dX2lxMyDFrfOiwthnl+V/g57b tKGMYg7TL7PvowEexodO3M79AmGTNxQN1Fk0dOEL/9gYPhvtmhm7SmNeP63oP5+6gLN2 YZug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E9Ay2NYv; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175295-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf2973f1si282731785a.163.2024.05.09.22.38.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 22:38:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175295-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E9Ay2NYv; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175295-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C06651C20D97 for ; Fri, 10 May 2024 05:38:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EC221607B1; Fri, 10 May 2024 05:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E9Ay2NYv" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C365515E800 for ; Fri, 10 May 2024 05:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715319491; cv=none; b=tJZan7rTgIWsfIhGQtJhFnDsQFJIeu214AvLfu6T/n47g83X06inz2sGf5Hf41FFt/ufr0KkRj2hshOPL56sQzfGEMb3uIk0V8gnales7z1FUzZLN6Jy3shRiYkV+sovUmAaeVq1tQOWszgU9D89pNiqLmu//G/VEEpVarLOrPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715319491; c=relaxed/simple; bh=zNU/+vvLwssObyq665v420J21ONwE2lm3SPbdGLqo8o=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BWhpY0IUwRTV1/gg0cSwWMsDT9Ove+0YCybBrcj6O6j3lyxZ/gm5uiT9WuckfQxaGTM/F1hY3tKbZGO7ETdg5+tc0S0rzu8G3NI/IJ0oIzc5bTyeeCpH5P6c/YhNL4zuxhqANTzen7USy8+m54SVxzTFHWdwe9D/b1NENPaBh0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=E9Ay2NYv; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be4601434so30386637b3.3 for ; Thu, 09 May 2024 22:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715319489; x=1715924289; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=U81cdFZOryTWzARq4P9O2qKcBTbob0BFWgpG3EYHhxM=; b=E9Ay2NYvkOyVjbvspBHGn2SUF5FAS5vWERXYyVUdbqm86SmN90aurIgG9tsiWqNGdT aKPQJQeEONSvpOTKNswD8nJgAXIEoyazcu7mJVk1HmVlnlz6pCdnbXtyDJDPib3akSwT mBfBFrGu3fWlSyNiMP58SosJ2KDMkNMHjqDriupJEt7IcIGM/kvJ40Q1Hy6OP2XJQ/Pk plxRkB0TFj/zzLaLYHxUlTaeILCBIpa9KsUZMydMSprsPl9rmyIKB1sqc1ngM4lr/KGX jGcJ3g5ffs1D1dZCqs4gLZRHAkJWWUGlqpBABK+eU1kYrD9W6qrfGV2ADgRz3Uey8xEy +S4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715319489; x=1715924289; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U81cdFZOryTWzARq4P9O2qKcBTbob0BFWgpG3EYHhxM=; b=Pj7zcgiTQdHyQoy7ERCxXriY/UdnGbd+ZcA3RofYkEHw6GS8Qf/n+pPONIACyjTLqp 7+PLLggt60N6lxP5GJKg9I4DmP5Elf8zFmp4t+JJ+fNZA9zuRwVGwqXVX7h23a9BLZiQ DHO5lCbDzMxipcrcsOxNEb9ufyqA30ZGLe1imq0o+iEYbVL1AX0WbzmG9fEgJS1q2tI0 Sk+vjzzpyjvI2JMIWNI1YI8Cn/c+zHUB9Tl/rhD7nhFj1zLGTq9NjhqoWATsvKFnJIzt Fu1byDHd/7qjW9ngZtJr7TuUJFzk39MbD/2b9xWKZT5JF1FvcV8HVsFlbqEmPyreuq1r od5w== X-Forwarded-Encrypted: i=1; AJvYcCUPN85lkyLcDe9c3Lq8hj/YmxqbevQb0HZvVgDo8H2mv5VDixS4MfaTw4+Ih4JGS2NCc8Spa2b3qaLJ8qwjr3mwLrvWHZaqCGPTItaD X-Gm-Message-State: AOJu0Yz3m9EJbn2ozVTj9dhdasQzbyy6y7egJHZhXRnLMTqIdkXuG0Ks umMUMLCJZ/npgkPowrgLHmiywg+eOpwKecuGBVJzcjgXSKbnuKRC0aDjciQFf9ZR5ihtq6+RBeR F7CH6jw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:79ed:c375:51e3:ed39]) (user=irogers job=sendgmr) by 2002:a05:690c:284:b0:614:f416:9415 with SMTP id 00721157ae682-622b0163084mr4450367b3.7.1715319488741; Thu, 09 May 2024 22:38:08 -0700 (PDT) Date: Thu, 9 May 2024 22:37:02 -0700 In-Reply-To: <20240510053705.2462258-1-irogers@google.com> Message-Id: <20240510053705.2462258-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510053705.2462258-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Subject: [PATCH v3 2/5] perf stat: Uniquify event name improvements From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , James Clark , Yang Jihong , Ze Gao , Leo Yan , Song Liu , K Prateek Nayak , Kaige Ye , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Without aggregation on Intel: ``` $ perf stat -e instructions,cycles ... ``` Will use "cycles" for the name of the legacy cycles event but as "instructions" has a sysfs name it will and a "[cpu]" PMU suffix. This often breaks things as the space between the event and the PMU name look like an extra column. The existing uniquify logic was also uniquifying in cases when all events are core and not with uncore events, it was not correctly handling modifiers, etc. Change the logic so that an initial pass that can disable uniquification is run. For individual counters, disable uniquification in more cases such as for consistency with legacy events or for libpfm4 events. Don't use the "[pmu]" style suffix in uniquification, always use "pmu/.../". Change how modifiers/terms are handled in the uniquification so that they look like parse-able events. This fixes "102: perf stat metrics (shadow stat) test:" that has been failing due to "instructions [cpu]" breaking its column/awk logic when values aren't aggregated. This started happening when instructions could match a sysfs rather than a legacy event, so the fixes tag reflects this. Fixes: 617824a7f0f7 ("perf parse-events: Prefer sysfs/JSON hardware events over legacy") Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 101 +++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bfc1d705f437..ea11e3437444 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -868,38 +868,66 @@ static void printout(struct perf_stat_config *config, struct outstate *os, static void uniquify_event_name(struct evsel *counter) { - char *new_name; - char *config; - int ret = 0; + const char *name, *pmu_name; + char *new_name, *config; + int ret; - if (counter->uniquified_name || counter->use_config_name || - !counter->pmu_name || !strncmp(evsel__name(counter), counter->pmu_name, - strlen(counter->pmu_name))) + /* The evsel was already uniquified. */ + if (counter->uniquified_name) return; - config = strchr(counter->name, '/'); + /* Avoid checking to uniquify twice. */ + counter->uniquified_name = true; + + /* The evsel has a "name=" config term or is from libpfm. */ + if (counter->use_config_name || counter->is_libpfm_event) + return; + + /* Legacy no PMU event, don't uniquify. */ + if (!counter->pmu || + (counter->pmu->type < PERF_TYPE_MAX && counter->pmu->type != PERF_TYPE_RAW)) + return; + + /* A sysfs or json event replacing a legacy event, don't uniquify. */ + if (counter->pmu->is_core && counter->alternate_hw_config != PERF_COUNT_HW_MAX) + return; + + name = evsel__name(counter); + pmu_name = counter->pmu->name; + /* Already prefixed by the PMU name. */ + if (!strncmp(name, pmu_name, strlen(pmu_name))) + return; + + config = strchr(name, '/'); if (config) { - if (asprintf(&new_name, - "%s%s", counter->pmu_name, config) > 0) { - free(counter->name); - counter->name = new_name; - } - } else { - if (evsel__is_hybrid(counter)) { - ret = asprintf(&new_name, "%s/%s/", - counter->pmu_name, counter->name); + int len = config - name; + + if (config[1] == '/') { + /* case: event// */ + ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 2); } else { - ret = asprintf(&new_name, "%s [%s]", - counter->name, counter->pmu_name); + /* case: event/.../ */ + ret = asprintf(&new_name, "%s/%.*s,%s", pmu_name, len, name, config + 1); } + } else { + config = strchr(name, ':'); + if (config) { + /* case: event:.. */ + int len = config - name; - if (ret) { - free(counter->name); - counter->name = new_name; + ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 1); + } else { + /* case: event */ + ret = asprintf(&new_name, "%s/%s/", pmu_name, name); } } - - counter->uniquified_name = true; + if (ret > 0) { + free(counter->name); + counter->name = new_name; + } else { + /* ENOMEM from asprintf. */ + counter->uniquified_name = false; + } } static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *config) @@ -1541,6 +1569,31 @@ static void print_cgroup_counter(struct perf_stat_config *config, struct evlist print_metric_end(config, os); } +static void disable_uniquify(struct evlist *evlist) +{ + struct evsel *counter; + struct perf_pmu *last_pmu = NULL; + bool first = true; + + evlist__for_each_entry(evlist, counter) { + /* If PMUs vary then uniquify can be useful. */ + if (!first && counter->pmu != last_pmu) + return; + first = false; + if (counter->pmu) { + /* Allow uniquify for uncore PMUs. */ + if (!counter->pmu->is_core) + return; + /* Keep hybrid event names uniquified for clarity. */ + if (perf_pmus__num_core_pmus() > 1) + return; + } + } + evlist__for_each_entry_continue(evlist, counter) { + counter->uniquified_name = true; + } +} + void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config, struct target *_target, struct timespec *ts, int argc, const char **argv) @@ -1554,6 +1607,8 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf .first = true, }; + disable_uniquify(evlist); + if (config->iostat_run) evlist->selected = evlist__first(evlist); -- 2.45.0.118.g7fe29c98d7-goog