lkml.org 
[lkml]   [2014]   [Sep]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V5 2/3] perf tools: parse the pmu event prefix and surfix
On Wed, Sep 10, 2014 at 01:55:31PM -0400, kan.liang@intel.com wrote:
> From: Kan Liang <kan.liang@intel.com>
>

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


\
 
 \ /
  Last update: 2014-09-11 11:21    [W:0.092 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site