Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: src/counters.cc

Issue 1695733002: [counters] Making counter properly reentrant. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2016-02-09_recursive_counters_1681943002
Patch Set: fixing comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/counters.h ('k') | src/vm-state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/counters.h" 5 #include "src/counters.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 8
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 #undef HP 191 #undef HP
192 192
193 #define HM(name, caption) name##_.Reset(); 193 #define HM(name, caption) name##_.Reset();
194 HISTOGRAM_LEGACY_MEMORY_LIST(HM) 194 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
195 #undef HM 195 #undef HM
196 } 196 }
197 197
198 class RuntimeCallStatEntries { 198 class RuntimeCallStatEntries {
199 public: 199 public:
200 void Print(std::ostream& os) { 200 void Print(std::ostream& os) {
201 if (total_call_count > 0) { 201 if (total_call_count == 0) return;
202 std::sort(entries.rbegin(), entries.rend()); 202 std::sort(entries.rbegin(), entries.rend());
203 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(10) 203 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(10)
204 << "Time" << std::setw(18) << "Count" << std::endl 204 << "Time" << std::setw(18) << "Count" << std::endl
205 << std::string(86, '=') << std::endl; 205 << std::string(86, '=') << std::endl;
206 for (Entry& entry : entries) { 206 for (Entry& entry : entries) {
207 entry.SetTotal(total_time, total_call_count); 207 entry.SetTotal(total_time, total_call_count);
208 entry.Print(os); 208 entry.Print(os);
209 }
210 os << std::string(86, '-') << std::endl;
211 Entry("Total", total_time, total_call_count).Print(os);
212 } 209 }
210 os << std::string(86, '-') << std::endl;
211 Entry("Total", total_time, total_call_count).Print(os);
213 } 212 }
214 213
215 void Add(const char* name, RuntimeCallCounter counter) { 214 void Add(RuntimeCallCounter* counter) {
216 entries.push_back(Entry(name, counter.time, counter.count)); 215 if (counter->count == 0) return;
217 total_time += counter.time; 216 entries.push_back(Entry(counter->name, counter->time, counter->count));
218 total_call_count += counter.count; 217 total_time += counter->time;
218 total_call_count += counter->count;
219 } 219 }
220 220
221 private: 221 private:
222 class Entry { 222 class Entry {
223 public: 223 public:
224 Entry(const char* name, base::TimeDelta time, uint64_t count) 224 Entry(const char* name, base::TimeDelta time, uint64_t count)
225 : name_(name), 225 : name_(name),
226 time_(time.InMilliseconds()), 226 time_(time.InMilliseconds()),
227 count_(count), 227 count_(count),
228 time_percent_(100), 228 time_percent_(100),
(...skipping 10 matching lines...) Expand all
239 os << std::fixed; 239 os << std::fixed;
240 os << std::setw(50) << name_; 240 os << std::setw(50) << name_;
241 os << std::setw(8) << time_ << "ms "; 241 os << std::setw(8) << time_ << "ms ";
242 os << std::setw(6) << time_percent_ << "%"; 242 os << std::setw(6) << time_percent_ << "%";
243 os << std::setw(10) << count_ << " "; 243 os << std::setw(10) << count_ << " ";
244 os << std::setw(6) << count_percent_ << "%"; 244 os << std::setw(6) << count_percent_ << "%";
245 os << std::endl; 245 os << std::endl;
246 } 246 }
247 247
248 void SetTotal(base::TimeDelta total_time, uint64_t total_count) { 248 void SetTotal(base::TimeDelta total_time, uint64_t total_count) {
249 time_percent_ = 100.0 * time_ / total_time.InMilliseconds(); 249 if (total_time.InMilliseconds() == 0) {
250 time_percent_ = 0;
251 } else {
252 time_percent_ = 100.0 * time_ / total_time.InMilliseconds();
253 }
250 count_percent_ = 100.0 * count_ / total_count; 254 count_percent_ = 100.0 * count_ / total_count;
251 } 255 }
252 256
253 private: 257 private:
254 const char* name_; 258 const char* name_;
255 int64_t time_; 259 int64_t time_;
256 uint64_t count_; 260 uint64_t count_;
257 double time_percent_; 261 double time_percent_;
258 double count_percent_; 262 double count_percent_;
259 }; 263 };
260 264
261 uint64_t total_call_count = 0; 265 uint64_t total_call_count = 0;
262 base::TimeDelta total_time; 266 base::TimeDelta total_time;
263 std::vector<Entry> entries; 267 std::vector<Entry> entries;
264 }; 268 };
265 269
266 void RuntimeCallCounter::Reset() { 270 void RuntimeCallCounter::Reset() {
267 count = 0; 271 count = 0;
268 time = base::TimeDelta(); 272 time = base::TimeDelta();
269 } 273 }
270 274
271 void RuntimeCallStats::Enter(RuntimeCallCounter* counter) { 275 void RuntimeCallStats::Enter(RuntimeCallCounter* counter) {
272 counter->count++; 276 Enter(new RuntimeCallTimer(counter, current_timer_));
273 counter->parent_counter = current_counter;
274 current_counter = counter;
275 } 277 }
276 void RuntimeCallStats::Leave(base::TimeDelta time) { 278
277 RuntimeCallCounter* counter = current_counter; 279 void RuntimeCallStats::Enter(RuntimeCallTimer* timer_) {
278 counter->time += time; 280 current_timer_ = timer_;
279 current_counter = counter->parent_counter; 281 current_timer_->Start();
280 counter->parent_counter = NULL; 282 }
281 if (current_counter != NULL) { 283
282 current_counter->time -= time; 284 void RuntimeCallStats::Leave() {
283 } 285 RuntimeCallTimer* timer = current_timer_;
286 Leave(timer);
287 delete timer;
288 }
289
290 void RuntimeCallStats::Leave(RuntimeCallTimer* timer) {
291 current_timer_ = timer->Stop();
284 } 292 }
285 293
286 void RuntimeCallStats::Print(std::ostream& os) { 294 void RuntimeCallStats::Print(std::ostream& os) {
287 RuntimeCallStatEntries entries; 295 RuntimeCallStatEntries entries;
288 296
289 #define PRINT_COUNTER(name, nargs, ressize) \ 297 #define PRINT_COUNTER(name, nargs, ressize) entries.Add(&this->Runtime_##name);
290 if (this->Runtime_##name.count > 0) { \
291 entries.Add(#name, this->Runtime_##name); \
292 }
293 FOR_EACH_INTRINSIC(PRINT_COUNTER) 298 FOR_EACH_INTRINSIC(PRINT_COUNTER)
294 #undef PRINT_COUNTER 299 #undef PRINT_COUNTER
295 #define PRINT_COUNTER(name, type) \ 300
296 if (this->Builtin_##name.count > 0) { \ 301 #define PRINT_COUNTER(name, type) entries.Add(&this->Builtin_##name);
297 entries.Add(#name, this->Builtin_##name); \
298 }
299 BUILTIN_LIST_C(PRINT_COUNTER) 302 BUILTIN_LIST_C(PRINT_COUNTER)
300 #undef PRINT_COUNTER 303 #undef PRINT_COUNTER
304
305 entries.Add(&this->ExternalCallback);
306 entries.Add(&this->UnexpectedStubMiss);
307
301 entries.Print(os); 308 entries.Print(os);
302 } 309 }
303 310
304 void RuntimeCallStats::Reset() { 311 void RuntimeCallStats::Reset() {
305 #define RESET_COUNTER(name, nargs, ressize) this->Runtime_##name.Reset(); 312 #define RESET_COUNTER(name, nargs, ressize) this->Runtime_##name.Reset();
306 FOR_EACH_INTRINSIC(RESET_COUNTER) 313 FOR_EACH_INTRINSIC(RESET_COUNTER)
307 #undef RESET_COUNTER 314 #undef RESET_COUNTER
308 #define RESET_COUNTER(name, type) this->Builtin_##name.Reset(); 315 #define RESET_COUNTER(name, type) this->Builtin_##name.Reset();
309 BUILTIN_LIST_C(RESET_COUNTER) 316 BUILTIN_LIST_C(RESET_COUNTER)
310 #undef RESET_COUNTER 317 #undef RESET_COUNTER
311 } 318 }
312 319
320 RuntimeCallTimerScope::RuntimeCallTimerScope(Isolate* isolate,
321 RuntimeCallCounter* counter)
322 : isolate_(isolate),
323 timer_(counter,
324 isolate->counters()->runtime_call_stats()->current_timer()) {
325 if (!FLAG_runtime_call_stats) return;
326 isolate->counters()->runtime_call_stats()->Enter(&timer_);
327 }
328
329 RuntimeCallTimerScope::~RuntimeCallTimerScope() {
330 if (!FLAG_runtime_call_stats) return;
331 isolate_->counters()->runtime_call_stats()->Leave(&timer_);
332 }
333
313 } // namespace internal 334 } // namespace internal
314 } // namespace v8 335 } // namespace v8
OLDNEW
« no previous file with comments | « src/counters.h ('k') | src/vm-state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698