From 8f82968945b4e4567f961dab42c9f291b66112a5 Mon Sep 17 00:00:00 2001 From: "isherman@chromium.org" Date: Fri, 27 Apr 2012 00:36:49 +0000 Subject: Explicitly track the time source type in base/profiler/alternate_timer.h We were previously implicitly tracking the time source as either default or tcmalloc-based; but as we add more time sources (e.g. cpu time), we'll want to have explicit tracking for this. BUG=none TEST=none TBR=jar@chromium.org (Recommit of [ https://chromiumcodereview.appspot.com/10225017/ ]) Review URL: http://codereview.chromium.org/10248001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134187 0039d316-1c4b-4281-b951-d872f2087c98 --- base/allocator/allocator_shim.cc | 3 ++- base/profiler/alternate_timer.cc | 9 ++++++++- base/profiler/alternate_timer.h | 12 ++++++++++-- chrome/browser/metrics/metrics_log.cc | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc index d61a9a4..075828d 100644 --- a/base/allocator/allocator_shim.cc +++ b/base/allocator/allocator_shim.cc @@ -270,7 +270,8 @@ extern "C" int _heap_init() { GetenvBeforeMain(tracked_objects::kAlternateProfilerTime); if (profiling && *profiling == '1') { tracked_objects::SetAlternateTimeSource( - tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread); + tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread, + tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); } return 1; diff --git a/base/profiler/alternate_timer.cc b/base/profiler/alternate_timer.cc index abf9180..4eba89c 100644 --- a/base/profiler/alternate_timer.cc +++ b/base/profiler/alternate_timer.cc @@ -9,6 +9,8 @@ namespace { tracked_objects::NowFunction* g_time_function = NULL; +tracked_objects::TimeSourceType g_time_source_type = + tracked_objects::TIME_SOURCE_TYPE_WALL_TIME; } // anonymous namespace @@ -18,13 +20,18 @@ const char kAlternateProfilerTime[] = "CHROME_PROFILER_TIME"; // Set an alternate timer function to replace the OS time function when // profiling. -void SetAlternateTimeSource(NowFunction* now_function) { +void SetAlternateTimeSource(NowFunction* now_function, TimeSourceType type) { DCHECK_EQ(reinterpret_cast(NULL), g_time_function); g_time_function = now_function; + g_time_source_type = type; } NowFunction* GetAlternateTimeSource() { return g_time_function; } +TimeSourceType GetTimeSourceType() { + return g_time_source_type; +} + } // namespace tracked_objects diff --git a/base/profiler/alternate_timer.h b/base/profiler/alternate_timer.h index 778dc62..eb0022d 100644 --- a/base/profiler/alternate_timer.h +++ b/base/profiler/alternate_timer.h @@ -12,6 +12,11 @@ namespace tracked_objects { +enum BASE_EXPORT TimeSourceType { + TIME_SOURCE_TYPE_WALL_TIME, + TIME_SOURCE_TYPE_TCMALLOC +}; + // Provide type for an alternate timer function. typedef unsigned int NowFunction(); @@ -24,11 +29,14 @@ extern const char kAlternateProfilerTime[]; // 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. -void SetAlternateTimeSource(NowFunction* now_function); +void SetAlternateTimeSource(NowFunction* now_function, TimeSourceType type); // Gets the pointer to a function that was set via SetAlternateTimeSource(). // Returns NULL if no set was done prior to calling GetAlternateTimeSource. -BASE_EXPORT NowFunction* GetAlternateTimeSource(); +NowFunction* GetAlternateTimeSource(); + +// Returns the type of the currently set time source. +BASE_EXPORT TimeSourceType GetTimeSourceType(); } // namespace tracked_objects diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 36be84f..b79ecef1 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -787,7 +787,8 @@ void MetricsLog::RecordProfilerData( content::ProcessType process_type) { DCHECK(!locked()); - if (tracked_objects::GetAlternateTimeSource()) { + if (tracked_objects::GetTimeSourceType() != + tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { // We currently only support the default time source, wall clock time. return; } -- cgit v1.1