OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/runtime/runtime.h" | 5 #include "src/runtime/runtime.h" |
6 | 6 |
7 #include <iomanip> | |
8 | |
9 #include "src/assembler.h" | 7 #include "src/assembler.h" |
10 #include "src/contexts.h" | 8 #include "src/contexts.h" |
11 #include "src/handles-inl.h" | 9 #include "src/handles-inl.h" |
12 #include "src/heap/heap.h" | 10 #include "src/heap/heap.h" |
13 #include "src/isolate.h" | 11 #include "src/isolate.h" |
14 #include "src/runtime/runtime-utils.h" | 12 #include "src/runtime/runtime-utils.h" |
15 | 13 |
16 namespace v8 { | 14 namespace v8 { |
17 namespace internal { | 15 namespace internal { |
18 | 16 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return kIntrinsicFunctions; | 124 return kIntrinsicFunctions; |
127 } | 125 } |
128 } | 126 } |
129 | 127 |
130 | 128 |
131 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) { | 129 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) { |
132 return os << Runtime::FunctionForId(id)->name; | 130 return os << Runtime::FunctionForId(id)->name; |
133 } | 131 } |
134 | 132 |
135 | 133 |
136 class RuntimeCallStatEntries { | |
137 public: | |
138 void Print(std::ostream& os) { | |
139 if (total_call_count > 0) { | |
140 std::sort(entries.rbegin(), entries.rend()); | |
141 os << "Runtime function Time " | |
142 "Count" | |
143 << std::endl | |
144 << std::string(70, '=') << std::endl; | |
145 for (Entry& entry : entries) { | |
146 entry.Print(os); | |
147 } | |
148 os << std::string(60, '-') << std::endl; | |
149 Entry("Total", total_time, total_call_count).Print(os); | |
150 } | |
151 } | |
152 | |
153 void Add(const char* name, base::TimeDelta time, uint32_t count) { | |
154 entries.push_back(Entry(name, time, count)); | |
155 total_time += time; | |
156 total_call_count += count; | |
157 } | |
158 | |
159 private: | |
160 class Entry { | |
161 public: | |
162 Entry(const char* name, base::TimeDelta time, uint64_t count) | |
163 : name_(name), time_(time.InMilliseconds()), count_(count) {} | |
164 | |
165 bool operator<(const Entry& other) const { | |
166 if (time_ < other.time_) return true; | |
167 if (time_ > other.time_) return false; | |
168 return count_ < other.count_; | |
169 } | |
170 | |
171 void Print(std::ostream& os) { | |
172 os << std::setw(50) << name_; | |
173 os << std::setw(8) << time_ << "ms"; | |
174 os << std::setw(10) << count_ << std::endl; | |
175 } | |
176 | |
177 private: | |
178 const char* name_; | |
179 int64_t time_; | |
180 uint64_t count_; | |
181 }; | |
182 | |
183 uint64_t total_call_count = 0; | |
184 base::TimeDelta total_time; | |
185 std::vector<Entry> entries; | |
186 }; | |
187 | |
188 | |
189 void RuntimeCallStats::Print(std::ostream& os) { | |
190 RuntimeCallStatEntries entries; | |
191 | |
192 #define PRINT_COUNTER(name, nargs, ressize) \ | |
193 if (this->Count_Runtime_##name > 0) { \ | |
194 entries.Add(#name, this->Time_Runtime_##name, this->Count_Runtime_##name); \ | |
195 } | |
196 FOR_EACH_INTRINSIC(PRINT_COUNTER) | |
197 #undef PRINT_COUNTER | |
198 entries.Print(os); | |
199 } | |
200 | |
201 | |
202 void RuntimeCallStats::Reset() { | |
203 #define RESET_COUNTER(name, nargs, ressize) \ | |
204 Count_Runtime_##name = 0; \ | |
205 Time_Runtime_##name = base::TimeDelta(); | |
206 FOR_EACH_INTRINSIC(RESET_COUNTER) | |
207 #undef RESET_COUNTER | |
208 } | |
209 | |
210 } // namespace internal | 134 } // namespace internal |
211 } // namespace v8 | 135 } // namespace v8 |
OLD | NEW |