Index: webkit/extensions/v8/benchmarking_extension.cc |
=================================================================== |
--- webkit/extensions/v8/benchmarking_extension.cc (revision 20745) |
+++ webkit/extensions/v8/benchmarking_extension.cc (working copy) |
@@ -4,6 +4,7 @@ |
#include "config.h" |
#include "Cache.h" |
+#include "base/stats_table.h" |
#include "webkit/extensions/v8/benchmarking_extension.h" |
#include "webkit/glue/webkit_glue.h" |
@@ -28,7 +29,12 @@ |
"chromium.benchmarking.closeConnections = function() {" |
" native function CloseConnections();" |
" CloseConnections();" |
- "};") {} |
+ "};" |
+ "chromium.benchmarking.counter = function(name) {" |
+ " native function GetCounter();" |
+ " return GetCounter(name);" |
+ "};" |
+ ) {} |
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
v8::Handle<v8::String> name) { |
@@ -36,6 +42,8 @@ |
return v8::FunctionTemplate::New(CloseConnections); |
} else if (name->Equals(v8::String::New("ClearCache"))) { |
return v8::FunctionTemplate::New(ClearCache); |
+ } else if (name->Equals(v8::String::New("GetCounter"))) { |
+ return v8::FunctionTemplate::New(GetCounter); |
} |
return v8::Handle<v8::FunctionTemplate>(); |
} |
@@ -54,6 +62,20 @@ |
WebCore::cache()->setDisabled(false); |
return v8::Undefined(); |
} |
+ |
+ static v8::Handle<v8::Value> GetCounter(const v8::Arguments& args) { |
+ if (!args.Length() || !args[0]->IsString()) |
+ return v8::Undefined(); |
+ |
+ // Extract the name argument |
+ char name[256]; |
+ name[0] = 'c'; |
+ name[1] = ':'; |
+ args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3); |
+ |
+ int counter = StatsTable::current()->GetCounterValue(name); |
+ return v8::Integer::New(counter); |
+ } |
}; |
v8::Extension* BenchmarkingExtension::Get() { |