Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 655735390
  • Loading branch information
Googler authored and blakej11 committed Jul 25, 2024
1 parent 5b27c28 commit b438c74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
30 changes: 17 additions & 13 deletions src/perf_data_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,23 @@ void Normalizer::HandleSample(PerfDataHandler::SampleContext* context) {
context->callchain.resize(sample.callchain_size());
for (int i = 0; i < sample.callchain_size(); ++i) {
++stat_.callchain_ips;
if (sample.callchain(i) == quipper::PERF_CONTEXT_USER) {
uint64_t ip = sample.callchain(i);
if (ip == quipper::PERF_CONTEXT_USER) {
ip_in_user_context = true;
} else if (sample.callchain(i) >= quipper::PERF_CONTEXT_MAX) {
} else if (ip >= quipper::PERF_CONTEXT_MAX) {
ip_in_user_context = false;
}
context->callchain[i].ip = sample.callchain(i);
context->callchain[i].mapping =
GetMappingFromPidAndIP(pid, sample.callchain(i), ip_in_user_context);
stat_.missing_callchain_mmap += context->callchain[i].mapping == nullptr;
const PerfDataHandler::Mapping* mapping;
if (ip >= quipper::PERF_CONTEXT_MAX) {
// This callchain frame is actually a context marker.
// Don't give it a mapping.
mapping = nullptr;
++stat_.missing_callchain_mmap;
} else {
mapping = GetMappingFromPidAndIP(pid, ip, ip_in_user_context);
}
context->callchain[i].ip = ip;
context->callchain[i].mapping = mapping;
}

// Normalize the branch_stack.
Expand Down Expand Up @@ -863,13 +871,9 @@ const PerfDataHandler::Mapping* Normalizer::TryLookupInPid(uint32_t pid,
// in our process.
const PerfDataHandler::Mapping* Normalizer::GetMappingFromPidAndIP(
uint32_t pid, uint64_t ip, bool ip_in_user_context) const {
if (ip >= quipper::PERF_CONTEXT_MAX || ip >> 60 == 0x8) {
// In case the ip is context hint or the highest 4 bits of ip is 1000,
// it has null mapping. For the latter case, we set the highest bit to mark
// the unmapped address. Kernel addresses in x86 and ARM have the high 16
// bits set, and for PowerPC the high 4 bits in range 0001 to 1011 is
// reserved space. So we would identify the unmapped address by checking
// its high four bits as 1000.
if (ip >> 60 == 0x8) {
// In case the highest 4 bits of ip is 1000, it has a null mapping. See
// the comment mentioning "highest 4 bits" in perf_parser.cc for details.
return nullptr;
}
// First look up the mapping for the ip in the address space of the given pid.
Expand Down
2 changes: 1 addition & 1 deletion src/quipper/compat/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROMIUMOS_WIDE_PROFILING_COMPAT_PROTO_H_
#define CHROMIUMOS_WIDE_PROFILING_COMPAT_PROTO_H_

#include "perf_data.pb.h"
#include "src/quipper/perf_data.pb.h"
#include "perf_parser_options.pb.h"
#include "perf_stat.pb.h"
#include "google/protobuf//arena.h"
Expand Down
4 changes: 2 additions & 2 deletions src/quipper/perf_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ bool PerfParser::MapIPAndPidAndGetNameAndOffset(
// address is guaranteed to be larger than the mapped quipper space. When
// options_.do_remap is false, the kernel addresses of x86 and ARM have
// the high 16 bit set and PowerPC has a reserved space from
// 0x1000000000000000 to 0xBFFFFFFFFFFFFFFF. Thus, setting highest byte of
// the unmapped address, which starts with 0x8, should not collide with
// 0x1000000000000000 to 0xBFFFFFFFFFFFFFFF. Thus, setting highest 4 bits
// of the unmapped address, which starts with 0x8, should not collide with
// any existing addresses or mapped quipper addresses.
mapped_addr = (ip & ~(0xfULL << 60)) | 0x8ULL << 60;
}
Expand Down

0 comments on commit b438c74

Please sign in to comment.