Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp598659imm; Fri, 15 Jun 2018 03:12:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIzR+Zt61pwGLrZFh4MAGaYYMa1YPYIohDmZI/kGMC+koYo4msaCPjPtX3FoPIMF8/o9xDp X-Received: by 2002:a63:6f8d:: with SMTP id k135-v6mr1027379pgc.48.1529057562478; Fri, 15 Jun 2018 03:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529057562; cv=none; d=google.com; s=arc-20160816; b=xN0z32d5lgp1277WLYQzC6wZw6uBXZw6Vm1C8yY2HHPFPIeE0NONJpgbLDTckGXmxz sr9bwtXKQsYMHA1iKxfgfhfoLhFgV8YaPZu41JwC5F4WL9yjNr2F9zFtfevacjHeIEDs T7jbEcl2JAh3fVQAnKc+j+hayXnYcIMzndypKa6aygPcKsHEMgKPcuCOmNfiRBxtnB8b xYUP05OOxvveo/qq7AgyOPnutGuyR6I3Wtdm0s/+5yDPJj+N52Ohw6kmOqeMG4LsU65T Ww3lor+iOyYbQCVQaM+3iAMm4B0nYAlCvKqQDWsQbuIGlgjNRQptG4FdC1voGs9LtlKF cCWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=BVA7vzV7Not0gnCwk20gqEnl+ZazrieysxxBmbihr6s=; b=Fmn0VPC8ew9XynYUhHLaMgYWrsylG8d+O6DW3rO2a2Lih0nqZu5CzoKIUcOdeRZB95 IXJtccME1mkmd/HbLoSqxQDm52zWkbIOPW7Vy/lQl+M9INYn+H25VvSabHSoEweu9CL5 HY1I1vtbDKL+PzFekZBsrcVsVVB+BosHl0efsHYOaTa1G4G/1Ag6X5Q0avQ9ldYckh9X 1gFvkBiEE7A/sCbauaqoyEOYhBF7fmTYAmohWQJ8SC3OPQICyOcoVP9R8NRLmRzoSfMN vdCV9e5V3CS1eehiLy7X9PNIfyXEyi6/mjZGPjGG5Z7apCm1cTWpJTYkW2TBFjvk5WsA KJeQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z13-v6si7926612plo.287.2018.06.15.03.12.27; Fri, 15 Jun 2018 03:12:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936234AbeFOKLT (ORCPT + 99 others); Fri, 15 Jun 2018 06:11:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38164 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934900AbeFOKLS (ORCPT ); Fri, 15 Jun 2018 06:11:18 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5FAAAYE078381 for ; Fri, 15 Jun 2018 06:11:17 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jm7gqs3s6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 15 Jun 2018 06:11:17 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Jun 2018 11:11:15 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 15 Jun 2018 11:11:12 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5FABBaa25165846 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 15 Jun 2018 10:11:11 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 09EB652041; Fri, 15 Jun 2018 10:00:37 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id B563E5203F; Fri, 15 Jun 2018 10:00:36 +0100 (BST) From: Thomas Richter To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org Cc: brueckner@linux.vnet.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, Thomas Richter , Jiri Olsa Subject: [PATCH 2/3 v2] perf alias: Rebuild alias expression string to make it comparable Date: Fri, 15 Jun 2018 12:11:04 +0200 X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180615101105.47047-1-tmricht@linux.ibm.com> References: <20180615101105.47047-1-tmricht@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18061510-0028-0000-0000-000002D1217A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18061510-0029-0000-0000-000023884E20 Message-Id: <20180615101105.47047-2-tmricht@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-15_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806150110 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Jiri Olsa --- 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 6d2012405f2b..208e427dc038 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); -- 2.14.3