Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2728534pxa; Tue, 25 Aug 2020 01:17:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSiqDAlxIusuEauuWAqiy1PuLifcypplv+F0zPDMYHzTfCCeyFxLiUtoDIKq+kOs/mvkRu X-Received: by 2002:a17:906:b286:: with SMTP id q6mr8787440ejz.99.1598343451475; Tue, 25 Aug 2020 01:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598343451; cv=none; d=google.com; s=arc-20160816; b=deFk1PBtj9qgw/QtIBo1zxko6zP1xjUKACoNaE/To/429qYNqRTpCC+ii5K+hHIF3e FynS2luFz+o+vd3KGK+UClAVdBvDwgJ8g3+niHC5Am2uPe38LgijxXXFlmRYlOSejRWf YhQHyik6iD6qCIV4tKWqn0dSbjNE1wPSnn9XABpqvhATWRP2mQWj3zLIxssOP2Uc8JpJ vbu0dJBzK2uJqm6r1XWrZB+UVUhIXhHa4PTYzXd0xpQi1Q7k+ziHr+57VQeVX1Cl9q3n z2SBFf/MiPJ/FcjH/dx3CvkadCuGk0Hbwp4lneoabwo1UQwMLCT6xqqD65QtQWTGeCPA n5nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=G3x9XcRvhd19ObK8OlQz91+iwzt4KFUnP9wwnIgTu9g=; b=Q/DUpfhxGTvg9kR6KeUH8VQXx61d0sn0vSiYoUQsKKQu2kaIGYjfUEWvALxAiRqrIT lHHF7i/u5gu+5imyO73WsYun214hXBzur4jdGvzt+UDn0f/9donCyL9ehWyJWpGI1w58 nv26pndY7mdbcFMZ8dN9rjapW5LSGGqo3TdXEDEE3VXC8Pzp90TbKGhxVGSLq2AhCdZP Vffy3FDc9J8t4k66ye5ZQwToPcbnxpvM28RdaYltc1A/eUUxCaOA+lsteo/QZUdBjHQK OWEeqLJ8qHFwxYyH2ugQNffT/+xzSho9JgZt1es10yGr46WUx5J8/0cobtyWUpQ8OWdt 9KgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si9003626edi.123.2020.08.25.01.17.09; Tue, 25 Aug 2020 01:17:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726365AbgHYIQj (ORCPT + 99 others); Tue, 25 Aug 2020 04:16:39 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2689 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725924AbgHYIQj (ORCPT ); Tue, 25 Aug 2020 04:16:39 -0400 Received: from lhreml724-chm.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 5C7627B498D567DE738A; Tue, 25 Aug 2020 09:16:37 +0100 (IST) Received: from [127.0.0.1] (10.47.8.13) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1913.5; Tue, 25 Aug 2020 09:16:36 +0100 Subject: Re: [RFC] perf/jevents: Add new structure to pass json fields. To: Kajol Jain , CC: , , , , , , , References: <20200825074041.378520-1-kjain@linux.ibm.com> From: John Garry Message-ID: Date: Tue, 25 Aug 2020 09:14:11 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <20200825074041.378520-1-kjain@linux.ibm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.8.13] X-ClientProxiedBy: lhreml702-chm.china.huawei.com (10.201.108.51) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/08/2020 08:40, Kajol Jain wrote: > This patch adds new structure called 'json_event' inside jevents.h > file to improve the callback prototype inside jevent files. > Initially, whenever user want to add new field, they need to update > in all function callback which make it more and more complex with > increased number of parmeters. > With this change, we just need to add it in new structure 'json_event'. > > > Signed-off-by: Kajol Jain > --- > tools/perf/pmu-events/jevents.c | 188 +++++++++++++------------------- > tools/perf/pmu-events/jevents.h | 28 +++-- > 2 files changed, 94 insertions(+), 122 deletions(-) > > This is the initial prototype to include structure for passing > json fileds. Please, Let me know if this is the right direction > to go forward. > This patch doen't include all the changes, like percore/perchip > field addition. If this looks fine I can send new patch set with > those changes. > > diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c > index fa86c5f997cc..606805af69fe 100644 > --- a/tools/perf/pmu-events/jevents.c > +++ b/tools/perf/pmu-events/jevents.c > @@ -318,12 +318,7 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) > close_table = 1; > } > > -static int print_events_table_entry(void *data, char *name, char *event, > - char *desc, char *long_desc, > - char *pmu, char *unit, char *perpkg, > - char *metric_expr, > - char *metric_name, char *metric_group, > - char *deprecated, char *metric_constraint) Right, too many paramaetrs of the same type, so looks reasonable to pass a struct [...] > if (arch_std) { > /* > * An arch standard event is referenced, so try to > * fixup any unassigned values. > */ > - err = try_fixup(fn, arch_std, &event, &desc, &name, > - &long_desc, &pmu, &filter, &perpkg, > - &unit, &metric_expr, &metric_name, > - &metric_group, eventcode, > - &deprecated, &metric_constraint); > + err = try_fixup(fn, arch_std, eventcode, je); > if (err) > goto free_strings; > } > - err = func(data, name, real_event(name, event), desc, long_desc, > - pmu, unit, perpkg, metric_expr, metric_name, > - metric_group, deprecated, metric_constraint); > + je->event = real_event(je->name, je->event); > + err = func(data, je); > free_strings: > - free(event); > - free(desc); > - free(name); > - free(long_desc); > free(extra_desc); > - free(pmu); > free(filter); > - free(perpkg); > - free(deprecated); > - free(unit); > - free(metric_expr); > - free(metric_name); > - free(metric_group); > - free(metric_constraint); > free(arch_std); > + free(je); > > if (err) > break; > diff --git a/tools/perf/pmu-events/jevents.h b/tools/perf/pmu-events/jevents.h > index 2afc8304529e..e696edf70e9a 100644 > --- a/tools/perf/pmu-events/jevents.h > +++ b/tools/perf/pmu-events/jevents.h Somewhat unrelated - this file only seems to be included in jevents.c, so I don't see why it exists... > @@ -2,14 +2,28 @@ > #ifndef JEVENTS_H > #define JEVENTS_H 1 > > +#include "pmu-events.h" > + > +struct json_event { > + char *name; > + char *event; > + char *desc; > + char *topic; > + char *long_desc; > + char *pmu; > + char *unit; > + char *perpkg; > + char *metric_expr; > + char *metric_name; > + char *metric_group; > + char *deprecated; > + char *metric_constraint; This looks very much like struct event_struct, so could look to consolidate: struct event_struct { struct list_head list; char *name; char *event; char *desc; char *long_desc; char *pmu; char *unit; char *perpkg; char *metric_expr; char *metric_name; char *metric_group; char *deprecated; char *metric_constraint; }; > +}; > + > int json_events(const char *fn, > - int (*func)(void *data, char *name, char *event, char *desc, > - char *long_desc, > - char *pmu, > - char *unit, char *perpkg, char *metric_expr, > - char *metric_name, char *metric_group, > - char *deprecated, char *metric_constraint), > - void *data); > + int (*func)(void *data, struct json_event *je), > + void *data); > + > char *get_cpu_str(void); > > #ifndef min >