]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
perf config: Call perf_config__init() lazily
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 16 May 2018 19:09:08 +0000 (16:09 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 16 May 2018 19:11:09 +0000 (16:11 -0300)
We check what perf_config__init() does at each perf_config() call,
namely if the static perf_config instance was created, so instead of
bailing out in that case, try to allocate it, bailing if it fails.

Now to get the perf_config() call out of the start of perf's main()
function, doing it also lazily.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Taeung Song <treeze.taeung@gmail.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-4bo45k6ivsmbxpfpdte4orsg@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/perf.c
tools/perf/util/config.c
tools/perf/util/config.h

index 20a08cb323329be20348fbf513091d40780ac12a..cd6ea55d4b0c64b46b0e8070b844fca1258fda17 100644 (file)
@@ -458,7 +458,6 @@ int main(int argc, const char **argv)
 
        srandom(time(NULL));
 
-       perf_config__init();
        err = perf_config(perf_default_config, NULL);
        if (err)
                return err;
index 84eb9393c7db1bf304b77d9984a11d5aea6a673d..5ac157056cdfcc1f536b68927500d5893abd63bc 100644 (file)
@@ -707,6 +707,14 @@ struct perf_config_set *perf_config_set__new(void)
        return set;
 }
 
+static int perf_config__init(void)
+{
+       if (config_set == NULL)
+               config_set = perf_config_set__new();
+
+       return config_set == NULL;
+}
+
 int perf_config(config_fn_t fn, void *data)
 {
        int ret = 0;
@@ -714,7 +722,7 @@ int perf_config(config_fn_t fn, void *data)
        struct perf_config_section *section;
        struct perf_config_item *item;
 
-       if (config_set == NULL)
+       if (config_set == NULL && perf_config__init())
                return -1;
 
        perf_config_set__for_each_entry(config_set, section, item) {
@@ -735,12 +743,6 @@ int perf_config(config_fn_t fn, void *data)
        return ret;
 }
 
-void perf_config__init(void)
-{
-       if (config_set == NULL)
-               config_set = perf_config_set__new();
-}
-
 void perf_config__exit(void)
 {
        perf_config_set__delete(config_set);
index baf82bf227acbadfb1ca547584bd123e121b3f14..bd0a5897c76a5daad5f68f6b561d1a744f029b76 100644 (file)
@@ -38,7 +38,6 @@ struct perf_config_set *perf_config_set__new(void);
 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);
-void perf_config__init(void);
 void perf_config__exit(void);
 void perf_config__refresh(void);