Commit 3282b515 authored by alph's avatar alph Committed by Commit bot

Make use of std::map for profiler code map.

Review-Url: https://codereview.chromium.org/2047243002
Cr-Commit-Position: refs/heads/master@{#36898}
parent dfb8d333
......@@ -11,7 +11,6 @@
#include "src/global-handles.h"
#include "src/profiler/profile-generator-inl.h"
#include "src/profiler/tick-sample.h"
#include "src/splay-tree-inl.h"
#include "src/unicode.h"
namespace v8 {
......@@ -384,82 +383,55 @@ void CpuProfile::AddPath(base::TimeTicks timestamp,
}
}
void CpuProfile::CalculateTotalTicksAndSamplingRate() {
end_time_ = base::TimeTicks::HighResolutionNow();
}
void CpuProfile::Print() {
base::OS::Print("[Top down]:\n");
top_down_.Print();
}
CodeMap::~CodeMap() {}
const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL;
void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
DeleteAllCoveredCode(addr, addr + size);
CodeTree::Locator locator;
tree_.Insert(addr, &locator);
locator.set_value(CodeEntryInfo(entry, size));
code_map_.insert({addr, CodeEntryInfo(entry, size)});
}
void CodeMap::DeleteAllCoveredCode(Address start, Address end) {
List<Address> to_delete;
Address addr = end - 1;
while (addr >= start) {
CodeTree::Locator locator;
if (!tree_.FindGreatestLessThan(addr, &locator)) break;
Address start2 = locator.key(), end2 = start2 + locator.value().size;
if (start2 < end && start < end2) to_delete.Add(start2);
addr = start2 - 1;
auto left = code_map_.upper_bound(start);
if (left != code_map_.begin()) {
--left;
if (left->first + left->second.size <= start) ++left;
}
for (int i = 0; i < to_delete.length(); ++i) tree_.Remove(to_delete[i]);
auto right = left;
while (right != code_map_.end() && right->first < end) ++right;
code_map_.erase(left, right);
}
CodeEntry* CodeMap::FindEntry(Address addr) {
CodeTree::Locator locator;
if (tree_.FindGreatestLessThan(addr, &locator)) {
// locator.key() <= addr. Need to check that addr is within entry.
const CodeEntryInfo& entry = locator.value();
if (addr < (locator.key() + entry.size)) {
return entry.entry;
}
}
return NULL;
auto it = code_map_.upper_bound(addr);
if (it == code_map_.begin()) return nullptr;
--it;
Address end_address = it->first + it->second.size;
return addr < end_address ? it->second.entry : nullptr;
}
void CodeMap::MoveCode(Address from, Address to) {
if (from == to) return;
CodeTree::Locator locator;
if (!tree_.Find(from, &locator)) return;
CodeEntryInfo entry = locator.value();
tree_.Remove(from);
AddCode(to, entry.entry, entry.size);
auto it = code_map_.find(from);
if (it == code_map_.end()) return;
CodeEntryInfo info = it->second;
code_map_.erase(it);
AddCode(to, info.entry, info.size);
}
void CodeMap::CodeTreePrinter::Call(
const Address& key, const CodeMap::CodeEntryInfo& value) {
base::OS::Print("%p %5d %s\n", static_cast<void*>(key), value.size,
value.entry->name());
}
void CodeMap::Print() {
CodeTreePrinter printer;
tree_.ForEach(&printer);
for (auto it = code_map_.begin(); it != code_map_.end(); ++it) {
base::OS::Print("%p %5d %s\n", static_cast<void*>(it->first),
it->second.size, it->second.entry->name());
}
}
CpuProfilesCollection::CpuProfilesCollection(Heap* heap)
: function_and_resource_names_(heap),
isolate_(heap->isolate()),
......
......@@ -263,16 +263,13 @@ class CpuProfile {
DISALLOW_COPY_AND_ASSIGN(CpuProfile);
};
class CodeMap {
public:
CodeMap() {}
~CodeMap();
void AddCode(Address addr, CodeEntry* entry, unsigned size);
void MoveCode(Address from, Address to);
CodeEntry* FindEntry(Address addr);
int GetSharedId(Address addr);
void Print();
private:
......@@ -283,30 +280,13 @@ class CodeMap {
unsigned size;
};
struct CodeTreeConfig {
typedef Address Key;
typedef CodeEntryInfo Value;
static const Key kNoKey;
static const Value NoValue() { return CodeEntryInfo(NULL, 0); }
static int Compare(const Key& a, const Key& b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
};
typedef SplayTree<CodeTreeConfig> CodeTree;
class CodeTreePrinter {
public:
void Call(const Address& key, const CodeEntryInfo& value);
};
void DeleteAllCoveredCode(Address start, Address end);
CodeTree tree_;
std::map<Address, CodeEntryInfo> code_map_;
DISALLOW_COPY_AND_ASSIGN(CodeMap);
};
class CpuProfilesCollection {
public:
explicit CpuProfilesCollection(Heap* heap);
......
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