From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753928AbbDNGo4 (ORCPT ); Tue, 14 Apr 2015 02:44:56 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:52044 "EHLO e19.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752987AbbDNGlY (ORCPT ); Tue, 14 Apr 2015 02:41:24 -0400 From: Sukadev Bhattiprolu To: mingo@redhat.com, ak@linux.intel.com, Michael Ellerman , Jiri Olsa , Arnaldo Carvalho de Melo Cc: peterz@infradead.org, namhyung@kernel.org, linuxppc-dev@lists.ozlabs.org, Subject: [PATCH v9 02/11] perf, tools: Add support for text descriptions of events and alias add Date: Mon, 13 Apr 2015 23:40:55 -0700 Message-Id: <1428993665-2133-3-git-send-email-sukadev@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1428993665-2133-1-git-send-email-sukadev@linux.vnet.ibm.com> References: <1428993665-2133-1-git-send-email-sukadev@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15041406-0013-0000-0000-00000060D0E1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Change pmu.c to allow descriptions of events and add interfaces to add aliases at runtime from another file. To be used by jevents in a followon patch Acked-by: Namhyung Kim Signed-off-by: Andi Kleen Signed-off-by: Sukadev Bhattiprolu --- Changelog[v9] by Sukadev Bhattiprolu Rebase to 4.0 v2: Move perf list changes to other patch. --- tools/perf/util/json.c | 1 + tools/perf/util/pmu.c | 48 +++++++++++++++++++++++++++++++++--------------- tools/perf/util/pmu.h | 1 + 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/json.c b/tools/perf/util/json.c index e20001f..2219844 100644 --- a/tools/perf/util/json.c +++ b/tools/perf/util/json.c @@ -38,6 +38,7 @@ #include "jsmn.h" #include "json.h" #include +#include "debug.h" static char *mapfile(const char *fn, size_t *size) { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4841167..527da74 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -198,17 +198,12 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, return 0; } -static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) +static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir, + char *desc, char *val) { struct perf_pmu_alias *alias; - char buf[256]; int ret; - ret = fread(buf, 1, sizeof(buf), file); - if (ret == 0) - return -EINVAL; - buf[ret] = 0; - alias = malloc(sizeof(*alias)); if (!alias) return -ENOMEM; @@ -218,26 +213,49 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI alias->unit[0] = '\0'; alias->per_pkg = false; - ret = parse_events_terms(&alias->terms, buf); + ret = parse_events_terms(&alias->terms, val); if (ret) { + pr_err("Cannot parse alias %s: %d\n", val, ret); free(alias); return ret; } alias->name = strdup(name); - /* - * load unit name and scale if available - */ - perf_pmu__parse_unit(alias, dir, name); - perf_pmu__parse_scale(alias, dir, name); - perf_pmu__parse_per_pkg(alias, dir, name); - perf_pmu__parse_snapshot(alias, dir, name); + + if (dir) { + /* + * load unit name and scale if available + */ + perf_pmu__parse_unit(alias, dir, name); + perf_pmu__parse_scale(alias, dir, name); + perf_pmu__parse_per_pkg(alias, dir, name); + perf_pmu__parse_snapshot(alias, dir, name); + } + + alias->desc = desc ? strdup(desc) : NULL; list_add_tail(&alias->list, list); return 0; } +static int perf_pmu__new_alias(struct list_head *list, + char *dir, + char *name, + FILE *file) +{ + char buf[256]; + int ret; + + ret = fread(buf, 1, sizeof(buf), file); + if (ret == 0) + return -EINVAL; + buf[ret] = 0; + + return __perf_pmu__new_alias(list, name, dir, NULL, buf); +} + + static inline bool pmu_alias_info_file(char *name) { size_t len; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 6b1249f..d06496d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -37,6 +37,7 @@ struct perf_pmu_info { struct perf_pmu_alias { char *name; + char *desc; struct list_head terms; /* HEAD struct parse_events_term -> list */ struct list_head list; /* ELEM */ char unit[UNIT_MAX_LEN+1]; -- 1.7.9.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from e9.ny.us.ibm.com (e9.ny.us.ibm.com [32.97.182.139]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 375031A0C8E for ; Tue, 14 Apr 2015 16:41:24 +1000 (AEST) Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Apr 2015 02:41:22 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 860D2C9004A for ; Tue, 14 Apr 2015 02:32:29 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3E6fKBX25428086 for ; Tue, 14 Apr 2015 06:41:20 GMT Received: from d01av02.pok.ibm.com (localhost [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3E6fHq7021762 for ; Tue, 14 Apr 2015 02:41:19 -0400 From: Sukadev Bhattiprolu To: mingo@redhat.com, ak@linux.intel.com, Michael Ellerman , Jiri Olsa , Arnaldo Carvalho de Melo Subject: [PATCH v9 02/11] perf, tools: Add support for text descriptions of events and alias add Date: Mon, 13 Apr 2015 23:40:55 -0700 Message-Id: <1428993665-2133-3-git-send-email-sukadev@linux.vnet.ibm.com> In-Reply-To: <1428993665-2133-1-git-send-email-sukadev@linux.vnet.ibm.com> References: <1428993665-2133-1-git-send-email-sukadev@linux.vnet.ibm.com> Cc: peterz@infradead.org, namhyung@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andi Kleen Change pmu.c to allow descriptions of events and add interfaces to add aliases at runtime from another file. To be used by jevents in a followon patch Acked-by: Namhyung Kim Signed-off-by: Andi Kleen Signed-off-by: Sukadev Bhattiprolu --- Changelog[v9] by Sukadev Bhattiprolu Rebase to 4.0 v2: Move perf list changes to other patch. --- tools/perf/util/json.c | 1 + tools/perf/util/pmu.c | 48 +++++++++++++++++++++++++++++++++--------------- tools/perf/util/pmu.h | 1 + 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/json.c b/tools/perf/util/json.c index e20001f..2219844 100644 --- a/tools/perf/util/json.c +++ b/tools/perf/util/json.c @@ -38,6 +38,7 @@ #include "jsmn.h" #include "json.h" #include +#include "debug.h" static char *mapfile(const char *fn, size_t *size) { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4841167..527da74 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -198,17 +198,12 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, return 0; } -static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) +static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir, + char *desc, char *val) { struct perf_pmu_alias *alias; - char buf[256]; int ret; - ret = fread(buf, 1, sizeof(buf), file); - if (ret == 0) - return -EINVAL; - buf[ret] = 0; - alias = malloc(sizeof(*alias)); if (!alias) return -ENOMEM; @@ -218,26 +213,49 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI alias->unit[0] = '\0'; alias->per_pkg = false; - ret = parse_events_terms(&alias->terms, buf); + ret = parse_events_terms(&alias->terms, val); if (ret) { + pr_err("Cannot parse alias %s: %d\n", val, ret); free(alias); return ret; } alias->name = strdup(name); - /* - * load unit name and scale if available - */ - perf_pmu__parse_unit(alias, dir, name); - perf_pmu__parse_scale(alias, dir, name); - perf_pmu__parse_per_pkg(alias, dir, name); - perf_pmu__parse_snapshot(alias, dir, name); + + if (dir) { + /* + * load unit name and scale if available + */ + perf_pmu__parse_unit(alias, dir, name); + perf_pmu__parse_scale(alias, dir, name); + perf_pmu__parse_per_pkg(alias, dir, name); + perf_pmu__parse_snapshot(alias, dir, name); + } + + alias->desc = desc ? strdup(desc) : NULL; list_add_tail(&alias->list, list); return 0; } +static int perf_pmu__new_alias(struct list_head *list, + char *dir, + char *name, + FILE *file) +{ + char buf[256]; + int ret; + + ret = fread(buf, 1, sizeof(buf), file); + if (ret == 0) + return -EINVAL; + buf[ret] = 0; + + return __perf_pmu__new_alias(list, name, dir, NULL, buf); +} + + static inline bool pmu_alias_info_file(char *name) { size_t len; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 6b1249f..d06496d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -37,6 +37,7 @@ struct perf_pmu_info { struct perf_pmu_alias { char *name; + char *desc; struct list_head terms; /* HEAD struct parse_events_term -> list */ struct list_head list; /* ELEM */ char unit[UNIT_MAX_LEN+1]; -- 1.7.9.5