Chromium Code Reviews

Unified Diff: src/basic-block-profiler.cc

Issue 593563005: [turbofan] basic block profiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: unit test file Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: src/basic-block-profiler.cc
diff --git a/src/basic-block-profiler.cc b/src/basic-block-profiler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7fdeb4066e019538253a8f92cbce196f83ea572c
--- /dev/null
+++ b/src/basic-block-profiler.cc
@@ -0,0 +1,100 @@
+// 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"
+
+namespace v8 {
+namespace internal {
+
+BasicBlockProfiler::Data::Data(size_t n_blocks)
+ : n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_) {}
+
+
+BasicBlockProfiler::Data::~Data() {}
+
+
+static void InsertIntoString(OStringStream* os, std::string* string) {
+ string->insert(string->begin(), os->c_str(), &os->c_str()[os->size()]);
+}
+
+
+void BasicBlockProfiler::Data::SetCode(OStringStream* os) {
+ InsertIntoString(os, &code_);
+}
+
+
+void BasicBlockProfiler::Data::SetFunctionName(OStringStream* os) {
+ InsertIntoString(os, &function_name_);
+}
+
+
+void BasicBlockProfiler::Data::SetSchedule(OStringStream* os) {
+ InsertIntoString(os, &schedule_);
+}
+
+
+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();
+ }
+}
+
+
+OStream& operator<<(OStream& os, const BasicBlockProfiler& p) {
+ os << "---- Start Profiling Data ----" << endl;
+ typedef BasicBlockProfiler::DataList::const_iterator iterator;
+ for (iterator i = p.data_list_.begin(); i != p.data_list_.end(); ++i) {
+ os << **i;
+ }
+ os << "---- End Profiling Data ----" << endl;
+ return os;
+}
+
+
+OStream& operator<<(OStream& os, const BasicBlockProfiler::Data& d) {
+ const char* name = "unknown function";
+ if (!d.function_name_.empty()) {
+ name = d.function_name_.c_str();
+ }
+ if (d.schedule_.empty()) {
+ os << "schedule for " << name << endl;
+ os << d.schedule_.c_str() << endl;
+ }
+ os << "block counts for " << name << ":" << endl;
+ for (size_t i = 0; i < d.n_blocks_; ++i) {
+ os << "block " << d.block_ids_[i] << " : " << d.counts_[i] << endl;
+ }
+ os << endl;
+ if (!d.code_.empty()) {
+ os << d.code_.c_str() << endl;
+ }
+ return os;
+}
+
+} // namespace internal
+} // namespace v8

Powered by Google App Engine