Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index c23c1a4a9c722f0839fd4ca4976c41e90b10cda0..e12a2451e1856e7a776432f033bd60e753aceb12 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -12,6 +12,7 @@ |
#include <stdlib.h> |
#include <string.h> |
#include <sys/stat.h> |
+#include <fstream> |
#ifdef V8_SHARED |
#include <assert.h> |
@@ -41,6 +42,7 @@ |
#include "src/base/platform/platform.h" |
#include "src/base/sys-info.h" |
#include "src/basic-block-profiler.h" |
+#include "src/interpreter/interpreter.h" |
#include "src/snapshot/natives.h" |
#include "src/utils.h" |
#include "src/v8.h" |
@@ -1275,6 +1277,63 @@ struct CounterAndKey { |
inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) { |
return strcmp(lhs.key, rhs.key) < 0; |
} |
+ |
+void Shell::WriteInterpreterDispatchCounters(Isolate* isolate) { |
rmcilroy
2016/04/08 17:15:47
Actually thinking about it, let's move this functi
Stefano Sanfilippo
2016/04/08 18:10:02
Done.
|
+ std::ofstream stream(i::FLAG_trace_ignition_dispatches_output_file); |
+ |
+ uintptr_t* bytecode_dispatch_count_table = |
+ reinterpret_cast<i::Isolate*>(isolate) |
+ ->interpreter() |
+ ->bytecode_dispatch_count_table(); |
+ |
+ static const int kCountersTableRowSize = |
+ static_cast<int>(i::interpreter::Bytecode::kLast) + 1; |
rmcilroy
2016/04/08 17:15:47
Update this constant name too.
Stefano Sanfilippo
2016/04/08 18:10:02
Done.
|
+ |
+ // Output is a JSON-encoded object of objects. |
+ // |
+ // Keys on the top level object are the source bytecodes, |
+ // and corresponding value are objects. Keys on these last are the |
+ // destinations of the dispatch and the value associated is a counter for |
+ // the correspondent source-destination dispatch chain. |
+ // |
+ // Only non-zero counters are written to file, but an entry in the top-level |
+ // object is always present, even if the value is empty because all counters |
+ // for that source are zero. |
+ |
+ stream << '{'; |
+ |
+ for (int from_index = 0; from_index < kCountersTableRowSize; ++from_index) { |
+ if (from_index > 0) stream << ",\n "; |
+ |
+ i::interpreter::Bytecode from_bytecode = |
+ i::interpreter::Bytecodes::FromByte(from_index); |
+ stream << "\"" << i::interpreter::Bytecodes::ToString(from_bytecode) |
+ << "\": {"; |
+ |
+ bool emitted_first = false; |
+ for (int to_index = 0; to_index < kCountersTableRowSize; ++to_index) { |
+ uintptr_t counter = |
+ bytecode_dispatch_count_table[from_index * kCountersTableRowSize + |
+ to_index]; |
+ if (counter > 0) { |
+ if (emitted_first) { |
+ stream << ", "; |
+ } else { |
+ emitted_first = true; |
+ } |
+ |
+ i::interpreter::Bytecode to_bytecode = |
+ i::interpreter::Bytecodes::FromByte(to_index); |
+ stream << '"' << i::interpreter::Bytecodes::ToString(to_bytecode) |
+ << "\": " << counter; |
+ } |
+ } |
+ |
+ stream << "}"; |
+ } |
+ stream << '}'; |
+} |
+ |
#endif // !V8_SHARED |
@@ -1312,6 +1371,11 @@ void Shell::OnExit(v8::Isolate* isolate) { |
"-------------+\n"); |
delete [] counters; |
} |
+ |
+ if (i::FLAG_trace_ignition_dispatches) { |
+ WriteInterpreterDispatchCounters(isolate); |
+ } |
+ |
delete counters_file_; |
delete counter_map_; |
#endif // !V8_SHARED |