diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 21:30:06 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 21:30:06 +0000 |
commit | 31d9ec81fd3e22b55568276b89447a1330494533 (patch) | |
tree | 4fb71aa7095a3c652d5c32f8efa078e2f7684126 /webkit/extensions | |
parent | 0f5ecffd8b245b99db6af9d1873cc10351ec0ef0 (diff) | |
download | chromium_src-31d9ec81fd3e22b55568276b89447a1330494533.zip chromium_src-31d9ec81fd3e22b55568276b89447a1330494533.tar.gz chromium_src-31d9ec81fd3e22b55568276b89447a1330494533.tar.bz2 |
Expose access for reading stats counters via the
benchmarking extension. This extension is only available
(already) when specifying chrome.exe --enable-benchmarking
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/149788
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/extensions')
-rw-r--r-- | webkit/extensions/v8/benchmarking_extension.cc | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/webkit/extensions/v8/benchmarking_extension.cc b/webkit/extensions/v8/benchmarking_extension.cc index e2e926d..501d483 100644 --- a/webkit/extensions/v8/benchmarking_extension.cc +++ b/webkit/extensions/v8/benchmarking_extension.cc @@ -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" @@ -15,20 +16,25 @@ class BenchmarkingWrapper : public v8::Extension { public: BenchmarkingWrapper() : v8::Extension(kBenchmarkingExtensionName, - "if (typeof(chromium) == 'undefined') {" - " chromium = {};" + "if (typeof(chrome) == 'undefined') {" + " chrome = {};" "};" - "if (typeof(chromium.benchmarking) == 'undefined') {" - " chromium.benchmarking = {};" + "if (typeof(chrome.benchmarking) == 'undefined') {" + " chrome.benchmarking = {};" "};" - "chromium.benchmarking.clearCache = function() {" + "chrome.benchmarking.clearCache = function() {" " native function ClearCache();" " ClearCache();" "};" - "chromium.benchmarking.closeConnections = function() {" + "chrome.benchmarking.closeConnections = function() {" " native function CloseConnections();" " CloseConnections();" - "};") {} + "};" + "chrome.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 @@ class BenchmarkingWrapper : public v8::Extension { 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 @@ class BenchmarkingWrapper : public v8::Extension { 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() { |