| Index: src/runtime/runtime.cc
|
| diff --git a/src/runtime/runtime.cc b/src/runtime/runtime.cc
|
| index c532d13b289f376b9e61ef4e9d754464d2137a78..a59a21b509f246cd95142c7b8c77da9b2f446932 100644
|
| --- a/src/runtime/runtime.cc
|
| +++ b/src/runtime/runtime.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "src/runtime/runtime.h"
|
|
|
| +#include <iomanip>
|
| +
|
| #include "src/assembler.h"
|
| #include "src/contexts.h"
|
| #include "src/handles-inl.h"
|
| @@ -130,5 +132,80 @@ std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) {
|
| return os << Runtime::FunctionForId(id)->name;
|
| }
|
|
|
| +
|
| +class RuntimeCallStatEntries {
|
| + public:
|
| + void Print(std::ostream& os) {
|
| + if (total_call_count > 0) {
|
| + std::sort(entries.rbegin(), entries.rend());
|
| + os << "Runtime function Time "
|
| + "Count"
|
| + << std::endl
|
| + << std::string(70, '=') << std::endl;
|
| + for (Entry& entry : entries) {
|
| + entry.Print(os);
|
| + }
|
| + os << std::string(60, '-') << std::endl;
|
| + Entry("Total", total_time, total_call_count).Print(os);
|
| + }
|
| + }
|
| +
|
| + void Add(const char* name, base::TimeDelta time, uint32_t count) {
|
| + entries.push_back(Entry(name, time, count));
|
| + total_time += time;
|
| + total_call_count += count;
|
| + }
|
| +
|
| + private:
|
| + class Entry {
|
| + public:
|
| + Entry(const char* name, base::TimeDelta time, uint64_t count)
|
| + : name_(name), time_(time.InMilliseconds()), count_(count) {}
|
| +
|
| + bool operator<(const Entry& other) const {
|
| + if (time_ < other.time_) return true;
|
| + if (time_ > other.time_) return false;
|
| + return count_ < other.count_;
|
| + }
|
| +
|
| + void Print(std::ostream& os) {
|
| + os << std::setw(50) << name_;
|
| + os << std::setw(8) << time_ << "ms";
|
| + os << std::setw(10) << count_ << std::endl;
|
| + }
|
| +
|
| + private:
|
| + const char* name_;
|
| + int64_t time_;
|
| + uint64_t count_;
|
| + };
|
| +
|
| + uint64_t total_call_count = 0;
|
| + base::TimeDelta total_time;
|
| + std::vector<Entry> entries;
|
| +};
|
| +
|
| +
|
| +void RuntimeCallStats::Print(std::ostream& os) {
|
| + RuntimeCallStatEntries entries;
|
| +
|
| +#define PRINT_COUNTER(name, nargs, ressize) \
|
| + if (this->Count_Runtime_##name > 0) { \
|
| + entries.Add(#name, this->Time_Runtime_##name, this->Count_Runtime_##name); \
|
| + }
|
| + FOR_EACH_INTRINSIC(PRINT_COUNTER)
|
| +#undef PRINT_COUNTER
|
| + entries.Print(os);
|
| +}
|
| +
|
| +
|
| +void RuntimeCallStats::Reset() {
|
| +#define RESET_COUNTER(name, nargs, ressize) \
|
| + Count_Runtime_##name = 0; \
|
| + Time_Runtime_##name = base::TimeDelta();
|
| + FOR_EACH_INTRINSIC(RESET_COUNTER)
|
| +#undef RESET_COUNTER
|
| +}
|
| +
|
| } // namespace internal
|
| } // namespace v8
|
|
|