Revision: 12081
Author:   [email protected]
Date:     Fri Jul 13 05:12:09 2012
Log: Factor out a Histogram class from HistogramTimer, and use it to measure external fragmentation

BUG=none
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10695056
Patch from Jochen Eisinger <[email protected]>.
http://code.google.com/p/v8/source/detail?r=12081

Modified:
 /branches/bleeding_edge/src/counters.cc
 /branches/bleeding_edge/src/counters.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/v8-counters.cc
 /branches/bleeding_edge/src/v8-counters.h

=======================================
--- /branches/bleeding_edge/src/counters.cc     Fri Mar 18 13:35:07 2011
+++ /branches/bleeding_edge/src/counters.cc     Fri Jul 13 05:12:09 2012
@@ -1,4 +1,4 @@
-// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -63,10 +63,21 @@
   int milliseconds = static_cast<int>(stop_time_ - start_time_) / 1000;
   counter_.Increment(milliseconds);
 }
+
+void Histogram::AddSample(int sample) {
+  if (Enabled()) {
+ Isolate::Current()->stats_table()->AddHistogramSample(histogram_, sample);
+  }
+}
+
+void* Histogram::CreateHistogram() const {
+  return Isolate::Current()->stats_table()->
+      CreateHistogram(name_, min_, max_, num_buckets_);
+}

 // Start the timer.
 void HistogramTimer::Start() {
-  if (GetHistogram() != NULL) {
+  if (histogram_.Enabled()) {
     stop_time_ = 0;
     start_time_ = OS::Ticks();
   }
@@ -74,20 +85,13 @@

 // Stop the timer and record the results.
 void HistogramTimer::Stop() {
-  if (histogram_ != NULL) {
+  if (histogram_.Enabled()) {
     stop_time_ = OS::Ticks();

     // Compute the delta between start and stop, in milliseconds.
     int milliseconds = static_cast<int>(stop_time_ - start_time_) / 1000;
-    Isolate::Current()->stats_table()->
-        AddHistogramSample(histogram_, milliseconds);
+    histogram_.AddSample(milliseconds);
   }
 }
-
-
-void* HistogramTimer::CreateHistogram() const {
-  return Isolate::Current()->stats_table()->
-      CreateHistogram(name_, 0, 10000, 50);
-}

 } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/counters.h      Fri Mar 18 13:35:07 2011
+++ /branches/bleeding_edge/src/counters.h      Fri Jul 13 05:12:09 2012
@@ -1,4 +1,4 @@
-// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -169,8 +169,7 @@
  protected:
   // Returns the cached address of this counter location.
   int* GetPtr() {
-    if (lookup_done_)
-      return ptr_;
+    if (lookup_done_) return ptr_;
     lookup_done_ = true;
     ptr_ = FindLocationInStatsTable();
     return ptr_;
@@ -199,25 +198,25 @@
   }
 };

-// A HistogramTimer allows distributions of results to be created
-// HistogramTimer t = { L"foo", NULL, false, 0, 0 };
-struct HistogramTimer {
+// A Histogram represents a dynamically created histogram in the StatsTable.
+//
+// This class is designed to be POD initialized. It will be registered with
+// the histogram system on first use.  For example:
+//   Histogram h = { "myhist", 0, 10000, 50, NULL, false };
+struct Histogram {
   const char* name_;
+  int min_;
+  int max_;
+  int num_buckets_;
   void* histogram_;
   bool lookup_done_;

-  int64_t start_time_;
-  int64_t stop_time_;
-
-  // Start the timer.
-  void Start();
-
-  // Stop the timer and record the results.
-  void Stop();
-
-  // Returns true if the timer is running.
-  bool Running() {
-    return (histogram_ != NULL) && (start_time_ != 0) && (stop_time_ == 0);
+  // Add a single sample to this histogram.
+  void AddSample(int sample);
+
+  // Returns true if this histogram is enabled.
+  bool Enabled() {
+    return GetHistogram() != NULL;
   }

  protected:
@@ -234,6 +233,26 @@
   void* CreateHistogram() const;
 };

+// A HistogramTimer allows distributions of results to be created
+// HistogramTimer t = { {L"foo", 0, 10000, 50, NULL, false}, 0, 0 };
+struct HistogramTimer {
+  Histogram histogram_;
+
+  int64_t start_time_;
+  int64_t stop_time_;
+
+  // Start the timer.
+  void Start();
+
+  // Stop the timer and record the results.
+  void Stop();
+
+  // Returns true if the timer is running.
+  bool Running() {
+    return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0);
+  }
+};
+
 // Helper class for scoping a HistogramTimer.
 class HistogramTimerScope BASE_EMBEDDED {
  public:
=======================================
--- /branches/bleeding_edge/src/heap.cc Wed Jul 11 07:29:16 2012
+++ /branches/bleeding_edge/src/heap.cc Fri Jul 13 05:12:09 2012
@@ -445,54 +445,26 @@
   isolate_->counters()->number_of_symbols()->Set(
       symbol_table()->NumberOfElements());

-  isolate_->counters()->new_space_bytes_available()->Set(
-      static_cast<int>(new_space()->Available()));
-  isolate_->counters()->new_space_bytes_committed()->Set(
-      static_cast<int>(new_space()->CommittedMemory()));
-  isolate_->counters()->new_space_bytes_used()->Set(
-      static_cast<int>(new_space()->SizeOfObjects()));
-
-  isolate_->counters()->old_pointer_space_bytes_available()->Set(
-      static_cast<int>(old_pointer_space()->Available()));
-  isolate_->counters()->old_pointer_space_bytes_committed()->Set(
-      static_cast<int>(old_pointer_space()->CommittedMemory()));
-  isolate_->counters()->old_pointer_space_bytes_used()->Set(
-      static_cast<int>(old_pointer_space()->SizeOfObjects()));
-
-  isolate_->counters()->old_data_space_bytes_available()->Set(
-      static_cast<int>(old_data_space()->Available()));
-  isolate_->counters()->old_data_space_bytes_committed()->Set(
-      static_cast<int>(old_data_space()->CommittedMemory()));
-  isolate_->counters()->old_data_space_bytes_used()->Set(
-      static_cast<int>(old_data_space()->SizeOfObjects()));
-
-  isolate_->counters()->code_space_bytes_available()->Set(
-      static_cast<int>(code_space()->Available()));
-  isolate_->counters()->code_space_bytes_committed()->Set(
-      static_cast<int>(code_space()->CommittedMemory()));
-  isolate_->counters()->code_space_bytes_used()->Set(
-      static_cast<int>(code_space()->SizeOfObjects()));
-
-  isolate_->counters()->map_space_bytes_available()->Set(
-      static_cast<int>(map_space()->Available()));
-  isolate_->counters()->map_space_bytes_committed()->Set(
-      static_cast<int>(map_space()->CommittedMemory()));
-  isolate_->counters()->map_space_bytes_used()->Set(
-      static_cast<int>(map_space()->SizeOfObjects()));
-
-  isolate_->counters()->cell_space_bytes_available()->Set(
-      static_cast<int>(cell_space()->Available()));
-  isolate_->counters()->cell_space_bytes_committed()->Set(
-      static_cast<int>(cell_space()->CommittedMemory()));
-  isolate_->counters()->cell_space_bytes_used()->Set(
-      static_cast<int>(cell_space()->SizeOfObjects()));
-
-  isolate_->counters()->lo_space_bytes_available()->Set(
-      static_cast<int>(lo_space()->Available()));
-  isolate_->counters()->lo_space_bytes_committed()->Set(
-      static_cast<int>(lo_space()->CommittedMemory()));
-  isolate_->counters()->lo_space_bytes_used()->Set(
-      static_cast<int>(lo_space()->SizeOfObjects()));
+#define UPDATE_COUNTERS_FOR_SPACE(space) \ + isolate_->counters()->space##_bytes_available()->Set( \ + static_cast<int>(space()->Available())); \ + isolate_->counters()->space##_bytes_committed()->Set( \ + static_cast<int>(space()->CommittedMemory())); \ + isolate_->counters()->space##_bytes_used()->Set( \ + static_cast<int>(space()->SizeOfObjects())); \ + if (space()->CommittedMemory() > 0) { \ + isolate_->counters()->external_fragmentation_##space()->AddSample( \ + static_cast<int>( \ + (space()->SizeOfObjects() * 100) / space()->CommittedMemory())); \
+  }
+  UPDATE_COUNTERS_FOR_SPACE(new_space)
+  UPDATE_COUNTERS_FOR_SPACE(old_pointer_space)
+  UPDATE_COUNTERS_FOR_SPACE(old_data_space)
+  UPDATE_COUNTERS_FOR_SPACE(code_space)
+  UPDATE_COUNTERS_FOR_SPACE(map_space)
+  UPDATE_COUNTERS_FOR_SPACE(cell_space)
+  UPDATE_COUNTERS_FOR_SPACE(lo_space)
+#undef UPDATE_COUNTERS_FOR_SPACE

 #if defined(DEBUG)
   ReportStatisticsAfterGC();
=======================================
--- /branches/bleeding_edge/src/v8-counters.cc  Fri Mar 18 13:35:07 2011
+++ /branches/bleeding_edge/src/v8-counters.cc  Fri Jul 13 05:12:09 2012
@@ -1,4 +1,4 @@
-// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -34,11 +34,17 @@

 Counters::Counters() {
 #define HT(name, caption) \
-    HistogramTimer name = { #caption, NULL, false, 0, 0 }; \
+ HistogramTimer name = { {#caption, 0, 10000, 50, NULL, false}, 0, 0 }; \
     name##_ = name;
     HISTOGRAM_TIMER_LIST(HT)
 #undef HT

+#define HP(name, caption) \
+    Histogram name = { #caption, 0, 101, 100, NULL, false }; \
+    name##_ = name;
+    HISTOGRAM_PERCENTAGE_LIST(HP)
+#undef HP
+
 #define SC(name, caption) \
     StatsCounter name = { "c:" #caption, NULL, false };\
     name##_ = name;
=======================================
--- /branches/bleeding_edge/src/v8-counters.h   Tue Jun 26 04:46:16 2012
+++ /branches/bleeding_edge/src/v8-counters.h   Fri Jul 13 05:12:09 2012
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -50,6 +50,23 @@
   HT(compile_lazy, V8.CompileLazy)


+#define HISTOGRAM_PERCENTAGE_LIST(HP)                                 \
+  HP(external_fragmentation_new_space,                                \
+     V8.MemoryExternalFragmentationNewSpace)                          \
+  HP(external_fragmentation_old_pointer_space,                        \
+     V8.MemoryExternalFragmentationOldPointerSpace)                   \
+  HP(external_fragmentation_old_data_space,                           \
+     V8.MemoryExternalFragmentationOldDataSpace)                      \
+  HP(external_fragmentation_code_space,                               \
+     V8.MemoryExternalFragmentationCodeSpace)                         \
+  HP(external_fragmentation_map_space,                                \
+     V8.MemoryExternalFragmentationMapSpace)                          \
+  HP(external_fragmentation_cell_space,                               \
+     V8.MemoryExternalFragmentationCellSpace)                         \
+  HP(external_fragmentation_lo_space,                                 \
+     V8.MemoryExternalFragmentationLoSpace)
+
+
 // WARNING: STATS_COUNTER_LIST_* is a very large macro that is causing MSVC
 // Intellisense to crash.  It was broken into two macros (each of length 40
 // lines) rather than one macro (of length about 80 lines) to work around
@@ -280,6 +297,11 @@
   HISTOGRAM_TIMER_LIST(HT)
 #undef HT

+#define HP(name, caption) \
+  Histogram* name() { return &name##_; }
+  HISTOGRAM_PERCENTAGE_LIST(HP)
+#undef HP
+
 #define SC(name, caption) \
   StatsCounter* name() { return &name##_; }
   STATS_COUNTER_LIST_1(SC)
@@ -290,6 +312,9 @@
 #define RATE_ID(name, caption) k_##name,
     HISTOGRAM_TIMER_LIST(RATE_ID)
 #undef RATE_ID
+#define PERCENTAGE_ID(name, caption) k_##name,
+    HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID)
+#undef PERCENTAGE_ID
 #define COUNTER_ID(name, caption) k_##name,
     STATS_COUNTER_LIST_1(COUNTER_ID)
     STATS_COUNTER_LIST_2(COUNTER_ID)
@@ -310,6 +335,11 @@
   HISTOGRAM_TIMER_LIST(HT)
 #undef HT

+#define HP(name, caption) \
+  Histogram name##_;
+  HISTOGRAM_PERCENTAGE_LIST(HP)
+#undef HP
+
 #define SC(name, caption) \
   StatsCounter name##_;
   STATS_COUNTER_LIST_1(SC)

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to