Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1066)

Unified Diff: base/tracked_objects.h

Issue 8496008: Revert 108752 - Support tracking of IPC messages as tasks in profiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/profiler/tracked_time_unittest.cc ('k') | base/tracked_objects.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/tracked_objects.h
===================================================================
--- base/tracked_objects.h (revision 109003)
+++ base/tracked_objects.h (working copy)
@@ -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 @@
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 @@
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
« no previous file with comments | « base/profiler/tracked_time_unittest.cc ('k') | base/tracked_objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698