diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 23:07:52 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 23:07:52 +0000 |
commit | c5d7f32f2fdae32e4ebf5c67b02026eefecc17b2 (patch) | |
tree | 85cce8731ba57fc701e3d49b1b9a9f1b2304eeb6 | |
parent | 9165f748223f75790fb7f504de538b3003c27e4f (diff) | |
download | chromium_src-c5d7f32f2fdae32e4ebf5c67b02026eefecc17b2.zip chromium_src-c5d7f32f2fdae32e4ebf5c67b02026eefecc17b2.tar.gz chromium_src-c5d7f32f2fdae32e4ebf5c67b02026eefecc17b2.tar.bz2 |
Support controlling the TCMalloc CPU profiler from script in test_shell
Review URL: http://codereview.chromium.org/607008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41218 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/profiler.cc | 14 | ||||
-rw-r--r-- | base/profiler.h | 3 | ||||
-rw-r--r-- | webkit/extensions/v8/profiler_extension.cc | 13 |
3 files changed, 30 insertions, 0 deletions
diff --git a/base/profiler.cc b/base/profiler.cc index cff16a5..1f28a73 100644 --- a/base/profiler.cc +++ b/base/profiler.cc @@ -5,6 +5,10 @@ #include "base/profiler.h" #include "base/string_util.h" +#if defined(USE_TCMALLOC) +#include "third_party/tcmalloc/chromium/src/google/profiler.h" +#endif + // When actually using quantify, uncomment the following line. // #define QUANTIFY @@ -20,12 +24,22 @@ namespace base { void Profiler::StartRecording() { #ifdef QUANTIFY QuantifyStartRecordingData(); +#elif defined(USE_TCMALLOC) && defined(OS_LINUX) + ProfilerStart("chrome-profile"); #endif } void Profiler::StopRecording() { #ifdef QUANTIFY QuantifyStopRecordingData(); +#elif defined(USE_TCMALLOC) && defined(OS_LINUX) + ProfilerStop(); +#endif +} + +void Profiler::Flush() { +#if defined(USE_TCMALLOC) && defined(OS_LINUX) + ProfilerFlush(); #endif } diff --git a/base/profiler.h b/base/profiler.h index 8a6cce8..4fd1117 100644 --- a/base/profiler.h +++ b/base/profiler.h @@ -26,6 +26,9 @@ class Profiler { // time in application startup. static void ClearData(); + // Flushes all recorded data to disk. No-op until recording is started. + static void Flush(); + // Sets the name of the current thread for display in the profiler's UI. static void SetThreadName(const char *name); diff --git a/webkit/extensions/v8/profiler_extension.cc b/webkit/extensions/v8/profiler_extension.cc index 7a4f13f..cbfc721 100644 --- a/webkit/extensions/v8/profiler_extension.cc +++ b/webkit/extensions/v8/profiler_extension.cc @@ -21,6 +21,7 @@ class ProfilerWrapper : public v8::Extension { "chromium.Profiler = function() {" " native function ProfilerStart();" " native function ProfilerStop();" + " native function ProfilerFlush();" " native function ProfilerClearData();" " native function ProfilerSetThreadName();" " this.start = function() {" @@ -32,6 +33,9 @@ class ProfilerWrapper : public v8::Extension { " this.clear = function() {" " ProfilerClearData();" " };" + " this.flush = function() {" + " ProfilerFlush();" + " };" " this.setThreadName = function(name) {" " ProfilerSetThreadName(name);" " };" @@ -45,6 +49,8 @@ class ProfilerWrapper : public v8::Extension { 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("ProfilerFlush"))) { + return v8::FunctionTemplate::New(ProfilerFlush); } else if (name->Equals(v8::String::New("ProfilerSetThreadName"))) { return v8::FunctionTemplate::New(ProfilerSetThreadName); } @@ -69,6 +75,13 @@ class ProfilerWrapper : public v8::Extension { return v8::Undefined(); } + static v8::Handle<v8::Value> ProfilerFlush( + const v8::Arguments& args) { + base::Profiler::Flush(); + return v8::Undefined(); + } + + static v8::Handle<v8::Value> ProfilerSetThreadName( const v8::Arguments& args) { if (args.Length() >= 1 && args[0]->IsString()) { |