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