diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-16 15:09:08 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-16 15:11:09 -0400 |
commit | d01bd1ac920e98e2a64f6bb5adf907180e0aaac7 (patch) | |
tree | 468945e79a156f11354c304b16cc0d0199f997ea /tools | |
parent | 5aafae8d097e2161ee5c6a12ad532100f8885d2b (diff) |
perf config: Call perf_config__init() lazily
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/perf.c | 1 | ||||
-rw-r--r-- | tools/perf/util/config.c | 16 | ||||
-rw-r--r-- | tools/perf/util/config.h | 1 |
3 files changed, 9 insertions, 9 deletions
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 20a08cb32332..cd6ea55d4b0c 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -458,7 +458,6 @@ int main(int argc, const char **argv) | |||
458 | 458 | ||
459 | srandom(time(NULL)); | 459 | srandom(time(NULL)); |
460 | 460 | ||
461 | perf_config__init(); | ||
462 | err = perf_config(perf_default_config, NULL); | 461 | err = perf_config(perf_default_config, NULL); |
463 | if (err) | 462 | if (err) |
464 | return err; | 463 | return err; |
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 84eb9393c7db..5ac157056cdf 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c | |||
@@ -707,6 +707,14 @@ struct perf_config_set *perf_config_set__new(void) | |||
707 | return set; | 707 | return set; |
708 | } | 708 | } |
709 | 709 | ||
710 | static int perf_config__init(void) | ||
711 | { | ||
712 | if (config_set == NULL) | ||
713 | config_set = perf_config_set__new(); | ||
714 | |||
715 | return config_set == NULL; | ||
716 | } | ||
717 | |||
710 | int perf_config(config_fn_t fn, void *data) | 718 | int perf_config(config_fn_t fn, void *data) |
711 | { | 719 | { |
712 | int ret = 0; | 720 | int ret = 0; |
@@ -714,7 +722,7 @@ int perf_config(config_fn_t fn, void *data) | |||
714 | struct perf_config_section *section; | 722 | struct perf_config_section *section; |
715 | struct perf_config_item *item; | 723 | struct perf_config_item *item; |
716 | 724 | ||
717 | if (config_set == NULL) | 725 | if (config_set == NULL && perf_config__init()) |
718 | return -1; | 726 | return -1; |
719 | 727 | ||
720 | perf_config_set__for_each_entry(config_set, section, item) { | 728 | perf_config_set__for_each_entry(config_set, section, item) { |
@@ -735,12 +743,6 @@ int perf_config(config_fn_t fn, void *data) | |||
735 | return ret; | 743 | return ret; |
736 | } | 744 | } |
737 | 745 | ||
738 | void perf_config__init(void) | ||
739 | { | ||
740 | if (config_set == NULL) | ||
741 | config_set = perf_config_set__new(); | ||
742 | } | ||
743 | |||
744 | void perf_config__exit(void) | 746 | void perf_config__exit(void) |
745 | { | 747 | { |
746 | perf_config_set__delete(config_set); | 748 | perf_config_set__delete(config_set); |
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h index baf82bf227ac..bd0a5897c76a 100644 --- a/tools/perf/util/config.h +++ b/tools/perf/util/config.h | |||
@@ -38,7 +38,6 @@ struct perf_config_set *perf_config_set__new(void); | |||
38 | void perf_config_set__delete(struct perf_config_set *set); | 38 | void perf_config_set__delete(struct perf_config_set *set); |
39 | int perf_config_set__collect(struct perf_config_set *set, const char *file_name, | 39 | int perf_config_set__collect(struct perf_config_set *set, const char *file_name, |
40 | const char *var, const char *value); | 40 | const char *var, const char *value); |
41 | void perf_config__init(void); | ||
42 | void perf_config__exit(void); | 41 | void perf_config__exit(void); |
43 | void perf_config__refresh(void); | 42 | void perf_config__refresh(void); |
44 | 43 | ||