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 @@
#include "src/profiler/cpu-profiler.h"
#include <unordered_map>
#include <utility>
#include "src/base/lazy-instance.h"
#include "src/base/platform/mutex.h"
#include "src/base/template-utils.h"
......@@ -252,33 +255,30 @@ class CpuProfilersManager {
public:
void AddProfiler(Isolate* isolate, CpuProfiler* profiler) {
base::LockGuard<base::Mutex> lock(&mutex_);
auto result = profilers_.insert(
std::pair<Isolate*, std::unique_ptr<std::set<CpuProfiler*>>>(
isolate, base::make_unique<std::set<CpuProfiler*>>()));
result.first->second->insert(profiler);
profilers_.emplace(isolate, profiler);
}
void RemoveProfiler(Isolate* isolate, CpuProfiler* profiler) {
base::LockGuard<base::Mutex> lock(&mutex_);
auto it = profilers_.find(isolate);
DCHECK(it != profilers_.end());
it->second->erase(profiler);
if (it->second->empty()) {
auto range = profilers_.equal_range(isolate);
for (auto it = range.first; it != range.second; ++it) {
if (it->second != profiler) continue;
profilers_.erase(it);
return;
}
UNREACHABLE();
}
void CallCollectSample(Isolate* isolate) {
base::LockGuard<base::Mutex> lock(&mutex_);
auto profilers = profilers_.find(isolate);
if (profilers == profilers_.end()) return;
for (auto it : *profilers->second) {
it->CollectSample();
auto range = profilers_.equal_range(isolate);
for (auto it = range.first; it != range.second; ++it) {
it->second->CollectSample();
}
}
private:
std::map<Isolate*, std::unique_ptr<std::set<CpuProfiler*>>> profilers_;
std::unordered_multimap<Isolate*, CpuProfiler*> profilers_;
base::Mutex mutex_;
};
......
......@@ -22,7 +22,7 @@ void SourcePositionTable::SetPosition(int pc_offset, int line) {
DCHECK_GE(pc_offset, 0);
DCHECK_GT(line, 0); // The 1-based number of the source 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.
USE(result);
DCHECK(result.second);
......@@ -30,10 +30,11 @@ void SourcePositionTable::SetPosition(int pc_offset, int line) {
}
int SourcePositionTable::GetSourceLineNumber(int pc_offset) const {
if (pc_offset_map_.empty()) return v8::CpuProfileNode::kNoLineNumberInfo;
PcOffsetMap::const_iterator it = pc_offset_map_.upper_bound(pc_offset);
if (it != pc_offset_map_.begin()) {
if (pc_offset_to_line_map_.empty()) {
return v8::CpuProfileNode::kNoLineNumberInfo;
}
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;
......
......@@ -24,16 +24,13 @@ struct TickSample;
// to the source line.
class SourcePositionTable : public Malloced {
public:
SourcePositionTable() {}
~SourcePositionTable() {}
SourcePositionTable() = default;
void SetPosition(int pc_offset, int line);
int GetSourceLineNumber(int pc_offset) const;
private:
// pc_offset -> source line
typedef std::map<int, int> PcOffsetMap;
PcOffsetMap pc_offset_map_;
std::map<int, int> pc_offset_to_line_map_;
DISALLOW_COPY_AND_ASSIGN(SourcePositionTable);
};
......@@ -127,9 +124,10 @@ class CodeEntry {
struct RareData {
const char* deopt_reason_ = kNoDeoptReason;
int deopt_id_ = kNoDeoptimizationId;
// Should be an unordered_map, but it doesn't currently work on Win & MacOS.
std::map<int, std::vector<std::unique_ptr<CodeEntry>>> inline_locations_;
std::map<int, std::vector<CpuProfileDeoptFrame>> deopt_inlined_frames_;
std::unordered_map<int, std::vector<std::unique_ptr<CodeEntry>>>
inline_locations_;
std::unordered_map<int, std::vector<CpuProfileDeoptFrame>>
deopt_inlined_frames_;
};
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