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
|
2010-02-04 02:52:04 +08:00
|
|
|
/*
|
|
|
|
* build-id.c
|
|
|
|
*
|
|
|
|
* build-id support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, 2010 Red Hat Inc.
|
|
|
|
* Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
|
|
|
|
*/
|
2010-05-20 23:15:33 +08:00
|
|
|
#include "util.h"
|
2017-04-18 23:26:44 +08:00
|
|
|
#include <dirent.h>
|
2017-04-18 21:46:11 +08:00
|
|
|
#include <errno.h>
|
2010-05-20 23:15:33 +08:00
|
|
|
#include <stdio.h>
|
2017-04-20 07:57:47 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2010-02-04 02:52:04 +08:00
|
|
|
#include "build-id.h"
|
|
|
|
#include "event.h"
|
2019-01-22 21:24:34 +08:00
|
|
|
#include "namespaces.h"
|
2019-01-27 20:42:37 +08:00
|
|
|
#include "map.h"
|
2010-02-04 02:52:04 +08:00
|
|
|
#include "symbol.h"
|
2017-04-20 08:34:35 +08:00
|
|
|
#include "thread.h"
|
2010-02-04 02:52:04 +08:00
|
|
|
#include <linux/kernel.h>
|
2010-07-31 05:28:42 +08:00
|
|
|
#include "debug.h"
|
2011-11-25 18:19:45 +08:00
|
|
|
#include "session.h"
|
2011-11-28 18:30:20 +08:00
|
|
|
#include "tool.h"
|
2014-11-04 09:14:30 +08:00
|
|
|
#include "header.h"
|
|
|
|
#include "vdso.h"
|
2017-04-18 22:33:48 +08:00
|
|
|
#include "path.h"
|
2016-07-01 16:04:10 +08:00
|
|
|
#include "probe-file.h"
|
2017-04-18 21:57:25 +08:00
|
|
|
#include "strlist.h"
|
2010-02-04 02:52:04 +08:00
|
|
|
|
2017-04-18 03:10:49 +08:00
|
|
|
#include "sane_ctype.h"
|
2014-11-07 21:57:56 +08:00
|
|
|
|
|
|
|
static bool no_buildid_cache;
|
|
|
|
|
2012-08-07 20:56:05 +08:00
|
|
|
int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
|
|
|
|
union perf_event *event,
|
2013-08-27 16:23:06 +08:00
|
|
|
struct perf_sample *sample,
|
2012-08-07 20:56:05 +08:00
|
|
|
struct perf_evsel *evsel __maybe_unused,
|
|
|
|
struct machine *machine)
|
2010-02-04 02:52:04 +08:00
|
|
|
{
|
|
|
|
struct addr_location al;
|
2013-08-27 16:23:06 +08:00
|
|
|
struct thread *thread = machine__findnew_thread(machine, sample->pid,
|
2014-05-12 08:56:42 +08:00
|
|
|
sample->tid);
|
2010-02-04 02:52:04 +08:00
|
|
|
|
|
|
|
if (thread == NULL) {
|
|
|
|
pr_err("problem processing %d event, skipping it.\n",
|
|
|
|
event->header.type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:58:56 +08:00
|
|
|
if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
|
2010-02-04 02:52:04 +08:00
|
|
|
al.map->dso->hit = 1;
|
|
|
|
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
thread__put(thread);
|
2010-02-04 02:52:04 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-11 06:15:03 +08:00
|
|
|
static int perf_event__exit_del_thread(struct perf_tool *tool __maybe_unused,
|
2011-11-25 18:19:45 +08:00
|
|
|
union perf_event *event,
|
2012-09-11 06:15:03 +08:00
|
|
|
struct perf_sample *sample
|
|
|
|
__maybe_unused,
|
2011-11-28 17:56:39 +08:00
|
|
|
struct machine *machine)
|
2010-07-31 05:28:42 +08:00
|
|
|
{
|
2013-08-27 16:23:03 +08:00
|
|
|
struct thread *thread = machine__findnew_thread(machine,
|
|
|
|
event->fork.pid,
|
|
|
|
event->fork.tid);
|
2010-07-31 05:28:42 +08:00
|
|
|
|
2011-01-30 00:01:45 +08:00
|
|
|
dump_printf("(%d:%d):(%d:%d)\n", event->fork.pid, event->fork.tid,
|
|
|
|
event->fork.ppid, event->fork.ptid);
|
2010-07-31 05:28:42 +08:00
|
|
|
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
if (thread) {
|
2015-04-10 17:35:00 +08:00
|
|
|
machine__remove_thread(machine, thread);
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
thread__put(thread);
|
|
|
|
}
|
2010-07-31 05:28:42 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-28 18:30:20 +08:00
|
|
|
struct perf_tool build_id__mark_dso_hit_ops = {
|
2010-02-04 02:52:04 +08:00
|
|
|
.sample = build_id__mark_dso_hit,
|
2011-01-30 00:01:45 +08:00
|
|
|
.mmap = perf_event__process_mmap,
|
2013-08-21 18:10:25 +08:00
|
|
|
.mmap2 = perf_event__process_mmap2,
|
2012-10-07 02:44:59 +08:00
|
|
|
.fork = perf_event__process_fork,
|
2011-01-30 00:01:45 +08:00
|
|
|
.exit = perf_event__exit_del_thread,
|
2012-05-15 19:28:15 +08:00
|
|
|
.attr = perf_event__process_attr,
|
|
|
|
.build_id = perf_event__process_build_id,
|
2015-11-13 17:48:31 +08:00
|
|
|
.ordered_events = true,
|
2010-02-04 02:52:04 +08:00
|
|
|
};
|
2010-05-20 23:15:33 +08:00
|
|
|
|
2012-10-28 05:18:28 +08:00
|
|
|
int build_id__sprintf(const u8 *build_id, int len, char *bf)
|
|
|
|
{
|
|
|
|
char *bid = bf;
|
|
|
|
const u8 *raw = build_id;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
sprintf(bid, "%02x", *raw);
|
|
|
|
++raw;
|
|
|
|
bid += 2;
|
|
|
|
}
|
|
|
|
|
2015-11-27 21:48:09 +08:00
|
|
|
return (bid - bf) + 1;
|
2012-10-28 05:18:28 +08:00
|
|
|
}
|
|
|
|
|
2015-08-15 19:42:59 +08:00
|
|
|
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
|
|
|
|
{
|
|
|
|
char notes[PATH_MAX];
|
|
|
|
u8 build_id[BUILD_ID_SIZE];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!root_dir)
|
|
|
|
root_dir = "";
|
|
|
|
|
|
|
|
scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
|
|
|
|
|
|
|
|
ret = sysfs__read_build_id(notes, build_id, sizeof(build_id));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
|
|
|
|
{
|
|
|
|
u8 build_id[BUILD_ID_SIZE];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = filename__read_build_id(pathname, build_id, sizeof(build_id));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
else if (ret != sizeof(build_id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
|
|
|
|
}
|
|
|
|
|
2015-02-10 17:18:53 +08:00
|
|
|
/* asnprintf consolidates asprintf and snprintf */
|
|
|
|
static int asnprintf(char **strp, size_t size, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!strp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if (*strp)
|
|
|
|
ret = vsnprintf(*strp, size, fmt, ap);
|
|
|
|
else
|
|
|
|
ret = vasprintf(strp, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
char *build_id_cache__kallsyms_path(const char *sbuild_id, char *bf,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
bool retry_old = true;
|
|
|
|
|
2016-06-07 11:54:38 +08:00
|
|
|
snprintf(bf, size, "%s/%s/%s/kallsyms",
|
|
|
|
buildid_dir, DSO__NAME_KALLSYMS, sbuild_id);
|
2016-05-28 23:15:37 +08:00
|
|
|
retry:
|
|
|
|
if (!access(bf, F_OK))
|
|
|
|
return bf;
|
|
|
|
if (retry_old) {
|
|
|
|
/* Try old style kallsyms cache */
|
2016-06-07 11:54:38 +08:00
|
|
|
snprintf(bf, size, "%s/%s/%s",
|
|
|
|
buildid_dir, DSO__NAME_KALLSYMS, sbuild_id);
|
2016-05-28 23:15:37 +08:00
|
|
|
retry_old = false;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-01 16:03:26 +08:00
|
|
|
char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size)
|
2015-02-10 17:18:53 +08:00
|
|
|
{
|
|
|
|
char *tmp = bf;
|
|
|
|
int ret = asnprintf(&bf, size, "%s/.build-id/%.2s/%s", buildid_dir,
|
|
|
|
sbuild_id, sbuild_id + 2);
|
|
|
|
if (ret < 0 || (tmp && size < (unsigned int)ret))
|
|
|
|
return NULL;
|
|
|
|
return bf;
|
|
|
|
}
|
|
|
|
|
2019-03-16 16:05:46 +08:00
|
|
|
/* The caller is responsible to free the returned buffer. */
|
2016-07-01 16:03:26 +08:00
|
|
|
char *build_id_cache__origname(const char *sbuild_id)
|
|
|
|
{
|
|
|
|
char *linkname;
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
char *ret = NULL, *p;
|
|
|
|
size_t offs = 5; /* == strlen("../..") */
|
2017-03-22 21:06:20 +08:00
|
|
|
ssize_t len;
|
2016-07-01 16:03:26 +08:00
|
|
|
|
|
|
|
linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
|
|
|
|
if (!linkname)
|
|
|
|
return NULL;
|
|
|
|
|
2017-03-22 21:06:20 +08:00
|
|
|
len = readlink(linkname, buf, sizeof(buf) - 1);
|
|
|
|
if (len <= 0)
|
2016-07-01 16:03:26 +08:00
|
|
|
goto out;
|
2017-03-22 21:06:20 +08:00
|
|
|
buf[len] = '\0';
|
|
|
|
|
2016-07-01 16:03:26 +08:00
|
|
|
/* The link should be "../..<origpath>/<sbuild_id>" */
|
|
|
|
p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */
|
|
|
|
if (p && (p > buf + offs)) {
|
|
|
|
*p = '\0';
|
|
|
|
if (buf[offs + 1] == '[')
|
|
|
|
offs++; /*
|
|
|
|
* This is a DSO name, like [kernel.kallsyms].
|
|
|
|
* Skip the first '/', since this is not the
|
|
|
|
* cache of a regular file.
|
|
|
|
*/
|
|
|
|
ret = strdup(buf + offs); /* Skip "../..[/]" */
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
free(linkname);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-12 18:04:54 +08:00
|
|
|
/* Check if the given build_id cache is valid on current running system */
|
|
|
|
static bool build_id_cache__valid_id(char *sbuild_id)
|
|
|
|
{
|
|
|
|
char real_sbuild_id[SBUILD_ID_SIZE] = "";
|
|
|
|
char *pathname;
|
|
|
|
int ret = 0;
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
pathname = build_id_cache__origname(sbuild_id);
|
|
|
|
if (!pathname)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!strcmp(pathname, DSO__NAME_KALLSYMS))
|
|
|
|
ret = sysfs__sprintf_build_id("/", real_sbuild_id);
|
|
|
|
else if (pathname[0] == '/')
|
|
|
|
ret = filename__sprintf_build_id(pathname, real_sbuild_id);
|
|
|
|
else
|
|
|
|
ret = -EINVAL; /* Should we support other special DSO cache? */
|
|
|
|
if (ret >= 0)
|
|
|
|
result = (strcmp(sbuild_id, real_sbuild_id) == 0);
|
|
|
|
free(pathname);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-06 09:48:13 +08:00
|
|
|
static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso,
|
|
|
|
bool is_debug)
|
2016-05-28 23:15:37 +08:00
|
|
|
{
|
2017-07-06 09:48:13 +08:00
|
|
|
return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : (is_debug ?
|
|
|
|
"debug" : "elf"));
|
2016-05-28 23:15:37 +08:00
|
|
|
}
|
|
|
|
|
2017-07-06 09:48:13 +08:00
|
|
|
char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size,
|
|
|
|
bool is_debug)
|
2010-05-20 23:15:33 +08:00
|
|
|
{
|
2016-05-28 23:15:37 +08:00
|
|
|
bool is_kallsyms = dso__is_kallsyms((struct dso *)dso);
|
|
|
|
bool is_vdso = dso__is_vdso((struct dso *)dso);
|
|
|
|
char sbuild_id[SBUILD_ID_SIZE];
|
|
|
|
char *linkname;
|
|
|
|
bool alloc = (bf == NULL);
|
|
|
|
int ret;
|
2010-05-20 23:15:33 +08:00
|
|
|
|
2013-10-23 06:01:31 +08:00
|
|
|
if (!dso->has_build_id)
|
2010-05-20 23:15:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
|
|
|
|
linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
|
|
|
|
if (!linkname)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Check if old style build_id cache */
|
|
|
|
if (is_regular_file(linkname))
|
|
|
|
ret = asnprintf(&bf, size, "%s", linkname);
|
|
|
|
else
|
|
|
|
ret = asnprintf(&bf, size, "%s/%s", linkname,
|
2017-07-06 09:48:13 +08:00
|
|
|
build_id_cache__basename(is_kallsyms, is_vdso,
|
|
|
|
is_debug));
|
2016-05-28 23:15:37 +08:00
|
|
|
if (ret < 0 || (!alloc && size < (unsigned int)ret))
|
|
|
|
bf = NULL;
|
|
|
|
free(linkname);
|
|
|
|
|
|
|
|
return bf;
|
2010-05-20 23:15:33 +08:00
|
|
|
}
|
2014-11-04 09:14:30 +08:00
|
|
|
|
|
|
|
#define dsos__for_each_with_build_id(pos, head) \
|
|
|
|
list_for_each_entry(pos, head, node) \
|
|
|
|
if (!pos->has_build_id) \
|
|
|
|
continue; \
|
|
|
|
else
|
|
|
|
|
|
|
|
static int write_buildid(const char *name, size_t name_len, u8 *build_id,
|
2017-07-18 12:25:39 +08:00
|
|
|
pid_t pid, u16 misc, struct feat_fd *fd)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct build_id_event b;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = name_len + 1;
|
|
|
|
len = PERF_ALIGN(len, NAME_ALIGN);
|
|
|
|
|
|
|
|
memset(&b, 0, sizeof(b));
|
|
|
|
memcpy(&b.build_id, build_id, BUILD_ID_SIZE);
|
|
|
|
b.pid = pid;
|
|
|
|
b.header.misc = misc;
|
|
|
|
b.header.size = sizeof(b) + len;
|
|
|
|
|
2017-07-18 12:25:38 +08:00
|
|
|
err = do_write(fd, &b, sizeof(b));
|
2014-11-04 09:14:30 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return write_padded(fd, name, name_len + 1, len);
|
|
|
|
}
|
|
|
|
|
2017-07-18 12:25:39 +08:00
|
|
|
static int machine__write_buildid_table(struct machine *machine,
|
|
|
|
struct feat_fd *fd)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
2015-05-29 00:06:42 +08:00
|
|
|
int err = 0;
|
2014-11-04 09:14:30 +08:00
|
|
|
struct dso *pos;
|
2015-05-29 00:06:42 +08:00
|
|
|
u16 kmisc = PERF_RECORD_MISC_KERNEL,
|
|
|
|
umisc = PERF_RECORD_MISC_USER;
|
|
|
|
|
|
|
|
if (!machine__is_host(machine)) {
|
|
|
|
kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
|
|
|
|
umisc = PERF_RECORD_MISC_GUEST_USER;
|
|
|
|
}
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2015-05-29 00:06:42 +08:00
|
|
|
dsos__for_each_with_build_id(pos, &machine->dsos.head) {
|
2014-11-04 09:14:30 +08:00
|
|
|
const char *name;
|
|
|
|
size_t name_len;
|
2016-01-30 01:40:51 +08:00
|
|
|
bool in_kernel = false;
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2016-05-12 16:43:11 +08:00
|
|
|
if (!pos->hit && !dso__is_vdso(pos))
|
2014-11-04 09:14:30 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dso__is_vdso(pos)) {
|
|
|
|
name = pos->short_name;
|
2016-04-19 16:17:27 +08:00
|
|
|
name_len = pos->short_name_len;
|
2014-11-04 09:14:30 +08:00
|
|
|
} else if (dso__is_kcore(pos)) {
|
2018-02-15 20:26:30 +08:00
|
|
|
name = machine->mmap_name;
|
|
|
|
name_len = strlen(name);
|
2014-11-04 09:14:30 +08:00
|
|
|
} else {
|
|
|
|
name = pos->long_name;
|
2016-04-19 16:17:27 +08:00
|
|
|
name_len = pos->long_name_len;
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
2016-01-30 01:40:51 +08:00
|
|
|
in_kernel = pos->kernel ||
|
|
|
|
is_kernel_module(name,
|
|
|
|
PERF_RECORD_MISC_CPUMODE_UNKNOWN);
|
2015-05-29 00:06:42 +08:00
|
|
|
err = write_buildid(name, name_len, pos->build_id, machine->pid,
|
2016-01-30 01:40:51 +08:00
|
|
|
in_kernel ? kmisc : umisc, fd);
|
2014-11-04 09:14:30 +08:00
|
|
|
if (err)
|
2015-05-29 00:06:42 +08:00
|
|
|
break;
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-07-18 12:25:39 +08:00
|
|
|
int perf_session__write_buildid_table(struct perf_session *session,
|
|
|
|
struct feat_fd *fd)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
int err = machine__write_buildid_table(&session->machines.host, fd);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-12-07 03:18:14 +08:00
|
|
|
for (nd = rb_first_cached(&session->machines.guests); nd;
|
|
|
|
nd = rb_next(nd)) {
|
2014-11-04 09:14:30 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
|
|
|
err = machine__write_buildid_table(pos, fd);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __dsos__hit_all(struct list_head *head)
|
|
|
|
{
|
|
|
|
struct dso *pos;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, head, node)
|
|
|
|
pos->hit = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int machine__hit_all_dsos(struct machine *machine)
|
|
|
|
{
|
2015-05-29 00:06:42 +08:00
|
|
|
return __dsos__hit_all(&machine->dsos.head);
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int dsos__hit_all(struct perf_session *session)
|
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = machine__hit_all_dsos(&session->machines.host);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-12-07 03:18:14 +08:00
|
|
|
for (nd = rb_first_cached(&session->machines.guests); nd;
|
|
|
|
nd = rb_next(nd)) {
|
2014-11-04 09:14:30 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
|
|
|
|
|
|
|
err = machine__hit_all_dsos(pos);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:57:56 +08:00
|
|
|
void disable_buildid_cache(void)
|
|
|
|
{
|
|
|
|
no_buildid_cache = true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 16:03:26 +08:00
|
|
|
static bool lsdir_bid_head_filter(const char *name __maybe_unused,
|
2017-04-18 23:20:19 +08:00
|
|
|
struct dirent *d)
|
2016-07-01 16:03:26 +08:00
|
|
|
{
|
|
|
|
return (strlen(d->d_name) == 2) &&
|
|
|
|
isxdigit(d->d_name[0]) && isxdigit(d->d_name[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool lsdir_bid_tail_filter(const char *name __maybe_unused,
|
2017-04-18 23:20:19 +08:00
|
|
|
struct dirent *d)
|
2016-07-01 16:03:26 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3)
|
|
|
|
i++;
|
|
|
|
return (i == SBUILD_ID_SIZE - 3) && (d->d_name[i] == '\0');
|
|
|
|
}
|
|
|
|
|
2016-07-12 18:04:54 +08:00
|
|
|
struct strlist *build_id_cache__list_all(bool validonly)
|
2016-07-01 16:03:26 +08:00
|
|
|
{
|
|
|
|
struct strlist *toplist, *linklist = NULL, *bidlist;
|
|
|
|
struct str_node *nd, *nd2;
|
|
|
|
char *topdir, *linkdir = NULL;
|
|
|
|
char sbuild_id[SBUILD_ID_SIZE];
|
|
|
|
|
2016-07-12 18:04:54 +08:00
|
|
|
/* for filename__ functions */
|
|
|
|
if (validonly)
|
|
|
|
symbol__init(NULL);
|
|
|
|
|
2016-07-01 16:03:26 +08:00
|
|
|
/* Open the top-level directory */
|
|
|
|
if (asprintf(&topdir, "%s/.build-id/", buildid_dir) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bidlist = strlist__new(NULL, NULL);
|
|
|
|
if (!bidlist)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
toplist = lsdir(topdir, lsdir_bid_head_filter);
|
|
|
|
if (!toplist) {
|
|
|
|
pr_debug("Error in lsdir(%s): %d\n", topdir, errno);
|
|
|
|
/* If there is no buildid cache, return an empty list */
|
|
|
|
if (errno == ENOENT)
|
|
|
|
goto out;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
strlist__for_each_entry(nd, toplist) {
|
|
|
|
if (asprintf(&linkdir, "%s/%s", topdir, nd->s) < 0)
|
|
|
|
goto err_out;
|
|
|
|
/* Open the lower-level directory */
|
|
|
|
linklist = lsdir(linkdir, lsdir_bid_tail_filter);
|
|
|
|
if (!linklist) {
|
|
|
|
pr_debug("Error in lsdir(%s): %d\n", linkdir, errno);
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
strlist__for_each_entry(nd2, linklist) {
|
|
|
|
if (snprintf(sbuild_id, SBUILD_ID_SIZE, "%s%s",
|
|
|
|
nd->s, nd2->s) != SBUILD_ID_SIZE - 1)
|
|
|
|
goto err_out;
|
2016-07-12 18:04:54 +08:00
|
|
|
if (validonly && !build_id_cache__valid_id(sbuild_id))
|
|
|
|
continue;
|
2016-07-01 16:03:26 +08:00
|
|
|
if (strlist__add(bidlist, sbuild_id) < 0)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
strlist__delete(linklist);
|
|
|
|
zfree(&linkdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
strlist__delete(toplist);
|
|
|
|
out:
|
|
|
|
free(topdir);
|
|
|
|
|
|
|
|
return bidlist;
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
strlist__delete(linklist);
|
|
|
|
zfree(&linkdir);
|
|
|
|
strlist__delete(bidlist);
|
|
|
|
bidlist = NULL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
perf probe: Support @BUILDID or @FILE suffix for SDT events
Support @BUILDID or @FILE suffix for SDT events. This allows perf to add
probes on SDTs/pre-cached events on given FILE or the file which has
given BUILDID (also, this complements BUILDID.)
For example, both gcc and libstdc++ has same SDTs as below. If you
would like to add a probe on sdt_libstdcxx:catch on gcc, you can do as
below.
----
# perf list sdt | tail -n 6
sdt_libstdcxx:catch@/usr/bin/gcc(0cc207fc4b27) [SDT event]
sdt_libstdcxx:catch@/usr/lib64/libstdc++.so.6.0.20(91c7a88fdf49)
sdt_libstdcxx:rethrow@/usr/bin/gcc(0cc207fc4b27) [SDT event]
sdt_libstdcxx:rethrow@/usr/lib64/libstdc++.so.6.0.20(91c7a88fdf49)
sdt_libstdcxx:throw@/usr/bin/gcc(0cc207fc4b27) [SDT event]
sdt_libstdcxx:throw@/usr/lib64/libstdc++.so.6.0.20(91c7a88fdf49)
# perf probe -a %sdt_libstdcxx:catch@0cc
Added new event:
sdt_libstdcxx:catch (on %catch in /usr/bin/gcc)
You can now use it in all perf tools, such as:
perf record -e sdt_libstdcxx:catch -aR sleep 1
----
Committer note:
Doing the full sequence of steps to get the results above:
With a clean build-id cache:
[root@jouet ~]# rm -rf ~/.debug/
[root@jouet ~]# perf list sdt
List of pre-defined events (to be used in -e):
[root@jouet ~]#
No events whatsoever, then, we can add all events in gcc to the build-id
cache, doing a --add + --dry-run:
[root@jouet ~]# perf probe --dry-run --cache -x /usr/bin/gcc --add %sdt_libstdcxx:\*
Added new events:
sdt_libstdcxx:throw (on %* in /usr/bin/gcc)
sdt_libstdcxx:rethrow (on %* in /usr/bin/gcc)
sdt_libstdcxx:catch (on %* in /usr/bin/gcc)
You can now use it in all perf tools, such as:
perf record -e sdt_libstdcxx:catch -aR sleep 1
[root@jouet ~]#
It really didn't add any events, it just cached them:
[root@jouet ~]# perf probe -l
[root@jouet ~]#
We can see that it was cached as:
[root@jouet ~]# ls -la ~/.debug/usr/bin/gcc/9a0730e2bcc6d2a2003d21ac46807e8ee6bcb7c2/
total 976
drwxr-xr-x. 2 root root 4096 Jul 13 21:47 .
drwxr-xr-x. 3 root root 4096 Jul 13 21:47 ..
-rwxr-xr-x. 4 root root 985912 Jun 22 18:52 elf
-rw-r--r--. 1 root root 303 Jul 13 21:47 probes
[root@jouet ~]# file ~/.debug/usr/bin/gcc/9a0730e2bcc6d2a2003d21ac46807e8ee6bcb7c2/elf
/root/.debug/usr/bin/gcc/9a0730e2bcc6d2a2003d21ac46807e8ee6bcb7c2/elf: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=9a0730e2bcc6d2a2003d21ac46807e8ee6bcb7c2, stripped
[root@jouet ~]# cat ~/.debug/usr/bin/gcc/9a0730e2bcc6d2a2003d21ac46807e8ee6bcb7c2/probes
%sdt_libstdcxx:throw=throw
p:sdt_libstdcxx/throw /usr/bin/gcc:0x71ffd
%sdt_libstdcxx:rethrow=rethrow
p:sdt_libstdcxx/rethrow /usr/bin/gcc:0x720b8
%sdt_libstdcxx:catch=catch
p:sdt_libstdcxx/catch /usr/bin/gcc:0x7307f
%sdt_libgcc:unwind=unwind
p:sdt_libgcc/unwind /usr/bin/gcc:0x7eec0
#sdt_libstdcxx:*=%*
[root@jouet ~]#
Ok, now we can use 'perf probe' to refer to those cached entries as:
Humm, nope, doing as above we end up with:
[root@jouet ~]# perf probe -a %sdt_libstdcxx:catch
Semantic error :* is bad for event name -it must follow C symbol-naming rule.
Error: Failed to add events.
[root@jouet ~]#
But it worked at some point, lets try not using --dry-run:
Resetting everything:
# rm -rf ~/.debug/
# perf probe -d *:*
# perf probe -l
# perf list sdt
List of pre-defined events (to be used in -e):
#
Ok, now it cached everything, even things we haven't asked it to
(sdt_libgcc:unwind):
[root@jouet ~]# perf probe -x /usr/bin/gcc --add %sdt_libstdcxx:\*
Added new events:
sdt_libstdcxx:throw (on %* in /usr/bin/gcc)
sdt_libstdcxx:rethrow (on %* in /usr/bin/gcc)
sdt_libstdcxx:catch (on %* in /usr/bin/gcc)
You can now use it in all perf tools, such as:
perf record -e sdt_libstdcxx:catch -aR sleep 1
[root@jouet ~]# perf list sdt
List of pre-defined events (to be used in -e):
sdt_libgcc:unwind [SDT event]
sdt_libstdcxx:catch [SDT event]
sdt_libstdcxx:rethrow [SDT event]
sdt_libstdcxx:throw [SDT event]
[root@jouet ~]#
And we have the events in place:
[root@jouet ~]# perf probe -l
sdt_libstdcxx:catch (on execute_cfa_program+1551@../../../libgcc/unwind-dw2.c in /usr/bin/gcc)
sdt_libstdcxx:rethrow (on d_print_subexpr+280@libsupc++/cp-demangle.c in /usr/bin/gcc)
sdt_libstdcxx:throw (on d_print_subexpr+93@libsupc++/cp-demangle.c in /usr/bin/gcc)
[root@jouet ~]#
And trying to use them at least has 'perf trace --event sdt*:*' working.
Then, if we try to add the ones in libstdc++:
[root@jouet ~]# perf probe -x /usr/lib64/libstdc++.so.6 -a %sdt_libstdcxx:\*
Error: event "catch" already exists.
Hint: Remove existing event by 'perf probe -d'
or force duplicates by 'perf probe -f'
or set 'force=yes' in BPF source.
Error: Failed to add events.
[root@jouet ~]#
Doesn't work, dups, but at least this served to, unbeknownst to the user, add
the SDT probes in /usr/lib64/libstdc++.so.6!
[root@jouet ~]# perf list sdt
List of pre-defined events (to be used in -e):
sdt_libgcc:unwind [SDT event]
sdt_libstdcxx:catch@/usr/bin/gcc(9a0730e2bcc6) [SDT event]
sdt_libstdcxx:catch@/usr/lib64/libstdc++.so.6.0.22(ef2b7066559a) [SDT event]
sdt_libstdcxx:rethrow@/usr/bin/gcc(9a0730e2bcc6) [SDT event]
sdt_libstdcxx:rethrow@/usr/lib64/libstdc++.so.6.0.22(ef2b7066559a) [SDT event]
sdt_libstdcxx:throw@/usr/bin/gcc(9a0730e2bcc6) [SDT event]
sdt_libstdcxx:throw@/usr/lib64/libstdc++.so.6.0.22(ef2b7066559a) [SDT event]
[root@jouet ~]#
Now we should be able to get to the original cset comment, if we remove all
SDTs events in place, not from the cache, from the kernel, where it was set up as:
[root@jouet ~]# ls -la /sys/kernel/debug/tracing/events/sdt_libstdcxx/
total 0
drwxr-xr-x. 5 root root 0 Jul 13 22:00 .
drwxr-xr-x. 80 root root 0 Jul 13 21:56 ..
drwxr-xr-x. 2 root root 0 Jul 13 22:00 catch
-rw-r--r--. 1 root root 0 Jul 13 22:00 enable
-rw-r--r--. 1 root root 0 Jul 13 22:00 filter
drwxr-xr-x. 2 root root 0 Jul 13 22:00 rethrow
drwxr-xr-x. 2 root root 0 Jul 13 22:00 throw
[root@jouet ~]#
[root@jouet ~]# head -2 /sys/kernel/debug/tracing/events/sdt_libstdcxx/throw/format
name: throw
ID: 2059
[root@jouet ~]#
Now to remove it:
[root@jouet ~]# perf probe -d sdt_libstdc*:*
Removed event: sdt_libstdcxx:catch
Removed event: sdt_libstdcxx:rethrow
Removed event: sdt_libstdcxx:throw
[root@jouet ~]#
Which caused:
[root@jouet ~]# ls -la /sys/kernel/debug/tracing/events/sdt_libstdcxx/
ls: cannot access '/sys/kernel/debug/tracing/events/sdt_libstdcxx/': No such file or directory
[root@jouet ~]#
Ok, now we can do:
[root@jouet ~]# perf list sdt_libstdcxx:catch
List of pre-defined events (to be used in -e):
sdt_libstdcxx:catch@/usr/bin/gcc(9a0730e2bcc6) [SDT event]
sdt_libstdcxx:catch@/usr/lib64/libstdc++.so.6.0.22(ef2b7066559a) [SDT event]
[root@jouet ~]#
So, these are not really 'pre-defined events', i.e. we can't use them with
'perf record --event':
[root@jouet ~]# perf record --event sdt_libstdcxx:catch*
event syntax error: 'sdt_libstdcxx:catch*'
\___ unknown tracepoint
Error: File /sys/kernel/debug/tracing/events/sdt_libstdcxx/catch* not found.
Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?.
<SNIP>
[root@jouet ~]#
To have it really pre-defined we must use perf probe to get its definition from
the cache and set it up in the kernel, creating the tracepoint to _then_ use it
with 'perf record --event':
[root@jouet ~]# perf probe -a sdt_libstdcxx:catch
Semantic error :There is non-digit char in line number.
<SNIP>
Oops, there is another gotcha here, we need that pesky '%' character:
[root@jouet ~]# perf probe -a %sdt_libstdcxx:catch
Added new events:
sdt_libstdcxx:catch (on %catch in /usr/bin/gcc)
sdt_libstdcxx:catch_1 (on %catch in /usr/lib64/libstdc++.so.6.0.22)
You can now use it in all perf tools, such as:
perf record -e sdt_libstdcxx:catch_1 -aR sleep 1
[root@jouet ~]#
But then we added _two_ events, one with the name we expected, the other one
with a _ added, when doing the analysis we need to pay attention to who maps to
who.
And here is where we get to the point of this patch, which is to be able to
disambiguate those definitions for 'catch' in the build-id cache, but first we need
remove those events we just added:
[root@jouet ~]# perf probe -d %sdt_libstdcxx:catch
Oops, that didn't remove anything, we need to _remove_ that % char in this case:
[root@jouet ~]# perf probe -d sdt_libstdcxx:catch
Removed event: sdt_libstdcxx:catch
And we need to remove the other event added, i.e. I forgot to add a * at the end:
[root@jouet ~]# perf probe -d sdt_libstdcxx:catch*
Removed event: sdt_libstdcxx:catch_1
[root@jouet ~]#
Ok, disambiguating it using what is in this patch:
[root@jouet ~]# perf list sdt_libstdcxx:catch
List of pre-defined events (to be used in -e):
sdt_libstdcxx:catch@/usr/bin/gcc(9a0730e2bcc6) [SDT event]
sdt_libstdcxx:catch@/usr/lib64/libstdc++.so.6.0.22(ef2b7066559a) [SDT event]
[root@jouet ~]#
[root@jouet ~]# perf probe -a %sdt_libstdcxx:catch@9a07
Added new event:
sdt_libstdcxx:catch (on %catch in /usr/bin/gcc)
You can now use it in all perf tools, such as:
perf record -e sdt_libstdcxx:catch -aR sleep 1
[root@jouet ~]# perf probe -l
sdt_libstdcxx:catch (on execute_cfa_program+1551@../../../libgcc/unwind-dw2.c in /usr/bin/gcc)
[root@jouet ~]#
Yeah, it works! But we need to try and simplify this :-)
Update: Some aspects of this simplification take place in the following
patches.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/146831793746.17065.13065062753978236612.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-07-12 18:05:37 +08:00
|
|
|
static bool str_is_build_id(const char *maybe_sbuild_id, size_t len)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (!isxdigit(maybe_sbuild_id[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the valid complete build-id */
|
|
|
|
char *build_id_cache__complement(const char *incomplete_sbuild_id)
|
|
|
|
{
|
|
|
|
struct strlist *bidlist;
|
|
|
|
struct str_node *nd, *cand = NULL;
|
|
|
|
char *sbuild_id = NULL;
|
|
|
|
size_t len = strlen(incomplete_sbuild_id);
|
|
|
|
|
|
|
|
if (len >= SBUILD_ID_SIZE ||
|
|
|
|
!str_is_build_id(incomplete_sbuild_id, len))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bidlist = build_id_cache__list_all(true);
|
|
|
|
if (!bidlist)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
strlist__for_each_entry(nd, bidlist) {
|
|
|
|
if (strncmp(nd->s, incomplete_sbuild_id, len) != 0)
|
|
|
|
continue;
|
|
|
|
if (cand) { /* Error: There are more than 2 candidates. */
|
|
|
|
cand = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cand = nd;
|
|
|
|
}
|
|
|
|
if (cand)
|
|
|
|
sbuild_id = strdup(cand->s);
|
|
|
|
strlist__delete(bidlist);
|
|
|
|
|
|
|
|
return sbuild_id;
|
|
|
|
}
|
|
|
|
|
2016-06-08 17:29:30 +08:00
|
|
|
char *build_id_cache__cachedir(const char *sbuild_id, const char *name,
|
2017-07-06 09:48:11 +08:00
|
|
|
struct nsinfo *nsi, bool is_kallsyms,
|
|
|
|
bool is_vdso)
|
2015-02-27 12:50:26 +08:00
|
|
|
{
|
|
|
|
char *realname = (char *)name, *filename;
|
|
|
|
bool slash = is_kallsyms || is_vdso;
|
|
|
|
|
|
|
|
if (!slash) {
|
2017-07-06 09:48:11 +08:00
|
|
|
realname = nsinfo__realpath(name, nsi);
|
2015-02-27 12:50:26 +08:00
|
|
|
if (!realname)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
if (asprintf(&filename, "%s%s%s%s%s", buildid_dir, slash ? "/" : "",
|
|
|
|
is_vdso ? DSO__NAME_VDSO : realname,
|
|
|
|
sbuild_id ? "/" : "", sbuild_id ?: "") < 0)
|
2015-02-27 12:50:26 +08:00
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
if (!slash)
|
|
|
|
free(realname);
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2017-07-06 09:48:11 +08:00
|
|
|
int build_id_cache__list_build_ids(const char *pathname, struct nsinfo *nsi,
|
2015-02-27 12:50:26 +08:00
|
|
|
struct strlist **result)
|
|
|
|
{
|
|
|
|
char *dir_name;
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-07-06 09:48:11 +08:00
|
|
|
dir_name = build_id_cache__cachedir(NULL, pathname, nsi, false, false);
|
2016-05-11 21:52:17 +08:00
|
|
|
if (!dir_name)
|
|
|
|
return -ENOMEM;
|
2015-02-27 12:50:26 +08:00
|
|
|
|
2016-05-11 21:52:17 +08:00
|
|
|
*result = lsdir(dir_name, lsdir_no_dot_filter);
|
|
|
|
if (!*result)
|
2015-02-27 12:50:26 +08:00
|
|
|
ret = -errno;
|
|
|
|
free(dir_name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-12 23:19:09 +08:00
|
|
|
#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_GELF_GETNOTE_SUPPORT)
|
2016-07-01 16:04:10 +08:00
|
|
|
static int build_id_cache__add_sdt_cache(const char *sbuild_id,
|
2017-07-06 09:48:11 +08:00
|
|
|
const char *realname,
|
|
|
|
struct nsinfo *nsi)
|
2016-07-01 16:04:10 +08:00
|
|
|
{
|
|
|
|
struct probe_cache *cache;
|
|
|
|
int ret;
|
2017-07-06 09:48:11 +08:00
|
|
|
struct nscookie nsc;
|
2016-07-01 16:04:10 +08:00
|
|
|
|
2017-07-06 09:48:11 +08:00
|
|
|
cache = probe_cache__new(sbuild_id, nsi);
|
2016-07-01 16:04:10 +08:00
|
|
|
if (!cache)
|
|
|
|
return -1;
|
|
|
|
|
2017-07-06 09:48:11 +08:00
|
|
|
nsinfo__mountns_enter(nsi, &nsc);
|
2016-07-01 16:04:10 +08:00
|
|
|
ret = probe_cache__scan_sdt(cache, realname);
|
2017-07-06 09:48:11 +08:00
|
|
|
nsinfo__mountns_exit(&nsc);
|
2016-07-01 16:04:10 +08:00
|
|
|
if (ret >= 0) {
|
2016-09-23 22:38:40 +08:00
|
|
|
pr_debug4("Found %d SDTs in %s\n", ret, realname);
|
2016-07-01 16:04:10 +08:00
|
|
|
if (probe_cache__commit(cache) < 0)
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
probe_cache__delete(cache);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
2017-07-06 09:48:11 +08:00
|
|
|
#define build_id_cache__add_sdt_cache(sbuild_id, realname, nsi) (0)
|
2016-07-01 16:04:10 +08:00
|
|
|
#endif
|
|
|
|
|
2017-07-06 09:48:13 +08:00
|
|
|
static char *build_id_cache__find_debug(const char *sbuild_id,
|
|
|
|
struct nsinfo *nsi)
|
|
|
|
{
|
|
|
|
char *realname = NULL;
|
|
|
|
char *debugfile;
|
|
|
|
struct nscookie nsc;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
debugfile = calloc(1, PATH_MAX);
|
|
|
|
if (!debugfile)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
len = __symbol__join_symfs(debugfile, PATH_MAX,
|
|
|
|
"/usr/lib/debug/.build-id/");
|
|
|
|
snprintf(debugfile + len, PATH_MAX - len, "%.2s/%s.debug", sbuild_id,
|
|
|
|
sbuild_id + 2);
|
|
|
|
|
|
|
|
nsinfo__mountns_enter(nsi, &nsc);
|
|
|
|
realname = realpath(debugfile, NULL);
|
|
|
|
if (realname && access(realname, R_OK))
|
|
|
|
zfree(&realname);
|
|
|
|
nsinfo__mountns_exit(&nsc);
|
|
|
|
out:
|
|
|
|
free(debugfile);
|
|
|
|
return realname;
|
|
|
|
}
|
|
|
|
|
2015-02-10 17:18:51 +08:00
|
|
|
int build_id_cache__add_s(const char *sbuild_id, const char *name,
|
2017-07-06 09:48:11 +08:00
|
|
|
struct nsinfo *nsi, bool is_kallsyms, bool is_vdso)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
|
|
|
const size_t size = PATH_MAX;
|
2015-02-27 12:50:26 +08:00
|
|
|
char *realname = NULL, *filename = NULL, *dir_name = NULL,
|
2016-05-28 23:15:37 +08:00
|
|
|
*linkname = zalloc(size), *tmp;
|
2017-07-06 09:48:13 +08:00
|
|
|
char *debugfile = NULL;
|
2015-02-27 12:50:26 +08:00
|
|
|
int err = -1;
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2015-02-27 12:50:26 +08:00
|
|
|
if (!is_kallsyms) {
|
2017-07-06 09:48:11 +08:00
|
|
|
if (!is_vdso)
|
|
|
|
realname = nsinfo__realpath(name, nsi);
|
|
|
|
else
|
|
|
|
realname = realpath(name, NULL);
|
2015-02-27 12:50:26 +08:00
|
|
|
if (!realname)
|
|
|
|
goto out_free;
|
|
|
|
}
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2017-07-06 09:48:11 +08:00
|
|
|
dir_name = build_id_cache__cachedir(sbuild_id, name, nsi, is_kallsyms,
|
|
|
|
is_vdso);
|
2015-02-27 12:50:26 +08:00
|
|
|
if (!dir_name)
|
2014-11-04 09:14:30 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
/* Remove old style build-id cache */
|
|
|
|
if (is_regular_file(dir_name))
|
|
|
|
if (unlink(dir_name))
|
|
|
|
goto out_free;
|
|
|
|
|
2015-02-27 12:50:26 +08:00
|
|
|
if (mkdir_p(dir_name, 0755))
|
2014-11-04 09:14:30 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
/* Save the allocated buildid dirname */
|
|
|
|
if (asprintf(&filename, "%s/%s", dir_name,
|
2017-07-06 09:48:13 +08:00
|
|
|
build_id_cache__basename(is_kallsyms, is_vdso,
|
|
|
|
false)) < 0) {
|
2015-02-27 12:50:26 +08:00
|
|
|
filename = NULL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
2014-11-04 09:14:30 +08:00
|
|
|
|
|
|
|
if (access(filename, F_OK)) {
|
|
|
|
if (is_kallsyms) {
|
2017-07-06 09:48:11 +08:00
|
|
|
if (copyfile("/proc/kallsyms", filename))
|
|
|
|
goto out_free;
|
|
|
|
} else if (nsi && nsi->need_setns) {
|
|
|
|
if (copyfile_ns(name, filename, nsi))
|
2014-11-04 09:14:30 +08:00
|
|
|
goto out_free;
|
2015-03-20 18:37:25 +08:00
|
|
|
} else if (link(realname, filename) && errno != EEXIST &&
|
|
|
|
copyfile(name, filename))
|
2014-11-04 09:14:30 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2017-07-06 09:48:13 +08:00
|
|
|
/* Some binaries are stripped, but have .debug files with their symbol
|
|
|
|
* table. Check to see if we can locate one of those, since the elf
|
|
|
|
* file itself may not be very useful to users of our tools without a
|
|
|
|
* symtab.
|
|
|
|
*/
|
|
|
|
if (!is_kallsyms && !is_vdso &&
|
|
|
|
strncmp(".ko", name + strlen(name) - 3, 3)) {
|
|
|
|
debugfile = build_id_cache__find_debug(sbuild_id, nsi);
|
|
|
|
if (debugfile) {
|
|
|
|
zfree(&filename);
|
|
|
|
if (asprintf(&filename, "%s/%s", dir_name,
|
|
|
|
build_id_cache__basename(false, false, true)) < 0) {
|
|
|
|
filename = NULL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (access(filename, F_OK)) {
|
|
|
|
if (nsi && nsi->need_setns) {
|
|
|
|
if (copyfile_ns(debugfile, filename,
|
|
|
|
nsi))
|
|
|
|
goto out_free;
|
|
|
|
} else if (link(debugfile, filename) &&
|
|
|
|
errno != EEXIST &&
|
|
|
|
copyfile(debugfile, filename))
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
if (!build_id_cache__linkname(sbuild_id, linkname, size))
|
2015-02-10 17:18:53 +08:00
|
|
|
goto out_free;
|
|
|
|
tmp = strrchr(linkname, '/');
|
|
|
|
*tmp = '\0';
|
2014-11-04 09:14:30 +08:00
|
|
|
|
|
|
|
if (access(linkname, X_OK) && mkdir_p(linkname, 0755))
|
|
|
|
goto out_free;
|
|
|
|
|
2015-02-10 17:18:53 +08:00
|
|
|
*tmp = '/';
|
2016-05-28 23:15:37 +08:00
|
|
|
tmp = dir_name + strlen(buildid_dir) - 5;
|
|
|
|
memcpy(tmp, "../..", 5);
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
if (symlink(tmp, linkname) == 0)
|
2014-11-04 09:14:30 +08:00
|
|
|
err = 0;
|
2016-07-01 16:04:10 +08:00
|
|
|
|
|
|
|
/* Update SDT cache : error is just warned */
|
2017-07-06 09:48:11 +08:00
|
|
|
if (realname &&
|
|
|
|
build_id_cache__add_sdt_cache(sbuild_id, realname, nsi) < 0)
|
2016-09-23 22:38:40 +08:00
|
|
|
pr_debug4("Failed to update/scan SDT cache for %s\n", realname);
|
2016-07-01 16:04:10 +08:00
|
|
|
|
2014-11-04 09:14:30 +08:00
|
|
|
out_free:
|
|
|
|
if (!is_kallsyms)
|
|
|
|
free(realname);
|
|
|
|
free(filename);
|
2017-07-06 09:48:13 +08:00
|
|
|
free(debugfile);
|
2015-02-27 12:50:26 +08:00
|
|
|
free(dir_name);
|
2014-11-04 09:14:30 +08:00
|
|
|
free(linkname);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
|
2017-07-06 09:48:11 +08:00
|
|
|
const char *name, struct nsinfo *nsi,
|
|
|
|
bool is_kallsyms, bool is_vdso)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
2015-07-15 17:14:28 +08:00
|
|
|
char sbuild_id[SBUILD_ID_SIZE];
|
2014-11-04 09:14:30 +08:00
|
|
|
|
|
|
|
build_id__sprintf(build_id, build_id_size, sbuild_id);
|
|
|
|
|
2017-07-06 09:48:11 +08:00
|
|
|
return build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms,
|
|
|
|
is_vdso);
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
2015-02-26 14:54:40 +08:00
|
|
|
bool build_id_cache__cached(const char *sbuild_id)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
2016-05-28 23:15:37 +08:00
|
|
|
char *filename = build_id_cache__linkname(sbuild_id, NULL, 0);
|
2015-02-26 14:54:40 +08:00
|
|
|
|
|
|
|
if (filename && !access(filename, F_OK))
|
|
|
|
ret = true;
|
|
|
|
free(filename);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-10 17:18:51 +08:00
|
|
|
int build_id_cache__remove_s(const char *sbuild_id)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
|
|
|
const size_t size = PATH_MAX;
|
|
|
|
char *filename = zalloc(size),
|
2015-02-10 17:18:53 +08:00
|
|
|
*linkname = zalloc(size), *tmp;
|
2014-11-04 09:14:30 +08:00
|
|
|
int err = -1;
|
|
|
|
|
|
|
|
if (filename == NULL || linkname == NULL)
|
|
|
|
goto out_free;
|
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
if (!build_id_cache__linkname(sbuild_id, linkname, size))
|
2015-02-10 17:18:53 +08:00
|
|
|
goto out_free;
|
2014-11-04 09:14:30 +08:00
|
|
|
|
|
|
|
if (access(linkname, F_OK))
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (readlink(linkname, filename, size - 1) < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (unlink(linkname))
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the link is relative, we must make it absolute:
|
|
|
|
*/
|
2015-02-10 17:18:53 +08:00
|
|
|
tmp = strrchr(linkname, '/') + 1;
|
|
|
|
snprintf(tmp, size - (tmp - linkname), "%s", filename);
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2016-05-28 23:15:37 +08:00
|
|
|
if (rm_rf(linkname))
|
2014-11-04 09:14:30 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
out_free:
|
|
|
|
free(filename);
|
|
|
|
free(linkname);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-02-10 17:18:51 +08:00
|
|
|
static int dso__cache_build_id(struct dso *dso, struct machine *machine)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
2016-05-28 23:15:37 +08:00
|
|
|
bool is_kallsyms = dso__is_kallsyms(dso);
|
2014-11-04 09:14:30 +08:00
|
|
|
bool is_vdso = dso__is_vdso(dso);
|
|
|
|
const char *name = dso->long_name;
|
|
|
|
|
|
|
|
if (dso__is_kcore(dso)) {
|
|
|
|
is_kallsyms = true;
|
2018-02-15 20:26:30 +08:00
|
|
|
name = machine->mmap_name;
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
return build_id_cache__add_b(dso->build_id, sizeof(dso->build_id), name,
|
2017-07-06 09:48:11 +08:00
|
|
|
dso->nsinfo, is_kallsyms, is_vdso);
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __dsos__cache_build_ids(struct list_head *head,
|
2015-02-10 17:18:51 +08:00
|
|
|
struct machine *machine)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
dsos__for_each_with_build_id(pos, head)
|
2015-02-10 17:18:51 +08:00
|
|
|
if (dso__cache_build_id(pos, machine))
|
2014-11-04 09:14:30 +08:00
|
|
|
err = -1;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-02-10 17:18:51 +08:00
|
|
|
static int machine__cache_build_ids(struct machine *machine)
|
2014-11-04 09:14:30 +08:00
|
|
|
{
|
2015-05-29 00:06:42 +08:00
|
|
|
return __dsos__cache_build_ids(&machine->dsos.head, machine);
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int perf_session__cache_build_ids(struct perf_session *session)
|
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
int ret;
|
|
|
|
|
2014-11-07 21:57:56 +08:00
|
|
|
if (no_buildid_cache)
|
|
|
|
return 0;
|
|
|
|
|
2014-12-02 03:06:23 +08:00
|
|
|
if (mkdir(buildid_dir, 0755) != 0 && errno != EEXIST)
|
2014-11-04 09:14:30 +08:00
|
|
|
return -1;
|
|
|
|
|
2015-02-10 17:18:51 +08:00
|
|
|
ret = machine__cache_build_ids(&session->machines.host);
|
2014-11-04 09:14:30 +08:00
|
|
|
|
2018-12-07 03:18:14 +08:00
|
|
|
for (nd = rb_first_cached(&session->machines.guests); nd;
|
|
|
|
nd = rb_next(nd)) {
|
2014-11-04 09:14:30 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2015-02-10 17:18:51 +08:00
|
|
|
ret |= machine__cache_build_ids(pos);
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
return ret ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool machine__read_build_ids(struct machine *machine, bool with_hits)
|
|
|
|
{
|
2015-05-29 00:06:42 +08:00
|
|
|
return __dsos__read_build_ids(&machine->dsos.head, with_hits);
|
2014-11-04 09:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
|
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
bool ret = machine__read_build_ids(&session->machines.host, with_hits);
|
|
|
|
|
2018-12-07 03:18:14 +08:00
|
|
|
for (nd = rb_first_cached(&session->machines.guests); nd;
|
|
|
|
nd = rb_next(nd)) {
|
2014-11-04 09:14:30 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
|
|
|
ret |= machine__read_build_ids(pos, with_hits);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|