Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp12851471pxu; Sat, 2 Jan 2021 14:08:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtYLA6nyV3mJ1Eqvcf5Nr8diS3lXmMUNSvOISWQhI5EBzH5tPJvts01quLL385ekRPEjFB X-Received: by 2002:a05:6402:312c:: with SMTP id dd12mr65806825edb.327.1609625288674; Sat, 02 Jan 2021 14:08:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609625288; cv=none; d=google.com; s=arc-20160816; b=duPsPqpDQW5nicuTzh+CWUTMY7BpTS/rQY76g7OH52yf+cIzk1aZDBPwDnOAAF1mV2 q5OlxoP74AbfeQwh4EFJk+7LTuSgwUxuGckI1Dn3XYMPrdSMYNyfSWwUvPKfVTLNPaxj CKZUfvFpjnFNGn0WxzHd56JeWvEgVXH8hOAsnLg9eAphN2FFEw951c6/M3iFsX3G5VNI VvyALXfHLj9J7kkHoVwT2RLJeRKaMxiNQMX7GW3zB2WoflbetNYwDnwA4LJYtva+1Zxe 0J33ZPyQT61qXmYq7ahEH/l5dDKmhUroiZQBXeCjVWW1w0HFfTFQIyQmt1B0nKCoX+ZQ fl+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DNIioq2y9bjujbH1ZF1WwLQytjQFEZyIV0S+ulK840Y=; b=vb3ix/MvzApQ9CY6qu+WnQ1zwj+g32Kcd1D/nHObBFt3YYIPMtXegx34udqpW5XF86 lyR44TRpYfWjpB2UZMU6cYO+NMcuPFpAEfP/SbYAErhm60p9/3zM7uYjdNU+qIbr6hhM 3Ws5PFW63c+KFSbSNndLmS0yFBljSDjJcGXyfG6smPfr6FqRwZdQZo+2lvq5KAzdYGTe Eut+CST5G35aFnvIb0b6l68agwXg7Y4B5A9AGWkZ6KkfXXkFZI8M+PD83tEO2O4Lyij+ ztOp8PjK2zgjD1kgf4sSqt/bmKJXbA1p+AYTxSoaocgBpdL9HLv2TzefQTsQEU6wz1ND iFPw== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si31395982edq.432.2021.01.02.14.07.45; Sat, 02 Jan 2021 14:08:08 -0800 (PST) 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbhABWFv convert rfc822-to-8bit (ORCPT + 99 others); Sat, 2 Jan 2021 17:05:51 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:48257 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbhABWFu (ORCPT ); Sat, 2 Jan 2021 17:05:50 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-TYf5ZODQO5GYtVsn8-Jg_w-1; Sat, 02 Jan 2021 17:04:53 -0500 X-MC-Unique: TYf5ZODQO5GYtVsn8-Jg_w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4DC2107ACE3; Sat, 2 Jan 2021 22:04:51 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25E6FE168; Sat, 2 Jan 2021 22:04:48 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: [PATCH 02/22] perf tools: Add config set interface Date: Sat, 2 Jan 2021 23:04:21 +0100 Message-Id: <20210102220441.794923-3-jolsa@kernel.org> In-Reply-To: <20210102220441.794923-1-jolsa@kernel.org> References: <20210102220441.794923-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add interface to load config set from custom file by using perf_config_set__load_file function. It will be used in perf daemon command to process custom config file. Signed-off-by: Jiri Olsa --- tools/perf/util/config.c | 28 +++++++++++++++++++++++----- tools/perf/util/config.h | 3 +++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 20be0504fb95..222cb2e2de25 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -738,6 +738,18 @@ struct perf_config_set *perf_config_set__new(void) return set; } +struct perf_config_set *perf_config_set__load_file(const char *file) +{ + struct perf_config_set *set = zalloc(sizeof(*set)); + + if (set) { + INIT_LIST_HEAD(&set->sections); + perf_config_from_file(collect_config, file, set); + } + + return set; +} + static int perf_config__init(void) { if (config_set == NULL) @@ -746,17 +758,15 @@ static int perf_config__init(void) return config_set == NULL; } -int perf_config(config_fn_t fn, void *data) +int perf_config_set(struct perf_config_set *set, + config_fn_t fn, void *data) { int ret = 0; char key[BUFSIZ]; struct perf_config_section *section; struct perf_config_item *item; - if (config_set == NULL && perf_config__init()) - return -1; - - perf_config_set__for_each_entry(config_set, section, item) { + perf_config_set__for_each_entry(set, section, item) { char *value = item->value; if (value) { @@ -778,6 +788,14 @@ int perf_config(config_fn_t fn, void *data) return ret; } +int perf_config(config_fn_t fn, void *data) +{ + if (config_set == NULL && perf_config__init()) + return -1; + + return perf_config_set(config_set, fn, data); +} + void perf_config__exit(void) { perf_config_set__delete(config_set); diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h index 2f753b2a034b..ee5a242446e9 100644 --- a/tools/perf/util/config.h +++ b/tools/perf/util/config.h @@ -29,6 +29,8 @@ typedef int (*config_fn_t)(const char *, const char *, void *); int perf_default_config(const char *, const char *, void *); int perf_config(config_fn_t fn, void *); +int perf_config_set(struct perf_config_set *set, + config_fn_t fn, void *data); int perf_config_int(int *dest, const char *, const char *); int perf_config_u8(u8 *dest, const char *name, const char *value); int perf_config_u64(u64 *dest, const char *, const char *); @@ -37,6 +39,7 @@ int config_error_nonbool(const char *); const char *perf_etc_perfconfig(void); struct perf_config_set *perf_config_set__new(void); +struct perf_config_set *perf_config_set__load_file(const char *file); void perf_config_set__delete(struct perf_config_set *set); int perf_config_set__collect(struct perf_config_set *set, const char *file_name, const char *var, const char *value); -- 2.26.2