Commit 3ed5dfb8 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[cpu-profiler] turn several std::map's into unordered_map's.

Change-Id: I8b9308d7628d7efc2a2212ef3a3aa52ccddbfb36
Reviewed-on: https://chromium-review.googlesource.com/1048036
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53133}
parent e9b66e87
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "src/profiler/cpu-profiler.h" #include "src/profiler/cpu-profiler.h"
#include <unordered_map>
#include <utility>
#include "src/base/lazy-instance.h" #include "src/base/lazy-instance.h"
#include "src/base/platform/mutex.h" #include "src/base/platform/mutex.h"
#include "src/base/template-utils.h" #include "src/base/template-utils.h"
...@@ -252,33 +255,30 @@ class CpuProfilersManager { ...@@ -252,33 +255,30 @@ class CpuProfilersManager {
public: public:
void AddProfiler(Isolate* isolate, CpuProfiler* profiler) { void AddProfiler(Isolate* isolate, CpuProfiler* profiler) {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
auto result = profilers_.insert( profilers_.emplace(isolate, profiler);
std::pair<Isolate*, std::unique_ptr<std::set<CpuProfiler*>>>(
isolate, base::make_unique<std::set<CpuProfiler*>>()));
result.first->second->insert(profiler);
} }
void RemoveProfiler(Isolate* isolate, CpuProfiler* profiler) { void RemoveProfiler(Isolate* isolate, CpuProfiler* profiler) {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
auto it = profilers_.find(isolate); auto range = profilers_.equal_range(isolate);
DCHECK(it != profilers_.end()); for (auto it = range.first; it != range.second; ++it) {
it->second->erase(profiler); if (it->second != profiler) continue;
if (it->second->empty()) {
profilers_.erase(it); profilers_.erase(it);
return;
} }
UNREACHABLE();
} }
void CallCollectSample(Isolate* isolate) { void CallCollectSample(Isolate* isolate) {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
auto profilers = profilers_.find(isolate); auto range = profilers_.equal_range(isolate);
if (profilers == profilers_.end()) return; for (auto it = range.first; it != range.second; ++it) {
for (auto it : *profilers->second) { it->second->CollectSample();
it->CollectSample();
} }
} }
private: private:
std::map<Isolate*, std::unique_ptr<std::set<CpuProfiler*>>> profilers_; std::unordered_multimap<Isolate*, CpuProfiler*> profilers_;
base::Mutex mutex_; base::Mutex mutex_;
}; };
......
...@@ -22,7 +22,7 @@ void SourcePositionTable::SetPosition(int pc_offset, int line) { ...@@ -22,7 +22,7 @@ void SourcePositionTable::SetPosition(int pc_offset, int line) {
DCHECK_GE(pc_offset, 0); DCHECK_GE(pc_offset, 0);
DCHECK_GT(line, 0); // The 1-based number of the source line. DCHECK_GT(line, 0); // The 1-based number of the source line.
if (GetSourceLineNumber(pc_offset) != line) { if (GetSourceLineNumber(pc_offset) != line) {
auto result = pc_offset_map_.insert(std::make_pair(pc_offset, line)); auto result = pc_offset_to_line_map_.emplace(pc_offset, line);
// Check that a new element was inserted. // Check that a new element was inserted.
USE(result); USE(result);
DCHECK(result.second); DCHECK(result.second);
...@@ -30,10 +30,11 @@ void SourcePositionTable::SetPosition(int pc_offset, int line) { ...@@ -30,10 +30,11 @@ void SourcePositionTable::SetPosition(int pc_offset, int line) {
} }
int SourcePositionTable::GetSourceLineNumber(int pc_offset) const { int SourcePositionTable::GetSourceLineNumber(int pc_offset) const {
if (pc_offset_map_.empty()) return v8::CpuProfileNode::kNoLineNumberInfo; if (pc_offset_to_line_map_.empty()) {
return v8::CpuProfileNode::kNoLineNumberInfo;
PcOffsetMap::const_iterator it = pc_offset_map_.upper_bound(pc_offset); }
if (it != pc_offset_map_.begin()) { auto it = pc_offset_to_line_map_.upper_bound(pc_offset);
if (it != pc_offset_to_line_map_.begin()) {
return (--it)->second; return (--it)->second;
} }
return it->second; return it->second;
......
...@@ -24,16 +24,13 @@ struct TickSample; ...@@ -24,16 +24,13 @@ struct TickSample;
// to the source line. // to the source line.
class SourcePositionTable : public Malloced { class SourcePositionTable : public Malloced {
public: public:
SourcePositionTable() {} SourcePositionTable() = default;
~SourcePositionTable() {}
void SetPosition(int pc_offset, int line); void SetPosition(int pc_offset, int line);
int GetSourceLineNumber(int pc_offset) const; int GetSourceLineNumber(int pc_offset) const;
private: private:
// pc_offset -> source line std::map<int, int> pc_offset_to_line_map_;
typedef std::map<int, int> PcOffsetMap;
PcOffsetMap pc_offset_map_;
DISALLOW_COPY_AND_ASSIGN(SourcePositionTable); DISALLOW_COPY_AND_ASSIGN(SourcePositionTable);
}; };
...@@ -127,9 +124,10 @@ class CodeEntry { ...@@ -127,9 +124,10 @@ class CodeEntry {
struct RareData { struct RareData {
const char* deopt_reason_ = kNoDeoptReason; const char* deopt_reason_ = kNoDeoptReason;
int deopt_id_ = kNoDeoptimizationId; int deopt_id_ = kNoDeoptimizationId;
// Should be an unordered_map, but it doesn't currently work on Win & MacOS. std::unordered_map<int, std::vector<std::unique_ptr<CodeEntry>>>
std::map<int, std::vector<std::unique_ptr<CodeEntry>>> inline_locations_; inline_locations_;
std::map<int, std::vector<CpuProfileDeoptFrame>> deopt_inlined_frames_; std::unordered_map<int, std::vector<CpuProfileDeoptFrame>>
deopt_inlined_frames_;
}; };
RareData* EnsureRareData(); RareData* EnsureRareData();
......
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