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

Side by Side Diff: src/counters.cc

Issue 2490643002: [counters] Implement off-isolate RuntimeCallStats for the Preparser (Closed)
Patch Set: fix merge conflict Created 4 years, 1 month 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
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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 time = base::TimeDelta(); 277 time = base::TimeDelta();
278 } 278 }
279 279
280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { 280 void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) {
281 value->BeginArray(name); 281 value->BeginArray(name);
282 value->AppendLongInteger(count); 282 value->AppendLongInteger(count);
283 value->AppendLongInteger(time.InMicroseconds()); 283 value->AppendLongInteger(time.InMicroseconds());
284 value->EndArray(); 284 value->EndArray();
285 } 285 }
286 286
287 void RuntimeCallCounter::Add(RuntimeCallCounter* other) {
288 count += other->count;
289 time += other->time;
290 }
291
287 // static 292 // static
288 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, 293 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
289 CounterId counter_id) { 294 CounterId counter_id) {
290 RuntimeCallCounter* counter = &(stats->*counter_id); 295 RuntimeCallCounter* counter = &(stats->*counter_id);
296 DCHECK(counter->name != NULL);
291 timer->Start(counter, stats->current_timer_.Value()); 297 timer->Start(counter, stats->current_timer_.Value());
292 stats->current_timer_.SetValue(timer); 298 stats->current_timer_.SetValue(timer);
293 } 299 }
294 300
295 // static 301 // static
296 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { 302 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
297 if (stats->current_timer_.Value() == timer) { 303 if (stats->current_timer_.Value() == timer) {
298 stats->current_timer_.SetValue(timer->Stop()); 304 stats->current_timer_.SetValue(timer->Stop());
299 } else { 305 } else {
300 // Must be a Threading cctest. Walk the chain of Timers to find the 306 // Must be a Threading cctest. Walk the chain of Timers to find the
301 // buried one that's leaving. We don't care about keeping nested timings 307 // buried one that's leaving. We don't care about keeping nested timings
302 // accurate, just avoid crashing by keeping the chain intact. 308 // accurate, just avoid crashing by keeping the chain intact.
303 RuntimeCallTimer* next = stats->current_timer_.Value(); 309 RuntimeCallTimer* next = stats->current_timer_.Value();
304 while (next && next->parent() != timer) next = next->parent(); 310 while (next->parent() != timer) next = next->parent();
305 if (next == nullptr) return;
306 next->parent_.SetValue(timer->Stop()); 311 next->parent_.SetValue(timer->Stop());
307 } 312 }
308 } 313 }
309 314
315 void RuntimeCallStats::Add(RuntimeCallStats* other) {
316 RuntimeCallCounter* current = &(this->First);
vogelheim 2016/11/14 10:20:33 (here and below): I take it you use First & Last
Camillo Bruni 2016/11/14 12:43:46 Yes, that's right, given that First and Last are j
317 RuntimeCallCounter* other_counter = &(other->First);
318 while (current < &(this->Last)) {
319 current = reinterpret_cast<RuntimeCallCounter*>(
320 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter));
321 other_counter = reinterpret_cast<RuntimeCallCounter*>(
322 reinterpret_cast<intptr_t>(other_counter) + sizeof(RuntimeCallCounter));
vogelheim 2016/11/14 10:20:33 A nitpick, loosely related to the comment above: T
Camillo Bruni 2016/11/14 12:43:46 Right, I had some discussions around this as it is
323 current->Add(other_counter);
324 }
325 }
326
310 // static 327 // static
311 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, 328 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats,
312 CounterId counter_id) { 329 CounterId counter_id) {
313 RuntimeCallTimer* timer = stats->current_timer_.Value(); 330 RuntimeCallTimer* timer = stats->current_timer_.Value();
314 // When RCS are enabled dynamically there might be no current timer set up. 331 // When RCS are enabled dynamically there might be no current timer set up.
315 if (timer == nullptr) return; 332 if (timer == nullptr) return;
316 timer->counter_ = &(stats->*counter_id); 333 timer->counter_ = &(stats->*counter_id);
317 } 334 }
318 335
319 void RuntimeCallStats::Print(std::ostream& os) { 336 void RuntimeCallStats::Print(std::ostream& os) {
320 RuntimeCallStatEntries entries; 337 RuntimeCallStatEntries entries;
321 if (current_timer_.Value() != nullptr) { 338 if (current_timer_.Value() != nullptr) {
322 current_timer_.Value()->Elapsed(); 339 current_timer_.Value()->Elapsed();
323 } 340 }
324 341 RuntimeCallCounter* current = &(this->First);
325 #define PRINT_COUNTER(name) entries.Add(&this->name); 342 while (current < &(this->Last)) {
326 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) 343 current = reinterpret_cast<RuntimeCallCounter*>(
327 #undef PRINT_COUNTER 344 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter));
328 345 entries.Add(current);
329 #define PRINT_COUNTER(name, nargs, ressize) entries.Add(&this->Runtime_##name); 346 }
330 FOR_EACH_INTRINSIC(PRINT_COUNTER)
331 #undef PRINT_COUNTER
332
333 #define PRINT_COUNTER(name) entries.Add(&this->Builtin_##name);
334 BUILTIN_LIST_C(PRINT_COUNTER)
335 #undef PRINT_COUNTER
336
337 #define PRINT_COUNTER(name) entries.Add(&this->API_##name);
338 FOR_EACH_API_COUNTER(PRINT_COUNTER)
339 #undef PRINT_COUNTER
340
341 #define PRINT_COUNTER(name) entries.Add(&this->Handler_##name);
342 FOR_EACH_HANDLER_COUNTER(PRINT_COUNTER)
343 #undef PRINT_COUNTER
344
345 entries.Print(os); 347 entries.Print(os);
346 } 348 }
347 349
348 void RuntimeCallStats::Reset() { 350 void RuntimeCallStats::Reset() {
349 if (V8_LIKELY(FLAG_runtime_stats == 0)) return; 351 if (V8_LIKELY(FLAG_runtime_stats == 0)) return;
350 352
351 // In tracing, we only what to trace the time spent on top level trace events, 353 // In tracing, we only what to trace the time spent on top level trace events,
352 // if runtime counter stack is not empty, we should clear the whole runtime 354 // if runtime counter stack is not empty, we should clear the whole runtime
353 // counter stack, and then reset counters so that we can dump counters into 355 // counter stack, and then reset counters so that we can dump counters into
354 // top level trace events accurately. 356 // top level trace events accurately.
355 while (current_timer_.Value()) { 357 while (current_timer_.Value()) {
356 current_timer_.SetValue(current_timer_.Value()->Stop()); 358 current_timer_.SetValue(current_timer_.Value()->Stop());
357 } 359 }
358 360
359 #define RESET_COUNTER(name) this->name.Reset(); 361 RuntimeCallCounter* current = &(this->First);
360 FOR_EACH_MANUAL_COUNTER(RESET_COUNTER) 362 while (current < &(this->Last)) {
361 #undef RESET_COUNTER 363 current = reinterpret_cast<RuntimeCallCounter*>(
362 364 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter));
363 #define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset(); 365 current->Reset();
364 FOR_EACH_INTRINSIC(RESET_COUNTER) 366 }
365 #undef RESET_COUNTER
366
367 #define RESET_COUNTER(name) this->Builtin_##name.Reset();
368 BUILTIN_LIST_C(RESET_COUNTER)
369 #undef RESET_COUNTER
370
371 #define RESET_COUNTER(name) this->API_##name.Reset();
372 FOR_EACH_API_COUNTER(RESET_COUNTER)
373 #undef RESET_COUNTER
374
375 #define RESET_COUNTER(name) this->Handler_##name.Reset();
376 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER)
377 #undef RESET_COUNTER
378 367
379 in_use_ = true; 368 in_use_ = true;
380 } 369 }
381 370
382 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { 371 void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) {
383 #define DUMP_COUNTER(name) \ 372 RuntimeCallCounter* current = &(this->First);
384 if (this->name.count > 0) this->name.Dump(value); 373 while (current < &(this->Last)) {
385 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) 374 current = reinterpret_cast<RuntimeCallCounter*>(
386 #undef DUMP_COUNTER 375 reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter));
387 376 if (current->count > 0) current->Dump(value);
388 #define DUMP_COUNTER(name, nargs, result_size) \ 377 }
389 if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(value);
390 FOR_EACH_INTRINSIC(DUMP_COUNTER)
391 #undef DUMP_COUNTER
392
393 #define DUMP_COUNTER(name) \
394 if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(value);
395 BUILTIN_LIST_C(DUMP_COUNTER)
396 #undef DUMP_COUNTER
397
398 #define DUMP_COUNTER(name) \
399 if (this->API_##name.count > 0) this->API_##name.Dump(value);
400 FOR_EACH_API_COUNTER(DUMP_COUNTER)
401 #undef DUMP_COUNTER
402
403 #define DUMP_COUNTER(name) \
404 if (this->Handler_##name.count > 0) this->Handler_##name.Dump(value);
405 FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER)
406 #undef DUMP_COUNTER
407 378
408 in_use_ = false; 379 in_use_ = false;
409 } 380 }
410 381
411 } // namespace internal 382 } // namespace internal
412 } // namespace v8 383 } // namespace v8
OLDNEW
« no previous file with comments | « src/counters.h ('k') | src/counters-inl.h » ('j') | src/parsing/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698