| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/basic-block-profiler.h" | 5 #include "src/basic-block-profiler.h" |
| 6 | 6 |
| 7 #include <sstream> |
| 8 |
| 7 namespace v8 { | 9 namespace v8 { |
| 8 namespace internal { | 10 namespace internal { |
| 9 | 11 |
| 10 BasicBlockProfiler::Data::Data(size_t n_blocks) | 12 BasicBlockProfiler::Data::Data(size_t n_blocks) |
| 11 : n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_, 0) {} | 13 : n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_, 0) {} |
| 12 | 14 |
| 13 | 15 |
| 14 BasicBlockProfiler::Data::~Data() {} | 16 BasicBlockProfiler::Data::~Data() {} |
| 15 | 17 |
| 16 | 18 |
| 17 static void InsertIntoString(OStringStream* os, std::string* string) { | 19 static void InsertIntoString(std::ostringstream* os, std::string* string) { |
| 18 string->insert(string->begin(), os->c_str(), &os->c_str()[os->size()]); | 20 string->insert(0, os->str()); |
| 19 } | 21 } |
| 20 | 22 |
| 21 | 23 |
| 22 void BasicBlockProfiler::Data::SetCode(OStringStream* os) { | 24 void BasicBlockProfiler::Data::SetCode(std::ostringstream* os) { |
| 23 InsertIntoString(os, &code_); | 25 InsertIntoString(os, &code_); |
| 24 } | 26 } |
| 25 | 27 |
| 26 | 28 |
| 27 void BasicBlockProfiler::Data::SetFunctionName(OStringStream* os) { | 29 void BasicBlockProfiler::Data::SetFunctionName(std::ostringstream* os) { |
| 28 InsertIntoString(os, &function_name_); | 30 InsertIntoString(os, &function_name_); |
| 29 } | 31 } |
| 30 | 32 |
| 31 | 33 |
| 32 void BasicBlockProfiler::Data::SetSchedule(OStringStream* os) { | 34 void BasicBlockProfiler::Data::SetSchedule(std::ostringstream* os) { |
| 33 InsertIntoString(os, &schedule_); | 35 InsertIntoString(os, &schedule_); |
| 34 } | 36 } |
| 35 | 37 |
| 36 | 38 |
| 37 void BasicBlockProfiler::Data::SetBlockId(size_t offset, size_t block_id) { | 39 void BasicBlockProfiler::Data::SetBlockId(size_t offset, size_t block_id) { |
| 38 DCHECK(offset < n_blocks_); | 40 DCHECK(offset < n_blocks_); |
| 39 block_ids_[offset] = block_id; | 41 block_ids_[offset] = block_id; |
| 40 } | 42 } |
| 41 | 43 |
| 42 | 44 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 70 } | 72 } |
| 71 | 73 |
| 72 | 74 |
| 73 void BasicBlockProfiler::ResetCounts() { | 75 void BasicBlockProfiler::ResetCounts() { |
| 74 for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) { | 76 for (DataList::iterator i = data_list_.begin(); i != data_list_.end(); ++i) { |
| 75 (*i)->ResetCounts(); | 77 (*i)->ResetCounts(); |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 | 81 |
| 80 OStream& operator<<(OStream& os, const BasicBlockProfiler& p) { | 82 std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler& p) { |
| 81 os << "---- Start Profiling Data ----" << endl; | 83 os << "---- Start Profiling Data ----" << std::endl; |
| 82 typedef BasicBlockProfiler::DataList::const_iterator iterator; | 84 typedef BasicBlockProfiler::DataList::const_iterator iterator; |
| 83 for (iterator i = p.data_list_.begin(); i != p.data_list_.end(); ++i) { | 85 for (iterator i = p.data_list_.begin(); i != p.data_list_.end(); ++i) { |
| 84 os << **i; | 86 os << **i; |
| 85 } | 87 } |
| 86 os << "---- End Profiling Data ----" << endl; | 88 os << "---- End Profiling Data ----" << std::endl; |
| 87 return os; | 89 return os; |
| 88 } | 90 } |
| 89 | 91 |
| 90 | 92 |
| 91 OStream& operator<<(OStream& os, const BasicBlockProfiler::Data& d) { | 93 std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& d) { |
| 92 const char* name = "unknown function"; | 94 const char* name = "unknown function"; |
| 93 if (!d.function_name_.empty()) { | 95 if (!d.function_name_.empty()) { |
| 94 name = d.function_name_.c_str(); | 96 name = d.function_name_.c_str(); |
| 95 } | 97 } |
| 96 if (!d.schedule_.empty()) { | 98 if (!d.schedule_.empty()) { |
| 97 os << "schedule for " << name << endl; | 99 os << "schedule for " << name << std::endl; |
| 98 os << d.schedule_.c_str() << endl; | 100 os << d.schedule_.c_str() << std::endl; |
| 99 } | 101 } |
| 100 os << "block counts for " << name << ":" << endl; | 102 os << "block counts for " << name << ":" << std::endl; |
| 101 for (size_t i = 0; i < d.n_blocks_; ++i) { | 103 for (size_t i = 0; i < d.n_blocks_; ++i) { |
| 102 os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << endl; | 104 os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << std::endl; |
| 103 } | 105 } |
| 104 os << endl; | 106 os << std::endl; |
| 105 if (!d.code_.empty()) { | 107 if (!d.code_.empty()) { |
| 106 os << d.code_.c_str() << endl; | 108 os << d.code_.c_str() << std::endl; |
| 107 } | 109 } |
| 108 return os; | 110 return os; |
| 109 } | 111 } |
| 110 | 112 |
| 111 } // namespace internal | 113 } // namespace internal |
| 112 } // namespace v8 | 114 } // namespace v8 |
| OLD | NEW |