diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 21:26:28 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 21:26:28 +0000 |
commit | 9b221756628153638da5db1e46ca5ab42e12e88f (patch) | |
tree | 908d7ba18dce8eaab48779f2a3371ea78a0f0d91 /base | |
parent | db811c343705e846aba6fe47015de1eb5bacaf14 (diff) | |
download | chromium_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 'base')
-rw-r--r-- | base/base.gyp | 2 | ||||
-rw-r--r-- | base/base.scons | 2 | ||||
-rw-r--r-- | base/build/base.vcproj | 8 | ||||
-rw-r--r-- | base/profiler.cc | 45 | ||||
-rw-r--r-- | base/profiler.h | 39 |
5 files changed, 96 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__ + |