From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753900AbaIKIrI (ORCPT ); Thu, 11 Sep 2014 04:47:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50884 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753315AbaIKIrF (ORCPT ); Thu, 11 Sep 2014 04:47:05 -0400 Date: Thu, 11 Sep 2014 10:46:59 +0200 From: Jiri Olsa To: kan.liang@intel.com Cc: acme@kernel.org, linux-kernel@vger.kernel.org, ak@linux.intel.com Subject: Re: [PATCH V5 2/3] perf tools: parse the pmu event prefix and surfix Message-ID: <20140911084659.GA7326@krava.brq.redhat.com> References: <1410371732-1185-1-git-send-email-kan.liang@intel.com> <1410371732-1185-2-git-send-email-kan.liang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1410371732-1185-2-git-send-email-kan.liang@intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 10, 2014 at 01:55:31PM -0400, kan.liang@intel.com wrote: > From: Kan Liang > SNIP > return 0; > } > > +static int > +comp_pmu(const void *p1, const void *p2) > +{ > + struct perf_pmu_event_symbol *pmu1 = > + (struct perf_pmu_event_symbol *) p1; > + struct perf_pmu_event_symbol *pmu2 = > + (struct perf_pmu_event_symbol *) p2; > + > + return strcmp(pmu1->symbol, pmu2->symbol); > +} > + > +/* > + * Read the pmu events list from sysfs > + * Save it into perf_pmu_events_list > + */ > +static void perf_pmu__parse_init(void) > +{ > + > + struct perf_pmu *pmu = NULL; > + struct perf_pmu_alias *alias; > + int len = 0; > + missing my previous comment being addressed: --- Why do we need to call scan here? Looks like: pmu = pmu_lookup("cpu") should be enough.. and could be used below as well --- or commented why not to do it.. jirka > + while ((pmu = perf_pmu__scan(pmu)) != NULL) > + list_for_each_entry(alias, &pmu->aliases, list) { > + if (!strcmp(pmu->name, "cpu")) { > + if (strchr(alias->name, '-')) > + len++; > + len++; > + } > + } > + if (len == 0) > + return; > + perf_pmu_events_list = > + malloc(sizeof(struct perf_pmu_event_symbol) * len); > + perf_pmu_events_list_num = len; > + > + pmu = NULL; > + len = 0; > + while ((pmu = perf_pmu__scan(pmu)) != NULL) > + list_for_each_entry(alias, &pmu->aliases, list) { > + if (!strcmp(pmu->name, "cpu")) { > + struct perf_pmu_event_symbol *p = > + perf_pmu_events_list + len; > + char *tmp = strchr(alias->name, '-'); > + > + if (tmp != NULL) { > + p->symbol = > + malloc(tmp - alias->name + 1); > + strlcpy(p->symbol, alias->name, > + tmp - alias->name + 1); > + p->type = KERNEL_PMU_EVENT_PREFIX; > + tmp++; > + p++; > + p->symbol = malloc(strlen(tmp) + 1); > + strcpy(p->symbol, tmp); > + p->type = KERNEL_PMU_EVENT_SUFFIX; > + len += 2; > + } else { > + p->symbol = > + malloc(strlen(alias->name) + 1); > + strcpy(p->symbol, alias->name); > + p->type = KERNEL_PMU_EVENT; > + len++; > + } > + } > + } > + qsort(perf_pmu_events_list, len, > + sizeof(struct perf_pmu_event_symbol), comp_pmu); > + > +} > + SNIP