summaryrefslogtreecommitdiffstats
path: root/base/tracked_objects.h
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-08 10:46:48 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-08 10:46:48 +0000
commit9d43cd1f7d78bcb696401bd1ab7359a8d76fde81 (patch)
tree0e7912dd1372987a584f687fe263b248c03122aa /base/tracked_objects.h
parentab39dc873522a528d61532fe3ab98d0d012caaff (diff)
downloadchromium_src-9d43cd1f7d78bcb696401bd1ab7359a8d76fde81.zip
chromium_src-9d43cd1f7d78bcb696401bd1ab7359a8d76fde81.tar.gz
chromium_src-9d43cd1f7d78bcb696401bd1ab7359a8d76fde81.tar.bz2
Revert 108752 - Support tracking of IPC messages as tasks in profiler
Also started to do more cleanup, including creating a base/profiler directory, and moving parts of the over-sized tracked_objects.* into that directory. r=rtenneti Review URL: http://codereview.chromium.org/8480014 TBR=jar@chromium.org Review URL: http://codereview.chromium.org/8496008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/tracked_objects.h')
-rw-r--r--base/tracked_objects.h103
1 files changed, 94 insertions, 9 deletions
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 94766ea..e89bcf9 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -13,13 +13,16 @@
#include "base/base_export.h"
#include "base/location.h"
-#include "base/profiler/tracked_time.h"
#include "base/time.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_local_storage.h"
#include "base/tracking_info.h"
#include "base/values.h"
+#if defined(OS_WIN)
+#include <mmsystem.h> // Declare timeGetTime();
+#endif
+
// TrackedObjects provides a database of stats about objects (generally Tasks)
// that are tracked. Tracking means their birth, death, duration, birth thread,
// death thread, and birth place are recorded. This data is carefully spread
@@ -170,6 +173,96 @@ class MessageLoop;
namespace tracked_objects {
//------------------------------------------------------------------------------
+
+#define USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS
+
+#if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
+
+// TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on
+// windows, a 64 bit timer is expensive to even obtain. We use a simple
+// millisecond counter for most of our time values, as well as millisecond units
+// of duration between those values. This means we can only handle durations
+// up to 49 days (range), or 24 days (non-negative time durations).
+// We only define enough methods to service the needs of the tracking classes,
+// and our interfaces are modeled after what TimeTicks and TimeDelta use (so we
+// can swap them into place if we want to use the "real" classes).
+
+class BASE_EXPORT Duration { // Similar to base::TimeDelta.
+ public:
+ Duration() : ms_(0) {}
+
+ Duration& operator+=(const Duration& other) {
+ ms_ += other.ms_;
+ return *this;
+ }
+
+ Duration operator+(const Duration& other) const {
+ return Duration(ms_ + other.ms_);
+ }
+
+ bool operator==(const Duration& other) const { return ms_ == other.ms_; }
+ bool operator!=(const Duration& other) const { return ms_ != other.ms_; }
+ bool operator>(const Duration& other) const { return ms_ > other.ms_; }
+
+ static Duration FromMilliseconds(int ms) { return Duration(ms); }
+
+ int32 InMilliseconds() const { return ms_; }
+
+ private:
+ friend class TrackedTime;
+ explicit Duration(int32 duration) : ms_(duration) {}
+
+ // Internal time is stored directly in milliseconds.
+ int32 ms_;
+};
+
+class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks.
+ public:
+ TrackedTime() : ms_(0) {}
+ explicit TrackedTime(const base::TimeTicks& time)
+ : ms_((time - base::TimeTicks()).InMilliseconds()) {
+ }
+
+ static TrackedTime Now() {
+#if defined(OS_WIN)
+ // Use lock-free accessor to 32 bit time.
+ // Note that TimeTicks::Now() is built on this, so we have "compatible"
+ // times when we down-convert a TimeTicks sample.
+ // TODO(jar): Surface this interface via something in base/time.h.
+ return TrackedTime(static_cast<int32>(::timeGetTime()));
+#else
+ // Posix has nice cheap 64 bit times, so we just down-convert it.
+ return TrackedTime(base::TimeTicks::Now());
+#endif // OS_WIN
+ }
+
+ Duration operator-(const TrackedTime& other) const {
+ return Duration(ms_ - other.ms_);
+ }
+
+ TrackedTime operator+(const Duration& other) const {
+ return TrackedTime(ms_ + other.ms_);
+ }
+
+ bool is_null() const { return ms_ == 0; }
+
+ private:
+ friend class Duration;
+ explicit TrackedTime(int32 ms) : ms_(ms) {}
+
+ // Internal duration is stored directly in milliseconds.
+ uint32 ms_;
+};
+
+#else
+
+// Just use full 64 bit time calculations, and the slower TimeTicks::Now().
+typedef base::TimeTicks TrackedTime;
+typedef base::TimeDelta Duration;
+
+#endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS
+
+//------------------------------------------------------------------------------
// For a specific thread, and a specific birth place, the collection of all
// death info (with tallies for each death thread, to prevent access conflicts).
class ThreadData;
@@ -620,17 +713,9 @@ class BASE_EXPORT ThreadData {
const TrackedTime& start_of_run,
const TrackedTime& end_of_run);
- // Record the end of execution in region, generally corresponding to a scope
- // being exited.
- static void TallyRunInAScopedRegionIfTracking(
- const Births* birth,
- const TrackedTime& start_of_run,
- const TrackedTime& end_of_run);
-
const std::string thread_name() const { return thread_name_; }
// ---------------------
- // TODO(jar):
// The following functions should all be private, and are only public because
// the collection is done externally. We need to relocate that code from the
// collection class into this class, and then all these methods can be made