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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-08-12 16:03:49 +08:00
|
|
|
/* For general debugging purposes */
|
|
|
|
|
2017-04-18 02:23:08 +08:00
|
|
|
#include <inttypes.h>
|
2009-08-12 16:03:49 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2019-07-04 22:21:24 +08:00
|
|
|
#include <stdlib.h>
|
2017-04-20 06:06:30 +08:00
|
|
|
#include <sys/wait.h>
|
2016-02-15 00:03:45 +08:00
|
|
|
#include <api/debug.h>
|
2019-08-30 04:19:02 +08:00
|
|
|
#include <linux/kernel.h>
|
2016-08-06 02:40:30 +08:00
|
|
|
#include <linux/time64.h>
|
2021-01-03 06:04:22 +08:00
|
|
|
#include <sys/time.h>
|
2017-04-20 03:21:59 +08:00
|
|
|
#ifdef HAVE_BACKTRACE_SUPPORT
|
|
|
|
#include <execinfo.h>
|
|
|
|
#endif
|
2009-08-17 04:05:48 +08:00
|
|
|
#include "color.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "debug.h"
|
2017-04-18 03:23:22 +08:00
|
|
|
#include "print_binary.h"
|
2012-05-07 13:09:02 +08:00
|
|
|
#include "target.h"
|
2019-08-30 03:18:59 +08:00
|
|
|
#include "ui/helpline.h"
|
2019-08-30 23:52:25 +08:00
|
|
|
#include "ui/ui.h"
|
2020-08-08 10:31:30 +08:00
|
|
|
#include "util/parse-sublevel-options.h"
|
2009-08-17 04:05:48 +08:00
|
|
|
|
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-26 04:27:31 +08:00
|
|
|
#include <linux/ctype.h>
|
2021-09-23 08:10:24 +08:00
|
|
|
#include <traceevent/event-parse.h>
|
|
|
|
|
|
|
|
#define MAKE_LIBTRACEEVENT_VERSION(a, b, c) ((a)*255*255+(b)*255+(c))
|
|
|
|
#ifndef LIBTRACEEVENT_VERSION
|
|
|
|
/*
|
|
|
|
* If LIBTRACEEVENT_VERSION wasn't computed then set to version 1.1.0 that ships
|
|
|
|
* with the Linux kernel tools.
|
|
|
|
*/
|
|
|
|
#define LIBTRACEEVENT_VERSION MAKE_LIBTRACEEVENT_VERSION(1, 1, 0)
|
|
|
|
#endif
|
2017-04-18 03:10:49 +08:00
|
|
|
|
2010-10-27 01:20:09 +08:00
|
|
|
int verbose;
|
2019-11-08 17:41:28 +08:00
|
|
|
int debug_peo_args;
|
2010-10-27 01:20:09 +08:00
|
|
|
bool dump_trace = false, quiet = false;
|
2014-07-11 20:49:54 +08:00
|
|
|
int debug_ordered_events;
|
2014-11-22 05:38:00 +08:00
|
|
|
static int redirect_to_stderr;
|
perf data: Add perf data to CTF conversion support
Adding 'perf data convert' to convert perf data file into different
format. This patch adds support for CTF format conversion.
To convert perf.data into CTF run:
$ perf data convert --to-ctf=./ctf-data/
[ perf data convert: Converted 'perf.data' into CTF data './ctf-data/' ]
[ perf data convert: Converted and wrote 11.268 MB (100230 samples) ]
The command will create CTF metadata out of perf.data file (or one
specified via -i option) and then convert all sample events into single
CTF stream.
Each sample_type bit is translated into separated CTF event field apart
from following exceptions:
PERF_SAMPLE_RAW - added in next patch
PERF_SAMPLE_READ - TODO
PERF_SAMPLE_CALLCHAIN - TODO
PERF_SAMPLE_BRANCH_STACK - TODO
PERF_SAMPLE_REGS_USER - TODO
PERF_SAMPLE_STACK_USER - TODO
$ perf --debug=data-convert=2 data convert ...
The converted CTF data could be analyzed by CTF tools, like babletrace
or tracecompass [1].
$ babeltrace ./ctf-data/
[03:19:13.962125533] (+?.?????????) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 1 }
[03:19:13.962130001] (+0.000004468) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 1 }
[03:19:13.962131936] (+0.000001935) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 8 }
[03:19:13.962133732] (+0.000001796) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 114 }
[03:19:13.962135557] (+0.000001825) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 2087 }
[03:19:13.962137627] (+0.000002070) cycles: { }, { ip = 0xFFFFFFFF81361938, tid = 20714, pid = 20714, period = 37582 }
[03:19:13.962161091] (+0.000023464) cycles: { }, { ip = 0xFFFFFFFF8124218F, tid = 20714, pid = 20714, period = 600246 }
[03:19:13.962517569] (+0.000356478) cycles: { }, { ip = 0xFFFFFFFF811A75DB, tid = 20714, pid = 20714, period = 1325731 }
[03:19:13.969518008] (+0.007000439) cycles: { }, { ip = 0x34080917B2, tid = 20714, pid = 20714, period = 1144298 }
The following members to the ctf-environment were decided to be added to
distinguish and specify perf CTF data:
- domain
It says "kernel" because it contains a kernel trace (not to be
confused with a user space like lttng-ust does)
- tracer_name
It says perf. This can be used to distinguish between lttng and perf
CTF based trace.
- version
The kernel version from stream. In addition to release, this is what
it looks like on a Debian kernel:
release = "3.14-1-amd64";
version = "3.14.0";
[1] http://projects.eclipse.org/projects/tools.tracecompass
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jeremie Galarneau <jgalar@efficios.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1424470628-5969-4-git-send-email-jolsa@kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-02-21 06:17:00 +08:00
|
|
|
int debug_data_convert;
|
2020-12-12 18:43:51 +08:00
|
|
|
static FILE *debug_file;
|
2021-01-03 06:04:22 +08:00
|
|
|
bool debug_display_time;
|
2020-12-12 18:43:51 +08:00
|
|
|
|
|
|
|
void debug_set_file(FILE *file)
|
|
|
|
{
|
|
|
|
debug_file = file;
|
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2021-01-03 06:04:22 +08:00
|
|
|
void debug_set_display_time(bool set)
|
|
|
|
{
|
|
|
|
debug_display_time = set;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fprintf_time(FILE *file)
|
|
|
|
{
|
|
|
|
struct timeval tod;
|
|
|
|
struct tm ltime;
|
|
|
|
char date[64];
|
|
|
|
|
|
|
|
if (!debug_display_time)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (gettimeofday(&tod, NULL) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (localtime_r(&tod.tv_sec, <ime) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
strftime(date, sizeof(date), "%F %H:%M:%S", <ime);
|
|
|
|
return fprintf(file, "[%s.%06lu] ", date, (long)tod.tv_usec);
|
|
|
|
}
|
|
|
|
|
2016-02-16 22:48:38 +08:00
|
|
|
int veprintf(int level, int var, const char *fmt, va_list args)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2014-07-15 05:46:49 +08:00
|
|
|
if (var >= level) {
|
2021-01-03 06:04:22 +08:00
|
|
|
if (use_browser >= 1 && !redirect_to_stderr) {
|
2012-11-15 00:47:41 +08:00
|
|
|
ui_helpline__vshow(fmt, args);
|
2021-01-03 06:04:22 +08:00
|
|
|
} else {
|
|
|
|
ret = fprintf_time(debug_file);
|
|
|
|
ret += vfprintf(debug_file, fmt, args);
|
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-08-17 01:24:21 +08:00
|
|
|
|
2014-07-15 05:46:49 +08:00
|
|
|
int eprintf(int level, int var, const char *fmt, ...)
|
2013-12-03 21:09:25 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2016-02-16 22:48:38 +08:00
|
|
|
ret = veprintf(level, var, fmt, args);
|
2013-12-03 21:09:25 +08:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-16 22:48:38 +08:00
|
|
|
static int veprintf_time(u64 t, const char *fmt, va_list args)
|
2014-07-11 20:49:54 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
u64 secs, usecs, nsecs = t;
|
|
|
|
|
2016-08-06 02:40:30 +08:00
|
|
|
secs = nsecs / NSEC_PER_SEC;
|
|
|
|
nsecs -= secs * NSEC_PER_SEC;
|
|
|
|
usecs = nsecs / NSEC_PER_USEC;
|
2014-07-11 20:49:54 +08:00
|
|
|
|
|
|
|
ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
|
|
|
|
secs, usecs);
|
|
|
|
ret += vfprintf(stderr, fmt, args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int eprintf_time(int level, int var, u64 t, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (var >= level) {
|
|
|
|
va_start(args, fmt);
|
2016-02-16 22:48:38 +08:00
|
|
|
ret = veprintf_time(t, fmt, args);
|
2014-07-11 20:49:54 +08:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-03 21:09:25 +08:00
|
|
|
/*
|
|
|
|
* Overloading libtraceevent standard info print
|
|
|
|
* function, display with -v in perf.
|
|
|
|
*/
|
|
|
|
void pr_stat(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2016-02-16 22:48:38 +08:00
|
|
|
veprintf(1, verbose, fmt, args);
|
2013-12-03 21:09:25 +08:00
|
|
|
va_end(args);
|
2014-07-15 05:46:49 +08:00
|
|
|
eprintf(1, verbose, "\n");
|
2013-12-03 21:09:25 +08:00
|
|
|
}
|
|
|
|
|
2009-08-17 01:24:21 +08:00
|
|
|
int dump_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (dump_trace) {
|
|
|
|
va_start(args, fmt);
|
|
|
|
ret = vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-08-17 04:05:48 +08:00
|
|
|
|
2017-10-17 21:35:00 +08:00
|
|
|
static int trace_event_printer(enum binary_printer_ops op,
|
|
|
|
unsigned int val, void *extra, FILE *fp)
|
2016-02-24 19:20:44 +08:00
|
|
|
{
|
|
|
|
const char *color = PERF_COLOR_BLUE;
|
|
|
|
union perf_event *event = (union perf_event *)extra;
|
|
|
|
unsigned char ch = (unsigned char)val;
|
2017-10-17 21:35:00 +08:00
|
|
|
int printed = 0;
|
2016-02-24 19:20:44 +08:00
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case BINARY_PRINT_DATA_BEGIN:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += fprintf(fp, ".");
|
|
|
|
printed += color_fprintf(fp, color, "\n. ... raw event: size %d bytes\n",
|
|
|
|
event->header.size);
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_LINE_BEGIN:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += fprintf(fp, ".");
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_ADDR:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, " %04x: ", val);
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_NUM_DATA:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, " %02x", val);
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_NUM_PAD:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, " ");
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_SEP:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, " ");
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_CHAR_DATA:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, "%c",
|
2016-02-24 19:20:44 +08:00
|
|
|
isprint(ch) ? ch : '.');
|
|
|
|
break;
|
|
|
|
case BINARY_PRINT_CHAR_PAD:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, " ");
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_LINE_END:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += color_fprintf(fp, color, "\n");
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
case BINARY_PRINT_DATA_END:
|
2017-10-17 21:35:00 +08:00
|
|
|
printed += fprintf(fp, "\n");
|
2016-02-24 19:20:44 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-10-17 21:35:00 +08:00
|
|
|
|
|
|
|
return printed;
|
2016-02-24 19:20:44 +08:00
|
|
|
}
|
|
|
|
|
2011-01-30 00:01:45 +08:00
|
|
|
void trace_event(union perf_event *event)
|
2009-08-17 04:05:48 +08:00
|
|
|
{
|
|
|
|
unsigned char *raw_event = (void *)event;
|
|
|
|
|
|
|
|
if (!dump_trace)
|
|
|
|
return;
|
|
|
|
|
2016-02-24 19:20:44 +08:00
|
|
|
print_binary(raw_event, event->header.size, 16,
|
|
|
|
trace_event_printer, event);
|
2009-08-17 04:05:48 +08:00
|
|
|
}
|
2014-07-17 18:55:00 +08:00
|
|
|
|
2020-08-08 10:31:30 +08:00
|
|
|
static struct sublevel_option debug_opts[] = {
|
|
|
|
{ .name = "verbose", .value_ptr = &verbose },
|
|
|
|
{ .name = "ordered-events", .value_ptr = &debug_ordered_events},
|
|
|
|
{ .name = "stderr", .value_ptr = &redirect_to_stderr},
|
|
|
|
{ .name = "data-convert", .value_ptr = &debug_data_convert },
|
|
|
|
{ .name = "perf-event-open", .value_ptr = &debug_peo_args },
|
2014-07-17 18:55:00 +08:00
|
|
|
{ .name = NULL, }
|
|
|
|
};
|
|
|
|
|
|
|
|
int perf_debug_option(const char *str)
|
|
|
|
{
|
2020-08-08 10:31:30 +08:00
|
|
|
int ret;
|
2014-07-17 18:55:00 +08:00
|
|
|
|
2020-08-08 10:31:30 +08:00
|
|
|
ret = perf_parse_sublevel_options(str, debug_opts);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-07-17 18:55:00 +08:00
|
|
|
|
2020-08-08 10:31:30 +08:00
|
|
|
/* Allow only verbose value in range (0, 10), otherwise set 0. */
|
|
|
|
verbose = (verbose < 0) || (verbose > 10) ? 0 : verbose;
|
2017-02-17 16:17:37 +08:00
|
|
|
|
2021-09-23 08:10:24 +08:00
|
|
|
#if MAKE_LIBTRACEEVENT_VERSION(1, 3, 0) <= LIBTRACEEVENT_VERSION
|
|
|
|
if (verbose == 1)
|
|
|
|
tep_set_loglevel(TEP_LOG_INFO);
|
|
|
|
else if (verbose == 2)
|
|
|
|
tep_set_loglevel(TEP_LOG_DEBUG);
|
|
|
|
else if (verbose >= 3)
|
|
|
|
tep_set_loglevel(TEP_LOG_ALL);
|
|
|
|
#endif
|
|
|
|
|
2014-07-17 18:55:00 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-02-15 00:03:45 +08:00
|
|
|
|
2017-02-17 16:17:37 +08:00
|
|
|
int perf_quiet_option(void)
|
|
|
|
{
|
2020-08-08 10:31:30 +08:00
|
|
|
struct sublevel_option *opt = &debug_opts[0];
|
2017-02-17 16:17:37 +08:00
|
|
|
|
|
|
|
/* disable all debug messages */
|
2020-08-08 10:31:30 +08:00
|
|
|
while (opt->name) {
|
|
|
|
*opt->value_ptr = -1;
|
|
|
|
opt++;
|
2017-02-17 16:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-15 00:03:45 +08:00
|
|
|
#define DEBUG_WRAPPER(__n, __l) \
|
|
|
|
static int pr_ ## __n ## _wrapper(const char *fmt, ...) \
|
|
|
|
{ \
|
|
|
|
va_list args; \
|
|
|
|
int ret; \
|
|
|
|
\
|
|
|
|
va_start(args, fmt); \
|
|
|
|
ret = veprintf(__l, verbose, fmt, args); \
|
|
|
|
va_end(args); \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_WRAPPER(warning, 0);
|
|
|
|
DEBUG_WRAPPER(debug, 1);
|
|
|
|
|
|
|
|
void perf_debug_setup(void)
|
|
|
|
{
|
2020-12-12 18:43:51 +08:00
|
|
|
debug_set_file(stderr);
|
2016-02-15 00:03:45 +08:00
|
|
|
libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper);
|
|
|
|
}
|
2017-04-20 03:21:59 +08:00
|
|
|
|
|
|
|
/* Obtain a backtrace and print it to stdout. */
|
|
|
|
#ifdef HAVE_BACKTRACE_SUPPORT
|
|
|
|
void dump_stack(void)
|
|
|
|
{
|
|
|
|
void *array[16];
|
|
|
|
size_t size = backtrace(array, ARRAY_SIZE(array));
|
|
|
|
char **strings = backtrace_symbols(array, size);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
printf("Obtained %zd stack frames.\n", size);
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
printf("%s\n", strings[i]);
|
|
|
|
|
|
|
|
free(strings);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void dump_stack(void) {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void sighandler_dump_stack(int sig)
|
|
|
|
{
|
|
|
|
psignal(sig, "perf");
|
|
|
|
dump_stack();
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
raise(sig);
|
|
|
|
}
|