summaryrefslogtreecommitdiffstats
path: root/webkit/extensions
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 21:26:28 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 21:26:28 +0000
commit9b221756628153638da5db1e46ca5ab42e12e88f (patch)
tree908d7ba18dce8eaab48779f2a3371ea78a0f0d91 /webkit/extensions
parentdb811c343705e846aba6fe47015de1eb5bacaf14 (diff)
downloadchromium_src-9b221756628153638da5db1e46ca5ab42e12e88f.zip
chromium_src-9b221756628153638da5db1e46ca5ab42e12e88f.tar.gz
chromium_src-9b221756628153638da5db1e46ca5ab42e12e88f.tar.bz2
Add API functions to control Quantify, as well as expose these
functions to javascript. Review URL: http://codereview.chromium.org/40255 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/extensions')
-rw-r--r--webkit/extensions/v8/profiler_extension.cc89
-rw-r--r--webkit/extensions/v8/profiler_extension.h24
2 files changed, 113 insertions, 0 deletions
diff --git a/webkit/extensions/v8/profiler_extension.cc b/webkit/extensions/v8/profiler_extension.cc
new file mode 100644
index 0000000..e4c64d1
--- /dev/null
+++ b/webkit/extensions/v8/profiler_extension.cc
@@ -0,0 +1,89 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "webkit/extensions/v8/profiler_extension.h"
+
+#include "base/profiler.h"
+
+namespace extensions_v8 {
+
+const char* kProfilerExtensionName = "v8/Profiler";
+
+class ProfilerWrapper : public v8::Extension {
+ public:
+ ProfilerWrapper() :
+ v8::Extension(kProfilerExtensionName,
+ "if (typeof(chromium) == 'undefined') {"
+ " chromium = {};"
+ "}"
+ "chromium.Profiler = function() {"
+ " native function ProfilerStart();"
+ " native function ProfilerStop();"
+ " native function ProfilerClearData();"
+ " native function ProfilerSetThreadName();"
+ " this.start = function() {"
+ " ProfilerStart();"
+ " };"
+ " this.stop = function() {"
+ " ProfilerStop();"
+ " };"
+ " this.clear = function() {"
+ " ProfilerClearData();"
+ " };"
+ " this.setThreadName = function(name) {"
+ " ProfilerSetThreadName(name);"
+ " };"
+ "};") {}
+
+ virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+ v8::Handle<v8::String> name) {
+ if (name->Equals(v8::String::New("ProfilerStart"))) {
+ return v8::FunctionTemplate::New(ProfilerStart);
+ } else if (name->Equals(v8::String::New("ProfilerStop"))) {
+ return v8::FunctionTemplate::New(ProfilerStop);
+ } else if (name->Equals(v8::String::New("ProfilerClearData"))) {
+ return v8::FunctionTemplate::New(ProfilerClearData);
+ } else if (name->Equals(v8::String::New("ProfilerSetThreadName"))) {
+ return v8::FunctionTemplate::New(ProfilerSetThreadName);
+ }
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ static v8::Handle<v8::Value> ProfilerStart(
+ const v8::Arguments& args) {
+ base::Profiler::StartRecording();
+ return v8::Undefined();
+ }
+
+ static v8::Handle<v8::Value> ProfilerStop(
+ const v8::Arguments& args) {
+ base::Profiler::StopRecording();
+ return v8::Undefined();
+ }
+
+ static v8::Handle<v8::Value> ProfilerClearData(
+ const v8::Arguments& args) {
+ base::Profiler::ClearData();
+ return v8::Undefined();
+ }
+
+ static v8::Handle<v8::Value> ProfilerSetThreadName(
+ const v8::Arguments& args) {
+ if (args.Length() >= 1 && args[0]->IsString()) {
+ v8::Local<v8::String> inputString = args[0]->ToString();
+ char nameBuffer[256];
+ inputString->WriteAscii(nameBuffer, 0, sizeof(nameBuffer)-1);
+ base::Profiler::SetThreadName(nameBuffer);
+ }
+ return v8::Undefined();
+ }
+};
+
+v8::Extension* ProfilerExtension::Get() {
+ return new ProfilerWrapper();
+}
+
+} // namespace extensions_v8
+
diff --git a/webkit/extensions/v8/profiler_extension.h b/webkit/extensions/v8/profiler_extension.h
new file mode 100644
index 0000000..8112da3
--- /dev/null
+++ b/webkit/extensions/v8/profiler_extension.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Profiler is an extension to allow javascript access to the API for
+// an external profiler program (such as Quantify). The "External" part of the
+// name is to distinguish it from the built-in V8 Profiler.
+
+#ifndef WEBKIT_EXTENSIONS_V8_PROFILER_EXTENSION_H_
+#define WEBKIT_EXTENSIONS_V8_PROFILER_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+class ProfilerExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // WEBKIT_EXTENSIONS_V8_PROFILER_EXTENSION_H_
+