From f575203535340c959309b4d5354b48a08e52c014 Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Tue, 1 May 2018 01:52:43 +0000 Subject: [PATCH] Add library name as metadata in trace file for Android The library name cannot be obtained from process maps since the library can be mapped from apk directly. The name is taken by reading the elf sections and added as metadata in trace file. This is useful for symbolizing traces. BUG=734705 Change-Id: I72761c3dc60fc45a9284e0d527929b4f3483eff2 Reviewed-on: https://chromium-review.googlesource.com/1035789 Commit-Queue: Siddhartha S Reviewed-by: Erik Chen Cr-Commit-Position: refs/heads/master@{#554966} --- .../browser/tracing/tracing_controller_impl.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc index 582ae775cd04ca..0ae496ae61e86e 100644 --- a/content/browser/tracing/tracing_controller_impl.cc +++ b/content/browser/tracing/tracing_controller_impl.cc @@ -61,6 +61,13 @@ #include "content/browser/tracing/etw_tracing_agent_win.h" #endif +#if defined(OS_ANDROID) +#include "base/debug/elf_reader_linux.h" + +// Symbol with virtual address of the start of ELF header of the current binary. +extern char __ehdr_start; +#endif // defined(OS_ANDROID) + namespace content { namespace { @@ -185,6 +192,17 @@ TracingControllerImpl::GenerateMetadataDict() const { metadata_dict->SetString("v8-version", V8_VERSION_STRING); metadata_dict->SetString("user-agent", GetContentClient()->GetUserAgent()); +#if defined(OS_ANDROID) + // The library name is used for symbolizing heap profiles. This cannot be + // obtained from process maps since library can be mapped from apk directly. + // This is not added as part of memory-infra os dumps since it is special case + // only for chrome library. + base::Optional soname = + base::debug::ReadElfLibraryName(&__ehdr_start); + if (soname) + metadata_dict->SetString("chrome-library-name", soname.value()); +#endif // defined(OS_ANDROID) + // OS #if defined(OS_CHROMEOS) metadata_dict->SetString("os-name", "CrOS");