Author: [email protected]
Date: Mon Apr 13 17:30:44 2009
New Revision: 1695

Modified:
    branches/bleeding_edge/src/d8.cc
    branches/bleeding_edge/src/d8.h

Log:
Reenable d8 stats timers, using the histogram mechanism

Review URL: http://codereview.chromium.org/67100

Modified: branches/bleeding_edge/src/d8.cc
==============================================================================
--- branches/bleeding_edge/src/d8.cc    (original)
+++ branches/bleeding_edge/src/d8.cc    Mon Apr 13 17:30:44 2009
@@ -268,12 +268,19 @@
  }


-int32_t* Counter::Bind(const char* name) {
+int32_t* Counter::Bind(const char* name, bool is_histogram) {
    int i;
    for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
      name_[i] = static_cast<char>(name[i]);
    name_[i] = '\0';
-  return &counter_;
+  is_histogram_ = is_histogram;
+  return ptr();
+}
+
+
+void Counter::AddSample(int32_t sample) {
+  count_++;
+  sample_total_ += sample;
  }


@@ -302,6 +309,8 @@
    }
    counters_ = static_cast<CounterCollection*>(memory);
    V8::SetCounterFunction(LookupCounter);
+  V8::SetCreateHistogramFunction(CreateHistogram);
+  V8::SetAddHistogramSampleFunction(AddHistogramSample);
  }


@@ -316,15 +325,44 @@
  }


-int* Shell::LookupCounter(const char* name) {
+Counter* Shell::GetCounter(const char* name, bool is_histogram) {
    Counter* counter = counter_map_->Lookup(name);
+
+  if (counter == NULL) {
+    counter = counters_->GetNextCounter();
+    if (counter != NULL) {
+      counter_map_->Set(name, counter);
+      counter->Bind(name, is_histogram);
+    }
+  } else {
+    ASSERT(counter->is_histogram() == is_histogram);
+  }
+  return counter;
+}
+
+
+int* Shell::LookupCounter(const char* name) {
+  Counter* counter = GetCounter(name, false);
+
    if (counter != NULL) {
      return counter->ptr();
+  } else {
+    return NULL;
    }
-  Counter* result = counters_->GetNextCounter();
-  if (result == NULL) return NULL;
-  counter_map_->Set(name, result);
-  return result->Bind(name);
+}
+
+
+void* Shell::CreateHistogram(const char* name,
+                             int min,
+                             int max,
+                             size_t buckets) {
+  return GetCounter(name, true);
+}
+
+
+void Shell::AddHistogramSample(void* histogram, int sample) {
+  Counter* counter = reinterpret_cast<Counter*>(histogram);
+  counter->AddSample(sample);
  }


@@ -333,8 +371,12 @@
    // Set up counters
    if (i::FLAG_map_counters != NULL)
      MapCounters(i::FLAG_map_counters);
-  if (i::FLAG_dump_counters)
+  if (i::FLAG_dump_counters) {
      V8::SetCounterFunction(LookupCounter);
+    V8::SetCreateHistogramFunction(CreateHistogram);
+    V8::SetAddHistogramSampleFunction(AddHistogramSample);
+  }
+
    // Initialize the global objects
    HandleScope scope;
    Handle<ObjectTemplate> global_template = ObjectTemplate::New();
@@ -406,7 +448,14 @@
      ::printf("+----------------------------------------+-------------+\n");
      for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
        Counter* counter = i.CurrentValue();
-      ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->value());
+      if (counter->is_histogram()) {
+        ::printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
+        ::printf("| t:%-36s | %11i |\n",
+                 i.CurrentKey(),
+                 counter->sample_total());
+      } else {
+        ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
+      }
      }
      ::printf("+----------------------------------------+-------------+\n");
    }

Modified: branches/bleeding_edge/src/d8.h
==============================================================================
--- branches/bleeding_edge/src/d8.h     (original)
+++ branches/bleeding_edge/src/d8.h     Mon Apr 13 17:30:44 2009
@@ -42,11 +42,16 @@
  class Counter {
   public:
    static const int kMaxNameSize = 64;
-  int32_t* Bind(const char* name);
-  int32_t* ptr() { return &counter_; }
-  int32_t value() { return counter_; }
+  int32_t* Bind(const char* name, bool histogram);
+  int32_t* ptr() { return &count_; }
+  int32_t count() { return count_; }
+  int32_t sample_total() { return sample_total_; }
+  bool is_histogram() { return is_histogram_; }
+  void AddSample(int32_t sample);
   private:
-  int32_t counter_;
+  int32_t count_;
+  int32_t sample_total_;
+  bool is_histogram_;
    uint8_t name_[kMaxNameSize];
  };

@@ -116,6 +121,11 @@
    static void Initialize();
    static void OnExit();
    static int* LookupCounter(const char* name);
+  static void* CreateHistogram(const char* name,
+                               int min,
+                               int max,
+                               size_t buckets);
+  static void AddHistogramSample(void* histogram, int sample);
    static void MapCounters(const char* name);
    static Handle<String> ReadFile(const char* name);
    static void RunShell();
@@ -179,6 +189,7 @@
    static CounterCollection local_counters_;
    static CounterCollection* counters_;
    static i::OS::MemoryMappedFile* counters_file_;
+  static Counter* GetCounter(const char* name, bool is_histogram);
  };



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

Reply via email to