1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "src/basic-block-profiler.h"
12 BasicBlockProfiler::Data::Data(size_t n_blocks)
13 : n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_, 0) {}
16 BasicBlockProfiler::Data::~Data() {}
19 static void InsertIntoString(std::ostringstream* os, std::string* string) {
20 string->insert(0, os->str());
24 void BasicBlockProfiler::Data::SetCode(std::ostringstream* os) {
25 InsertIntoString(os, &code_);
29 void BasicBlockProfiler::Data::SetFunctionName(std::ostringstream* os) {
30 InsertIntoString(os, &function_name_);
34 void BasicBlockProfiler::Data::SetSchedule(std::ostringstream* os) {
35 InsertIntoString(os, &schedule_);
39 void BasicBlockProfiler::Data::SetBlockId(size_t offset, size_t block_id) {
40 DCHECK(offset < n_blocks_);
41 block_ids_[offset] = block_id;
45 uint32_t* BasicBlockProfiler::Data::GetCounterAddress(size_t offset) {
46 DCHECK(offset < n_blocks_);
47 return &counts_[offset];
51 void BasicBlockProfiler::Data::ResetCounts() {
52 for (size_t i = 0; i < n_blocks_; ++i) {
58 BasicBlockProfiler::BasicBlockProfiler() {}
61 BasicBlockProfiler::Data* BasicBlockProfiler::NewData(size_t n_blocks) {
62 Data* data = new Data(n_blocks);
63 data_list_.push_back(data);
68 BasicBlockProfiler::~BasicBlockProfiler() {
69 for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) {
75 void BasicBlockProfiler::ResetCounts() {
76 for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) {
82 std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler& p) {
83 os << "---- Start Profiling Data ----" << std::endl;
84 typedef BasicBlockProfiler::DataList::const_iterator iterator;
85 for (iterator i = p.data_list_.begin(); i != p.data_list_.end(); ++i) {
88 os << "---- End Profiling Data ----" << std::endl;
93 std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& d) {
94 const char* name = "unknown function";
95 if (!d.function_name_.empty()) {
96 name = d.function_name_.c_str();
98 if (!d.schedule_.empty()) {
99 os << "schedule for " << name << std::endl;
100 os << d.schedule_.c_str() << std::endl;
102 os << "block counts for " << name << ":" << std::endl;
103 for (size_t i = 0; i < d.n_blocks_; ++i) {
104 os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << std::endl;
107 if (!d.code_.empty()) {
108 os << d.code_.c_str() << std::endl;
113 } // namespace internal