Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1515033 > unrolled thread
| Started by | Taeung Song <treeze.taeung@gmail.com> |
|---|---|
| First post | 2016-11-04 07:50 +0100 |
| Last post | 2016-11-04 07:50 +0100 |
| Articles | 5 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 0/6] perf config: Add support for setting and getting functionalities Taeung Song <treeze.taeung@gmail.com> - 2016-11-04 07:50 +0100
[PATCH 3/6] perf config: Parse config variable arguments before getting functionality Taeung Song <treeze.taeung@gmail.com> - 2016-11-04 07:50 +0100
[PATCH 1/6] perf config: Add support for getting config key-value pairs Taeung Song <treeze.taeung@gmail.com> - 2016-11-04 07:50 +0100
[PATCH 6/6] perf config: Mark where are config items from (user or system) Taeung Song <treeze.taeung@gmail.com> - 2016-11-04 07:50 +0100
[PATCH 4/6] perf config: Add support for writing configs to a config file Taeung Song <treeze.taeung@gmail.com> - 2016-11-04 07:50 +0100
| From | Taeung Song <treeze.taeung@gmail.com> |
|---|---|
| Date | 2016-11-04 07:50 +0100 |
| Subject | [PATCH 0/6] perf config: Add support for setting and getting functionalities |
| Message-ID | <szGu5-6zz-5@gated-at.bofh.it> |
Hello, :)
Add setting and getting features to perf-config.
I had worked at the related patchset https://lkml.org/lkml/2016/2/22/38
But I remake new this patchset for only support for read/write config file.
And There're Namhyung's requests https://lkml.org/lkml/2016/10/24/47.
In particular, I agonized implement way for setting functionality.
I especially wonder other opinions of new perf_config_set__collect()
and bool from_system_config variable.
If someone review this patchset and give me some feedback,
I'd appreciated it. :)
Thanks,
Taeung
Taeung Song (6):
perf config: Add support for getting config key-value pairs
perf config: Document examples to get config key-value pairs in man
page
perf config: Parse config variable arguments before getting
functionality
perf config: Add support for writing configs to a config file
perf config: Document examples to set config variables with values in
man page
perf config: Mark where are config items from (user or system)
tools/perf/Documentation/perf-config.txt | 35 ++++++++
tools/perf/builtin-config.c | 135 ++++++++++++++++++++++++++++++-
tools/perf/util/config.c | 20 +++++
tools/perf/util/config.h | 4 +
4 files changed, 191 insertions(+), 3 deletions(-)
--
2.7.4
[toc] | [next] | [standalone]
| From | Taeung Song <treeze.taeung@gmail.com> |
|---|---|
| Date | 2016-11-04 07:50 +0100 |
| Subject | [PATCH 3/6] perf config: Parse config variable arguments before getting functionality |
| Message-ID | <szGu5-6zz-15@gated-at.bofh.it> |
| In reply to | #1515033 |
You can get several config items as below,
# perf config report.queue-size call-graph.record-mode
but it would be needed to more precisely check arguments,
before show_spec_config() takes over the arguments.
The function would be also used when parse config key-value pairs
arguments in the near future.
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
tools/perf/builtin-config.c | 45 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index df3fa1c..fe253f3 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -82,6 +82,27 @@ static int show_config(struct perf_config_set *set)
return 0;
}
+static int parse_config_arg(char *arg, char **var)
+{
+ const char *last_dot = strchr(arg, '.');
+
+ /*
+ * Since "var" actually contains the section name and the real
+ * config variable name separated by a dot, we have to know where the dot is.
+ */
+ if (last_dot == NULL || last_dot == arg) {
+ pr_err("The config variable does not contain a section: %s\n", arg);
+ return -1;
+ }
+ if (!last_dot[1]) {
+ pr_err("The config varible does not contain variable name: %s\n", arg);
+ return -1;
+ }
+
+ *var = arg;
+ return 0;
+}
+
int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
{
int i, ret = 0;
@@ -130,10 +151,26 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
}
break;
default:
- if (argc)
- for (i = 0; argv[i]; i++)
- ret = show_spec_config(set, argv[i]);
- else
+ if (argc) {
+ for (i = 0; argv[i]; i++) {
+ char *var, *arg = strdup(argv[i]);
+
+ if (!arg) {
+ pr_err("%s: strdup failed\n", __func__);
+ ret = -1;
+ break;
+ }
+
+ if (parse_config_arg(arg, &var) < 0) {
+ free(arg);
+ ret = -1;
+ break;
+ }
+
+ ret = show_spec_config(set, var);
+ free(arg);
+ }
+ } else
usage_with_options(config_usage, config_options);
}
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Taeung Song <treeze.taeung@gmail.com> |
|---|---|
| Date | 2016-11-04 07:50 +0100 |
| Subject | [PATCH 1/6] perf config: Add support for getting config key-value pairs |
| Message-ID | <szGu5-6zz-17@gated-at.bofh.it> |
| In reply to | #1515033 |
Add a functionality getting specific config key-value pairs.
For the syntax examples,
perf config [<file-option>] [section.name ...]
e.g. To query config items 'report.queue-size' and 'report.children', do
# perf config report.queue-size report.children
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
tools/perf/builtin-config.c | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index e4207a2..df3fa1c 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -17,7 +17,7 @@
static bool use_system_config, use_user_config;
static const char * const config_usage[] = {
- "perf config [<file-option>] [options]",
+ "perf config [<file-option>] [options] [section.name ...]",
NULL
};
@@ -33,6 +33,36 @@ static struct option config_options[] = {
OPT_END()
};
+static int show_spec_config(struct perf_config_set *set, const char *var)
+{
+ struct perf_config_section *section;
+ struct perf_config_item *item;
+
+ if (set == NULL)
+ return -1;
+
+ perf_config_items__for_each_entry(&set->sections, section) {
+ if (prefixcmp(var, section->name) != 0)
+ continue;
+
+ perf_config_items__for_each_entry(§ion->items, item) {
+ const char *name = var + strlen(section->name) + 1;
+
+ if (strcmp(name, item->name) == 0) {
+ char *value = item->value;
+
+ if (value) {
+ printf("%s=%s\n", var, value);
+ return 0;
+ }
+ }
+
+ }
+ }
+
+ return 0;
+}
+
static int show_config(struct perf_config_set *set)
{
struct perf_config_section *section;
@@ -54,7 +84,7 @@ static int show_config(struct perf_config_set *set)
int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
{
- int ret = 0;
+ int i, ret = 0;
struct perf_config_set *set;
char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
@@ -100,7 +130,11 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
}
break;
default:
- usage_with_options(config_usage, config_options);
+ if (argc)
+ for (i = 0; argv[i]; i++)
+ ret = show_spec_config(set, argv[i]);
+ else
+ usage_with_options(config_usage, config_options);
}
perf_config_set__delete(set);
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Taeung Song <treeze.taeung@gmail.com> |
|---|---|
| Date | 2016-11-04 07:50 +0100 |
| Subject | [PATCH 6/6] perf config: Mark where are config items from (user or system) |
| Message-ID | <szGu5-6zz-19@gated-at.bofh.it> |
| In reply to | #1515033 |
To write config items to a particular config file,
we should know where is each config section and item from.
Current setting functionality of perf-config use autogenerating
way by overwriting collected config items to a config file.
For example,
When collecting config items from user and system config
files (i.e. ~/.perfconfig and $(sysconf)/perfconfig),
perf_config_set can contain both user and system config items.
So we should know where each value is from to avoid merging
user and system config items on user config file.
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
tools/perf/builtin-config.c | 6 +++++-
tools/perf/util/config.c | 16 +++++++++++++++-
tools/perf/util/config.h | 4 +++-
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 5313702..f4541d7 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -46,14 +46,18 @@ static int set_config(struct perf_config_set *set, const char *file_name,
if (set == NULL)
return -1;
- perf_config_set__collect(set, var, value);
+ perf_config_set__collect(set, file_name, var, value);
fprintf(fp, "%s\n", first_line);
/* overwrite configvariables */
perf_config_items__for_each_entry(&set->sections, section) {
+ if (!use_system_config && section->from_system_config)
+ continue;
fprintf(fp, "[%s]\n", section->name);
perf_config_items__for_each_entry(§ion->items, item) {
+ if (!use_system_config && section->from_system_config)
+ continue;
if (item->value)
fprintf(fp, "\t%s = %s\n",
item->name, item->value);
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index c8fb65d..3d906db 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -594,6 +594,19 @@ static int collect_config(const char *var, const char *value,
goto out_free;
}
+ /* perf_config_set can contain both user and system config items.
+ * So we should know where each value is from.
+ * The classification would be needed when a particular config file
+ * is overwrited by setting feature i.e. set_config().
+ */
+ if (strcmp(config_file_name, perf_etc_perfconfig()) == 0) {
+ section->from_system_config = true;
+ item->from_system_config = true;
+ } else {
+ section->from_system_config = false;
+ item->from_system_config = false;
+ }
+
ret = set_value(item, value);
return ret;
@@ -602,9 +615,10 @@ static int collect_config(const char *var, const char *value,
return -1;
}
-int perf_config_set__collect(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)
{
+ config_file_name = file_name;
return collect_config(var, value, set);
}
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index 0fcdb8c..1a59a6b 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -7,12 +7,14 @@
struct perf_config_item {
char *name;
char *value;
+ bool from_system_config;
struct list_head node;
};
struct perf_config_section {
char *name;
struct list_head items;
+ bool from_system_config;
struct list_head node;
};
@@ -33,7 +35,7 @@ const char *perf_etc_perfconfig(void);
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,
+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);
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Taeung Song <treeze.taeung@gmail.com> |
|---|---|
| Date | 2016-11-04 07:50 +0100 |
| Subject | [PATCH 4/6] perf config: Add support for writing configs to a config file |
| Message-ID | <szGu6-6zz-23@gated-at.bofh.it> |
| In reply to | #1515033 |
Add setting feature that can add config variables with their values
to a config file (i.e. user or system config file) or modify
config key-value pairs in a config file.
For the syntax examples,
perf config [<file-option>] [section.name[=value] ...]
e.g. You can set the ui.show-headers to false with
# perf config ui.show-headers=false
If you want to add or modify several config items, you can do like
# perf config annotate.show_nr_jumps=false kmem.default=slab
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
tools/perf/builtin-config.c | 66 ++++++++++++++++++++++++++++++++++++++++-----
tools/perf/util/config.c | 6 +++++
tools/perf/util/config.h | 2 ++
3 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index fe253f3..5313702 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -17,7 +17,7 @@
static bool use_system_config, use_user_config;
static const char * const config_usage[] = {
- "perf config [<file-option>] [options] [section.name ...]",
+ "perf config [<file-option>] [options] [section.name[=value] ...]",
NULL
};
@@ -33,6 +33,37 @@ static struct option config_options[] = {
OPT_END()
};
+static int set_config(struct perf_config_set *set, const char *file_name,
+ const char *var, const char *value)
+{
+ struct perf_config_section *section = NULL;
+ struct perf_config_item *item = NULL;
+ const char *first_line = "# this file is auto-generated.";
+ FILE *fp = fopen(file_name, "w");
+
+ if (!fp)
+ return -1;
+ if (set == NULL)
+ return -1;
+
+ perf_config_set__collect(set, var, value);
+ fprintf(fp, "%s\n", first_line);
+
+ /* overwrite configvariables */
+ perf_config_items__for_each_entry(&set->sections, section) {
+ fprintf(fp, "[%s]\n", section->name);
+
+ perf_config_items__for_each_entry(§ion->items, item) {
+ if (item->value)
+ fprintf(fp, "\t%s = %s\n",
+ item->name, item->value);
+ }
+ }
+ fclose(fp);
+
+ return 0;
+}
+
static int show_spec_config(struct perf_config_set *set, const char *var)
{
struct perf_config_section *section;
@@ -82,7 +113,7 @@ static int show_config(struct perf_config_set *set)
return 0;
}
-static int parse_config_arg(char *arg, char **var)
+static int parse_config_arg(char *arg, char **var, char **value)
{
const char *last_dot = strchr(arg, '.');
@@ -99,7 +130,21 @@ static int parse_config_arg(char *arg, char **var)
return -1;
}
- *var = arg;
+ *value = strchr(arg, '=');
+ if (*value == NULL)
+ *var = arg;
+ else if (!strcmp(*value, "=")) {
+ pr_err("The config variable does not contain a value: %s\n", arg);
+ return -1;
+ } else {
+ *value = *value + 1; /* excluding a first character '=' */
+ *var = strsep(&arg, "=");
+ if (*var[0] == '\0') {
+ pr_err("invalid config variable: %s\n", arg);
+ return -1;
+ }
+ }
+
return 0;
}
@@ -153,7 +198,8 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
default:
if (argc) {
for (i = 0; argv[i]; i++) {
- char *var, *arg = strdup(argv[i]);
+ char *var, *value;
+ char *arg = strdup(argv[i]);
if (!arg) {
pr_err("%s: strdup failed\n", __func__);
@@ -161,13 +207,21 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
break;
}
- if (parse_config_arg(arg, &var) < 0) {
+ if (parse_config_arg(arg, &var, &value) < 0) {
free(arg);
ret = -1;
break;
}
- ret = show_spec_config(set, var);
+ if (value == NULL)
+ ret = show_spec_config(set, var);
+ else {
+ const char *config_filename = config_exclusive_filename;
+
+ if (!config_exclusive_filename)
+ config_filename = user_config;
+ ret = set_config(set, config_filename, var, value);
+ }
free(arg);
}
} else
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 18dae74..c8fb65d 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -602,6 +602,12 @@ static int collect_config(const char *var, const char *value,
return -1;
}
+int perf_config_set__collect(struct perf_config_set *set,
+ const char *var, const char *value)
+{
+ return collect_config(var, value, set);
+}
+
static int perf_config_set__init(struct perf_config_set *set)
{
int ret = -1;
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index 6f813d4..0fcdb8c 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -33,6 +33,8 @@ const char *perf_etc_perfconfig(void);
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 *var, const char *value);
void perf_config__init(void);
void perf_config__exit(void);
void perf_config__refresh(void);
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web