| 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 #ifndef V8_COUNTERS_H_ | 5 #ifndef V8_COUNTERS_H_ | 
| 6 #define V8_COUNTERS_H_ | 6 #define V8_COUNTERS_H_ | 
| 7 | 7 | 
| 8 #include "include/v8.h" | 8 #include "include/v8.h" | 
| 9 #include "src/allocation.h" | 9 #include "src/allocation.h" | 
| 10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" | 
|  | 11 #include "src/base/platform/time.h" | 
| 11 #include "src/globals.h" | 12 #include "src/globals.h" | 
| 12 #include "src/objects.h" | 13 #include "src/objects.h" | 
| 13 | 14 | 
| 14 namespace v8 { | 15 namespace v8 { | 
| 15 namespace internal { | 16 namespace internal { | 
| 16 | 17 | 
| 17 // StatsCounters is an interface for plugging into external | 18 // StatsCounters is an interface for plugging into external | 
| 18 // counters for monitoring.  Counters can be looked up and | 19 // counters for monitoring.  Counters can be looked up and | 
| 19 // manipulated by name. | 20 // manipulated by name. | 
| 20 | 21 | 
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 284 #endif | 285 #endif | 
| 285   } | 286   } | 
| 286 | 287 | 
| 287  private: | 288  private: | 
| 288   HistogramTimer* timer_; | 289   HistogramTimer* timer_; | 
| 289 #ifdef DEBUG | 290 #ifdef DEBUG | 
| 290   bool skipped_timer_start_; | 291   bool skipped_timer_start_; | 
| 291 #endif | 292 #endif | 
| 292 }; | 293 }; | 
| 293 | 294 | 
|  | 295 | 
|  | 296 // A histogram timer that can aggregate events within a larger scope. | 
|  | 297 // | 
|  | 298 // Intended use of this timer is to have an outer (aggregating) and an inner | 
|  | 299 // (to be aggregated) scope, where the inner scope measure the time of events, | 
|  | 300 // and all those inner scope measurements will be summed up by the outer scope. | 
|  | 301 // An example use might be to aggregate the time spent in lazy compilation | 
|  | 302 // while running a script. | 
|  | 303 // | 
|  | 304 // Helpers: | 
|  | 305 // - AggregatingHistogramTimerScope, the "outer" scope within which | 
|  | 306 //     times will be summed up. | 
|  | 307 // - AggregatedHistogramTimerScope, the "inner" scope which defines the | 
|  | 308 //     events to be timed. | 
|  | 309 class AggregatableHistogramTimer : public Histogram { | 
|  | 310  public: | 
|  | 311   AggregatableHistogramTimer() {} | 
|  | 312   AggregatableHistogramTimer(const char* name, int min, int max, | 
|  | 313                              int num_buckets, Isolate* isolate) | 
|  | 314       : Histogram(name, min, max, num_buckets, isolate) {} | 
|  | 315 | 
|  | 316   // Start/stop the "outer" scope. | 
|  | 317   void Start() { time_ = base::TimeDelta(); } | 
|  | 318   void Stop() { AddSample(static_cast<int>(time_.InMilliseconds())); } | 
|  | 319 | 
|  | 320   // Add a time value ("inner" scope). | 
|  | 321   void Add(base::TimeDelta other) { time_ += other; } | 
|  | 322 | 
|  | 323  private: | 
|  | 324   base::TimeDelta time_; | 
|  | 325 }; | 
|  | 326 | 
|  | 327 | 
|  | 328 // A helper class for use with AggregatableHistogramTimer. | 
|  | 329 class AggregatingHistogramTimerScope { | 
|  | 330  public: | 
|  | 331   explicit AggregatingHistogramTimerScope(AggregatableHistogramTimer* histogram) | 
|  | 332       : histogram_(histogram) { | 
|  | 333     histogram_->Start(); | 
|  | 334   } | 
|  | 335   ~AggregatingHistogramTimerScope() { histogram_->Stop(); } | 
|  | 336 | 
|  | 337  private: | 
|  | 338   AggregatableHistogramTimer* histogram_; | 
|  | 339 }; | 
|  | 340 | 
|  | 341 | 
|  | 342 // A helper class for use with AggregatableHistogramTimer. | 
|  | 343 class AggregatedHistogramTimerScope { | 
|  | 344  public: | 
|  | 345   explicit AggregatedHistogramTimerScope(AggregatableHistogramTimer* histogram) | 
|  | 346       : histogram_(histogram) { | 
|  | 347     timer_.Start(); | 
|  | 348   } | 
|  | 349   ~AggregatedHistogramTimerScope() { histogram_->Add(timer_.Elapsed()); } | 
|  | 350 | 
|  | 351  private: | 
|  | 352   base::ElapsedTimer timer_; | 
|  | 353   AggregatableHistogramTimer* histogram_; | 
|  | 354 }; | 
|  | 355 | 
|  | 356 | 
| 294 #define HISTOGRAM_RANGE_LIST(HR)                                              \ | 357 #define HISTOGRAM_RANGE_LIST(HR)                                              \ | 
| 295   /* Generic range histograms */                                              \ | 358   /* Generic range histograms */                                              \ | 
| 296   HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101)   \ | 359   HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101)   \ | 
| 297   HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ | 360   HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ | 
| 298   HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, 101) | 361   HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, 101) | 
| 299 | 362 | 
| 300 #define HISTOGRAM_TIMER_LIST(HT)                             \ | 363 #define HISTOGRAM_TIMER_LIST(HT)                             \ | 
| 301   /* Garbage collection timers. */                           \ | 364   /* Garbage collection timers. */                           \ | 
| 302   HT(gc_compactor, V8.GCCompactor)                           \ | 365   HT(gc_compactor, V8.GCCompactor)                           \ | 
| 303   HT(gc_scavenger, V8.GCScavenger)                           \ | 366   HT(gc_scavenger, V8.GCScavenger)                           \ | 
| 304   HT(gc_context, V8.GCContext) /* GC context cleanup time */ \ | 367   HT(gc_context, V8.GCContext) /* GC context cleanup time */ \ | 
| 305   HT(gc_idle_notification, V8.GCIdleNotification)            \ | 368   HT(gc_idle_notification, V8.GCIdleNotification)            \ | 
| 306   HT(gc_incremental_marking, V8.GCIncrementalMarking)        \ | 369   HT(gc_incremental_marking, V8.GCIncrementalMarking)        \ | 
| 307   HT(gc_low_memory_notification, V8.GCLowMemoryNotification) \ | 370   HT(gc_low_memory_notification, V8.GCLowMemoryNotification) \ | 
| 308   /* Parsing timers. */                                      \ | 371   /* Parsing timers. */                                      \ | 
| 309   HT(parse, V8.Parse)                                        \ | 372   HT(parse, V8.Parse)                                        \ | 
| 310   HT(parse_lazy, V8.ParseLazy)                               \ | 373   HT(parse_lazy, V8.ParseLazy)                               \ | 
| 311   HT(pre_parse, V8.PreParse)                                 \ | 374   HT(pre_parse, V8.PreParse)                                 \ | 
| 312   /* Compilation times. */                                   \ | 375   /* Compilation times. */                                   \ | 
| 313   HT(compile, V8.Compile)                                    \ | 376   HT(compile, V8.Compile)                                    \ | 
| 314   HT(compile_eval, V8.CompileEval)                           \ | 377   HT(compile_eval, V8.CompileEval)                           \ | 
| 315   /* Serialization as part of compilation (code caching) */  \ | 378   /* Serialization as part of compilation (code caching) */  \ | 
| 316   HT(compile_serialize, V8.CompileSerialize)                 \ | 379   HT(compile_serialize, V8.CompileSerialize)                 \ | 
| 317   HT(compile_deserialize, V8.CompileDeserialize)             \ | 380   HT(compile_deserialize, V8.CompileDeserialize)             \ | 
| 318   /* Total compilation time incl. caching/parsing */         \ | 381   /* Total compilation time incl. caching/parsing */         \ | 
| 319   HT(compile_script, V8.CompileScript) | 382   HT(compile_script, V8.CompileScript) | 
| 320 | 383 | 
| 321 | 384 | 
|  | 385 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ | 
|  | 386   AHT(compile_lazy, V8.CompileLazy) | 
|  | 387 | 
|  | 388 | 
| 322 #define HISTOGRAM_PERCENTAGE_LIST(HP)                                 \ | 389 #define HISTOGRAM_PERCENTAGE_LIST(HP)                                 \ | 
| 323   /* Heap fragmentation. */                                           \ | 390   /* Heap fragmentation. */                                           \ | 
| 324   HP(external_fragmentation_total,                                    \ | 391   HP(external_fragmentation_total,                                    \ | 
| 325      V8.MemoryExternalFragmentationTotal)                             \ | 392      V8.MemoryExternalFragmentationTotal)                             \ | 
| 326   HP(external_fragmentation_old_pointer_space,                        \ | 393   HP(external_fragmentation_old_pointer_space,                        \ | 
| 327      V8.MemoryExternalFragmentationOldPointerSpace)                   \ | 394      V8.MemoryExternalFragmentationOldPointerSpace)                   \ | 
| 328   HP(external_fragmentation_old_data_space,                           \ | 395   HP(external_fragmentation_old_data_space,                           \ | 
| 329      V8.MemoryExternalFragmentationOldDataSpace)                      \ | 396      V8.MemoryExternalFragmentationOldDataSpace)                      \ | 
| 330   HP(external_fragmentation_code_space,                               \ | 397   HP(external_fragmentation_code_space,                               \ | 
| 331      V8.MemoryExternalFragmentationCodeSpace)                         \ | 398      V8.MemoryExternalFragmentationCodeSpace)                         \ | 
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 562 #define HR(name, caption, min, max, num_buckets) \ | 629 #define HR(name, caption, min, max, num_buckets) \ | 
| 563   Histogram* name() { return &name##_; } | 630   Histogram* name() { return &name##_; } | 
| 564   HISTOGRAM_RANGE_LIST(HR) | 631   HISTOGRAM_RANGE_LIST(HR) | 
| 565 #undef HR | 632 #undef HR | 
| 566 | 633 | 
| 567 #define HT(name, caption) \ | 634 #define HT(name, caption) \ | 
| 568   HistogramTimer* name() { return &name##_; } | 635   HistogramTimer* name() { return &name##_; } | 
| 569   HISTOGRAM_TIMER_LIST(HT) | 636   HISTOGRAM_TIMER_LIST(HT) | 
| 570 #undef HT | 637 #undef HT | 
| 571 | 638 | 
|  | 639 #define AHT(name, caption) \ | 
|  | 640   AggregatableHistogramTimer* name() { return &name##_; } | 
|  | 641   AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 
|  | 642 #undef AHT | 
|  | 643 | 
| 572 #define HP(name, caption) \ | 644 #define HP(name, caption) \ | 
| 573   Histogram* name() { return &name##_; } | 645   Histogram* name() { return &name##_; } | 
| 574   HISTOGRAM_PERCENTAGE_LIST(HP) | 646   HISTOGRAM_PERCENTAGE_LIST(HP) | 
| 575 #undef HP | 647 #undef HP | 
| 576 | 648 | 
| 577 #define HM(name, caption) \ | 649 #define HM(name, caption) \ | 
| 578   Histogram* name() { return &name##_; } | 650   Histogram* name() { return &name##_; } | 
| 579   HISTOGRAM_MEMORY_LIST(HM) | 651   HISTOGRAM_MEMORY_LIST(HM) | 
| 580 #undef HM | 652 #undef HM | 
| 581 | 653 | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 612     { return &count_of_CODE_AGE_##name##_; } \ | 684     { return &count_of_CODE_AGE_##name##_; } \ | 
| 613   StatsCounter* size_of_CODE_AGE_##name() \ | 685   StatsCounter* size_of_CODE_AGE_##name() \ | 
| 614     { return &size_of_CODE_AGE_##name##_; } | 686     { return &size_of_CODE_AGE_##name##_; } | 
| 615   CODE_AGE_LIST_COMPLETE(SC) | 687   CODE_AGE_LIST_COMPLETE(SC) | 
| 616 #undef SC | 688 #undef SC | 
| 617 | 689 | 
| 618   enum Id { | 690   enum Id { | 
| 619 #define RATE_ID(name, caption) k_##name, | 691 #define RATE_ID(name, caption) k_##name, | 
| 620     HISTOGRAM_TIMER_LIST(RATE_ID) | 692     HISTOGRAM_TIMER_LIST(RATE_ID) | 
| 621 #undef RATE_ID | 693 #undef RATE_ID | 
|  | 694 #define AGGREGATABLE_ID(name, caption) k_##name, | 
|  | 695     AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) | 
|  | 696 #undef AGGREGATABLE_ID | 
| 622 #define PERCENTAGE_ID(name, caption) k_##name, | 697 #define PERCENTAGE_ID(name, caption) k_##name, | 
| 623     HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) | 698     HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) | 
| 624 #undef PERCENTAGE_ID | 699 #undef PERCENTAGE_ID | 
| 625 #define MEMORY_ID(name, caption) k_##name, | 700 #define MEMORY_ID(name, caption) k_##name, | 
| 626     HISTOGRAM_MEMORY_LIST(MEMORY_ID) | 701     HISTOGRAM_MEMORY_LIST(MEMORY_ID) | 
| 627 #undef MEMORY_ID | 702 #undef MEMORY_ID | 
| 628 #define COUNTER_ID(name, caption) k_##name, | 703 #define COUNTER_ID(name, caption) k_##name, | 
| 629     STATS_COUNTER_LIST_1(COUNTER_ID) | 704     STATS_COUNTER_LIST_1(COUNTER_ID) | 
| 630     STATS_COUNTER_LIST_2(COUNTER_ID) | 705     STATS_COUNTER_LIST_2(COUNTER_ID) | 
| 631 #undef COUNTER_ID | 706 #undef COUNTER_ID | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 653  private: | 728  private: | 
| 654 #define HR(name, caption, min, max, num_buckets) Histogram name##_; | 729 #define HR(name, caption, min, max, num_buckets) Histogram name##_; | 
| 655   HISTOGRAM_RANGE_LIST(HR) | 730   HISTOGRAM_RANGE_LIST(HR) | 
| 656 #undef HR | 731 #undef HR | 
| 657 | 732 | 
| 658 #define HT(name, caption) \ | 733 #define HT(name, caption) \ | 
| 659   HistogramTimer name##_; | 734   HistogramTimer name##_; | 
| 660   HISTOGRAM_TIMER_LIST(HT) | 735   HISTOGRAM_TIMER_LIST(HT) | 
| 661 #undef HT | 736 #undef HT | 
| 662 | 737 | 
|  | 738 #define AHT(name, caption) \ | 
|  | 739   AggregatableHistogramTimer name##_; | 
|  | 740   AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 
|  | 741 #undef AHT | 
|  | 742 | 
| 663 #define HP(name, caption) \ | 743 #define HP(name, caption) \ | 
| 664   Histogram name##_; | 744   Histogram name##_; | 
| 665   HISTOGRAM_PERCENTAGE_LIST(HP) | 745   HISTOGRAM_PERCENTAGE_LIST(HP) | 
| 666 #undef HP | 746 #undef HP | 
| 667 | 747 | 
| 668 #define HM(name, caption) \ | 748 #define HM(name, caption) \ | 
| 669   Histogram name##_; | 749   Histogram name##_; | 
| 670   HISTOGRAM_MEMORY_LIST(HM) | 750   HISTOGRAM_MEMORY_LIST(HM) | 
| 671 #undef HM | 751 #undef HM | 
| 672 | 752 | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 703   friend class Isolate; | 783   friend class Isolate; | 
| 704 | 784 | 
| 705   explicit Counters(Isolate* isolate); | 785   explicit Counters(Isolate* isolate); | 
| 706 | 786 | 
| 707   DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 787   DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 
| 708 }; | 788 }; | 
| 709 | 789 | 
| 710 } }  // namespace v8::internal | 790 } }  // namespace v8::internal | 
| 711 | 791 | 
| 712 #endif  // V8_COUNTERS_H_ | 792 #endif  // V8_COUNTERS_H_ | 
| OLD | NEW | 
|---|