OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "src/basic-block-profiler.h" |
| 6 |
| 7 namespace v8 { |
| 8 namespace internal { |
| 9 |
| 10 BasicBlockProfiler::Data::Data(size_t n_blocks) |
| 11 : n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_) {} |
| 12 |
| 13 |
| 14 BasicBlockProfiler::Data::~Data() {} |
| 15 |
| 16 |
| 17 static void InsertIntoString(OStringStream* os, std::string* string) { |
| 18 string->insert(string->begin(), os->c_str(), &os->c_str()[os->size()]); |
| 19 } |
| 20 |
| 21 |
| 22 void BasicBlockProfiler::Data::SetCode(OStringStream* os) { |
| 23 InsertIntoString(os, &code_); |
| 24 } |
| 25 |
| 26 |
| 27 void BasicBlockProfiler::Data::SetFunctionName(OStringStream* os) { |
| 28 InsertIntoString(os, &function_name_); |
| 29 } |
| 30 |
| 31 |
| 32 void BasicBlockProfiler::Data::SetSchedule(OStringStream* os) { |
| 33 InsertIntoString(os, &schedule_); |
| 34 } |
| 35 |
| 36 |
| 37 void BasicBlockProfiler::Data::ResetCounts() { |
| 38 for (size_t i = 0; i < n_blocks_; ++i) { |
| 39 counts_[i] = 0; |
| 40 } |
| 41 } |
| 42 |
| 43 |
| 44 BasicBlockProfiler::BasicBlockProfiler() {} |
| 45 |
| 46 |
| 47 BasicBlockProfiler::Data* BasicBlockProfiler::NewData(size_t n_blocks) { |
| 48 Data* data = new Data(n_blocks); |
| 49 data_list_.push_back(data); |
| 50 return data; |
| 51 } |
| 52 |
| 53 |
| 54 BasicBlockProfiler::~BasicBlockProfiler() { |
| 55 for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) { |
| 56 delete (*i); |
| 57 } |
| 58 } |
| 59 |
| 60 |
| 61 void BasicBlockProfiler::ResetCounts() { |
| 62 for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) { |
| 63 (*i)->ResetCounts(); |
| 64 } |
| 65 } |
| 66 |
| 67 |
| 68 OStream& operator<<(OStream& os, const BasicBlockProfiler& p) { |
| 69 os << "---- Start Profiling Data ----" << endl; |
| 70 typedef BasicBlockProfiler::DataList::const_iterator iterator; |
| 71 for (iterator i = p.data_list_.begin(); i != p.data_list_.end(); ++i) { |
| 72 os << **i; |
| 73 } |
| 74 os << "---- End Profiling Data ----" << endl; |
| 75 return os; |
| 76 } |
| 77 |
| 78 |
| 79 OStream& operator<<(OStream& os, const BasicBlockProfiler::Data& d) { |
| 80 const char* name = "unknown function"; |
| 81 if (!d.function_name_.empty()) { |
| 82 name = d.function_name_.c_str(); |
| 83 } |
| 84 if (d.schedule_.empty()) { |
| 85 os << "schedule for " << name << endl; |
| 86 os << d.schedule_.c_str() << endl; |
| 87 } |
| 88 os << "block counts for " << name << ":" << endl; |
| 89 for (size_t i = 0; i < d.n_blocks_; ++i) { |
| 90 os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << endl; |
| 91 } |
| 92 os << endl; |
| 93 if (!d.code_.empty()) { |
| 94 os << d.code_.c_str() << endl; |
| 95 } |
| 96 return os; |
| 97 } |
| 98 |
| 99 } // namespace internal |
| 100 } // namespace v8 |
OLD | NEW |