* external string resource.
*/
static Local<String> NewExternal(ExternalStringResource* resource);
-
+
/**
* Associate an external string resource with this string by transforming it
* in place so that existing references to this string in the JavaScript heap
* external string resource.
*/
static Local<String> NewExternal(ExternalAsciiStringResource* resource);
-
+
/**
* Associate an external string resource with this string by transforming it
* in place so that existing references to this string in the JavaScript heap
typedef int* (*CounterLookupCallback)(const char* name);
+typedef void* (*CreateHistogramCallback)(const char* name,
+ int min,
+ int max,
+ size_t buckets);
+
+typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
+
// --- F a i l e d A c c e s s C h e c k C a l l b a c k ---
typedef void (*FailedAccessCheckCallback)(Local<Object> target,
AccessType type,
*/
static void SetCounterFunction(CounterLookupCallback);
+ /**
+ * Enables the host application to provide a mechanism for recording
+ * histograms. The CreateHistogram function returns a
+ * histogram which will later be passed to the AddHistogramSample
+ * function.
+ */
+ static void SetCreateHistogramFunction(CreateHistogramCallback);
+ static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
+
/**
* Enables the computation of a sliding window of states. The sliding
* window information is recorded in statistics counters.
i::StatsTable::SetCounterFunction(callback);
}
+void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) {
+ if (IsDeadCheck("v8::V8::SetCreateHistogramFunction()")) return;
+ i::StatsTable::SetCreateHistogramFunction(callback);
+}
+
+void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) {
+ if (IsDeadCheck("v8::V8::SetAddHistogramSampleFunction()")) return;
+ i::StatsTable::SetAddHistogramSampleFunction(callback);
+}
void V8::EnableSlidingStateWindow() {
if (IsDeadCheck("v8::V8::EnableSlidingStateWindow()")) return;
// Measure how long it takes to do the compilation; only take the
// rest of the function into account to avoid overlap with the
// parsing statistics.
- StatsRate* rate = is_eval
+ HistogramTimer* rate = is_eval
? &Counters::compile_eval
: &Counters::compile;
- StatsRateScope timer(rate);
+ HistogramTimerScope timer(rate);
// Compile the code.
Handle<Code> code = MakeCode(lit, script, context, is_eval);
// Measure how long it takes to do the lazy compilation; only take
// the rest of the function into account to avoid overlap with the
// lazy parsing statistics.
- StatsRateScope timer(&Counters::compile_lazy);
+ HistogramTimerScope timer(&Counters::compile_lazy);
// Compile the code.
Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false);
namespace v8 { namespace internal {
CounterLookupCallback StatsTable::lookup_function_ = NULL;
+CreateHistogramCallback StatsTable::create_histogram_function_ = NULL;
+AddHistogramSampleCallback StatsTable::add_histogram_sample_function_ = NULL;
// Start the timer.
void StatsCounterTimer::Start() {
counter_.Increment(milliseconds);
}
+// Start the timer.
+void HistogramTimer::Start() {
+ if (GetHistogram() != NULL) {
+ stop_time_ = 0;
+ start_time_ = OS::Ticks();
+ }
+}
+
+// Stop the timer and record the results.
+void HistogramTimer::Stop() {
+ if (histogram_ != NULL) {
+ stop_time_ = OS::Ticks();
+
+ // Compute the delta between start and stop, in milliseconds.
+ int milliseconds = static_cast<int>(stop_time_ - start_time_) / 1000;
+ StatsTable::AddHistogramSample(histogram_, milliseconds);
+ }
+}
+
} } // namespace v8::internal
lookup_function_ = f;
}
+ // Register an application-defined function to create
+ // a histogram for passing to the AddHistogramSample function
+ static void SetCreateHistogramFunction(CreateHistogramCallback f) {
+ create_histogram_function_ = f;
+ }
+
+ // Register an application-defined function to add a sample
+ // to a histogram created with CreateHistogram function
+ static void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
+ add_histogram_sample_function_ = f;
+ }
+
static bool HasCounterFunction() {
return lookup_function_ != NULL;
}
return lookup_function_(name);
}
+ // Create a histogram by name. If the create is successful,
+ // returns a non-NULL pointer for use with AddHistogramSample
+ // function. min and max define the expected minimum and maximum
+ // sample values. buckets is the maximum number of buckets
+ // that the samples will be grouped into.
+ static void *CreateHistogram(const char* name,
+ int min,
+ int max,
+ size_t buckets) {
+ if (!create_histogram_function_) return NULL;
+ return create_histogram_function_(name, min, max, buckets);
+ }
+
+ // Add a sample to a histogram created with the CreateHistogram
+ // function.
+ static void AddHistogramSample(void* histogram, int sample) {
+ if (!add_histogram_sample_function_) return;
+ return add_histogram_sample_function_(histogram, sample);
+ }
+
private:
static CounterLookupCallback lookup_function_;
+ static CreateHistogramCallback create_histogram_function_;
+ static AddHistogramSampleCallback add_histogram_sample_function_;
};
// StatsCounters are dynamically created values which can be tracked in
}
};
-// A StatsRate is a combination of both a timer and a counter so that
-// several statistics can be produced:
-// min, max, avg, count, total
-//
-// For example:
-// StatsCounter c = { { { L"t:myrate", NULL, false }, 0, 0 },
-// { L"c:myrate", NULL, false } };
-struct StatsRate {
- StatsCounterTimer timer_;
- StatsCounter counter_;
+// A HistogramTimer allows distributions of results to be created
+// HistogramTimer t = { L"foo", NULL, false, 0, 0 };
+struct HistogramTimer {
+ const char* name_;
+ void* histogram_;
+ bool lookup_done_;
- // Starts the rate timer.
- void Start() {
- timer_.Start();
+ 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);
}
- // Stops the rate and records the time.
- void Stop() {
- if (timer_.Running()) {
- timer_.Stop();
- counter_.Increment();
+ protected:
+ // Returns the handle to the histogram.
+ void* GetHistogram() {
+ if (!lookup_done_) {
+ lookup_done_ = true;
+ histogram_ = StatsTable::CreateHistogram(name_, 0, 10000, 50);
}
+ return histogram_;
}
};
-
-// Helper class for scoping a rate.
-class StatsRateScope BASE_EMBEDDED {
+// Helper class for scoping a HistogramTimer.
+class HistogramTimerScope BASE_EMBEDDED {
public:
- explicit StatsRateScope(StatsRate* rate) :
- rate_(rate) {
- rate_->Start();
+ explicit HistogramTimerScope(HistogramTimer* timer) :
+ timer_(timer) {
+ timer_->Start();
}
- ~StatsRateScope() {
- rate_->Stop();
+ ~HistogramTimerScope() {
+ timer_->Stop();
}
private:
- StatsRate* rate_;
+ HistogramTimer* timer_;
};
// contexts are disposed and leave it to the embedder to make
// informed decisions about when to force a collection.
if (!FLAG_expose_gc && context_disposed_pending_) {
- StatsRateScope scope(&Counters::gc_context);
+ HistogramTimerScope scope(&Counters::gc_context);
CollectAllGarbage();
}
context_disposed_pending_ = false;
// Tell the tracer which collector we've selected.
tracer.set_collector(collector);
- StatsRate* rate = (collector == SCAVENGER)
+ HistogramTimer* rate = (collector == SCAVENGER)
? &Counters::gc_scavenger
: &Counters::gc_compactor;
rate->Start();
bool Parser::PreParseProgram(unibrow::CharacterStream* stream) {
- StatsRateScope timer(&Counters::pre_parse);
+ HistogramTimerScope timer(&Counters::pre_parse);
StackGuard guard;
AssertNoZoneAllocation assert_no_zone_allocation;
AssertNoAllocation assert_no_allocation;
bool in_global_context) {
ZoneScope zone_scope(DONT_DELETE_ON_EXIT);
- StatsRateScope timer(&Counters::parse);
+ HistogramTimerScope timer(&Counters::parse);
StringShape shape(*source);
Counters::total_parse_size.Increment(source->length(shape));
int start_position,
bool is_expression) {
ZoneScope zone_scope(DONT_DELETE_ON_EXIT);
- StatsRateScope timer(&Counters::parse_lazy);
+ HistogramTimerScope timer(&Counters::parse_lazy);
source->TryFlattenIfNotFlat(StringShape(*source));
StringShape shape(*source);
Counters::total_parse_size.Increment(source->length(shape));
namespace v8 { namespace internal {
-#define SR(name, caption) \
- StatsRate Counters::name = { \
- { { "t:" #caption, NULL, false }, 0, 0 }, \
- { "c:" #caption, NULL, false } };
+#define HT(name, caption) \
+ HistogramTimer Counters::name = { #caption, NULL, false, 0, 0 }; \
- STATS_RATE_LIST(SR)
+ HISTOGRAM_TIMER_LIST(HT)
#undef SR
#define SC(name, caption) \
namespace v8 { namespace internal {
-#define STATS_RATE_LIST(SR) \
- SR(gc_compactor, V8.GCCompactor) /* GC Compactor time */ \
- SR(gc_scavenger, V8.GCScavenger) /* GC Scavenger time */ \
- SR(gc_context, V8.GCContext) /* GC context cleanup time */ \
- SR(compile, V8.Compile) /* Compile time*/ \
- SR(compile_eval, V8.CompileEval) /* Eval compile time */ \
- SR(compile_lazy, V8.CompileLazy) /* Lazy compile time */ \
- SR(parse, V8.Parse) /* Parse time */ \
- SR(parse_lazy, V8.ParseLazy) /* Lazy parse time */ \
- SR(pre_parse, V8.PreParse) /* Pre-parse time */
+#define HISTOGRAM_TIMER_LIST(HT) \
+ HT(gc_compactor, V8.GCCompactor) /* GC Compactor time */ \
+ HT(gc_scavenger, V8.GCScavenger) /* GC Scavenger time */ \
+ HT(gc_context, V8.GCContext) /* GC context cleanup time */ \
+ HT(compile, V8.Compile) /* Compile time*/ \
+ HT(compile_eval, V8.CompileEval) /* Eval compile time */ \
+ HT(compile_lazy, V8.CompileLazy) /* Lazy compile time */ \
+ HT(parse, V8.Parse) /* Parse time */ \
+ HT(parse_lazy, V8.ParseLazy) /* Lazy parse time */ \
+ HT(pre_parse, V8.PreParse) /* Pre-parse time */
// 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
// This file contains all the v8 counters that are in use.
class Counters : AllStatic {
public:
-#define SR(name, caption) \
- static StatsRate name;
- STATS_RATE_LIST(SR)
-#undef SR
+#define HT(name, caption) \
+ static HistogramTimer name;
+ HISTOGRAM_TIMER_LIST(HT)
+#undef HT
#define SC(name, caption) \
static StatsCounter name;
enum Id {
#define RATE_ID(name, caption) k_##name,
- STATS_RATE_LIST(RATE_ID)
+ HISTOGRAM_TIMER_LIST(RATE_ID)
#undef RATE_ID
#define COUNTER_ID(name, caption) k_##name,
STATS_COUNTER_LIST_1(COUNTER_ID)