Skip to content

Commit

Permalink
[cpu-profiler] Use unique_ptrs in the inline stack
Browse files Browse the repository at this point in the history
Small cleanup.

Change-Id: I80f7ede4de1aed3e37c2b20cb3706cb9ef3aa9be
Reviewed-on: https://chromium-review.googlesource.com/897810
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51056}
  • Loading branch information
fhinkel authored and Commit Bot committed Feb 2, 2018
1 parent 9232b4b commit 0ee2eef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 9 additions & 11 deletions src/profiler/profile-generator.cc
Expand Up @@ -87,11 +87,6 @@ CodeEntry* CodeEntry::UnresolvedEntryCreateTrait::Create() {

CodeEntry::~CodeEntry() {
delete line_info_;
for (auto location : inline_locations_) {
for (auto entry : location.second) {
delete entry;
}
}
}


Expand Down Expand Up @@ -137,12 +132,13 @@ int CodeEntry::GetSourceLine(int pc_offset) const {
return v8::CpuProfileNode::kNoLineNumberInfo;
}

void CodeEntry::AddInlineStack(int pc_offset,
std::vector<CodeEntry*> inline_stack) {
void CodeEntry::AddInlineStack(
int pc_offset, std::vector<std::unique_ptr<CodeEntry>> inline_stack) {
inline_locations_.insert(std::make_pair(pc_offset, std::move(inline_stack)));
}

const std::vector<CodeEntry*>* CodeEntry::GetInlineStack(int pc_offset) const {
const std::vector<std::unique_ptr<CodeEntry>>* CodeEntry::GetInlineStack(
int pc_offset) const {
auto it = inline_locations_.find(pc_offset);
return it != inline_locations_.end() ? &it->second : nullptr;
}
Expand Down Expand Up @@ -684,11 +680,13 @@ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
// Find out if the entry has an inlining stack associated.
int pc_offset =
static_cast<int>(stack_pos - entry->instruction_start());
const std::vector<CodeEntry*>* inline_stack =
const std::vector<std::unique_ptr<CodeEntry>>* inline_stack =
entry->GetInlineStack(pc_offset);
if (inline_stack) {
entries.insert(entries.end(), inline_stack->rbegin(),
inline_stack->rend());
std::transform(
inline_stack->rbegin(), inline_stack->rend(),
std::back_inserter(entries),
[](const std::unique_ptr<CodeEntry>& ptr) { return ptr.get(); });
}
// Skip unresolved frames (e.g. internal frame) and get source line of
// the first JS caller.
Expand Down
8 changes: 5 additions & 3 deletions src/profiler/profile-generator.h
Expand Up @@ -91,8 +91,10 @@ class CodeEntry {

int GetSourceLine(int pc_offset) const;

void AddInlineStack(int pc_offset, std::vector<CodeEntry*> inline_stack);
const std::vector<CodeEntry*>* GetInlineStack(int pc_offset) const;
void AddInlineStack(int pc_offset,
std::vector<std::unique_ptr<CodeEntry>> inline_stack);
const std::vector<std::unique_ptr<CodeEntry>>* GetInlineStack(
int pc_offset) const;

void AddDeoptInlinedFrames(int deopt_id, std::vector<CpuProfileDeoptFrame>);
bool HasDeoptInlinedFramesFor(int deopt_id) const;
Expand Down Expand Up @@ -163,7 +165,7 @@ class CodeEntry {
JITLineInfoTable* line_info_;
Address instruction_start_;
// Should be an unordered_map, but it doesn't currently work on Win & MacOS.
std::map<int, std::vector<CodeEntry*>> inline_locations_;
std::map<int, std::vector<std::unique_ptr<CodeEntry>>> inline_locations_;
std::map<int, std::vector<CpuProfileDeoptFrame>> deopt_inlined_frames_;

DISALLOW_COPY_AND_ASSIGN(CodeEntry);
Expand Down
4 changes: 2 additions & 2 deletions src/profiler/profiler-listener.cc
Expand Up @@ -199,7 +199,7 @@ void ProfilerListener::RecordInliningInfo(CodeEntry* entry,
DCHECK_EQ(Translation::BEGIN, opcode);
it.Skip(Translation::NumberOfOperandsFor(opcode));
int depth = 0;
std::vector<CodeEntry*> inline_stack;
std::vector<std::unique_ptr<CodeEntry>> inline_stack;
while (it.HasNext() &&
Translation::BEGIN !=
(opcode = static_cast<Translation::Opcode>(it.Next()))) {
Expand Down Expand Up @@ -227,7 +227,7 @@ void ProfilerListener::RecordInliningInfo(CodeEntry* entry,
CpuProfileNode::kNoColumnNumberInfo, nullptr,
code->instruction_start());
inline_entry->FillFunctionInfo(shared_info);
inline_stack.push_back(inline_entry);
inline_stack.emplace_back(inline_entry);
}
if (!inline_stack.empty()) {
entry->AddInlineStack(pc_offset, std::move(inline_stack));
Expand Down

0 comments on commit 0ee2eef

Please sign in to comment.