summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-21 18:05:41 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-21 18:05:41 +0000
commitc62dd9d42bd87964a131adc688d0c70f63cc4cac (patch)
treeb57f3bc0843d2acace088498ecb40e0bfc213b6c /base
parentb6bb36e2e8c9a09b4fd733bf74b60a6f02a5a7e9 (diff)
downloadchromium_src-c62dd9d42bd87964a131adc688d0c70f63cc4cac.zip
chromium_src-c62dd9d42bd87964a131adc688d0c70f63cc4cac.tar.gz
chromium_src-c62dd9d42bd87964a131adc688d0c70f63cc4cac.tar.bz2
Delete Tracked, and move Location to its own file.
The Birth/Death tracking of tasks has been moved out-of-band into MessageLoop's PendingTask structure. Thus, Task no longer needs to inherit from Tracked. Since Task was the only child of Tracked, delete the Tracked class and move Location to its own file. BUG=none TEST=builds Review URL: http://codereview.chromium.org/7879006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102132 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi4
-rw-r--r--base/files/file_path_watcher_linux.cc1
-rw-r--r--base/location.cc (renamed from base/tracked.cc)70
-rw-r--r--base/location.h (renamed from base/tracked.h)76
-rw-r--r--base/message_loop.h2
-rw-r--r--base/message_loop_proxy.cc1
-rw-r--r--base/message_loop_proxy.h4
-rw-r--r--base/message_loop_proxy_impl.cc2
-rw-r--r--base/observer_list_threadsafe.h1
-rw-r--r--base/synchronization/waitable_event_watcher_posix.cc1
-rw-r--r--base/task.h3
-rw-r--r--base/test/thread_test_helper.cc2
-rw-r--r--base/threading/worker_pool.h5
-rw-r--r--base/threading/worker_pool_posix.h2
-rw-r--r--base/threading/worker_pool_unittest.cc6
-rw-r--r--base/timer.h1
-rw-r--r--base/tracked_objects.h29
-rw-r--r--base/tracked_objects_unittest.cc14
18 files changed, 52 insertions, 172 deletions
diff --git a/base/base.gypi b/base/base.gypi
index c6ea838..6860c2d2 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -119,6 +119,8 @@
'lazy_instance.cc',
'lazy_instance.h',
'linked_list.h',
+ 'location.cc',
+ 'location.h',
'logging.cc',
'logging.h',
'logging_win.cc',
@@ -308,8 +310,6 @@
'time_win.cc',
'timer.cc',
'timer.h',
- 'tracked.cc',
- 'tracked.h',
'tracked_objects.cc',
'tracked_objects.h',
'tuple.h',
diff --git a/base/files/file_path_watcher_linux.cc b/base/files/file_path_watcher_linux.cc
index 2dfd54bd..c85202c 100644
--- a/base/files/file_path_watcher_linux.cc
+++ b/base/files/file_path_watcher_linux.cc
@@ -21,6 +21,7 @@
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/lazy_instance.h"
+#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
diff --git a/base/tracked.cc b/base/location.cc
index 517591b..cda5159 100644
--- a/base/tracked.cc
+++ b/base/location.cc
@@ -7,22 +7,16 @@
#if defined(COMPILER_MSVC)
// MSDN says to #include <intrin.h>, but that breaks the VS2005 build.
extern "C" {
-void* _ReturnAddress();
+ void* _ReturnAddress();
}
#endif
-#include "base/tracked.h"
-
+#include "base/location.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
-#include "base/tracked_objects.h"
-
-using base::TimeTicks;
namespace tracked_objects {
-//------------------------------------------------------------------------------
-
Location::Location(const char* function_name,
const char* file_name,
int line_number,
@@ -90,64 +84,4 @@ BASE_EXPORT const void* GetProgramCounter() {
return NULL;
}
-//------------------------------------------------------------------------------
-
-#if !defined(TRACK_ALL_TASK_OBJECTS)
-
-Tracked::Tracked() : birth_program_counter_(NULL) {}
-Tracked::~Tracked() {}
-
-void Tracked::SetBirthPlace(const Location& from_here) {
- birth_program_counter_ = from_here.program_counter();
-}
-
-const Location Tracked::GetBirthPlace() const {
- static Location kNone("NoFunctionName", "NeedToSetBirthPlace", -1, NULL);
- return kNone;
-}
-bool Tracked::MissingBirthPlace() const { return false; }
-void Tracked::ResetBirthTime() {}
-
-#else
-
-Tracked::Tracked()
- : tracked_births_(NULL),
- tracked_birth_time_(TimeTicks::Now()) {
-}
-
-Tracked::~Tracked() {
- if (!ThreadData::IsActive() || !tracked_births_)
- return;
- ThreadData::current()->TallyADeath(*tracked_births_,
- TimeTicks::Now() - tracked_birth_time_);
-}
-
-void Tracked::SetBirthPlace(const Location& from_here) {
- if (!ThreadData::IsActive())
- return;
- if (tracked_births_)
- tracked_births_->ForgetBirth();
- ThreadData* current_thread_data = ThreadData::current();
- if (!current_thread_data)
- return; // Shutdown started, and this thread wasn't registered.
- tracked_births_ = current_thread_data->TallyABirth(from_here);
-
- birth_program_counter_ = from_here.program_counter();
-}
-
-const Location Tracked::GetBirthPlace() const {
- static Location kNone("UnknownFunctionName", "UnknownFile", -1, NULL);
- return tracked_births_ ? tracked_births_->location() : kNone;
-}
-
-void Tracked::ResetBirthTime() {
- tracked_birth_time_ = TimeTicks::Now();
-}
-
-bool Tracked::MissingBirthPlace() const {
- return !tracked_births_ || tracked_births_->location().line_number() == -1;
-}
-
-#endif // !defined(TRACK_ALL_TASK_OBJECTS)
-
} // namespace tracked_objects
diff --git a/base/tracked.h b/base/location.h
index 337f3e0..fab8f4f 100644
--- a/base/tracked.h
+++ b/base/location.h
@@ -2,27 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-//------------------------------------------------------------------------------
-// Tracked is the base class for all tracked objects. During construction, it
-// registers the fact that an instance was created, and at destruction time, it
-// records that event. The instance may be tagged with a name, which is refered
-// to as its Location. The Location is a file and line number, most
-// typically indicated where the object was constructed. In some cases, as the
-// object's significance is refined (for example, a Task object is augmented to
-// do additonal things), its Location may be redefined to that later location.
-
-// Tracking includes (for each instance) recording the birth thread, death
-// thread, and duration of life (from construction to destruction). All this
-// data is accumulated and filtered for review at about:objects.
-
-#ifndef BASE_TRACKED_H_
-#define BASE_TRACKED_H_
-#pragma once
+#ifndef BASE_LOCATION_H_
+#define BASE_LOCATION_H_
#include <string>
#include "base/base_export.h"
-#include "base/time.h"
#ifndef NDEBUG
#ifndef TRACK_ALL_TASK_OBJECTS
@@ -32,10 +17,8 @@
namespace tracked_objects {
-//------------------------------------------------------------------------------
// Location provides basic info where of an object was constructed, or was
// significantly brought to life.
-
class BASE_EXPORT Location {
public:
// Constructor should be called with a long-lived char*, such as __FILE__.
@@ -85,66 +68,13 @@ class BASE_EXPORT Location {
BASE_EXPORT const void* GetProgramCounter();
-//------------------------------------------------------------------------------
// Define a macro to record the current source location.
-
#define FROM_HERE tracked_objects::Location( \
__FUNCTION__, \
__FILE__, \
__LINE__, \
tracked_objects::GetProgramCounter()) \
-
-//------------------------------------------------------------------------------
-
-
-class Births;
-
-class BASE_EXPORT Tracked {
- public:
- Tracked();
- virtual ~Tracked();
-
- // Used to record the FROM_HERE location of a caller.
- void SetBirthPlace(const Location& from_here);
- const Location GetBirthPlace() const;
-
- // When a task sits around a long time, such as in a timer, or object watcher,
- // this method should be called when the task becomes active, and its
- // significant lifetime begins (and its waiting to be woken up has passed).
- void ResetBirthTime();
-
- bool MissingBirthPlace() const;
-
-#if defined(TRACK_ALL_TASK_OBJECTS)
- base::TimeTicks tracked_birth_time() const { return tracked_birth_time_; }
-#else
- base::TimeTicks tracked_birth_time() const { return base::TimeTicks::Now(); }
-#endif // defined(TRACK_ALL_TASK_OBJECTS)
-
- // Returns null if SetBirthPlace has not been called.
- const void* get_birth_program_counter() const {
- return birth_program_counter_;
- }
-
- private:
-#if defined(TRACK_ALL_TASK_OBJECTS)
-
- // Pointer to instance were counts of objects with the same birth location
- // (on the same thread) are stored.
- Births* tracked_births_;
- // The time this object was constructed. If its life consisted of a long
- // waiting period, and then it became active, then this value is generally
- // reset before the object begins it active life.
- base::TimeTicks tracked_birth_time_;
-
-#endif // defined(TRACK_ALL_TASK_OBJECTS)
-
- const void* birth_program_counter_;
-
- DISALLOW_COPY_AND_ASSIGN(Tracked);
-};
-
} // namespace tracked_objects
-#endif // BASE_TRACKED_H_
+#endif // BASE_LOCATION_H_
diff --git a/base/message_loop.h b/base/message_loop.h
index 4742b5f..ab4978a 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -12,6 +12,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop_proxy.h"
#include "base/message_pump.h"
@@ -19,7 +20,6 @@
#include "base/synchronization/lock.h"
#include "base/task.h"
#include "base/time.h"
-#include "base/tracked.h"
#if defined(OS_WIN)
// We need this to declare base::MessagePumpWin::Dispatcher, which we should
diff --git a/base/message_loop_proxy.cc b/base/message_loop_proxy.cc
index 7433e25..c821704 100644
--- a/base/message_loop_proxy.cc
+++ b/base/message_loop_proxy.cc
@@ -5,6 +5,7 @@
#include "base/message_loop_proxy.h"
#include "base/bind.h"
+#include "base/location.h"
namespace base {
diff --git a/base/message_loop_proxy.h b/base/message_loop_proxy.h
index 89da97d..d783b4e 100644
--- a/base/message_loop_proxy.h
+++ b/base/message_loop_proxy.h
@@ -12,6 +12,10 @@
#include "base/memory/ref_counted.h"
#include "base/task.h"
+namespace tracked_objects {
+class Location;
+} // namespace tracked_objects
+
namespace base {
struct MessageLoopProxyTraits;
diff --git a/base/message_loop_proxy_impl.cc b/base/message_loop_proxy_impl.cc
index 6b52351..b826916 100644
--- a/base/message_loop_proxy_impl.cc
+++ b/base/message_loop_proxy_impl.cc
@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "base/message_loop_proxy_impl.h"
+
+#include "base/location.h"
#include "base/threading/thread_restrictions.h"
namespace base {
diff --git a/base/observer_list_threadsafe.h b/base/observer_list_threadsafe.h
index 22cc951..9dbc041 100644
--- a/base/observer_list_threadsafe.h
+++ b/base/observer_list_threadsafe.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/callback_old.h"
+#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
diff --git a/base/synchronization/waitable_event_watcher_posix.cc b/base/synchronization/waitable_event_watcher_posix.cc
index 0d6ff26..cdb7df690 100644
--- a/base/synchronization/waitable_event_watcher_posix.cc
+++ b/base/synchronization/waitable_event_watcher_posix.cc
@@ -4,6 +4,7 @@
#include "base/synchronization/waitable_event_watcher.h"
+#include "base/location.h"
#include "base/message_loop.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
diff --git a/base/task.h b/base/task.h
index 3ff0640..4a33de0 100644
--- a/base/task.h
+++ b/base/task.h
@@ -10,7 +10,6 @@
#include "base/debug/alias.h"
#include "base/memory/raw_scoped_refptr_mismatch_checker.h"
#include "base/memory/weak_ptr.h"
-#include "base/tracked.h"
#include "base/tuple.h"
namespace base {
@@ -22,7 +21,7 @@ const size_t kDeadTask = 0xDEAD7A53;
// A task is a generic runnable thingy, usually used for running code on a
// different thread or for scheduling future tasks off of the message loop.
-class BASE_EXPORT Task : public tracked_objects::Tracked {
+class BASE_EXPORT Task {
public:
Task();
virtual ~Task();
diff --git a/base/test/thread_test_helper.cc b/base/test/thread_test_helper.cc
index e79ca92..b762d97 100644
--- a/base/test/thread_test_helper.cc
+++ b/base/test/thread_test_helper.cc
@@ -4,6 +4,8 @@
#include "base/test/thread_test_helper.h"
+#include "base/location.h"
+
namespace base {
ThreadTestHelper::ThreadTestHelper(MessageLoopProxy* target_thread)
diff --git a/base/threading/worker_pool.h b/base/threading/worker_pool.h
index 384dcd1..697cc7c 100644
--- a/base/threading/worker_pool.h
+++ b/base/threading/worker_pool.h
@@ -8,10 +8,13 @@
#include "base/base_export.h"
#include "base/callback.h"
-#include "base/tracked.h"
class Task;
+namespace tracked_objects {
+class Location;
+} // namespace tracked_objects
+
namespace base {
// This is a facility that runs tasks that don't require a specific thread or
diff --git a/base/threading/worker_pool_posix.h b/base/threading/worker_pool_posix.h
index b1930e6..990f50a 100644
--- a/base/threading/worker_pool_posix.h
+++ b/base/threading/worker_pool_posix.h
@@ -30,12 +30,12 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
-#include "base/tracked.h"
class Task;
diff --git a/base/threading/worker_pool_unittest.cc b/base/threading/worker_pool_unittest.cc
index f044e10..2d2b055 100644
--- a/base/threading/worker_pool_unittest.cc
+++ b/base/threading/worker_pool_unittest.cc
@@ -1,10 +1,12 @@
-// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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/threading/worker_pool.h"
+
+#include "base/location.h"
#include "base/task.h"
#include "base/synchronization/waitable_event.h"
-#include "base/threading/worker_pool.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
diff --git a/base/timer.h b/base/timer.h
index 30cb109..4f443a2 100644
--- a/base/timer.h
+++ b/base/timer.h
@@ -48,6 +48,7 @@
// should be able to tell the difference.
#include "base/base_export.h"
+#include "base/location.h"
#include "base/logging.h"
#include "base/task.h"
#include "base/time.h"
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 6044408..508099a 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -11,8 +11,9 @@
#include <vector>
#include "base/base_export.h"
+#include "base/location.h"
+#include "base/time.h"
#include "base/synchronization/lock.h"
-#include "base/tracked.h"
#include "base/threading/thread_local_storage.h"
// TrackedObjects provides a database of stats about objects (generally Tasks)
@@ -57,23 +58,24 @@
// freely accessed by any thread at any time (i.e., only the statistic needs to
// be handled carefully, and it is ONLY read or written by the birth thread).
//
-// Having now either constructed or found the Births instance described above, a
-// pointer to the Births instance is then embedded in a base class of the
-// instance we're tracking (usually a Task). This fact alone is very useful in
+// For Tasks, having now either constructed or found the Births instance
+// described above, a pointer to the Births instance is then recorded into the
+// PendingTask structure in MessageLoop. This fact alone is very useful in
// debugging, when there is a question of where an instance came from. In
-// addition, the birth time is also embedded in the base class Tracked (see
-// tracked.h), and used to later evaluate the lifetime duration.
-// As a result of the above embedding, we can (for any tracked instance) find
-// out its location of birth, and thread of birth, without using any locks, as
-// all that data is constant across the life of the process.
+// addition, the birth time is also recorded and used to later evaluate the
+// lifetime duration of the whole Task. As a result of the above embedding, we
+// can find out a Task's location of birth, and thread of birth, without using
+// any locks, as all that data is constant across the life of the process.
+//
+// This can also be done for any other object as well by calling
+// TallyABirthIfActive() and TallyADeathIfActive() as appropriate.
//
// The amount of memory used in the above data structures depends on how many
// threads there are, and how many Locations of construction there are.
// Fortunately, we don't use memory that is the product of those two counts, but
// rather we only need one Births instance for each thread that constructs an
-// instance at a Location. In many cases, instances (such as Tasks) are only
-// created on one thread, so the memory utilization is actually fairly
-// restrained.
+// instance at a Location. In many cases, instances are only created on one
+// thread, so the memory utilization is actually fairly restrained.
//
// Lastly, when an instance is deleted, the final tallies of statistics are
// carefully accumulated. That tallying wrties into slots (members) in a
@@ -147,9 +149,8 @@
// are 64bit quantities, and are not atomicly accessed (reset or incremented
// etc.). For basic profiling, this will work "most of the time," and should be
// sufficient... but storing away DataCollections is the "right way" to do this.
-//
-class MessageLoop;
+class MessageLoop;
namespace tracked_objects {
diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc
index e7d07a7..e10659d4 100644
--- a/base/tracked_objects_unittest.cc
+++ b/base/tracked_objects_unittest.cc
@@ -7,6 +7,7 @@
#include "base/tracked_objects.h"
#include "base/message_loop.h"
+#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace tracked_objects {
@@ -52,17 +53,13 @@ TEST_F(TrackedObjectsTest, MinimalStartupShutdown) {
ThreadData::ShutdownSingleThreadedCleanup();
}
-class NoopTracked : public tracked_objects::Tracked {
-};
-
TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
if (!ThreadData::StartTracking(true))
return;
// Instigate tracking on a single tracked object, or our thread.
const Location& location = FROM_HERE;
- NoopTracked tracked;
- tracked.SetBirthPlace(location);
+ ThreadData::TallyABirthIfActive(location);
const ThreadData* data = ThreadData::first();
ASSERT_TRUE(data);
@@ -78,9 +75,10 @@ TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
// Now instigate a birth, and a death.
- NoopTracked* new_tracked = new NoopTracked;
- new_tracked->SetBirthPlace(location);
- delete new_tracked;
+ const Births* second_birth = ThreadData::TallyABirthIfActive(location);
+ ThreadData::TallyADeathIfActive(
+ second_birth,
+ base::TimeDelta::FromSeconds(1) /* Bogus duration. */);
birth_map.clear();
data->SnapshotBirthMap(&birth_map);