From: Adrian Hunter <adrian.hunter@intel.com>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 08/35] perf buildid-cache: Add guestmount'd files to the build ID cache
Date: Tue, 9 Aug 2022 15:21:36 +0300 [thread overview]
Message-ID: <90a76d0f-78ef-8304-1d22-cc65ce3ad964@intel.com> (raw)
In-Reply-To: <CAP-5=fUF_feSL-+=LQpg=6cRd_nXTWKCM4zU1k8TP-6veP26Rw@mail.gmail.com>
On 19/07/22 20:41, Ian Rogers wrote:
> On Mon, Jul 11, 2022 at 2:33 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>>
>> When the guestmount option is used, a guest machine's file system mount
>> point is recorded in machine->root_dir.
>>
>> perf already iterates guest machines when adding files to the build ID
>> cache, but does not take machine->root_dir into account.
>>
>> Use machine->root_dir to find files for guest build IDs, and add them to
>> the build ID cache using the "proper" name i.e. relative to the guest root
>> directory not the host root directory.
>>
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>
> Is it plausible to add a test for this? Our tests create workload but
> there's no existing hypervisor way to do this. Perhaps the test can
> run in a hypervisor? Or maybe there's a route that doesn't involve
> hypervisors.
Too complicated I think.
>
> Acked-by: Ian Rogers <irogers@google.com>
>
> Thanks,
> Ian
>
>> ---
>> tools/perf/util/build-id.c | 67 +++++++++++++++++++++++++++++---------
>> tools/perf/util/build-id.h | 16 ++++++---
>> 2 files changed, 63 insertions(+), 20 deletions(-)
>>
>> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
>> index 4c9093b64d1f..7c9f441936ee 100644
>> --- a/tools/perf/util/build-id.c
>> +++ b/tools/perf/util/build-id.c
>> @@ -625,9 +625,12 @@ static int build_id_cache__add_sdt_cache(const char *sbuild_id,
>> #endif
>>
>> static char *build_id_cache__find_debug(const char *sbuild_id,
>> - struct nsinfo *nsi)
>> + struct nsinfo *nsi,
>> + const char *root_dir)
>> {
>> + const char *dirname = "/usr/lib/debug/.build-id/";
>> char *realname = NULL;
>> + char dirbuf[PATH_MAX];
>> char *debugfile;
>> struct nscookie nsc;
>> size_t len = 0;
>> @@ -636,8 +639,12 @@ static char *build_id_cache__find_debug(const char *sbuild_id,
>> if (!debugfile)
>> goto out;
>>
>> - len = __symbol__join_symfs(debugfile, PATH_MAX,
>> - "/usr/lib/debug/.build-id/");
>> + if (root_dir) {
>> + path__join(dirbuf, PATH_MAX, root_dir, dirname);
>> + dirname = dirbuf;
>> + }
>> +
>> + len = __symbol__join_symfs(debugfile, PATH_MAX, dirname);
>> snprintf(debugfile + len, PATH_MAX - len, "%.2s/%s.debug", sbuild_id,
>> sbuild_id + 2);
>>
>> @@ -668,14 +675,18 @@ static char *build_id_cache__find_debug(const char *sbuild_id,
>>
>> int
>> build_id_cache__add(const char *sbuild_id, const char *name, const char *realname,
>> - struct nsinfo *nsi, bool is_kallsyms, bool is_vdso)
>> + struct nsinfo *nsi, bool is_kallsyms, bool is_vdso,
>> + const char *proper_name, const char *root_dir)
>> {
>> const size_t size = PATH_MAX;
>> char *filename = NULL, *dir_name = NULL, *linkname = zalloc(size), *tmp;
>> char *debugfile = NULL;
>> int err = -1;
>>
>> - dir_name = build_id_cache__cachedir(sbuild_id, name, nsi, is_kallsyms,
>> + if (!proper_name)
>> + proper_name = name;
>> +
>> + dir_name = build_id_cache__cachedir(sbuild_id, proper_name, nsi, is_kallsyms,
>> is_vdso);
>> if (!dir_name)
>> goto out_free;
>> @@ -715,7 +726,7 @@ build_id_cache__add(const char *sbuild_id, const char *name, const char *realnam
>> */
>> if (!is_kallsyms && !is_vdso &&
>> strncmp(".ko", name + strlen(name) - 3, 3)) {
>> - debugfile = build_id_cache__find_debug(sbuild_id, nsi);
>> + debugfile = build_id_cache__find_debug(sbuild_id, nsi, root_dir);
>> if (debugfile) {
>> zfree(&filename);
>> if (asprintf(&filename, "%s/%s", dir_name,
>> @@ -781,8 +792,9 @@ build_id_cache__add(const char *sbuild_id, const char *name, const char *realnam
>> return err;
>> }
>>
>> -int build_id_cache__add_s(const char *sbuild_id, const char *name,
>> - struct nsinfo *nsi, bool is_kallsyms, bool is_vdso)
>> +int __build_id_cache__add_s(const char *sbuild_id, const char *name,
>> + struct nsinfo *nsi, bool is_kallsyms, bool is_vdso,
>> + const char *proper_name, const char *root_dir)
>> {
>> char *realname = NULL;
>> int err = -1;
>> @@ -796,8 +808,8 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
>> goto out_free;
>> }
>>
>> - err = build_id_cache__add(sbuild_id, name, realname, nsi, is_kallsyms, is_vdso);
>> -
>> + err = build_id_cache__add(sbuild_id, name, realname, nsi,
>> + is_kallsyms, is_vdso, proper_name, root_dir);
>> out_free:
>> if (!is_kallsyms)
>> free(realname);
>> @@ -806,14 +818,16 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
>>
>> static int build_id_cache__add_b(const struct build_id *bid,
>> const char *name, struct nsinfo *nsi,
>> - bool is_kallsyms, bool is_vdso)
>> + bool is_kallsyms, bool is_vdso,
>> + const char *proper_name,
>> + const char *root_dir)
>> {
>> char sbuild_id[SBUILD_ID_SIZE];
>>
>> build_id__sprintf(bid, sbuild_id);
>>
>> - return build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms,
>> - is_vdso);
>> + return __build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms,
>> + is_vdso, proper_name, root_dir);
>> }
>>
>> bool build_id_cache__cached(const char *sbuild_id)
>> @@ -896,6 +910,10 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,
>> bool is_kallsyms = dso__is_kallsyms(dso);
>> bool is_vdso = dso__is_vdso(dso);
>> const char *name = dso->long_name;
>> + const char *proper_name = NULL;
>> + const char *root_dir = NULL;
>> + char *allocated_name = NULL;
>> + int ret = 0;
>>
>> if (!dso->has_build_id)
>> return 0;
>> @@ -905,11 +923,28 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,
>> name = machine->mmap_name;
>> }
>>
>> + if (!machine__is_host(machine)) {
>> + if (*machine->root_dir) {
>> + root_dir = machine->root_dir;
>> + ret = asprintf(&allocated_name, "%s/%s", root_dir, name);
>> + if (ret < 0)
>> + return ret;
>> + proper_name = name;
>> + name = allocated_name;
>> + } else if (is_kallsyms) {
>> + /* Cannot get guest kallsyms */
>> + return 0;
>> + }
>> + }
>> +
>> if (!is_kallsyms && dso__build_id_mismatch(dso, name))
>> - return 0;
>> + goto out_free;
>>
>> - return build_id_cache__add_b(&dso->bid, name, dso->nsinfo,
>> - is_kallsyms, is_vdso);
>> + ret = build_id_cache__add_b(&dso->bid, name, dso->nsinfo,
>> + is_kallsyms, is_vdso, proper_name, root_dir);
>> +out_free:
>> + free(allocated_name);
>> + return ret;
>> }
>>
>> static int
>> diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
>> index c19617151670..4e3a1169379b 100644
>> --- a/tools/perf/util/build-id.h
>> +++ b/tools/perf/util/build-id.h
>> @@ -66,10 +66,18 @@ int build_id_cache__list_build_ids(const char *pathname, struct nsinfo *nsi,
>> struct strlist **result);
>> bool build_id_cache__cached(const char *sbuild_id);
>> int build_id_cache__add(const char *sbuild_id, const char *name, const char *realname,
>> - struct nsinfo *nsi, bool is_kallsyms, bool is_vdso);
>> -int build_id_cache__add_s(const char *sbuild_id,
>> - const char *name, struct nsinfo *nsi,
>> - bool is_kallsyms, bool is_vdso);
>> + struct nsinfo *nsi, bool is_kallsyms, bool is_vdso,
>> + const char *proper_name, const char *root_dir);
>> +int __build_id_cache__add_s(const char *sbuild_id,
>> + const char *name, struct nsinfo *nsi,
>> + bool is_kallsyms, bool is_vdso,
>> + const char *proper_name, const char *root_dir);
>> +static inline int build_id_cache__add_s(const char *sbuild_id,
>> + const char *name, struct nsinfo *nsi,
>> + bool is_kallsyms, bool is_vdso)
>> +{
>> + return __build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms, is_vdso, NULL, NULL);
>> +}
>> int build_id_cache__remove_s(const char *sbuild_id);
>>
>> extern char buildid_dir[];
>> --
>> 2.25.1
>>
next prev parent reply other threads:[~2022-08-09 12:21 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 9:31 [PATCH 00/35] perf intel-pt: Add support for tracing virtual machine user space on the host Adrian Hunter
2022-07-11 9:31 ` [PATCH 01/35] perf tools: Fix dso_id inode generation comparison Adrian Hunter
2022-07-18 14:57 ` Arnaldo Carvalho de Melo
2022-07-19 10:18 ` Adrian Hunter
2022-07-19 15:13 ` Ian Rogers
2022-07-19 19:16 ` Arnaldo Carvalho de Melo
2022-07-11 9:31 ` [PATCH 02/35] perf tools: Export dsos__for_each_with_build_id() Adrian Hunter
2022-07-19 16:55 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 03/35] perf ordered_events: Add ordered_events__last_flush_time() Adrian Hunter
2022-07-19 16:56 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 04/35] perf tools: Export perf_event__process_finished_round() Adrian Hunter
2022-07-19 17:04 ` Ian Rogers
2022-08-09 11:37 ` Adrian Hunter
2022-07-11 9:31 ` [PATCH 05/35] perf tools: Factor out evsel__id_hdr_size() Adrian Hunter
2022-07-19 17:09 ` Ian Rogers
2022-08-09 11:49 ` Adrian Hunter
2022-08-09 17:07 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 06/35] perf tools: Add perf_event__synthesize_id_sample() Adrian Hunter
2022-07-19 17:10 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 07/35] perf script: Add --dump-unsorted-raw-trace option Adrian Hunter
2022-07-19 17:11 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 08/35] perf buildid-cache: Add guestmount'd files to the build ID cache Adrian Hunter
2022-07-19 17:41 ` Ian Rogers
2022-08-09 12:21 ` Adrian Hunter [this message]
2022-07-11 9:31 ` [PATCH 09/35] perf buildid-cache: Do not require purge files to also be in the file system Adrian Hunter
2022-07-19 17:44 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 10/35] perf tools: Add machine_pid and vcpu to id_index Adrian Hunter
2022-07-19 17:48 ` Ian Rogers
2022-08-09 12:19 ` Adrian Hunter
2022-07-11 9:31 ` [PATCH 11/35] perf session: Create guest machines from id_index Adrian Hunter
2022-07-19 17:51 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 12/35] perf tools: Add guest_cpu to hypervisor threads Adrian Hunter
2022-07-20 0:23 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 13/35] perf tools: Add machine_pid and vcpu to perf_sample Adrian Hunter
2022-07-20 0:36 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 14/35] perf tools: Use sample->machine_pid to find guest machine Adrian Hunter
2022-07-20 0:37 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 15/35] perf script: Add machine_pid and vcpu Adrian Hunter
2022-07-20 0:39 ` Ian Rogers
2022-07-11 9:31 ` [PATCH 16/35] perf dlfilter: " Adrian Hunter
2022-07-20 0:42 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 17/35] perf auxtrace: Add machine_pid and vcpu to auxtrace_error Adrian Hunter
2022-07-20 0:43 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 18/35] perf script python: Add machine_pid and vcpu Adrian Hunter
2022-07-20 0:43 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 19/35] perf script python: intel-pt-events: " Adrian Hunter
2022-07-20 0:44 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 20/35] perf tools: Remove also guest kcore_dir with host kcore_dir Adrian Hunter
2022-07-20 0:45 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 21/35] perf tools: Make has_kcore_dir() work also for guest kcore_dir Adrian Hunter
2022-07-20 0:49 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 22/35] perf tools: Automatically use guest kcore_dir if present Adrian Hunter
2022-07-20 0:51 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 23/35] perf tools: Add reallocarray_as_needed() Adrian Hunter
2022-07-20 0:55 ` Ian Rogers
2022-08-09 16:48 ` Adrian Hunter
2022-07-11 9:32 ` [PATCH 24/35] perf inject: Add support for injecting guest sideband events Adrian Hunter
2022-07-20 1:06 ` Ian Rogers
2022-08-11 17:19 ` Adrian Hunter
2022-07-11 9:32 ` [PATCH 25/35] perf machine: Use realloc_array_as_needed() in machine__set_current_tid() Adrian Hunter
2022-07-11 9:32 ` [PATCH 26/35] perf tools: Handle injected guest kernel mmap event Adrian Hunter
2022-07-20 1:09 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 27/35] perf tools: Add perf_event__is_guest() Adrian Hunter
2022-07-20 1:11 ` Ian Rogers
2022-07-20 14:06 ` Arnaldo Carvalho de Melo
2022-07-20 14:56 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 28/35] perf intel-pt: Remove guest_machine_pid Adrian Hunter
2022-07-20 1:12 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 29/35] perf intel-pt: Add some more logging to intel_pt_walk_next_insn() Adrian Hunter
2022-07-20 1:13 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 30/35] perf intel-pt: Track guest context switches Adrian Hunter
2022-07-20 1:13 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 31/35] perf intel-pt: Disable sync switch with guest sideband Adrian Hunter
2022-07-20 1:14 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 32/35] perf intel-pt: Determine guest thread from " Adrian Hunter
2022-07-20 1:15 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 33/35] perf intel-pt: Add machine_pid and vcpu to auxtrace_error Adrian Hunter
2022-07-20 5:27 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 34/35] perf intel-pt: Use guest pid/tid etc in guest samples Adrian Hunter
2022-07-20 5:28 ` Ian Rogers
2022-07-11 9:32 ` [PATCH 35/35] perf intel-pt: Add documentation for tracing guest machine user space Adrian Hunter
2022-07-20 5:29 ` Ian Rogers
2022-07-18 15:28 ` [PATCH 00/35] perf intel-pt: Add support for tracing virtual machine user space on the host Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=90a76d0f-78ef-8304-1d22-cc65ce3ad964@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).