summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--base/base.gyp2
-rw-r--r--base/base.scons2
-rw-r--r--base/build/base.vcproj8
-rw-r--r--base/profiler.cc45
-rw-r--r--base/profiler.h39
-rw-r--r--webkit/build/V8Bindings/SConscript1
-rw-r--r--webkit/build/V8Bindings/V8Bindings.vcproj8
-rw-r--r--webkit/extensions/v8/profiler_extension.cc89
-rw-r--r--webkit/extensions/v8/profiler_extension.h24
-rw-r--r--webkit/tools/test_shell/test_shell_main.cc5
-rw-r--r--webkit/tools/test_shell/test_shell_switches.cc3
-rw-r--r--webkit/tools/test_shell/test_shell_switches.h1
-rw-r--r--webkit/webkit.gyp2
13 files changed, 229 insertions, 0 deletions
diff --git a/base/base.gyp b/base/base.gyp
index e647911..97b9e45 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -167,6 +167,8 @@
'platform_thread_posix.cc',
'platform_thread_win.cc',
'port.h',
+ 'profiler.cc',
+ 'profiler.h',
'process.h',
'process_posix.cc',
'process_util.h',
diff --git a/base/base.scons b/base/base.scons
index dcc524d..485dd13 100644
--- a/base/base.scons
+++ b/base/base.scons
@@ -160,6 +160,8 @@ input_files = ChromeFileList([
'platform_thread.h',
'platform_thread_win.cc',
'port.h',
+ 'profiler.cc',
+ 'profiler.h',
'third_party/nspr/prcpucfg.h',
'third_party/nspr/prcpucfg_win.h',
'process.h',
diff --git a/base/build/base.vcproj b/base/build/base.vcproj
index b31949f..cecff6e 100644
--- a/base/build/base.vcproj
+++ b/base/build/base.vcproj
@@ -630,6 +630,14 @@
>
</File>
<File
+ RelativePath="..\profiler.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\profiler.h"
+ >
+ </File>
+ <File
RelativePath="..\third_party\nspr\prtime.cc"
>
</File>
diff --git a/base/profiler.cc b/base/profiler.cc
new file mode 100644
index 0000000..3f19597
--- /dev/null
+++ b/base/profiler.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2009 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 "base/profiler.h"
+#include "base/string_util.h"
+
+#ifdef PURIFY
+// this #define is used to prevent people from directly using pure.h
+// instead of profiler.h
+#define PURIFY_PRIVATE_INCLUDE
+#include "base/third_party/purify/pure.h"
+#endif
+
+namespace base {
+
+void Profiler::StartRecording() {
+#ifdef PURIFY
+ QuantifyStartRecordingData();
+#endif
+}
+
+void Profiler::StopRecording() {
+#ifdef PURIFY
+ QuantifyStopRecordingData();
+#endif
+}
+
+void Profiler::ClearData() {
+#ifdef PURIFY
+ QuantifyClearData();
+#endif
+}
+
+void Profiler::SetThreadName(const char *name) {
+#ifdef PURIFY
+ // make a copy since the Quantify function takes a char*, not const char*
+ char buffer[512];
+ base::snprintf(buffer, sizeof(buffer)-1, "%s", name);
+ QuantifySetThreadName(buffer);
+#endif
+}
+
+} // namespace base
+
diff --git a/base/profiler.h b/base/profiler.h
new file mode 100644
index 0000000..6882c02
--- /dev/null
+++ b/base/profiler.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2009 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.
+
+// An abstraction for functions used to control execution time profiling.
+// All methods are effectively no-ops unless this program is being run through
+// a supported tool (currently only Quantify, a companion tool to Purify)
+
+#ifndef BASE_PROFILER_H__
+#define BASE_PROFILER_H__
+
+#include "base/basictypes.h"
+
+namespace base {
+
+class Profiler {
+ public:
+ // Starts or resumes recording.
+ static void StartRecording();
+
+ // Stops recording until StartRecording is called or the program exits.
+ static void StopRecording();
+
+ // Throw away data collected so far. This can be useful to call before
+ // your first call to StartRecording, for instance to avoid counting any
+ // time in application startup.
+ static void ClearData();
+
+ // Sets the name of the current thread for display in the profiler's UI.
+ static void SetThreadName(const char *name);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(Profiler);
+};
+
+} // namespace base
+
+#endif // BASE_PROFILER_H__
+
diff --git a/webkit/build/V8Bindings/SConscript b/webkit/build/V8Bindings/SConscript
index 7739356..46417a7 100644
--- a/webkit/build/V8Bindings/SConscript
+++ b/webkit/build/V8Bindings/SConscript
@@ -391,6 +391,7 @@ inputs = [
'$WEBKIT_DIR/extensions/v8/gears_extension.cc',
'$WEBKIT_DIR/extensions/v8/interval_extension.cc',
'$WEBKIT_DIR/extensions/v8/playback_extension.cc',
+ '$WEBKIT_DIR/extensions/v8/profiler_extension.cc',
]
if env.Bit('windows'):
diff --git a/webkit/build/V8Bindings/V8Bindings.vcproj b/webkit/build/V8Bindings/V8Bindings.vcproj
index 87d4964..1958c33 100644
--- a/webkit/build/V8Bindings/V8Bindings.vcproj
+++ b/webkit/build/V8Bindings/V8Bindings.vcproj
@@ -2699,6 +2699,14 @@
RelativePath="..\..\extensions\v8\playback_extension.h"
>
</File>
+ <File
+ RelativePath="..\..\extensions\v8\profiler_extension.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\extensions\v8\profiler_extension.h"
+ >
+ </File>
</Filter>
<File
RelativePath="..\..\port\bindings\v8\dom_wrapper_map.h"
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_
+
diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc
index dcf2557..fb0ecae 100644
--- a/webkit/tools/test_shell/test_shell_main.cc
+++ b/webkit/tools/test_shell/test_shell_main.cc
@@ -29,6 +29,7 @@
#include "webkit/glue/window_open_disposition.h"
#include "webkit/extensions/v8/gc_extension.h"
#include "webkit/extensions/v8/playback_extension.h"
+#include "webkit/extensions/v8/profiler_extension.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/test_shell.h"
#include "webkit/tools/test_shell/test_shell_platform_delegate.h"
@@ -192,6 +193,10 @@ int main(int argc, char* argv[]) {
// Expose GCController to JavaScript.
WebKit::registerExtension(extensions_v8::GCExtension::Get());
+ if (parsed_command_line.HasSwitch(test_shell::kProfiler)) {
+ WebKit::registerExtension(extensions_v8::ProfilerExtension::Get());
+ }
+
// Load and initialize the stats table. Attempt to construct a somewhat
// unique name to isolate separate instances from each other.
StatsTable *table = new StatsTable(
diff --git a/webkit/tools/test_shell/test_shell_switches.cc b/webkit/tools/test_shell/test_shell_switches.cc
index b271f18..6604769 100644
--- a/webkit/tools/test_shell/test_shell_switches.cc
+++ b/webkit/tools/test_shell/test_shell_switches.cc
@@ -71,5 +71,8 @@ extern const wchar_t kEnableVideo[] = L"enable-video";
// to happen even if in layout test mode.
extern const wchar_t kGDB[] = L"gdb";
+// Make functions of the Profiler class available in javascript
+extern const wchar_t kProfiler[] = L"profiler";
+
} // namespace test_shell
diff --git a/webkit/tools/test_shell/test_shell_switches.h b/webkit/tools/test_shell/test_shell_switches.h
index c6c52c2..aad92e9 100644
--- a/webkit/tools/test_shell/test_shell_switches.h
+++ b/webkit/tools/test_shell/test_shell_switches.h
@@ -30,6 +30,7 @@ extern const wchar_t kAllowScriptsToCloseWindows[];
extern const wchar_t kCheckLayoutTestSystemDeps[];
extern const wchar_t kEnableVideo[];
extern const wchar_t kGDB[];
+extern const wchar_t kProfiler[];
} // namespace test_shell
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index a258baa..77c2b62 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -1035,6 +1035,8 @@
'extensions/v8/interval_extension.h',
'extensions/v8/playback_extension.cc',
'extensions/v8/playback_extension.h',
+ 'extensions/v8/profiler_extension.cc',
+ 'extensions/v8/profiler_extension.h',
'port/bindings/v8/JSDOMBinding.cpp',
'port/bindings/v8/JSDOMBinding.h',
'port/bindings/v8/JSXPathNSResolver.cpp',