Commit 77df4489 authored by ssid's avatar ssid Committed by Commit Bot

Support reached code profiler for arm64

The version number is not sufficient to differentiate between 32 or 64
bit binaries for symbolization, so include the module debug id in trace
for correct symbolization.

Change-Id: I3411821b55b9ce2c73ea616bf791866542aebe0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373235Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Commit-Queue: ssid <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801747}
parent 7bc05178
......@@ -1500,9 +1500,8 @@ component("base") {
]
}
if (current_cpu != "arm") {
# The reached code profiler is only supported on Android with 32-bit arm
# arch.
if (current_cpu != "arm" && current_cpu != "arm64") {
# The reached code profiler is only supported on Android arm arch.
sources -= [ "android/reached_code_profiler.cc" ]
sources += [ "android/reached_code_profiler_stub.cc" ]
}
......
......@@ -34,6 +34,7 @@
#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#if !BUILDFLAG(SUPPORTS_CODE_ORDERING)
#error Code ordering support is required for the reached code profiler.
......@@ -72,7 +73,11 @@ void HandleSignal(int signal, siginfo_t* info, void* context) {
return;
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
uint32_t address = ucontext->uc_mcontext.arm_pc;
#if defined(ARCH_CPU_ARM64)
uintptr_t address = ucontext->uc_mcontext.pc;
#else
uintptr_t address = ucontext->uc_mcontext.arm_pc;
#endif
ReachedAddressesBitset::GetTextBitset()->RecordAddress(address);
}
......
......@@ -9,11 +9,17 @@
#include "base/android/reached_addresses_bitset.h"
#include "base/android/reached_code_profiler.h"
#include "base/debug/elf_reader.h"
#include "services/tracing/public/cpp/perfetto/perfetto_producer.h"
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
#include "third_party/perfetto/include/perfetto/tracing/data_source.h"
#include "third_party/perfetto/protos/perfetto/trace/interned_data/interned_data.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/profiling/profile_common.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/profiling/profile_packet.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet.pbzero.h"
extern char __ehdr_start;
namespace tracing {
// static
......@@ -47,9 +53,30 @@ void ReachedCodeDataSource::StopTracing(
if (!bitset) {
return;
}
std::vector<uint32_t> offsets = bitset->GetReachedOffsets();
perfetto::TraceWriter::TracePacketHandle trace_packet =
trace_writer_->NewTracePacket();
auto* interned_data = trace_packet->set_interned_data();
base::debug::ElfBuildIdBuffer buf;
size_t size = base::debug::ReadElfBuildId(&__ehdr_start, true, buf);
if (size > 0) {
std::string module_id(buf, size);
TracingSamplerProfiler::MangleModuleIDIfNeeded(&module_id);
auto* str = interned_data->add_build_ids();
str->set_iid(0);
str->set_str(module_id);
}
base::Optional<base::StringPiece> library_name =
base::debug::ReadElfLibraryName(&__ehdr_start);
if (library_name) {
auto* str = interned_data->add_mapping_paths();
str->set_iid(0);
str->set_str(library_name->as_string());
}
std::vector<uint32_t> offsets = bitset->GetReachedOffsets();
// Delta encoded timestamps and interned data require incremental state.
auto* streaming_profile_packet = trace_packet->set_streaming_profile_packet();
for (uint32_t offset : offsets) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment