From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761421Ab3EAPQj (ORCPT ); Wed, 1 May 2013 11:16:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42115 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752938Ab3EAPQb (ORCPT ); Wed, 1 May 2013 11:16:31 -0400 From: Jiri Olsa To: linux-kernel@vger.kernel.org Cc: Jiri Olsa , Andi Kleen , Corey Ashford , David Ahern , Frederic Weisbecker , Ingo Molnar , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Ulrich Drepper , Arnaldo Carvalho de Melo , Will Deacon , Stephane Eranian Subject: [PATCH 2/8] perf tools: Factorize event parsing to be more general Date: Wed, 1 May 2013 17:15:40 +0200 Message-Id: <1367421346-18257-3-git-send-email-jolsa@redhat.com> In-Reply-To: <1367421346-18257-1-git-send-email-jolsa@redhat.com> References: <1367421346-18257-1-git-send-email-jolsa@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Making the event parsing processing more general so we can plug in strings with special processing like formula definition. The formula changes are coming in following patches. Signed-off-by: Jiri Olsa Cc: Andi Kleen Cc: Corey Ashford Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Ulrich Drepper Cc: Arnaldo Carvalho de Melo Cc: Will Deacon Cc: Stephane Eranian --- tools/perf/util/parse-events.c | 21 ++++++++++++++++++ tools/perf/util/parse-events.h | 17 +++++++++++++++ tools/perf/util/parse-events.y | 48 +++++++++++++++++++++++++++++++----------- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6c8bb0f..e8e9dc8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1238,3 +1238,24 @@ void parse_events__free_terms(struct list_head *terms) free(terms); } + +int parse_events_config_process(struct parse_events_evlist *data, + struct list_head *head) +{ + struct parse_events_config *cfg, *h; + + list_for_each_entry_safe(cfg, h, head, list) { + switch (cfg->type) { + case PARSE_EVENTS_CONFIG_EVENTS: + parse_events_update_lists(cfg->events, &data->list); + break; + default: + break; + } + + list_del(&cfg->list); + free(cfg); + } + + return 0; +} diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 8a48593..98810f1 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -71,6 +71,23 @@ struct parse_events_terms { struct list_head *terms; }; +enum parse_events_config_type { + PARSE_EVENTS_CONFIG_EVENTS, +}; + +struct parse_events_config { + enum parse_events_config_type type; + + union { + struct list_head *events; + void *val; + }; + + struct list_head list; +}; + +int parse_events_config_process(struct parse_events_evlist *data, + struct list_head *head); int parse_events__is_hardcoded_term(struct parse_events_term *term); int parse_events_term__num(struct parse_events_term **_term, int type_term, char *config, u64 num); diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index afc44c1..bae1879 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -30,6 +30,21 @@ static inc_group_count(struct list_head *list, data->nr_groups++; } +#define CONFIG(t, v) ({ \ + struct parse_events_config *c = zalloc(sizeof(*c)); \ + ABORT_ON(!c); \ + c->type = PARSE_EVENTS_CONFIG_ ## t; \ + c->val = v; \ + c; \ +}) + +#define HEAD() ({ \ + struct list_head *h = zalloc(sizeof(*h)); \ + ABORT_ON(!h); \ + INIT_LIST_HEAD(h); \ + h; \ +}) + %} %token PE_START_EVENTS PE_START_TERMS @@ -69,6 +84,7 @@ static inc_group_count(struct list_head *list, %type group_def %type group %type groups +%type groups_config %union { @@ -76,6 +92,7 @@ static inc_group_count(struct list_head *list, u64 num; struct list_head *head; struct parse_events_term *term; + struct parse_events_config *cfg; } %% @@ -88,31 +105,38 @@ start_events: groups { struct parse_events_evlist *data = _data; - parse_events_update_lists($1, &data->list); + ABORT_ON(parse_events_config_process(data, $1)); } groups: -groups ',' group +groups ',' groups_config { - struct list_head *list = $1; - struct list_head *group = $3; + struct list_head *head = $1; + struct parse_events_config *cfg = $3; - parse_events_update_lists(group, list); - $$ = list; + list_add_tail(&cfg->list, head); + $$ = head; } | -groups ',' event +groups_config { - struct list_head *list = $1; - struct list_head *event = $3; + struct list_head *head = HEAD(); + struct parse_events_config *cfg = $1; - parse_events_update_lists(event, list); - $$ = list; + list_add_tail(&cfg->list, head); + $$ = head; } -| + +groups_config: group +{ + $$ = CONFIG(EVENTS, $1); +} | event +{ + $$ = CONFIG(EVENTS, $1); +} group: group_def ':' PE_MODIFIER_EVENT -- 1.7.11.7