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

Side by Side Diff: src/counters.h

Issue 1125683004: Add aggregated memory histograms. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add comments Created 5 years, 7 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 | « no previous file | src/counters.cc » ('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 #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"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 timer_.Start(); 351 timer_.Start();
352 } 352 }
353 ~AggregatedHistogramTimerScope() { histogram_->Add(timer_.Elapsed()); } 353 ~AggregatedHistogramTimerScope() { histogram_->Add(timer_.Elapsed()); }
354 354
355 private: 355 private:
356 base::ElapsedTimer timer_; 356 base::ElapsedTimer timer_;
357 AggregatableHistogramTimer* histogram_; 357 AggregatableHistogramTimer* histogram_;
358 }; 358 };
359 359
360 360
361 // AggretatedMemoryHistogram collects (time, value) sample pairs and turns
362 // them into time-uniform samples for the backing historgram, such that the
363 // backing histogram receives one sample every T ms, where the T is controlled
364 // by the FLAG_histogram_interval.
365 //
366 // More formally: let F be a real-valued function that maps time to sample
367 // values. We define F as a linear interpolation between adjacent samples. For
368 // each time interval [x; x + T) the backing histogram gets one sample value
369 // that is the average of F(t) in the interval.
370 template <typename Histogram>
371 class AggregatedMemoryHistogram {
372 public:
373 AggregatedMemoryHistogram()
374 : is_initialized_(false),
375 start_ms_(0.0),
376 last_ms_(0.0),
377 aggregate_value_(0.0),
378 last_value_(0.0),
379 backing_histogram_(NULL) {}
380
381 explicit AggregatedMemoryHistogram(Histogram* backing_histogram)
382 : AggregatedMemoryHistogram() {
383 backing_histogram_ = backing_histogram;
384 }
385
386 // Invariants that hold before and after AddSample if
387 // is_initialized_ is true:
388 //
389 // 1) For we processed samples that came in before start_ms_ and sent the
390 // corresponding aggregated samples to backing histogram.
391 // 2) (last_ms_, last_value_) is the last received sample.
392 // 3) last_ms_ < start_ms_ + FLAG_histogram_interval.
393 // 4) aggregate_value_ is the average of the function that is constructed by
394 // linearly interpolating samples received between start_ms_ and last_ms_.
395 void AddSample(double current_ms, double current_value);
396
397 private:
398 double Aggregate(double current_ms, double current_value);
399 bool is_initialized_;
400 double start_ms_;
401 double last_ms_;
402 double aggregate_value_;
403 double last_value_;
404 Histogram* backing_histogram_;
405 };
406
407
408 template <typename Histogram>
409 void AggregatedMemoryHistogram<Histogram>::AddSample(double current_ms,
410 double current_value) {
411 if (!is_initialized_) {
412 aggregate_value_ = current_value;
413 start_ms_ = current_ms;
414 last_value_ = current_value;
415 last_ms_ = current_ms;
416 is_initialized_ = true;
417 } else {
418 const double kEpsilon = 1e-6;
419 const int kMaxSamples = 1000;
420 if (current_ms < last_ms_ + kEpsilon) {
421 // Two samples have the same time, remember the last one.
422 last_value_ = current_value;
423 } else {
424 double sample_interval_ms = FLAG_histogram_interval;
425 double end_ms = start_ms_ + sample_interval_ms;
426 if (end_ms <= current_ms + kEpsilon) {
427 // Linearly interpolate between the last_ms_ and the current_ms.
428 double slope = (current_value - last_value_) / (current_ms - last_ms_);
429 int i;
430 // Send aggregated samples to the backing histogram from the start_ms
431 // to the current_ms.
432 for (i = 0; i < kMaxSamples && end_ms <= current_ms + kEpsilon; i++) {
433 double end_value = last_value_ + (end_ms - last_ms_) * slope;
434 double sample_value;
435 if (i == 0) {
436 // Take aggregate_value_ into account.
437 sample_value = Aggregate(end_ms, end_value);
438 } else {
439 // There is no aggregate_value_ for i > 0.
440 sample_value = (last_value_ + end_value) / 2;
441 }
442 backing_histogram_->AddSample(static_cast<int>(sample_value + 0.5));
443 last_value_ = end_value;
444 last_ms_ = end_ms;
445 end_ms += sample_interval_ms;
446 }
447 if (i == kMaxSamples) {
448 // We hit the sample limit, ignore the remaining samples.
449 aggregate_value_ = current_value;
450 start_ms_ = current_ms;
451 } else {
452 aggregate_value_ = last_value_;
453 start_ms_ = last_ms_;
454 }
455 }
456 aggregate_value_ = current_ms > start_ms_ + kEpsilon
457 ? Aggregate(current_ms, current_value)
458 : aggregate_value_;
459 last_value_ = current_value;
460 last_ms_ = current_ms;
461 }
462 }
463 }
464
465
466 template <typename Histogram>
467 double AggregatedMemoryHistogram<Histogram>::Aggregate(double current_ms,
468 double current_value) {
469 double interval_ms = current_ms - start_ms_;
470 double value = (current_value + last_value_) / 2;
471 // The aggregate_value_ is the average for [start_ms_; last_ms_].
472 // The value is the average for [last_ms_; current_ms].
473 // Return the weighted average of the aggregate_value_ and the value.
474 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) +
475 value * ((current_ms - last_ms_) / interval_ms);
476 }
477
478
361 #define HISTOGRAM_RANGE_LIST(HR) \ 479 #define HISTOGRAM_RANGE_LIST(HR) \
362 /* Generic range histograms */ \ 480 /* Generic range histograms */ \
363 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ 481 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \
364 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ 482 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \
365 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ 483 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \
366 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ 484 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \
367 101) \ 485 101) \
368 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) 486 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6)
369 487
370 #define HISTOGRAM_TIMER_LIST(HT) \ 488 #define HISTOGRAM_TIMER_LIST(HT) \
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 /* Percentages of heap committed to each space. */ \ 525 /* Percentages of heap committed to each space. */ \
408 HP(heap_fraction_new_space, V8.MemoryHeapFractionNewSpace) \ 526 HP(heap_fraction_new_space, V8.MemoryHeapFractionNewSpace) \
409 HP(heap_fraction_old_space, V8.MemoryHeapFractionOldSpace) \ 527 HP(heap_fraction_old_space, V8.MemoryHeapFractionOldSpace) \
410 HP(heap_fraction_code_space, V8.MemoryHeapFractionCodeSpace) \ 528 HP(heap_fraction_code_space, V8.MemoryHeapFractionCodeSpace) \
411 HP(heap_fraction_map_space, V8.MemoryHeapFractionMapSpace) \ 529 HP(heap_fraction_map_space, V8.MemoryHeapFractionMapSpace) \
412 HP(heap_fraction_lo_space, V8.MemoryHeapFractionLoSpace) \ 530 HP(heap_fraction_lo_space, V8.MemoryHeapFractionLoSpace) \
413 /* Percentage of crankshafted codegen. */ \ 531 /* Percentage of crankshafted codegen. */ \
414 HP(codegen_fraction_crankshaft, V8.CodegenFractionCrankshaft) 532 HP(codegen_fraction_crankshaft, V8.CodegenFractionCrankshaft)
415 533
416 534
417 #define HISTOGRAM_MEMORY_LIST(HM) \ 535 #define HISTOGRAM_LEGACY_MEMORY_LIST(HM) \
418 HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted) \ 536 HM(heap_sample_total_committed, V8.MemoryHeapSampleTotalCommitted) \
419 HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed) \ 537 HM(heap_sample_total_used, V8.MemoryHeapSampleTotalUsed) \
420 HM(heap_sample_map_space_committed, \ 538 HM(heap_sample_map_space_committed, V8.MemoryHeapSampleMapSpaceCommitted) \
421 V8.MemoryHeapSampleMapSpaceCommitted) \ 539 HM(heap_sample_code_space_committed, V8.MemoryHeapSampleCodeSpaceCommitted) \
422 HM(heap_sample_code_space_committed, \ 540 HM(heap_sample_maximum_committed, V8.MemoryHeapSampleMaximumCommitted)
Alexei Svitkine (slow) 2016/06/28 16:54:39 Hi, this histogram doesn't appear to be in histogr
423 V8.MemoryHeapSampleCodeSpaceCommitted) \ 541
424 HM(heap_sample_maximum_committed, \ 542 #define HISTOGRAM_MEMORY_LIST(HM) \
425 V8.MemoryHeapSampleMaximumCommitted) \ 543 HM(memory_heap_committed, V8.MemoryHeapCommitted) \
544 HM(memory_heap_used, V8.MemoryHeapUsed)
426 545
427 546
428 // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC 547 // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC
429 // Intellisense to crash. It was broken into two macros (each of length 40 548 // Intellisense to crash. It was broken into two macros (each of length 40
430 // lines) rather than one macro (of length about 80 lines) to work around 549 // lines) rather than one macro (of length about 80 lines) to work around
431 // this problem. Please avoid using recursive macros of this length when 550 // this problem. Please avoid using recursive macros of this length when
432 // possible. 551 // possible.
433 #define STATS_COUNTER_LIST_1(SC) \ 552 #define STATS_COUNTER_LIST_1(SC) \
434 /* Global Handle Count*/ \ 553 /* Global Handle Count*/ \
435 SC(global_handles, V8.GlobalHandles) \ 554 SC(global_handles, V8.GlobalHandles) \
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) 732 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
614 #undef AHT 733 #undef AHT
615 734
616 #define HP(name, caption) \ 735 #define HP(name, caption) \
617 Histogram* name() { return &name##_; } 736 Histogram* name() { return &name##_; }
618 HISTOGRAM_PERCENTAGE_LIST(HP) 737 HISTOGRAM_PERCENTAGE_LIST(HP)
619 #undef HP 738 #undef HP
620 739
621 #define HM(name, caption) \ 740 #define HM(name, caption) \
622 Histogram* name() { return &name##_; } 741 Histogram* name() { return &name##_; }
742 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
623 HISTOGRAM_MEMORY_LIST(HM) 743 HISTOGRAM_MEMORY_LIST(HM)
624 #undef HM 744 #undef HM
625 745
746 #define HM(name, caption) \
747 AggregatedMemoryHistogram<Histogram>* aggregated_##name() { \
748 return &aggregated_##name##_; \
749 }
750 HISTOGRAM_MEMORY_LIST(HM)
751 #undef HM
752
626 #define SC(name, caption) \ 753 #define SC(name, caption) \
627 StatsCounter* name() { return &name##_; } 754 StatsCounter* name() { return &name##_; }
628 STATS_COUNTER_LIST_1(SC) 755 STATS_COUNTER_LIST_1(SC)
629 STATS_COUNTER_LIST_2(SC) 756 STATS_COUNTER_LIST_2(SC)
630 #undef SC 757 #undef SC
631 758
632 #define SC(name) \ 759 #define SC(name) \
633 StatsCounter* count_of_##name() { return &count_of_##name##_; } \ 760 StatsCounter* count_of_##name() { return &count_of_##name##_; } \
634 StatsCounter* size_of_##name() { return &size_of_##name##_; } 761 StatsCounter* size_of_##name() { return &size_of_##name##_; }
635 INSTANCE_TYPE_LIST(SC) 762 INSTANCE_TYPE_LIST(SC)
(...skipping 27 matching lines...) Expand all
663 #define RATE_ID(name, caption, max, res) k_##name, 790 #define RATE_ID(name, caption, max, res) k_##name,
664 HISTOGRAM_TIMER_LIST(RATE_ID) 791 HISTOGRAM_TIMER_LIST(RATE_ID)
665 #undef RATE_ID 792 #undef RATE_ID
666 #define AGGREGATABLE_ID(name, caption) k_##name, 793 #define AGGREGATABLE_ID(name, caption) k_##name,
667 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) 794 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID)
668 #undef AGGREGATABLE_ID 795 #undef AGGREGATABLE_ID
669 #define PERCENTAGE_ID(name, caption) k_##name, 796 #define PERCENTAGE_ID(name, caption) k_##name,
670 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) 797 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID)
671 #undef PERCENTAGE_ID 798 #undef PERCENTAGE_ID
672 #define MEMORY_ID(name, caption) k_##name, 799 #define MEMORY_ID(name, caption) k_##name,
800 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID)
673 HISTOGRAM_MEMORY_LIST(MEMORY_ID) 801 HISTOGRAM_MEMORY_LIST(MEMORY_ID)
674 #undef MEMORY_ID 802 #undef MEMORY_ID
675 #define COUNTER_ID(name, caption) k_##name, 803 #define COUNTER_ID(name, caption) k_##name,
676 STATS_COUNTER_LIST_1(COUNTER_ID) 804 STATS_COUNTER_LIST_1(COUNTER_ID)
677 STATS_COUNTER_LIST_2(COUNTER_ID) 805 STATS_COUNTER_LIST_2(COUNTER_ID)
678 #undef COUNTER_ID 806 #undef COUNTER_ID
679 #define COUNTER_ID(name) kCountOf##name, kSizeOf##name, 807 #define COUNTER_ID(name) kCountOf##name, kSizeOf##name,
680 INSTANCE_TYPE_LIST(COUNTER_ID) 808 INSTANCE_TYPE_LIST(COUNTER_ID)
681 #undef COUNTER_ID 809 #undef COUNTER_ID
682 #define COUNTER_ID(name) kCountOfCODE_TYPE_##name, \ 810 #define COUNTER_ID(name) kCountOfCODE_TYPE_##name, \
(...skipping 28 matching lines...) Expand all
711 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) 839 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
712 #undef AHT 840 #undef AHT
713 841
714 #define HP(name, caption) \ 842 #define HP(name, caption) \
715 Histogram name##_; 843 Histogram name##_;
716 HISTOGRAM_PERCENTAGE_LIST(HP) 844 HISTOGRAM_PERCENTAGE_LIST(HP)
717 #undef HP 845 #undef HP
718 846
719 #define HM(name, caption) \ 847 #define HM(name, caption) \
720 Histogram name##_; 848 Histogram name##_;
849 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
721 HISTOGRAM_MEMORY_LIST(HM) 850 HISTOGRAM_MEMORY_LIST(HM)
722 #undef HM 851 #undef HM
723 852
853 #define HM(name, caption) \
854 AggregatedMemoryHistogram<Histogram> aggregated_##name##_;
855 HISTOGRAM_MEMORY_LIST(HM)
856 #undef HM
857
724 #define SC(name, caption) \ 858 #define SC(name, caption) \
725 StatsCounter name##_; 859 StatsCounter name##_;
726 STATS_COUNTER_LIST_1(SC) 860 STATS_COUNTER_LIST_1(SC)
727 STATS_COUNTER_LIST_2(SC) 861 STATS_COUNTER_LIST_2(SC)
728 #undef SC 862 #undef SC
729 863
730 #define SC(name) \ 864 #define SC(name) \
731 StatsCounter size_of_##name##_; \ 865 StatsCounter size_of_##name##_; \
732 StatsCounter count_of_##name##_; 866 StatsCounter count_of_##name##_;
733 INSTANCE_TYPE_LIST(SC) 867 INSTANCE_TYPE_LIST(SC)
(...skipping 20 matching lines...) Expand all
754 friend class Isolate; 888 friend class Isolate;
755 889
756 explicit Counters(Isolate* isolate); 890 explicit Counters(Isolate* isolate);
757 891
758 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); 892 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
759 }; 893 };
760 894
761 } } // namespace v8::internal 895 } } // namespace v8::internal
762 896
763 #endif // V8_COUNTERS_H_ 897 #endif // V8_COUNTERS_H_
OLDNEW
« no previous file with comments | « no previous file | src/counters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698