summaryrefslogtreecommitdiff
path: root/deps/v8/src/basic-block-profiler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/basic-block-profiler.cc')
-rw-r--r--deps/v8/src/basic-block-profiler.cc59
1 files changed, 45 insertions, 14 deletions
diff --git a/deps/v8/src/basic-block-profiler.cc b/deps/v8/src/basic-block-profiler.cc
index deb1a532d0..eaecd5dc68 100644
--- a/deps/v8/src/basic-block-profiler.cc
+++ b/deps/v8/src/basic-block-profiler.cc
@@ -4,14 +4,28 @@
#include "src/basic-block-profiler.h"
+#include <algorithm>
+#include <numeric>
#include <sstream>
+#include "src/base/lazy-instance.h"
+
namespace v8 {
namespace internal {
-BasicBlockProfiler::Data::Data(size_t n_blocks)
- : n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_, 0) {}
+namespace {
+base::LazyInstance<BasicBlockProfiler>::type kBasicBlockProfiler =
+ LAZY_INSTANCE_INITIALIZER;
+}
+BasicBlockProfiler* BasicBlockProfiler::Get() {
+ return kBasicBlockProfiler.Pointer();
+}
+
+BasicBlockProfiler::Data::Data(size_t n_blocks)
+ : n_blocks_(n_blocks),
+ block_rpo_numbers_(n_blocks_),
+ counts_(n_blocks_, 0) {}
BasicBlockProfiler::Data::~Data() {}
@@ -20,31 +34,31 @@ static void InsertIntoString(std::ostringstream* os, std::string* string) {
string->insert(0, os->str());
}
+static void InsertIntoString(const char* data, std::string* string) {
+ string->insert(0, data);
+}
void BasicBlockProfiler::Data::SetCode(std::ostringstream* os) {
InsertIntoString(os, &code_);
}
-
-void BasicBlockProfiler::Data::SetFunctionName(std::ostringstream* os) {
- InsertIntoString(os, &function_name_);
+void BasicBlockProfiler::Data::SetFunctionName(std::unique_ptr<char[]> name) {
+ InsertIntoString(name.get(), &function_name_);
}
-
void BasicBlockProfiler::Data::SetSchedule(std::ostringstream* os) {
InsertIntoString(os, &schedule_);
}
-
-void BasicBlockProfiler::Data::SetBlockId(size_t offset, size_t block_id) {
+void BasicBlockProfiler::Data::SetBlockRpoNumber(size_t offset,
+ int32_t block_rpo) {
DCHECK(offset < n_blocks_);
- block_ids_[offset] = block_id;
+ block_rpo_numbers_[offset] = block_rpo;
}
-
-uint32_t* BasicBlockProfiler::Data::GetCounterAddress(size_t offset) {
+intptr_t BasicBlockProfiler::Data::GetCounterAddress(size_t offset) {
DCHECK(offset < n_blocks_);
- return &counts_[offset];
+ return reinterpret_cast<intptr_t>(&(counts_[offset]));
}
@@ -59,6 +73,7 @@ BasicBlockProfiler::BasicBlockProfiler() {}
BasicBlockProfiler::Data* BasicBlockProfiler::NewData(size_t n_blocks) {
+ base::LockGuard<base::Mutex> lock(&data_list_mutex_);
Data* data = new Data(n_blocks);
data_list_.push_back(data);
return data;
@@ -91,17 +106,33 @@ std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler& p) {
std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& d) {
+ int block_count_sum = std::accumulate(d.counts_.begin(), d.counts_.end(), 0);
+ if (block_count_sum == 0) return os;
const char* name = "unknown function";
if (!d.function_name_.empty()) {
name = d.function_name_.c_str();
}
if (!d.schedule_.empty()) {
- os << "schedule for " << name << std::endl;
+ os << "schedule for " << name << " (B0 entered " << d.counts_[0]
+ << " times)" << std::endl;
os << d.schedule_.c_str() << std::endl;
}
os << "block counts for " << name << ":" << std::endl;
+ std::vector<std::pair<int32_t, uint32_t>> pairs;
+ pairs.reserve(d.n_blocks_);
for (size_t i = 0; i < d.n_blocks_; ++i) {
- os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << std::endl;
+ pairs.push_back(std::make_pair(d.block_rpo_numbers_[i], d.counts_[i]));
+ }
+ std::sort(pairs.begin(), pairs.end(),
+ [=](std::pair<int32_t, uint32_t> left,
+ std::pair<int32_t, uint32_t> right) {
+ if (right.second == left.second)
+ return left.first < right.first;
+ return right.second < left.second;
+ });
+ for (auto it : pairs) {
+ if (it.second == 0) break;
+ os << "block B" << it.first << " : " << it.second << std::endl;
}
os << std::endl;
if (!d.code_.empty()) {