13 #include <subcmd/parse-options.h> 17 #include <linux/string.h> 22 "perf config [<file-option>] [options] [section.name[=value] ...]",
31 OPT_SET_UINT(
'l',
"list", &
actions,
42 const char *first_line =
"# this file is auto-generated.";
48 fp = fopen(file_name,
"w");
52 fprintf(fp,
"%s\n", first_line);
58 fprintf(fp,
"[%s]\n", section->
name);
64 fprintf(fp,
"\t%s = %s\n",
82 if (!strstarts(var, section->
name))
86 const char *
name = var + strlen(section->
name) + 1;
88 if (strcmp(name, item->
name) == 0) {
92 printf(
"%s=%s\n", var, value);
115 printf(
"%s.%s=%s\n", section->
name,
124 const char *last_dot = strchr(arg,
'.');
130 if (last_dot == NULL || last_dot == arg) {
131 pr_err(
"The config variable does not contain a section name: %s\n", arg);
135 pr_err(
"The config variable does not contain a variable name: %s\n", arg);
139 *value = strchr(arg,
'=');
142 else if (!strcmp(*value,
"=")) {
143 pr_err(
"The config variable does not contain a value: %s\n", arg);
147 *var = strsep(&arg,
"=");
148 if (*var[0] ==
'\0') {
149 pr_err(
"invalid config variable: %s\n", arg);
161 char *user_config =
mkpath(
"%s/.perfconfig", getenv(
"HOME"));
162 const char *config_filename;
163 bool changed =
false;
166 PARSE_OPT_STOP_AT_NON_OPTION);
169 pr_err(
"Error: only one config file at a time\n");
181 config_filename = user_config;
196 pr_err(
"Error: takes no arguments\n");
200 pr_err(
"Nothing configured, " 201 "please check your %s \n", config_filename);
212 for (i = 0; argv[i]; i++) {
214 char *arg = strdup(argv[i]);
217 pr_err(
"%s: strdup failed\n", __func__);
228 pr_err(
"%s is not configured: %s\n",
229 var, config_filename);
236 pr_err(
"Failed to add '%s=%s'\n",
250 pr_err(
"Failed to set the configs on %s\n",
void perf_config_set__delete(struct perf_config_set *set)
static int parse_config_arg(char *arg, char **var, char **value)
static int set_config(struct perf_config_set *set, const char *file_name)
static bool use_system_config
static int show_spec_config(struct perf_config_set *set, const char *var)
static const char *const config_usage[]
static struct option config_options[]
#define perf_config_items__for_each_entry(list, item)
struct perf_config_set * perf_config_set__new(void)
const char * config_exclusive_filename
static int show_config(struct perf_config_set *set)
const char * perf_etc_perfconfig(void)
static bool use_user_config
#define perf_config_set__for_each_entry(set, section, item)
int cmd_config(int argc, const char **argv)
int perf_config_set__collect(struct perf_config_set *set, const char *file_name, const char *var, const char *value)
char * mkpath(const char *fmt,...) __printf(1