2009-04-20 13:00:56 +00:00
|
|
|
/*
|
2011-12-13 13:52:03 +00:00
|
|
|
* config.c
|
|
|
|
*
|
|
|
|
* Helper functions for parsing config items.
|
|
|
|
* Originally copied from GIT source.
|
2009-04-20 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) Linus Torvalds, 2005
|
|
|
|
* Copyright (C) Johannes Schindelin, 2005
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "util.h"
|
|
|
|
#include "cache.h"
|
2015-12-15 15:39:39 +00:00
|
|
|
#include <subcmd/exec-cmd.h>
|
2014-01-14 03:02:15 +00:00
|
|
|
#include "util/hist.h" /* perf_hist_config */
|
2015-07-21 11:13:34 +00:00
|
|
|
#include "util/llvm-utils.h" /* perf_llvm_config */
|
2016-04-14 07:53:18 +00:00
|
|
|
#include "config.h"
|
2009-04-20 13:00:56 +00:00
|
|
|
|
|
|
|
#define MAXNAME (256)
|
|
|
|
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
#define DEBUG_CACHE_DIR ".debug"
|
|
|
|
|
|
|
|
|
|
|
|
char buildid_dir[MAXPATHLEN]; /* root dir for buildid, binary cache */
|
|
|
|
|
2009-04-20 13:00:56 +00:00
|
|
|
static FILE *config_file;
|
|
|
|
static const char *config_file_name;
|
|
|
|
static int config_linenr;
|
|
|
|
static int config_file_eof;
|
|
|
|
|
2016-02-10 17:51:17 +00:00
|
|
|
const char *config_exclusive_filename;
|
2009-04-20 13:00:56 +00:00
|
|
|
|
|
|
|
static int get_next_char(void)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
c = '\n';
|
|
|
|
if ((f = config_file) != NULL) {
|
|
|
|
c = fgetc(f);
|
|
|
|
if (c == '\r') {
|
|
|
|
/* DOS like systems */
|
|
|
|
c = fgetc(f);
|
|
|
|
if (c != '\n') {
|
|
|
|
ungetc(c, f);
|
|
|
|
c = '\r';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == '\n')
|
|
|
|
config_linenr++;
|
|
|
|
if (c == EOF) {
|
|
|
|
config_file_eof = 1;
|
|
|
|
c = '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *parse_value(void)
|
|
|
|
{
|
|
|
|
static char value[1024];
|
2009-07-01 10:37:06 +00:00
|
|
|
int quote = 0, comment = 0, space = 0;
|
|
|
|
size_t len = 0;
|
2009-04-20 13:00:56 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c = get_next_char();
|
2009-07-01 10:37:06 +00:00
|
|
|
|
2009-04-20 13:00:56 +00:00
|
|
|
if (len >= sizeof(value) - 1)
|
|
|
|
return NULL;
|
|
|
|
if (c == '\n') {
|
|
|
|
if (quote)
|
|
|
|
return NULL;
|
|
|
|
value[len] = 0;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
if (comment)
|
|
|
|
continue;
|
|
|
|
if (isspace(c) && !quote) {
|
|
|
|
space = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!quote) {
|
|
|
|
if (c == ';' || c == '#') {
|
|
|
|
comment = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (space) {
|
|
|
|
if (len)
|
|
|
|
value[len++] = ' ';
|
|
|
|
space = 0;
|
|
|
|
}
|
|
|
|
if (c == '\\') {
|
|
|
|
c = get_next_char();
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
continue;
|
|
|
|
case 't':
|
|
|
|
c = '\t';
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
c = '\b';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
c = '\n';
|
|
|
|
break;
|
|
|
|
/* Some characters escape as themselves */
|
|
|
|
case '\\': case '"':
|
|
|
|
break;
|
|
|
|
/* Reject unknown escape sequences */
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
value[len++] = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == '"') {
|
|
|
|
quote = 1-quote;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
value[len++] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int iskeychar(int c)
|
|
|
|
{
|
2012-05-30 00:59:02 +00:00
|
|
|
return isalnum(c) || c == '-' || c == '_';
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
/* Get the full name */
|
|
|
|
for (;;) {
|
|
|
|
c = get_next_char();
|
|
|
|
if (config_file_eof)
|
|
|
|
break;
|
|
|
|
if (!iskeychar(c))
|
|
|
|
break;
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
name[len++] = c;
|
2009-04-20 13:00:56 +00:00
|
|
|
if (len >= MAXNAME)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
name[len] = 0;
|
|
|
|
while (c == ' ' || c == '\t')
|
|
|
|
c = get_next_char();
|
|
|
|
|
|
|
|
value = NULL;
|
|
|
|
if (c != '\n') {
|
|
|
|
if (c != '=')
|
|
|
|
return -1;
|
|
|
|
value = parse_value();
|
|
|
|
if (!value)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return fn(name, value, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_extended_base_var(char *name, int baselen, int c)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
if (c == '\n')
|
|
|
|
return -1;
|
|
|
|
c = get_next_char();
|
|
|
|
} while (isspace(c));
|
|
|
|
|
|
|
|
/* We require the format to be '[base "extension"]' */
|
|
|
|
if (c != '"')
|
|
|
|
return -1;
|
|
|
|
name[baselen++] = '.';
|
|
|
|
|
|
|
|
for (;;) {
|
2009-08-15 10:26:57 +00:00
|
|
|
int ch = get_next_char();
|
|
|
|
|
|
|
|
if (ch == '\n')
|
2009-04-20 13:00:56 +00:00
|
|
|
return -1;
|
2009-08-15 10:26:57 +00:00
|
|
|
if (ch == '"')
|
2009-04-20 13:00:56 +00:00
|
|
|
break;
|
2009-08-15 10:26:57 +00:00
|
|
|
if (ch == '\\') {
|
|
|
|
ch = get_next_char();
|
|
|
|
if (ch == '\n')
|
2009-04-20 13:00:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-08-15 10:26:57 +00:00
|
|
|
name[baselen++] = ch;
|
2009-04-20 13:00:56 +00:00
|
|
|
if (baselen > MAXNAME / 2)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Final ']' */
|
|
|
|
if (get_next_char() != ']')
|
|
|
|
return -1;
|
|
|
|
return baselen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_base_var(char *name)
|
|
|
|
{
|
|
|
|
int baselen = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c = get_next_char();
|
|
|
|
if (config_file_eof)
|
|
|
|
return -1;
|
|
|
|
if (c == ']')
|
|
|
|
return baselen;
|
|
|
|
if (isspace(c))
|
|
|
|
return get_extended_base_var(name, baselen, c);
|
|
|
|
if (!iskeychar(c) && c != '.')
|
|
|
|
return -1;
|
|
|
|
if (baselen > MAXNAME / 2)
|
|
|
|
return -1;
|
|
|
|
name[baselen++] = tolower(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int perf_parse_file(config_fn_t fn, void *data)
|
|
|
|
{
|
|
|
|
int comment = 0;
|
|
|
|
int baselen = 0;
|
|
|
|
static char var[MAXNAME];
|
|
|
|
|
|
|
|
/* U+FEFF Byte Order Mark in UTF8 */
|
|
|
|
static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf";
|
|
|
|
const unsigned char *bomptr = utf8_bom;
|
|
|
|
|
|
|
|
for (;;) {
|
2014-09-23 11:56:56 +00:00
|
|
|
int line, c = get_next_char();
|
|
|
|
|
2009-04-20 13:00:56 +00:00
|
|
|
if (bomptr && *bomptr) {
|
|
|
|
/* We are at the file beginning; skip UTF8-encoded BOM
|
|
|
|
* if present. Sane editors won't put this in on their
|
|
|
|
* own, but e.g. Windows Notepad will do it happily. */
|
|
|
|
if ((unsigned char) c == *bomptr) {
|
|
|
|
bomptr++;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* Do not tolerate partial BOM. */
|
|
|
|
if (bomptr != utf8_bom)
|
|
|
|
break;
|
|
|
|
/* No BOM at file beginning. Cool. */
|
|
|
|
bomptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == '\n') {
|
|
|
|
if (config_file_eof)
|
|
|
|
return 0;
|
|
|
|
comment = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (comment || isspace(c))
|
|
|
|
continue;
|
|
|
|
if (c == '#' || c == ';') {
|
|
|
|
comment = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == '[') {
|
|
|
|
baselen = get_base_var(var);
|
|
|
|
if (baselen <= 0)
|
|
|
|
break;
|
|
|
|
var[baselen++] = '.';
|
|
|
|
var[baselen] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!isalpha(c))
|
|
|
|
break;
|
|
|
|
var[baselen] = tolower(c);
|
2014-09-23 11:56:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The get_value function might or might not reach the '\n',
|
|
|
|
* so saving the current line number for error reporting.
|
|
|
|
*/
|
|
|
|
line = config_linenr;
|
|
|
|
if (get_value(fn, data, var, baselen+1) < 0) {
|
|
|
|
config_linenr = line;
|
2009-04-20 13:00:56 +00:00
|
|
|
break;
|
2014-09-23 11:56:56 +00:00
|
|
|
}
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
|
|
|
die("bad config file line %d in %s", config_linenr, config_file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_unit_factor(const char *end, unsigned long *val)
|
|
|
|
{
|
|
|
|
if (!*end)
|
|
|
|
return 1;
|
|
|
|
else if (!strcasecmp(end, "k")) {
|
|
|
|
*val *= 1024;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (!strcasecmp(end, "m")) {
|
|
|
|
*val *= 1024 * 1024;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (!strcasecmp(end, "g")) {
|
|
|
|
*val *= 1024 * 1024 * 1024;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:27:28 +00:00
|
|
|
static int perf_parse_llong(const char *value, long long *ret)
|
|
|
|
{
|
|
|
|
if (value && *value) {
|
|
|
|
char *end;
|
|
|
|
long long val = strtoll(value, &end, 0);
|
|
|
|
unsigned long factor = 1;
|
|
|
|
|
|
|
|
if (!parse_unit_factor(end, &factor))
|
|
|
|
return 0;
|
|
|
|
*ret = val * factor;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-20 13:00:56 +00:00
|
|
|
static int perf_parse_long(const char *value, long *ret)
|
|
|
|
{
|
|
|
|
if (value && *value) {
|
|
|
|
char *end;
|
|
|
|
long val = strtol(value, &end, 0);
|
|
|
|
unsigned long factor = 1;
|
|
|
|
if (!parse_unit_factor(end, &factor))
|
|
|
|
return 0;
|
|
|
|
*ret = val * factor;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void die_bad_config(const char *name)
|
|
|
|
{
|
|
|
|
if (config_file_name)
|
|
|
|
die("bad config value for '%s' in %s", name, config_file_name);
|
|
|
|
die("bad config value for '%s'", name);
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:27:28 +00:00
|
|
|
u64 perf_config_u64(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
long long ret = 0;
|
|
|
|
|
|
|
|
if (!perf_parse_llong(value, &ret))
|
|
|
|
die_bad_config(name);
|
|
|
|
return (u64) ret;
|
|
|
|
}
|
|
|
|
|
2009-04-20 13:00:56 +00:00
|
|
|
int perf_config_int(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
long ret = 0;
|
|
|
|
if (!perf_parse_long(value, &ret))
|
|
|
|
die_bad_config(name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-18 21:29:23 +00:00
|
|
|
static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
*is_bool = 1;
|
|
|
|
if (!value)
|
|
|
|
return 1;
|
|
|
|
if (!*value)
|
|
|
|
return 0;
|
|
|
|
if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
|
|
|
|
return 1;
|
|
|
|
if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
|
|
|
|
return 0;
|
|
|
|
*is_bool = 0;
|
|
|
|
return perf_config_int(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_config_bool(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
int discard;
|
|
|
|
return !!perf_config_bool_or_int(name, value, &discard);
|
|
|
|
}
|
|
|
|
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
const char *perf_config_dirname(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-03-27 17:22:19 +00:00
|
|
|
static int perf_buildid_config(const char *var, const char *value)
|
|
|
|
{
|
|
|
|
/* same dir for all commands */
|
|
|
|
if (!strcmp(var, "buildid.dir")) {
|
2016-04-04 22:07:39 +00:00
|
|
|
const char *dir = perf_config_dirname(var, value);
|
2016-03-27 17:22:19 +00:00
|
|
|
|
2016-04-04 22:07:39 +00:00
|
|
|
if (!dir)
|
2016-03-27 17:22:19 +00:00
|
|
|
return -1;
|
2016-04-04 22:07:39 +00:00
|
|
|
strncpy(buildid_dir, dir, MAXPATHLEN-1);
|
2016-03-27 17:22:19 +00:00
|
|
|
buildid_dir[MAXPATHLEN-1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-10 22:15:03 +00:00
|
|
|
static int perf_default_core_config(const char *var __maybe_unused,
|
|
|
|
const char *value __maybe_unused)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
2011-08-15 00:02:26 +00:00
|
|
|
/* Add other config variables here. */
|
2009-04-20 13:00:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-27 16:26:58 +00:00
|
|
|
static int perf_ui_config(const char *var, const char *value)
|
|
|
|
{
|
|
|
|
/* Add other config variables here. */
|
|
|
|
if (!strcmp(var, "ui.show-headers")) {
|
|
|
|
symbol_conf.show_hist_headers = perf_config_bool(var, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-10 22:15:03 +00:00
|
|
|
int perf_default_config(const char *var, const char *value,
|
|
|
|
void *dummy __maybe_unused)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
if (!prefixcmp(var, "core."))
|
|
|
|
return perf_default_core_config(var, value);
|
|
|
|
|
2014-01-14 03:02:15 +00:00
|
|
|
if (!prefixcmp(var, "hist."))
|
|
|
|
return perf_hist_config(var, value);
|
|
|
|
|
2014-06-27 16:26:58 +00:00
|
|
|
if (!prefixcmp(var, "ui."))
|
|
|
|
return perf_ui_config(var, value);
|
|
|
|
|
2014-09-23 01:01:43 +00:00
|
|
|
if (!prefixcmp(var, "call-graph."))
|
|
|
|
return perf_callchain_config(var, value);
|
|
|
|
|
2015-07-21 11:13:34 +00:00
|
|
|
if (!prefixcmp(var, "llvm."))
|
|
|
|
return perf_llvm_config(var, value);
|
|
|
|
|
2016-03-27 17:22:19 +00:00
|
|
|
if (!prefixcmp(var, "buildid."))
|
|
|
|
return perf_buildid_config(var, value);
|
|
|
|
|
2011-08-15 00:02:26 +00:00
|
|
|
/* Add other config variables here. */
|
2009-04-20 13:00:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 21:29:23 +00:00
|
|
|
static int perf_config_from_file(config_fn_t fn, const char *filename, void *data)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
FILE *f = fopen(filename, "r");
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
if (f) {
|
|
|
|
config_file = f;
|
|
|
|
config_file_name = filename;
|
|
|
|
config_linenr = 1;
|
|
|
|
config_file_eof = 0;
|
|
|
|
ret = perf_parse_file(fn, data);
|
|
|
|
fclose(f);
|
|
|
|
config_file_name = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-10 17:51:17 +00:00
|
|
|
const char *perf_etc_perfconfig(void)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
static const char *system_wide;
|
|
|
|
if (!system_wide)
|
|
|
|
system_wide = system_path(ETC_PERFCONFIG);
|
|
|
|
return system_wide;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int perf_env_bool(const char *k, int def)
|
|
|
|
{
|
|
|
|
const char *v = getenv(k);
|
|
|
|
return v ? perf_config_bool(k, v) : def;
|
|
|
|
}
|
|
|
|
|
2010-05-18 21:29:23 +00:00
|
|
|
static int perf_config_system(void)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
return !perf_env_bool("PERF_CONFIG_NOSYSTEM", 0);
|
|
|
|
}
|
|
|
|
|
2010-05-18 21:29:23 +00:00
|
|
|
static int perf_config_global(void)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_config(config_fn_t fn, void *data)
|
|
|
|
{
|
|
|
|
int ret = 0, found = 0;
|
|
|
|
const char *home = NULL;
|
|
|
|
|
|
|
|
/* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
|
|
|
|
if (config_exclusive_filename)
|
|
|
|
return perf_config_from_file(fn, config_exclusive_filename, data);
|
|
|
|
if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK)) {
|
|
|
|
ret += perf_config_from_file(fn, perf_etc_perfconfig(),
|
|
|
|
data);
|
|
|
|
found += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
home = getenv("HOME");
|
|
|
|
if (perf_config_global() && home) {
|
|
|
|
char *user_config = strdup(mkpath("%s/.perfconfig", home));
|
2011-08-09 15:42:13 +00:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (user_config == NULL) {
|
|
|
|
warning("Not enough memory to process %s/.perfconfig, "
|
|
|
|
"ignoring it.", home);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat(user_config, &st) < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (st.st_uid && (st.st_uid != geteuid())) {
|
|
|
|
warning("File %s not owned by current user or root, "
|
|
|
|
"ignoring it.", user_config);
|
|
|
|
goto out_free;
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
2011-08-09 15:42:13 +00:00
|
|
|
|
|
|
|
if (!st.st_size)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
ret += perf_config_from_file(fn, user_config, data);
|
|
|
|
found += 1;
|
|
|
|
out_free:
|
2009-04-20 13:00:56 +00:00
|
|
|
free(user_config);
|
|
|
|
}
|
2011-08-09 15:42:13 +00:00
|
|
|
out:
|
2009-04-20 13:00:56 +00:00
|
|
|
if (found == 0)
|
|
|
|
return -1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-14 07:53:18 +00:00
|
|
|
static struct perf_config_section *find_section(struct list_head *sections,
|
|
|
|
const char *section_name)
|
|
|
|
{
|
|
|
|
struct perf_config_section *section;
|
|
|
|
|
|
|
|
list_for_each_entry(section, sections, node)
|
|
|
|
if (!strcmp(section->name, section_name))
|
|
|
|
return section;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct perf_config_item *find_config_item(const char *name,
|
|
|
|
struct perf_config_section *section)
|
|
|
|
{
|
|
|
|
struct perf_config_item *item;
|
|
|
|
|
|
|
|
list_for_each_entry(item, §ion->items, node)
|
|
|
|
if (!strcmp(item->name, name))
|
|
|
|
return item;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct perf_config_section *add_section(struct list_head *sections,
|
|
|
|
const char *section_name)
|
|
|
|
{
|
|
|
|
struct perf_config_section *section = zalloc(sizeof(*section));
|
|
|
|
|
|
|
|
if (!section)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(§ion->items);
|
|
|
|
section->name = strdup(section_name);
|
|
|
|
if (!section->name) {
|
|
|
|
pr_debug("%s: strdup failed\n", __func__);
|
|
|
|
free(section);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(§ion->node, sections);
|
|
|
|
return section;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct perf_config_item *add_config_item(struct perf_config_section *section,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct perf_config_item *item = zalloc(sizeof(*item));
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
item->name = strdup(name);
|
|
|
|
if (!item->name) {
|
|
|
|
pr_debug("%s: strdup failed\n", __func__);
|
|
|
|
free(item);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&item->node, §ion->items);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_value(struct perf_config_item *item, const char *value)
|
|
|
|
{
|
|
|
|
char *val = strdup(value);
|
|
|
|
|
|
|
|
if (!val)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
zfree(&item->value);
|
|
|
|
item->value = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int collect_config(const char *var, const char *value,
|
|
|
|
void *perf_config_set)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char *ptr, *key;
|
|
|
|
char *section_name, *name;
|
|
|
|
struct perf_config_section *section = NULL;
|
|
|
|
struct perf_config_item *item = NULL;
|
|
|
|
struct perf_config_set *set = perf_config_set;
|
|
|
|
struct list_head *sections = &set->sections;
|
|
|
|
|
|
|
|
key = ptr = strdup(var);
|
|
|
|
if (!key) {
|
|
|
|
pr_debug("%s: strdup failed\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
section_name = strsep(&ptr, ".");
|
|
|
|
name = ptr;
|
|
|
|
if (name == NULL || value == NULL)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
section = find_section(sections, section_name);
|
|
|
|
if (!section) {
|
|
|
|
section = add_section(sections, section_name);
|
|
|
|
if (!section)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = find_config_item(name, section);
|
|
|
|
if (!item) {
|
|
|
|
item = add_config_item(section, name);
|
|
|
|
if (!item)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = set_value(item, value);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free(key);
|
|
|
|
perf_config_set__delete(set);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct perf_config_set *perf_config_set__new(void)
|
|
|
|
{
|
|
|
|
struct perf_config_set *set = zalloc(sizeof(*set));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
INIT_LIST_HEAD(&set->sections);
|
|
|
|
perf_config(collect_config, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_config_item__delete(struct perf_config_item *item)
|
|
|
|
{
|
|
|
|
zfree(&item->name);
|
|
|
|
zfree(&item->value);
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_config_section__purge(struct perf_config_section *section)
|
|
|
|
{
|
|
|
|
struct perf_config_item *item, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(item, tmp, §ion->items, node) {
|
|
|
|
list_del_init(&item->node);
|
|
|
|
perf_config_item__delete(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_config_section__delete(struct perf_config_section *section)
|
|
|
|
{
|
|
|
|
perf_config_section__purge(section);
|
|
|
|
zfree(§ion->name);
|
|
|
|
free(section);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void perf_config_set__purge(struct perf_config_set *set)
|
|
|
|
{
|
|
|
|
struct perf_config_section *section, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(section, tmp, &set->sections, node) {
|
|
|
|
list_del_init(§ion->node);
|
|
|
|
perf_config_section__delete(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_config_set__delete(struct perf_config_set *set)
|
|
|
|
{
|
|
|
|
perf_config_set__purge(set);
|
|
|
|
free(set);
|
|
|
|
}
|
|
|
|
|
2009-04-20 13:00:56 +00:00
|
|
|
/*
|
|
|
|
* Call this to report error for your variable that should not
|
|
|
|
* get a boolean value (i.e. "[my] var" means "true").
|
|
|
|
*/
|
|
|
|
int config_error_nonbool(const char *var)
|
|
|
|
{
|
|
|
|
return error("Missing value for '%s'", var);
|
|
|
|
}
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
|
2014-12-01 19:06:24 +00:00
|
|
|
void set_buildid_dir(const char *dir)
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
{
|
2014-12-01 19:06:24 +00:00
|
|
|
if (dir)
|
|
|
|
scnprintf(buildid_dir, MAXPATHLEN-1, "%s", dir);
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
|
|
|
|
/* default to $HOME/.debug */
|
|
|
|
if (buildid_dir[0] == '\0') {
|
2016-03-27 17:22:20 +00:00
|
|
|
char *home = getenv("HOME");
|
|
|
|
|
|
|
|
if (home) {
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
snprintf(buildid_dir, MAXPATHLEN-1, "%s/%s",
|
2016-03-27 17:22:20 +00:00
|
|
|
home, DEBUG_CACHE_DIR);
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-01 19:25:01 +00:00
|
|
|
} else {
|
|
|
|
strncpy(buildid_dir, DEBUG_CACHE_DIR, MAXPATHLEN-1);
|
|
|
|
}
|
|
|
|
buildid_dir[MAXPATHLEN-1] = '\0';
|
|
|
|
}
|
|
|
|
/* for communicating with external commands */
|
|
|
|
setenv("PERF_BUILDID_DIR", buildid_dir, 1);
|
|
|
|
}
|