Commit ca2b0e36 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Expose counters in javascript.

R=rossberg
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10803008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12124 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c20c99a9
......@@ -72,6 +72,7 @@ SOURCES = {
execution.cc
extensions/externalize-string-extension.cc
extensions/gc-extension.cc
extensions/statistics-extension.cc
factory.cc
fast-dtoa.cc
fixed-dtoa.cc
......
......@@ -42,6 +42,7 @@
#include "snapshot.h"
#include "extensions/externalize-string-extension.h"
#include "extensions/gc-extension.h"
#include "extensions/statistics-extension.h"
namespace v8 {
namespace internal {
......@@ -95,6 +96,7 @@ void Bootstrapper::Initialize(bool create_heap_objects) {
extensions_cache_.Initialize(create_heap_objects);
GCExtension::Register();
ExternalizeStringExtension::Register();
StatisticsExtension::Register();
}
......@@ -1997,6 +1999,9 @@ bool Genesis::InstallExtensions(Handle<Context> global_context,
if (FLAG_expose_externalize_string) {
InstallExtension("v8/externalize", &extension_states);
}
if (FLAG_track_gc_object_stats) {
InstallExtension("v8/statistics", &extension_states);
}
if (extensions == NULL) return true;
// Install required extensions
......
......@@ -1211,7 +1211,7 @@ void Shell::Initialize() {
// Set up counters
if (i::StrLength(i::FLAG_map_counters) != 0)
MapCounters(i::FLAG_map_counters);
if (i::FLAG_dump_counters) {
if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) {
V8::SetCounterFunction(LookupCounter);
V8::SetCreateHistogramFunction(CreateHistogram);
V8::SetAddHistogramSampleFunction(AddHistogramSample);
......
// Copyright 2010 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:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "statistics-extension.h"
namespace v8 {
namespace internal {
const char* const StatisticsExtension::kSource =
"native function getV8Statistics();";
v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction(
v8::Handle<v8::String> str) {
ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0);
return v8::FunctionTemplate::New(StatisticsExtension::GetCounters);
}
v8::Handle<v8::Value> StatisticsExtension::GetCounters(
const v8::Arguments& args) {
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
if (args.Length() > 0) { // GC if first argument evaluates to true.
if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
}
}
Counters* counters = isolate->counters();
v8::Local<v8::Object> result = v8::Object::New();
StatsCounter* counter = NULL;
#define ADD_COUNTER(name, caption) \
counter = counters->name(); \
if (counter->Enabled()) \
result->Set(v8::String::New(#name), \
v8::Number::New(*counter->GetInternalPointer()));
STATS_COUNTER_LIST_1(ADD_COUNTER)
STATS_COUNTER_LIST_2(ADD_COUNTER)
#undef ADD_COUNTER
#define ADD_COUNTER(name) \
counter = counters->count_of_##name(); \
if (counter->Enabled()) \
result->Set(v8::String::New("count_of_" #name), \
v8::Number::New(*counter->GetInternalPointer())); \
counter = counters->size_of_##name(); \
if (counter->Enabled()) \
result->Set(v8::String::New("size_of_" #name), \
v8::Number::New(*counter->GetInternalPointer()));
INSTANCE_TYPE_LIST(ADD_COUNTER)
#undef ADD_COUNTER
#define ADD_COUNTER(name) \
result->Set(v8::String::New("count_of_CODE_TYPE_" #name), \
v8::Number::New( \
*counters->count_of_CODE_TYPE_##name()->GetInternalPointer())); \
result->Set(v8::String::New("size_of_CODE_TYPE_" #name), \
v8::Number::New( \
*counters->size_of_CODE_TYPE_##name()->GetInternalPointer()));
CODE_KIND_LIST(ADD_COUNTER)
#undef ADD_COUNTER
return result;
}
void StatisticsExtension::Register() {
static StatisticsExtension statistics_extension;
static v8::DeclareExtension declaration(&statistics_extension);
}
} } // namespace v8::internal
// Copyright 2010 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:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_EXTENSIONS_STATISTICS_EXTENSION_H_
#define V8_EXTENSIONS_STATISTICS_EXTENSION_H_
#include "v8.h"
namespace v8 {
namespace internal {
class StatisticsExtension : public v8::Extension {
public:
StatisticsExtension() : v8::Extension("v8/statistics", kSource) {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name);
static v8::Handle<v8::Value> GetCounters(const v8::Arguments& args);
static void Register();
private:
static const char* const kSource;
};
} } // namespace v8::internal
#endif // V8_EXTENSIONS_STATISTICS_EXTENSION_H_
......@@ -303,6 +303,8 @@
'../../src/extensions/externalize-string-extension.h',
'../../src/extensions/gc-extension.cc',
'../../src/extensions/gc-extension.h',
'../../src/extensions/statistics-extension.cc',
'../../src/extensions/statistics-extension.h',
'../../src/factory.cc',
'../../src/factory.h',
'../../src/fast-dtoa.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment