13 #include <sys/param.h> 16 #include <subcmd/exec-cmd.h> 20 #include <sys/types.h> 23 #include <linux/string.h> 29 #define DEBUG_CACHE_DIR ".debug" 70 static char value[1024];
71 int quote = 0, comment = 0, space = 0;
77 if (len >=
sizeof(value) - 1)
92 if (c ==
';' || c ==
'#') {
136 return isalnum(c) || c ==
'-' || c ==
'_';
156 while (c ==
' ' || c ==
'\t')
167 return fn(name, value, data);
181 name[baselen++] =
'.';
195 name[baselen++] = ch;
233 static const unsigned char *utf8_bom = (
unsigned char *)
"\xef\xbb\xbf";
234 const unsigned char *bomptr = utf8_bom;
239 if (bomptr && *bomptr) {
243 if ((
unsigned char) c == *bomptr) {
248 if (bomptr != utf8_bom)
262 if (c ==
'#' || c ==
';') {
270 var[baselen++] =
'.';
283 if (
get_value(fn, data, var, baselen+1) < 0) {
296 else if (!strcasecmp(end,
"k")) {
300 else if (!strcasecmp(end,
"m")) {
304 else if (!strcasecmp(end,
"g")) {
305 *val *= 1024 * 1024 * 1024;
313 if (value && *value) {
315 long long val = strtoll(value, &end, 0);
316 unsigned long factor = 1;
328 if (value && *value) {
330 long val = strtol(value, &end, 0);
331 unsigned long factor = 1;
345 pr_warning(
"bad config value for '%s', ignoring...\n", name);
381 if (!strcasecmp(value,
"true") || !strcasecmp(value,
"yes") || !strcasecmp(value,
"on"))
383 if (!strcasecmp(value,
"false") || !strcasecmp(value,
"no") || !strcasecmp(value,
"off"))
405 if (!strcmp(var,
"buildid.dir")) {
409 pr_err(
"Invalid buildid directory!\n");
420 const char *
value __maybe_unused)
429 if (!strcmp(var,
"ui.show-headers"))
436 void *dummy __maybe_unused)
438 if (strstarts(var,
"core."))
441 if (strstarts(var,
"hist."))
444 if (strstarts(var,
"ui."))
447 if (strstarts(var,
"call-graph."))
450 if (strstarts(var,
"llvm."))
453 if (strstarts(var,
"buildid."))
463 FILE *
f = fopen(filename,
"r");
482 system_wide = system_path(ETC_PERFCONFIG);
488 const char *v = getenv(k);
503 const char *section_name)
507 list_for_each_entry(section, sections,
node)
508 if (!strcmp(section->
name, section_name))
519 list_for_each_entry(item, §ion->
items,
node)
520 if (!strcmp(item->
name, name))
527 const char *section_name)
534 INIT_LIST_HEAD(§ion->
items);
535 section->
name = strdup(section_name);
536 if (!section->
name) {
537 pr_debug(
"%s: strdup failed\n", __func__);
542 list_add_tail(§ion->
node, sections);
554 item->
name = strdup(name);
556 pr_debug(
"%s: strdup failed\n", __func__);
561 list_add_tail(&item->
node, §ion->
items);
567 char *val = strdup(value);
582 char *section_name, *
name;
585 struct perf_config_set *
set = perf_config_set;
586 struct list_head *sections;
591 sections = &
set->sections;
592 key = ptr = strdup(var);
594 pr_debug(
"%s: strdup failed\n", __func__);
598 section_name = strsep(&ptr,
".");
600 if (name == NULL || value == NULL)
639 const char *var,
const char *
value)
648 const char *home = NULL;
660 home = getenv(
"HOME");
670 user_config = strdup(
mkpath(
"%s/.perfconfig", home));
671 if (user_config == NULL) {
672 pr_warning(
"Not enough memory to process %s/.perfconfig, ignoring it.", home);
676 if (stat(user_config, &st) < 0) {
684 if (st.st_uid && (st.st_uid != geteuid())) {
685 pr_warning(
"File %s not owned by current user or root, ignoring it.", user_config);
703 INIT_LIST_HEAD(&set->sections);
712 if (config_set == NULL)
715 return config_set == NULL;
732 scnprintf(key,
sizeof(key),
"%s.%s",
734 ret = fn(key, value, data);
736 pr_err(
"Error: wrong config key-value pair %s=%s\n",
769 list_for_each_entry_safe(item, tmp, §ion->
items,
node) {
770 list_del_init(&item->
node);
786 list_for_each_entry_safe(section, tmp, &set->sections,
node) {
787 list_del_init(§ion->
node);
807 pr_err(
"Missing value for '%s'", var);
818 char *home = getenv(
"HOME");
static const char * perf_config_dirname(const char *name, const char *value)
static void perf_config_set__purge(struct perf_config_set *set)
static int perf_parse_long(const char *value, long *ret)
static struct perf_config_section * find_section(struct list_head *sections, const char *section_name)
static int iskeychar(int c)
void perf_config_set__delete(struct perf_config_set *set)
static void bad_config(const char *name)
static int perf_config_from_file(config_fn_t fn, const char *filename, void *data)
int perf_default_config(const char *var, const char *value, void *dummy __maybe_unused)
static int perf_config_set__init(struct perf_config_set *set)
int perf_config_int(int *dest, const char *name, const char *value)
int perf_hist_config(const char *var, const char *value)
static int parse_unit_factor(const char *end, unsigned long *val)
int perf_config_bool(const char *name, const char *value)
static void perf_config_section__purge(struct perf_config_section *section)
static int collect_config(const char *var, const char *value, void *perf_config_set)
static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
int perf_llvm_config(const char *var, const char *value)
static int perf_buildid_config(const char *var, const char *value)
struct perf_config_set * perf_config_set__new(void)
#define pr_debug(fmt,...)
char buildid_dir[MAXPATHLEN]
static struct perf_config_item * find_config_item(const char *name, struct perf_config_section *section)
static int get_extended_base_var(char *name, int baselen, int c)
static int perf_config_system(void)
const char * config_exclusive_filename
void perf_config__exit(void)
static int config_file_eof
int perf_config_u64(u64 *dest, const char *name, const char *value)
static int perf_parse_llong(const char *value, long long *ret)
static int perf_config_global(void)
static FILE * config_file
static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool)
static int perf_parse_file(config_fn_t fn, void *data)
void perf_config__refresh(void)
static struct perf_config_set * config_set
const char * perf_etc_perfconfig(void)
static int perf_env_bool(const char *k, int def)
static int perf_default_core_config(const char *var __maybe_unused, const char *value __maybe_unused)
static int set_value(struct perf_config_item *item, const char *value)
static int get_next_char(void)
int perf_config(config_fn_t fn, void *data)
static void perf_config_section__delete(struct perf_config_section *section)
static char * parse_value(void)
static struct perf_config_item * add_config_item(struct perf_config_section *section, const char *name)
static struct perf_config_section * add_section(struct list_head *sections, const char *section_name)
int(* config_fn_t)(const char *, const char *, void *)
static int perf_config__init(void)
int perf_callchain_config(const char *var, const char *value)
void set_buildid_dir(const char *dir)
#define pr_warning(fmt,...)
#define perf_config_set__for_each_entry(set, section, item)
static void perf_config_item__delete(struct perf_config_item *item)
static int get_base_var(char *name)
int config_error_nonbool(const char *var)
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
static const char * config_file_name
static int perf_ui_config(const char *var, const char *value)
void static void * zalloc(size_t size)