Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf config: Add config set interface

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 <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20210102220441.794923-3-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
a523026c 64b9705b

+26 -5
+23 -5
tools/perf/util/config.c
··· 738 738 return set; 739 739 } 740 740 741 + struct perf_config_set *perf_config_set__load_file(const char *file) 742 + { 743 + struct perf_config_set *set = zalloc(sizeof(*set)); 744 + 745 + if (set) { 746 + INIT_LIST_HEAD(&set->sections); 747 + perf_config_from_file(collect_config, file, set); 748 + } 749 + 750 + return set; 751 + } 752 + 741 753 static int perf_config__init(void) 742 754 { 743 755 if (config_set == NULL) ··· 758 746 return config_set == NULL; 759 747 } 760 748 761 - int perf_config(config_fn_t fn, void *data) 749 + int perf_config_set(struct perf_config_set *set, 750 + config_fn_t fn, void *data) 762 751 { 763 752 int ret = 0; 764 753 char key[BUFSIZ]; 765 754 struct perf_config_section *section; 766 755 struct perf_config_item *item; 767 756 768 - if (config_set == NULL && perf_config__init()) 769 - return -1; 770 - 771 - perf_config_set__for_each_entry(config_set, section, item) { 757 + perf_config_set__for_each_entry(set, section, item) { 772 758 char *value = item->value; 773 759 774 760 if (value) { ··· 786 776 } 787 777 out: 788 778 return ret; 779 + } 780 + 781 + int perf_config(config_fn_t fn, void *data) 782 + { 783 + if (config_set == NULL && perf_config__init()) 784 + return -1; 785 + 786 + return perf_config_set(config_set, fn, data); 789 787 } 790 788 791 789 void perf_config__exit(void)
+3
tools/perf/util/config.h
··· 29 29 30 30 int perf_default_config(const char *, const char *, void *); 31 31 int perf_config(config_fn_t fn, void *); 32 + int perf_config_set(struct perf_config_set *set, 33 + config_fn_t fn, void *data); 32 34 int perf_config_int(int *dest, const char *, const char *); 33 35 int perf_config_u8(u8 *dest, const char *name, const char *value); 34 36 int perf_config_u64(u64 *dest, const char *, const char *); ··· 39 37 const char *perf_etc_perfconfig(void); 40 38 41 39 struct perf_config_set *perf_config_set__new(void); 40 + struct perf_config_set *perf_config_set__load_file(const char *file); 42 41 void perf_config_set__delete(struct perf_config_set *set); 43 42 int perf_config_set__collect(struct perf_config_set *set, const char *file_name, 44 43 const char *var, const char *value);