Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4781720imm; Mon, 25 Jun 2018 23:59:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIu8z/gMh1L7l9T7s2ifGmL/PGFJWXAyA8KCPMCg2ukXNIbxx+6WfYxOqp14Bu7xIBiUJb1 X-Received: by 2002:a17:902:88:: with SMTP id a8-v6mr344761pla.156.1529996374189; Mon, 25 Jun 2018 23:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529996374; cv=none; d=google.com; s=arc-20160816; b=CHSljjbIwbsos88vsPiWWVDrN6UooSzW2jC+4HAVXaBKW9D/PY3O9URRysX1Y3zyTE uqIN0KkRNrmmka9qTOeVOj23AgHhKxKw3qdneg1KFLDaE5CFKrjGSqrjSliekw8glOgv ysq6wUz2yQwB5bKI2BIlAF8JhxbnL7D54EGSnLgHP2MHslLouVt43kXIPOaDW4timwEG co0SK5IDJzndJjtgm6/aCyiEJp9Qzl68NQPG+huA+WvuL7u6Wb/FxwQJWn0cDCEtWYpP gY2NAXZrbwNNhcJ1bqerKDrcRpsMTgQqcTFf6hO+7Hi6s/uhfiZQW0bpM8gekuMgmr0q M7hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=Q/0UwbRiFSH3BXhmujd3Ihkv02q6r4rH+TuqAL3oKGE=; b=HTa6aP3BFmyVTif8MRR3pqTjxq+WlfSFrqqZMoVlxypADW/KEk+EebCRCSgq5tJBd5 5eB0BdqwOU5YTHQHf7wYfSP4I8RunvsbaMlXKeXPhymwnKbCKIN7uXvXZj3uxhujCLqF ezraNvDgcria3P5IpZ0u/SU3rxQpC/ITwSHscBmGTI9sw+TwBTQG8WM+rHqhzQYKD01b n7ZwgVCU5BGWN5Y2tFcXsyRLD6Av1TqH7BR/cYBT0xk6fTDoq60XxnwIf8zXs6L6kHv2 WnOmG0lvNgf64DU2GWmXqoTn9MrBNuTLSsEjJabPQ2cGDhhfJ70KTclqqdDTzD3+88DG uCUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3-v6si787768pgv.573.2018.06.25.23.59.20; Mon, 25 Jun 2018 23:59:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752428AbeFZG6a (ORCPT + 99 others); Tue, 26 Jun 2018 02:58:30 -0400 Received: from terminus.zytor.com ([198.137.202.136]:54591 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbeFZG63 (ORCPT ); Tue, 26 Jun 2018 02:58:29 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w5Q6wKGt1591864 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 25 Jun 2018 23:58:20 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w5Q6wKAr1591861; Mon, 25 Jun 2018 23:58:20 -0700 Date: Mon, 25 Jun 2018 23:58:20 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Richter Message-ID: Cc: tmricht@linux.ibm.com, brueckner@linux.ibm.com, schwidefsky@de.ibm.com, jolsa@redhat.com, acme@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, heiko.carstens@de.ibm.com, tglx@linutronix.de, hpa@zytor.com Reply-To: tmricht@linux.ibm.com, brueckner@linux.ibm.com, schwidefsky@de.ibm.com, jolsa@redhat.com, acme@redhat.com, heiko.carstens@de.ibm.com, mingo@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, hpa@zytor.com In-Reply-To: <20180615101105.47047-2-tmricht@linux.ibm.com> References: <20180615101105.47047-2-tmricht@linux.ibm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf alias: Rebuild alias expression string to make it comparable Git-Commit-ID: 0c24d6fb7bd3578e5b9e4972d01bbe3d087ded33 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 0c24d6fb7bd3578e5b9e4972d01bbe3d087ded33 Gitweb: https://git.kernel.org/tip/0c24d6fb7bd3578e5b9e4972d01bbe3d087ded33 Author: Thomas Richter AuthorDate: Fri, 15 Jun 2018 12:11:04 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 25 Jun 2018 11:59:37 -0300 perf alias: Rebuild alias expression string to make it comparable PMU alias definitions in sysfs files may have spaces, newlines and numbers with leading zeroes. Some alias definitions may also appear in JSON files without spaces, etc. Scan alias definitions and remove leading zeroes, spaces, newlines, etc and rebuild string to make alias->str member comparable. s390 for example has terms specified as event=0x0091 (read from files ..//events/ and terms specified as event=0x91 (read from JSON files). Signed-off-by: Thomas Richter Reviewed-by: Hendrik Brueckner Cc: Heiko Carstens Cc: Jiri Olsa Cc: Martin Schwidefsky Link: http://lkml.kernel.org/r/20180615101105.47047-2-tmricht@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 2738fc8d200d..f321ce97d9ec 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -241,9 +241,11 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, char *metric_expr, char *metric_name) { + struct parse_events_term *term; struct perf_pmu_alias *alias; int ret; int num; + char newval[256]; alias = malloc(sizeof(*alias)); if (!alias) @@ -262,6 +264,27 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, return ret; } + /* Scan event and remove leading zeroes, spaces, newlines, some + * platforms have terms specified as + * event=0x0091 (read from files ..//events/ + * and terms specified as event=0x91 (read from JSON files). + * + * Rebuild string to make alias->str member comparable. + */ + memset(newval, 0, sizeof(newval)); + ret = 0; + list_for_each_entry(term, &alias->terms, list) { + if (ret) + ret += scnprintf(newval + ret, sizeof(newval) - ret, + ","); + if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) + ret += scnprintf(newval + ret, sizeof(newval) - ret, + "%s=%#x", term->config, term->val.num); + else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) + ret += scnprintf(newval + ret, sizeof(newval) - ret, + "%s=%s", term->config, term->val.str); + } + alias->name = strdup(name); if (dir) { /* @@ -285,7 +308,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, snprintf(alias->unit, sizeof(alias->unit), "%s", unit); } alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1; - alias->str = strdup(val); + alias->str = strdup(newval); list_add_tail(&alias->list, list);