License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
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
|
|
|
|
*
|
|
|
|
*/
|
2017-04-18 13:46:11 +00:00
|
|
|
#include <errno.h>
|
2017-04-19 21:51:14 +00:00
|
|
|
#include <sys/param.h>
|
2009-04-20 13:00:56 +00:00
|
|
|
#include "cache.h"
|
2019-01-29 10:11:04 +00:00
|
|
|
#include "callchain.h"
|
2015-12-15 15:39:39 +00:00
|
|
|
#include <subcmd/exec-cmd.h>
|
2018-12-04 20:34:20 +00:00
|
|
|
#include "util/event.h" /* proc_map_timeout */
|
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 */
|
2020-05-20 16:23:35 +00:00
|
|
|
#include "util/stat.h" /* perf_stat__set_big_num */
|
2021-04-25 21:43:31 +00:00
|
|
|
#include "util/evsel.h" /* evsel__hw_names, evsel__use_bpf_counters */
|
2023-06-08 06:18:12 +00:00
|
|
|
#include "util/srcline.h" /* addr2line_timeout_ms */
|
2019-08-29 20:19:02 +00:00
|
|
|
#include "build-id.h"
|
|
|
|
#include "debug.h"
|
2016-04-14 07:53:18 +00:00
|
|
|
#include "config.h"
|
2017-04-19 23:57:47 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2019-08-30 17:45:20 +00:00
|
|
|
#include <stdlib.h>
|
2017-04-19 23:57:47 +00:00
|
|
|
#include <unistd.h>
|
2017-07-20 18:27:39 +00:00
|
|
|
#include <linux/string.h>
|
2019-07-04 14:32:27 +00:00
|
|
|
#include <linux/zalloc.h>
|
tools perf: Move from sane_ctype.h obtained from git to the Linux's original
We got the sane_ctype.h headers from git and kept using it so far, but
since that code originally came from the kernel sources to the git
sources, perhaps its better to just use the one in the kernel, so that
we can leverage tools/perf/check_headers.sh to be notified when our copy
gets out of sync, i.e. when fixes or goodies are added to the code we've
copied.
This will help with things like tools/lib/string.c where we want to have
more things in common with the kernel, such as strim(), skip_spaces(),
etc so as to go on removing the things that we have in tools/perf/util/
and instead using the code in the kernel, indirectly and removing things
like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements
are made to the original code.
Hopefully this also should help with reducing the difference of code
hosted in tools/ to the one in the kernel proper.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxygn12@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-06-25 20:27:31 +00:00
|
|
|
#include <linux/ctype.h>
|
2017-04-17 19:10:49 +00:00
|
|
|
|
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-06-23 14:14:31 +00:00
|
|
|
static struct perf_config_set *config_set;
|
2009-04-20 13:00:56 +00:00
|
|
|
|
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
|
|
|
}
|
2016-06-06 10:52:52 +00:00
|
|
|
pr_err("bad config file line %d in %s\n", config_linenr, config_file_name);
|
|
|
|
return -1;
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-27 14:44:58 +00:00
|
|
|
static void bad_config(const char *name)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
if (config_file_name)
|
2017-06-27 14:44:58 +00:00
|
|
|
pr_warning("bad config value for '%s' in %s, ignoring...\n", name, config_file_name);
|
|
|
|
else
|
|
|
|
pr_warning("bad config value for '%s', ignoring...\n", name);
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 14:44:58 +00:00
|
|
|
int perf_config_u64(u64 *dest, const char *name, const char *value)
|
2014-06-06 09:27:28 +00:00
|
|
|
{
|
|
|
|
long long ret = 0;
|
|
|
|
|
2017-06-27 14:44:58 +00:00
|
|
|
if (!perf_parse_llong(value, &ret)) {
|
|
|
|
bad_config(name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = ret;
|
|
|
|
return 0;
|
2014-06-06 09:27:28 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 14:44:58 +00:00
|
|
|
int perf_config_int(int *dest, const char *name, const char *value)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
long ret = 0;
|
2017-06-27 14:44:58 +00:00
|
|
|
if (!perf_parse_long(value, &ret)) {
|
|
|
|
bad_config(name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*dest = ret;
|
|
|
|
return 0;
|
2020-02-13 06:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int perf_config_u8(u8 *dest, const char *name, const char *value)
|
|
|
|
{
|
|
|
|
long ret = 0;
|
|
|
|
|
|
|
|
if (!perf_parse_long(value, &ret)) {
|
|
|
|
bad_config(name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*dest = ret;
|
|
|
|
return 0;
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-06-27 14:44:58 +00:00
|
|
|
int ret;
|
|
|
|
|
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;
|
2017-06-27 14:44:58 +00:00
|
|
|
return perf_config_int(&ret, name, value) < 0 ? -1 : ret;
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int perf_config_bool(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
int discard;
|
|
|
|
return !!perf_config_bool_or_int(name, value, &discard);
|
|
|
|
}
|
|
|
|
|
2016-06-16 20:10:46 +00:00
|
|
|
static const char *perf_config_dirname(const char *name, const char *value)
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-01-24 16:44:10 +00:00
|
|
|
if (!dir) {
|
|
|
|
pr_err("Invalid buildid directory!\n");
|
2016-03-27 17:22:19 +00:00
|
|
|
return -1;
|
2017-01-24 16:44:10 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2023-06-08 06:18:12 +00:00
|
|
|
static int perf_default_core_config(const char *var, const char *value)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
2018-12-04 20:34:20 +00:00
|
|
|
if (!strcmp(var, "core.proc-map-timeout"))
|
|
|
|
proc_map_timeout = strtoul(value, NULL, 10);
|
|
|
|
|
2023-06-08 06:18:12 +00:00
|
|
|
if (!strcmp(var, "core.addr2line-timeout"))
|
|
|
|
addr2line_timeout_ms = strtoul(value, NULL, 10);
|
|
|
|
|
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. */
|
2017-01-24 16:44:10 +00:00
|
|
|
if (!strcmp(var, "ui.show-headers"))
|
2014-06-27 16:26:58 +00:00
|
|
|
symbol_conf.show_hist_headers = perf_config_bool(var, value);
|
2017-01-24 16:44:10 +00:00
|
|
|
|
2014-06-27 16:26:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-20 16:23:35 +00:00
|
|
|
static int perf_stat_config(const char *var, const char *value)
|
|
|
|
{
|
|
|
|
if (!strcmp(var, "stat.big-num"))
|
|
|
|
perf_stat__set_big_num(perf_config_bool(var, value));
|
|
|
|
|
perf stat: Align CSV output for summary mode
The 'perf stat' subcommand supports the request for a summary of the
interval counter readings. But the summary lines break the CSV output
so it's hard for scripts to parse the result.
Before:
# perf stat -x, -I1000 --interval-count 1 --summary
1.001323097,8013.48,msec,cpu-clock,8013483384,100.00,8.013,CPUs utilized
1.001323097,270,,context-switches,8013513297,100.00,0.034,K/sec
1.001323097,13,,cpu-migrations,8013530032,100.00,0.002,K/sec
1.001323097,184,,page-faults,8013546992,100.00,0.023,K/sec
1.001323097,20574191,,cycles,8013551506,100.00,0.003,GHz
1.001323097,10562267,,instructions,8013564958,100.00,0.51,insn per cycle
1.001323097,2019244,,branches,8013575673,100.00,0.252,M/sec
1.001323097,106152,,branch-misses,8013585776,100.00,5.26,of all branches
8013.48,msec,cpu-clock,8013483384,100.00,7.984,CPUs utilized
270,,context-switches,8013513297,100.00,0.034,K/sec
13,,cpu-migrations,8013530032,100.00,0.002,K/sec
184,,page-faults,8013546992,100.00,0.023,K/sec
20574191,,cycles,8013551506,100.00,0.003,GHz
10562267,,instructions,8013564958,100.00,0.51,insn per cycle
2019244,,branches,8013575673,100.00,0.252,M/sec
106152,,branch-misses,8013585776,100.00,5.26,of all branches
The summary line loses the timestamp column, which breaks the CSV
output.
We add a column at the original 'timestamp' position and it just says
'summary' for the summary line.
After:
# perf stat -x, -I1000 --interval-count 1 --summary
1.001196053,8012.72,msec,cpu-clock,8012722903,100.00,8.013,CPUs utilized
1.001196053,218,,context-switches,8012753271,100.00,0.027,K/sec
1.001196053,9,,cpu-migrations,8012769767,100.00,0.001,K/sec
1.001196053,0,,page-faults,8012786257,100.00,0.000,K/sec
1.001196053,15004518,,cycles,8012790637,100.00,0.002,GHz
1.001196053,7954691,,instructions,8012804027,100.00,0.53,insn per cycle
1.001196053,1590259,,branches,8012814766,100.00,0.198,M/sec
1.001196053,82601,,branch-misses,8012824365,100.00,5.19,of all branches
summary,8012.72,msec,cpu-clock,8012722903,100.00,7.986,CPUs utilized
summary,218,,context-switches,8012753271,100.00,0.027,K/sec
summary,9,,cpu-migrations,8012769767,100.00,0.001,K/sec
summary,0,,page-faults,8012786257,100.00,0.000,K/sec
summary,15004518,,cycles,8012790637,100.00,0.002,GHz
summary,7954691,,instructions,8012804027,100.00,0.53,insn per cycle
summary,1590259,,branches,8012814766,100.00,0.198,M/sec
summary,82601,,branch-misses,8012824365,100.00,5.19,of all branches
Now it's easy for script to analyse the summary lines.
Of course, we also consider not to break possible existing scripts which
can continue to use the broken CSV format by using a new '--no-csv-summary.'
option.
# perf stat -x, -I1000 --interval-count 1 --summary --no-csv-summary
1.001213261,8012.67,msec,cpu-clock,8012672327,100.00,8.013,CPUs utilized
1.001213261,197,,context-switches,8012703742,100.00,24.586,/sec
1.001213261,9,,cpu-migrations,8012720902,100.00,1.123,/sec
1.001213261,644,,page-faults,8012738266,100.00,80.373,/sec
1.001213261,18350698,,cycles,8012744109,100.00,0.002,GHz
1.001213261,12745021,,instructions,8012759001,100.00,0.69,insn per cycle
1.001213261,2458033,,branches,8012770864,100.00,306.768,K/sec
1.001213261,102107,,branch-misses,8012781751,100.00,4.15,of all branches
8012.67,msec,cpu-clock,8012672327,100.00,7.985,CPUs utilized
197,,context-switches,8012703742,100.00,24.586,/sec
9,,cpu-migrations,8012720902,100.00,1.123,/sec
644,,page-faults,8012738266,100.00,80.373,/sec
18350698,,cycles,8012744109,100.00,0.002,GHz
12745021,,instructions,8012759001,100.00,0.69,insn per cycle
2458033,,branches,8012770864,100.00,306.768,K/sec
102107,,branch-misses,8012781751,100.00,4.15,of all branches
This option can be enabled in perf config by setting the variable
'stat.no-csv-summary'.
# perf config stat.no-csv-summary=true
# perf config -l
stat.no-csv-summary=true
# perf stat -x, -I1000 --interval-count 1 --summary
1.001330198,8013.28,msec,cpu-clock,8013279201,100.00,8.013,CPUs utilized
1.001330198,205,,context-switches,8013308394,100.00,25.583,/sec
1.001330198,10,,cpu-migrations,8013324681,100.00,1.248,/sec
1.001330198,0,,page-faults,8013340926,100.00,0.000,/sec
1.001330198,8027742,,cycles,8013344503,100.00,0.001,GHz
1.001330198,2871717,,instructions,8013356501,100.00,0.36,insn per cycle
1.001330198,553564,,branches,8013366204,100.00,69.081,K/sec
1.001330198,54021,,branch-misses,8013375952,100.00,9.76,of all branches
8013.28,msec,cpu-clock,8013279201,100.00,7.985,CPUs utilized
205,,context-switches,8013308394,100.00,25.583,/sec
10,,cpu-migrations,8013324681,100.00,1.248,/sec
0,,page-faults,8013340926,100.00,0.000,/sec
8027742,,cycles,8013344503,100.00,0.001,GHz
2871717,,instructions,8013356501,100.00,0.36,insn per cycle
553564,,branches,8013366204,100.00,69.081,K/sec
54021,,branch-misses,8013375952,100.00,9.76,of all branches
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210319070156.20394-1-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-03-19 07:01:55 +00:00
|
|
|
if (!strcmp(var, "stat.no-csv-summary"))
|
|
|
|
perf_stat__set_no_csv_summary(perf_config_bool(var, value));
|
|
|
|
|
2021-04-25 21:43:31 +00:00
|
|
|
if (!strcmp(var, "stat.bpf-counter-events"))
|
|
|
|
evsel__bpf_counter_events = strdup(value);
|
|
|
|
|
2020-05-20 16:23:35 +00:00
|
|
|
/* Add other config variables here. */
|
|
|
|
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
|
|
|
{
|
2017-07-20 18:27:39 +00:00
|
|
|
if (strstarts(var, "core."))
|
2009-04-20 13:00:56 +00:00
|
|
|
return perf_default_core_config(var, value);
|
|
|
|
|
2017-07-20 18:27:39 +00:00
|
|
|
if (strstarts(var, "hist."))
|
2014-01-14 03:02:15 +00:00
|
|
|
return perf_hist_config(var, value);
|
|
|
|
|
2017-07-20 18:27:39 +00:00
|
|
|
if (strstarts(var, "ui."))
|
2014-06-27 16:26:58 +00:00
|
|
|
return perf_ui_config(var, value);
|
|
|
|
|
2017-07-20 18:27:39 +00:00
|
|
|
if (strstarts(var, "call-graph."))
|
2014-09-23 01:01:43 +00:00
|
|
|
return perf_callchain_config(var, value);
|
|
|
|
|
2017-07-20 18:27:39 +00:00
|
|
|
if (strstarts(var, "llvm."))
|
2015-07-21 11:13:34 +00:00
|
|
|
return perf_llvm_config(var, value);
|
|
|
|
|
2017-07-20 18:27:39 +00:00
|
|
|
if (strstarts(var, "buildid."))
|
2016-03-27 17:22:19 +00:00
|
|
|
return perf_buildid_config(var, value);
|
|
|
|
|
2020-05-20 16:23:35 +00:00
|
|
|
if (strstarts(var, "stat."))
|
|
|
|
return perf_stat_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;
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:20 +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;
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:24 +00:00
|
|
|
int perf_config_system(void)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
return !perf_env_bool("PERF_CONFIG_NOSYSTEM", 0);
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:25 +00:00
|
|
|
int perf_config_global(void)
|
2009-04-20 13:00:56 +00:00
|
|
|
{
|
|
|
|
return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0);
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:23 +00:00
|
|
|
static char *home_perfconfig(void)
|
|
|
|
{
|
|
|
|
const char *home = NULL;
|
|
|
|
char *config;
|
|
|
|
struct stat st;
|
2023-05-26 18:33:57 +00:00
|
|
|
char path[PATH_MAX];
|
2021-01-02 22:04:23 +00:00
|
|
|
|
|
|
|
home = getenv("HOME");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip reading user config if:
|
|
|
|
* - there is no place to read it from (HOME)
|
|
|
|
* - we are asked not to (PERF_CONFIG_NOGLOBAL=1)
|
|
|
|
*/
|
|
|
|
if (!home || !*home || !perf_config_global())
|
|
|
|
return NULL;
|
|
|
|
|
2023-05-26 18:33:57 +00:00
|
|
|
config = strdup(mkpath(path, sizeof(path), "%s/.perfconfig", home));
|
2021-01-02 22:04:23 +00:00
|
|
|
if (config == NULL) {
|
2022-10-22 09:27:35 +00:00
|
|
|
pr_warning("Not enough memory to process %s/.perfconfig, ignoring it.\n", home);
|
2021-01-02 22:04:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat(config, &st) < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (st.st_uid && (st.st_uid != geteuid())) {
|
2022-10-22 09:27:35 +00:00
|
|
|
pr_warning("File %s not owned by current user or root, ignoring it.\n", config);
|
2021-01-02 22:04:23 +00:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (st.st_size)
|
|
|
|
return config;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free(config);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *perf_home_perfconfig(void)
|
|
|
|
{
|
|
|
|
static const char *config;
|
|
|
|
static bool failed;
|
|
|
|
|
2021-08-20 14:13:36 +00:00
|
|
|
if (failed || config)
|
|
|
|
return config;
|
|
|
|
|
|
|
|
config = home_perfconfig();
|
2021-01-02 22:04:23 +00:00
|
|
|
if (!config)
|
|
|
|
failed = true;
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
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;
|
2016-06-06 10:52:54 +00:00
|
|
|
struct list_head *sections;
|
2016-04-14 07:53:18 +00:00
|
|
|
|
2016-06-06 10:52:54 +00:00
|
|
|
if (set == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
sections = &set->sections;
|
2016-04-14 07:53:18 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-04 06:44:22 +00:00
|
|
|
/* 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
|
2021-03-23 16:09:15 +00:00
|
|
|
* is overwritten by setting feature i.e. set_config().
|
2016-11-04 06:44:22 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-04-14 07:53:18 +00:00
|
|
|
ret = set_value(item, value);
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free(key);
|
2019-03-16 08:05:45 +00:00
|
|
|
return ret;
|
2016-04-14 07:53:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 06:44:22 +00:00
|
|
|
int perf_config_set__collect(struct perf_config_set *set, const char *file_name,
|
2016-11-04 06:44:20 +00:00
|
|
|
const char *var, const char *value)
|
|
|
|
{
|
2016-11-04 06:44:22 +00:00
|
|
|
config_file_name = file_name;
|
2016-11-04 06:44:20 +00:00
|
|
|
return collect_config(var, value, set);
|
|
|
|
}
|
|
|
|
|
2016-06-07 09:26:12 +00:00
|
|
|
static int perf_config_set__init(struct perf_config_set *set)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
|
|
|
|
if (config_exclusive_filename)
|
|
|
|
return perf_config_from_file(collect_config, config_exclusive_filename, set);
|
|
|
|
if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK)) {
|
|
|
|
if (perf_config_from_file(collect_config, perf_etc_perfconfig(), set) < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
2021-01-02 22:04:23 +00:00
|
|
|
if (perf_config_global() && perf_home_perfconfig()) {
|
|
|
|
if (perf_config_from_file(collect_config, perf_home_perfconfig(), set) < 0)
|
|
|
|
goto out;
|
2017-03-30 14:46:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 09:26:12 +00:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-14 07:53:18 +00:00
|
|
|
struct perf_config_set *perf_config_set__new(void)
|
|
|
|
{
|
|
|
|
struct perf_config_set *set = zalloc(sizeof(*set));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
INIT_LIST_HEAD(&set->sections);
|
2017-09-07 03:18:56 +00:00
|
|
|
perf_config_set__init(set);
|
2016-04-14 07:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:21 +00:00
|
|
|
struct perf_config_set *perf_config_set__load_file(const char *file)
|
|
|
|
{
|
|
|
|
struct perf_config_set *set = zalloc(sizeof(*set));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
INIT_LIST_HEAD(&set->sections);
|
|
|
|
perf_config_from_file(collect_config, file, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2018-05-16 19:09:08 +00:00
|
|
|
static int perf_config__init(void)
|
|
|
|
{
|
|
|
|
if (config_set == NULL)
|
|
|
|
config_set = perf_config_set__new();
|
|
|
|
|
|
|
|
return config_set == NULL;
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:21 +00:00
|
|
|
int perf_config_set(struct perf_config_set *set,
|
|
|
|
config_fn_t fn, void *data)
|
2016-06-23 14:14:31 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char key[BUFSIZ];
|
|
|
|
struct perf_config_section *section;
|
|
|
|
struct perf_config_item *item;
|
|
|
|
|
2021-01-02 22:04:21 +00:00
|
|
|
perf_config_set__for_each_entry(set, section, item) {
|
2016-06-23 14:14:31 +00:00
|
|
|
char *value = item->value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
scnprintf(key, sizeof(key), "%s.%s",
|
|
|
|
section->name, item->name);
|
|
|
|
ret = fn(key, value, data);
|
|
|
|
if (ret < 0) {
|
2021-09-24 11:58:17 +00:00
|
|
|
pr_err("Error in the given config file: wrong config key-value pair %s=%s\n",
|
2016-06-23 14:14:31 +00:00
|
|
|
key, value);
|
2019-06-06 13:56:55 +00:00
|
|
|
/*
|
|
|
|
* Can't be just a 'break', as perf_config_set__for_each_entry()
|
|
|
|
* expands to two nested for() loops.
|
|
|
|
*/
|
|
|
|
goto out;
|
2016-06-23 14:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 13:56:55 +00:00
|
|
|
out:
|
2016-06-23 14:14:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:04:21 +00:00
|
|
|
int perf_config(config_fn_t fn, void *data)
|
|
|
|
{
|
|
|
|
if (config_set == NULL && perf_config__init())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return perf_config_set(config_set, fn, data);
|
|
|
|
}
|
|
|
|
|
2016-06-23 14:14:31 +00:00
|
|
|
void perf_config__exit(void)
|
|
|
|
{
|
|
|
|
perf_config_set__delete(config_set);
|
|
|
|
config_set = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void perf_config__refresh(void)
|
|
|
|
{
|
|
|
|
perf_config__exit();
|
|
|
|
perf_config__init();
|
|
|
|
}
|
|
|
|
|
2016-04-14 07:53:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-06-08 12:36:49 +00:00
|
|
|
if (set == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-04-14 07:53:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2017-06-27 14:22:31 +00:00
|
|
|
pr_err("Missing value for '%s'", var);
|
|
|
|
return -1;
|
2009-04-20 13:00:56 +00:00
|
|
|
}
|
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)
|
2018-12-01 15:46:03 +00:00
|
|
|
scnprintf(buildid_dir, MAXPATHLEN, "%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) {
|
2018-12-01 15:46:03 +00:00
|
|
|
snprintf(buildid_dir, MAXPATHLEN, "%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);
|
|
|
|
}
|
2022-09-05 07:34:19 +00:00
|
|
|
|
|
|
|
struct perf_config_scan_data {
|
|
|
|
const char *name;
|
|
|
|
const char *fmt;
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int perf_config_scan_cb(const char *var, const char *value, void *data)
|
|
|
|
{
|
|
|
|
struct perf_config_scan_data *d = data;
|
|
|
|
|
|
|
|
if (!strcmp(var, d->name))
|
|
|
|
d->ret = vsscanf(value, d->fmt, d->args);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int perf_config_scan(const char *name, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct perf_config_scan_data d = {
|
|
|
|
.name = name,
|
|
|
|
.fmt = fmt,
|
|
|
|
};
|
|
|
|
|
|
|
|
va_start(d.args, fmt);
|
|
|
|
perf_config(perf_config_scan_cb, &d);
|
|
|
|
va_end(d.args);
|
|
|
|
|
|
|
|
return d.ret;
|
|
|
|
}
|