diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 23:05:01 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 23:05:01 +0000 |
commit | 90895d0f3265926221f00b3571332066a0bcb375 (patch) | |
tree | ee36e96f7bc1bfd52d0370cfc9324bee7ac1d631 /base/profiler | |
parent | a8c119da0066b18c472559dd80e58e9895d5ee06 (diff) | |
download | chromium_src-90895d0f3265926221f00b3571332066a0bcb375.zip chromium_src-90895d0f3265926221f00b3571332066a0bcb375.tar.gz chromium_src-90895d0f3265926221f00b3571332066a0bcb375.tar.bz2 |
Support use of third party time function for about:profiler
This uses TCMalloc to provide a time function, allowing
us to see how much memory was allocated on a single thread
during the running of a task. The alternate time function
is put in place only when a specific environment variable
is detected during TCMalloc startup.
This change currently is activated only in Windows/Linux,
as it is based on changes TCMalloc (not used on Mac).
We also create an infrastructure for using any alternate
timer, to replace the "wall clock time," on a per-thread
basis, in the about:profiler infrastructure. That interface
may be used on other platforms, including scenarios where
we have a per-thread-CPU-time function to replace the
wall-clock timer. In all cases, when this alternate timer
is activated, we lose the ability to calculated queueing
time. Queueing time is based on a time snapshot taken on
a second thread, and hence is not comparable to the
alternate timer (when the alternate timer is engaged).
r=rtenneti
BUG=103321
Review URL: https://chromiumcodereview.appspot.com/9212025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/profiler')
-rw-r--r-- | base/profiler/alternate_timer.cc | 25 | ||||
-rw-r--r-- | base/profiler/alternate_timer.h | 36 | ||||
-rw-r--r-- | base/profiler/tracked_time.h | 2 |
3 files changed, 63 insertions, 0 deletions
diff --git a/base/profiler/alternate_timer.cc b/base/profiler/alternate_timer.cc new file mode 100644 index 0000000..05a983c --- /dev/null +++ b/base/profiler/alternate_timer.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2012 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/alternate_timer.h" + +#include "base/logging.h" + +namespace tracked_objects { + +static NowFunction* g_time_function = NULL; + +const char kAlternateProfilerTime[] = "CHROME_PROFILER_TIME"; + +// Set an alternate timer function to replace the OS time function when +// profiling. +void SetAlternateTimeSource(NowFunction* now_function) { + DCHECK_EQ(g_time_function, reinterpret_cast<NowFunction*>(NULL)); + g_time_function = now_function; +} + +extern NowFunction* GetAlternateTimeSource() { + return g_time_function; +} +} // tracked_objects diff --git a/base/profiler/alternate_timer.h b/base/profiler/alternate_timer.h new file mode 100644 index 0000000..883b24f --- /dev/null +++ b/base/profiler/alternate_timer.h @@ -0,0 +1,36 @@ +// Copyright (c) 2012 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. + +// This is a glue file, which allows third party code to call into our profiler +// without having to include most any functions from base. + + +#ifndef BASE_PROFILER_ALTERNATE_TIMER_H_ +#define BASE_PROFILER_ALTERNATE_TIMER_H_ + +namespace tracked_objects { + +// Provide type for an alternate timer function. +typedef unsigned int NowFunction(); + +// Set an alternate timer function to replace the OS time function when +// profiling. Typically this is called by an allocator that is providing a +// function that indicates how much memory has been allocated on any given +// thread. +extern void SetAlternateTimeSource(NowFunction* now_function); + +// Gets the pointer to a function that was set via SetAlternateTimeSource(). +// Returns NULL if no set was done prior to calling GetAlternateTimeSource. +extern NowFunction* GetAlternateTimeSource(); + +// Environment variable name that is used to activate alternate timer profiling +// (such as using TCMalloc allocations to provide a pseudo-timer) for tasks +// instead of wall clock profiling. +extern const char kAlternateProfilerTime[]; + + + +} // tracked_objects + +#endif // BASE_PROFILER_ALTERNATE_TIMER_H_ diff --git a/base/profiler/tracked_time.h b/base/profiler/tracked_time.h index 6f4bc7e..5493e20 100644 --- a/base/profiler/tracked_time.h +++ b/base/profiler/tracked_time.h @@ -62,6 +62,8 @@ class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks. TrackedTime operator+(const Duration& other) const; bool is_null() const; + static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); } + private: friend class Duration; explicit TrackedTime(int32 ms); |