summaryrefslogtreecommitdiffstats
path: root/base/tracked_objects_unittest.cc
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_unittest.cc
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_unittest.cc')
-rw-r--r--base/tracked_objects_unittest.cc97
1 files changed, 97 insertions, 0 deletions
diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc
index de7451a..a46f4ed 100644
--- a/base/tracked_objects_unittest.cc
+++ b/base/tracked_objects_unittest.cc
@@ -634,5 +634,102 @@ TEST_F(TrackedObjectsTest, DifferentLives) {
EXPECT_EQ(one_line_result, json);
}
+TEST_F(TrackedObjectsTest, TrackedTimerMilliseconds) {
+ // First make sure we basicallly transfer simple milliseconds values as
+ // expected. Most critically, things should not become null.
+ int32 kSomeMilliseconds = 243; // Some example times.
+ int64 kReallyBigMilliseconds = (1LL << 35) + kSomeMilliseconds;
+
+ TrackedTime some = TrackedTime() +
+ Duration::FromMilliseconds(kSomeMilliseconds);
+ EXPECT_EQ(kSomeMilliseconds, (some - TrackedTime()).InMilliseconds());
+ EXPECT_FALSE(some.is_null());
+
+ // Now create a big time, to check that it is wrapped modulo 2^32.
+ base::TimeTicks big = base::TimeTicks() +
+ base::TimeDelta::FromMilliseconds(kReallyBigMilliseconds);
+ EXPECT_EQ(kReallyBigMilliseconds, (big - base::TimeTicks()).InMilliseconds());
+
+ TrackedTime wrapped_big(big);
+#if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
+ // Expect wrapping at 32 bits.
+ EXPECT_EQ(kSomeMilliseconds, (wrapped_big - TrackedTime()).InMilliseconds());
+#else // !USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
+ // Expect no wrapping at 32 bits.
+ EXPECT_EQ(kReallyBigMilliseconds,
+ (wrapped_big - TrackedTime()).InMilliseconds());
+#endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS)
+}
+
+TEST_F(TrackedObjectsTest, TrackedTimerDuration) {
+ int kFirstMilliseconds = 793;
+ int kSecondMilliseconds = 14889;
+
+ Duration first = Duration::FromMilliseconds(kFirstMilliseconds);
+ Duration second = Duration::FromMilliseconds(kSecondMilliseconds);
+
+ EXPECT_EQ(kFirstMilliseconds, first.InMilliseconds());
+ EXPECT_EQ(kSecondMilliseconds, second.InMilliseconds());
+
+ Duration sum = first + second;
+ EXPECT_EQ(kFirstMilliseconds + kSecondMilliseconds, sum.InMilliseconds());
+}
+
+TEST_F(TrackedObjectsTest, TrackedTimerVsTimeTicks) {
+ // Make sure that our 32 bit timer is aligned with the TimeTicks() timer.
+
+ // First get a 64 bit timer (which should not be null).
+ base::TimeTicks ticks_before = base::TimeTicks::Now();
+ EXPECT_FALSE(ticks_before.is_null());
+
+ // Then get a 32 bit timer that can be be null when it wraps.
+ TrackedTime now = TrackedTime::Now();
+
+ // Then get a bracketing time.
+ base::TimeTicks ticks_after = base::TimeTicks::Now();
+ EXPECT_FALSE(ticks_after.is_null());
+
+ // Now make sure that we bracketed our tracked time nicely.
+ Duration before = now - TrackedTime(ticks_before);
+ EXPECT_LE(0, before.InMilliseconds());
+ Duration after = now - TrackedTime(ticks_after);
+ EXPECT_GE(0, after.InMilliseconds());
+}
+
+TEST_F(TrackedObjectsTest, TrackedTimerDisabled) {
+ // Check to be sure disabling the collection of data induces a null time
+ // (which we know will return much faster).
+ if (!ThreadData::InitializeAndSetTrackingStatus(false))
+ return;
+ // Since we disabled tracking, we should get a null response.
+ TrackedTime track_now = ThreadData::Now();
+ EXPECT_TRUE(track_now.is_null());
+}
+
+TEST_F(TrackedObjectsTest, TrackedTimerEnabled) {
+ if (!ThreadData::InitializeAndSetTrackingStatus(true))
+ return;
+ // Make sure that when we enable tracking, we get a real timer result.
+
+ // First get a 64 bit timer (which should not be null).
+ base::TimeTicks ticks_before = base::TimeTicks::Now();
+ EXPECT_FALSE(ticks_before.is_null());
+
+ // Then get a 32 bit timer that can be null when it wraps.
+ // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use
+ // ThreadData::Now(). It can sometimes return the null time.
+ TrackedTime now = ThreadData::Now();
+
+ // Then get a bracketing time.
+ base::TimeTicks ticks_after = base::TimeTicks::Now();
+ EXPECT_FALSE(ticks_after.is_null());
+
+ // Now make sure that we bracketed our tracked time nicely.
+ Duration before = now - TrackedTime(ticks_before);
+ EXPECT_LE(0, before.InMilliseconds());
+ Duration after = now - TrackedTime(ticks_after);
+ EXPECT_GE(0, after.InMilliseconds());
+}
+
} // namespace tracked_objects