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

Unified Diff: base/profiler/tracked_time.h

Issue 8480014: Support tracking of IPC messages as tasks in profiler (Closed) Base URL: svn://chrome-svn/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/scoped_profile.cc ('k') | base/profiler/tracked_time.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/profiler/tracked_time.h
===================================================================
--- base/profiler/tracked_time.h (revision 0)
+++ base/profiler/tracked_time.h (revision 0)
@@ -0,0 +1,84 @@
+// 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.
+
+#ifndef BASE_PROFILER_TRACKED_TIME_H_
+#define BASE_PROFILER_TRACKED_TIME_H_
+
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+#include "base/time.h"
+
+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();
+
+ Duration& operator+=(const Duration& other);
+ Duration operator+(const Duration& other) const;
+
+ bool operator==(const Duration& other) const;
+ bool operator!=(const Duration& other) const;
+ bool operator>(const Duration& other) const;
+
+ static Duration FromMilliseconds(int ms);
+
+ int32 InMilliseconds() const;
+
+ private:
+ friend class TrackedTime;
+ explicit Duration(int32 duration);
+
+ // Internal time is stored directly in milliseconds.
+ int32 ms_;
+};
+
+class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks.
+ public:
+ TrackedTime();
+ explicit TrackedTime(const base::TimeTicks& time);
+
+ static TrackedTime Now();
+ Duration operator-(const TrackedTime& other) const;
+ TrackedTime operator+(const Duration& other) const;
+ bool is_null() const;
+
+ private:
+ friend class Duration;
+ explicit TrackedTime(int32 ms);
+
+ // Internal duration is stored directly in milliseconds.
+ uint32 ms_;
+};
+
+#else
+
+// Just use full 64 bit time calculations, and the slower TimeTicks::Now().
+// This allows us (as an alternative) to test with larger ranges of times, and
+// with a more thoroughly tested class.
+
+typedef base::TimeTicks TrackedTime;
+typedef base::TimeDelta Duration;
+
+#endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS
+
+} // namespace tracked_objects
+
+#endif // BASE_PROFILER_TRACKED_TIME_H_
« no previous file with comments | « base/profiler/scoped_profile.cc ('k') | base/profiler/tracked_time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698