2014-09-29 07:29:14 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/basic-block-profiler.h"
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2014-09-29 07:29:14 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
BasicBlockProfiler::Data::Data(size_t n_blocks)
|
2014-09-30 08:23:20 +00:00
|
|
|
: n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_, 0) {}
|
2014-09-29 07:29:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
BasicBlockProfiler::Data::~Data() {}
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
static void InsertIntoString(std::ostringstream* os, std::string* string) {
|
|
|
|
string->insert(0, os->str());
|
2014-09-29 07:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
void BasicBlockProfiler::Data::SetCode(std::ostringstream* os) {
|
2014-09-29 07:29:14 +00:00
|
|
|
InsertIntoString(os, &code_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
void BasicBlockProfiler::Data::SetFunctionName(std::ostringstream* os) {
|
2014-09-29 07:29:14 +00:00
|
|
|
InsertIntoString(os, &function_name_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
void BasicBlockProfiler::Data::SetSchedule(std::ostringstream* os) {
|
2014-09-29 07:29:14 +00:00
|
|
|
InsertIntoString(os, &schedule_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 08:23:20 +00:00
|
|
|
void BasicBlockProfiler::Data::SetBlockId(size_t offset, size_t block_id) {
|
2014-09-29 07:29:14 +00:00
|
|
|
DCHECK(offset < n_blocks_);
|
|
|
|
block_ids_[offset] = block_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t* BasicBlockProfiler::Data::GetCounterAddress(size_t offset) {
|
|
|
|
DCHECK(offset < n_blocks_);
|
|
|
|
return &counts_[offset];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BasicBlockProfiler::Data::ResetCounts() {
|
|
|
|
for (size_t i = 0; i < n_blocks_; ++i) {
|
|
|
|
counts_[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BasicBlockProfiler::BasicBlockProfiler() {}
|
|
|
|
|
|
|
|
|
|
|
|
BasicBlockProfiler::Data* BasicBlockProfiler::NewData(size_t n_blocks) {
|
|
|
|
Data* data = new Data(n_blocks);
|
|
|
|
data_list_.push_back(data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BasicBlockProfiler::~BasicBlockProfiler() {
|
|
|
|
for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) {
|
|
|
|
delete (*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BasicBlockProfiler::ResetCounts() {
|
|
|
|
for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) {
|
|
|
|
(*i)->ResetCounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler& p) {
|
|
|
|
os << "---- Start Profiling Data ----" << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
typedef BasicBlockProfiler::DataList::const_iterator iterator;
|
|
|
|
for (iterator i = p.data_list_.begin(); i != p.data_list_.end(); ++i) {
|
|
|
|
os << **i;
|
|
|
|
}
|
2014-09-30 10:29:32 +00:00
|
|
|
os << "---- End Profiling Data ----" << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& d) {
|
2014-09-29 07:29:14 +00:00
|
|
|
const char* name = "unknown function";
|
|
|
|
if (!d.function_name_.empty()) {
|
|
|
|
name = d.function_name_.c_str();
|
|
|
|
}
|
|
|
|
if (!d.schedule_.empty()) {
|
2014-09-30 10:29:32 +00:00
|
|
|
os << "schedule for " << name << std::endl;
|
|
|
|
os << d.schedule_.c_str() << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
}
|
2014-09-30 10:29:32 +00:00
|
|
|
os << "block counts for " << name << ":" << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
for (size_t i = 0; i < d.n_blocks_; ++i) {
|
2014-09-30 10:29:32 +00:00
|
|
|
os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
}
|
2014-09-30 10:29:32 +00:00
|
|
|
os << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
if (!d.code_.empty()) {
|
2014-09-30 10:29:32 +00:00
|
|
|
os << d.code_.c_str() << std::endl;
|
2014-09-29 07:29:14 +00:00
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|