fischman@chromium.org | 998561e | 2012-01-24 07:56:41 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | // Test of classes in the tracked_objects.h classes. |
| 6 | |
| 7 | #include "base/tracked_objects.h" |
phajdan.jr@chromium.org | 6dce3c2 | 2009-06-04 00:01:29 +0900 | [diff] [blame] | 8 | |
mostynb@opera.com | f29dd61 | 2013-09-04 08:29:12 +0900 | [diff] [blame] | 9 | #include <stddef.h> |
| 10 | |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
rsesek@chromium.org | 687756f | 2013-07-26 06:38:23 +0900 | [diff] [blame] | 12 | #include "base/process/process_handle.h" |
avi@chromium.org | b45ec93 | 2013-06-29 00:14:18 +0900 | [diff] [blame] | 13 | #include "base/time/time.h" |
mostynb@opera.com | f29dd61 | 2013-09-04 08:29:12 +0900 | [diff] [blame] | 14 | #include "base/tracking_info.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
| 16 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 17 | const int kLineNumber = 1776; |
| 18 | const char kFile[] = "FixedUnitTestFileName"; |
| 19 | const char kWorkerThreadName[] = "WorkerThread-1"; |
| 20 | const char kMainThreadName[] = "SomeMainThreadName"; |
| 21 | const char kStillAlive[] = "Still_Alive"; |
| 22 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 23 | namespace tracked_objects { |
| 24 | |
| 25 | class TrackedObjectsTest : public testing::Test { |
jar@chromium.org | 7ad4a62 | 2011-11-07 04:14:48 +0900 | [diff] [blame] | 26 | protected: |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 27 | TrackedObjectsTest() { |
| 28 | // On entry, leak any database structures in case they are still in use by |
| 29 | // prior threads. |
| 30 | ThreadData::ShutdownSingleThreadedCleanup(true); |
| 31 | } |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 32 | |
rsleevi@chromium.org | de3a6cf | 2012-04-06 12:53:02 +0900 | [diff] [blame] | 33 | virtual ~TrackedObjectsTest() { |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 34 | // We should not need to leak any structures we create, since we are |
| 35 | // single threaded, and carefully accounting for items. |
| 36 | ThreadData::ShutdownSingleThreadedCleanup(false); |
| 37 | } |
jar@chromium.org | 7ad4a62 | 2011-11-07 04:14:48 +0900 | [diff] [blame] | 38 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 39 | // Reset the profiler state. |
| 40 | void Reset() { |
| 41 | ThreadData::ShutdownSingleThreadedCleanup(false); |
| 42 | } |
| 43 | |
| 44 | // Simulate a birth on the thread named |thread_name|, at the given |
| 45 | // |location|. |
| 46 | void TallyABirth(const Location& location, const std::string& thread_name) { |
| 47 | // If the |thread_name| is empty, we don't initialize system with a thread |
| 48 | // name, so we're viewed as a worker thread. |
| 49 | if (!thread_name.empty()) |
| 50 | ThreadData::InitializeThreadContext(kMainThreadName); |
| 51 | |
| 52 | // Do not delete |birth|. We don't own it. |
| 53 | Births* birth = ThreadData::TallyABirthIfActive(location); |
| 54 | |
| 55 | if (ThreadData::status() == ThreadData::DEACTIVATED) |
| 56 | EXPECT_EQ(reinterpret_cast<Births*>(NULL), birth); |
| 57 | else |
| 58 | EXPECT_NE(reinterpret_cast<Births*>(NULL), birth); |
| 59 | } |
| 60 | |
| 61 | // Helper function to verify the most common test expectations. |
| 62 | void ExpectSimpleProcessData(const ProcessDataSnapshot& process_data, |
| 63 | const std::string& function_name, |
| 64 | const std::string& birth_thread, |
| 65 | const std::string& death_thread, |
| 66 | int count, |
| 67 | int run_ms, |
| 68 | int queue_ms) { |
| 69 | ASSERT_EQ(1u, process_data.tasks.size()); |
| 70 | |
| 71 | EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); |
| 72 | EXPECT_EQ(function_name, |
| 73 | process_data.tasks[0].birth.location.function_name); |
| 74 | EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); |
| 75 | |
| 76 | EXPECT_EQ(birth_thread, process_data.tasks[0].birth.thread_name); |
| 77 | |
| 78 | EXPECT_EQ(count, process_data.tasks[0].death_data.count); |
| 79 | EXPECT_EQ(count * run_ms, |
| 80 | process_data.tasks[0].death_data.run_duration_sum); |
| 81 | EXPECT_EQ(run_ms, process_data.tasks[0].death_data.run_duration_max); |
| 82 | EXPECT_EQ(run_ms, process_data.tasks[0].death_data.run_duration_sample); |
| 83 | EXPECT_EQ(count * queue_ms, |
| 84 | process_data.tasks[0].death_data.queue_duration_sum); |
| 85 | EXPECT_EQ(queue_ms, process_data.tasks[0].death_data.queue_duration_max); |
| 86 | EXPECT_EQ(queue_ms, process_data.tasks[0].death_data.queue_duration_sample); |
| 87 | |
| 88 | EXPECT_EQ(death_thread, process_data.tasks[0].death_thread_name); |
| 89 | |
| 90 | EXPECT_EQ(0u, process_data.descendants.size()); |
| 91 | |
| 92 | EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
jar@chromium.org | 7ad4a62 | 2011-11-07 04:14:48 +0900 | [diff] [blame] | 93 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 94 | }; |
| 95 | |
darin@google.com | aca48f5 | 2008-08-26 15:44:38 +0900 | [diff] [blame] | 96 | TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 97 | // Minimal test doesn't even create any tasks. |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 98 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 99 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 100 | return; |
| 101 | |
| 102 | EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
jar@chromium.org | 79a58c3 | 2011-10-16 08:52:45 +0900 | [diff] [blame] | 103 | ThreadData* data = ThreadData::Get(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 104 | EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 105 | ASSERT_TRUE(data); |
| 106 | EXPECT_FALSE(data->next()); |
jar@chromium.org | 79a58c3 | 2011-10-16 08:52:45 +0900 | [diff] [blame] | 107 | EXPECT_EQ(data, ThreadData::Get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 108 | ThreadData::BirthMap birth_map; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 109 | ThreadData::DeathMap death_map; |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 110 | ThreadData::ParentChildSet parent_child_set; |
| 111 | data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 112 | EXPECT_EQ(0u, birth_map.size()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 113 | EXPECT_EQ(0u, death_map.size()); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 114 | EXPECT_EQ(0u, parent_child_set.size()); |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 115 | |
| 116 | // Clean up with no leaking. |
| 117 | Reset(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 118 | |
| 119 | // Do it again, just to be sure we reset state completely. |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 120 | EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 121 | ThreadData::PROFILING_CHILDREN_ACTIVE)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 122 | EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
jar@chromium.org | 79a58c3 | 2011-10-16 08:52:45 +0900 | [diff] [blame] | 123 | data = ThreadData::Get(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 124 | EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 125 | ASSERT_TRUE(data); |
| 126 | EXPECT_FALSE(data->next()); |
jar@chromium.org | 79a58c3 | 2011-10-16 08:52:45 +0900 | [diff] [blame] | 127 | EXPECT_EQ(data, ThreadData::Get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 128 | birth_map.clear(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 129 | death_map.clear(); |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 130 | parent_child_set.clear(); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 131 | data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 132 | EXPECT_EQ(0u, birth_map.size()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 133 | EXPECT_EQ(0u, death_map.size()); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 134 | EXPECT_EQ(0u, parent_child_set.size()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 135 | } |
| 136 | |
darin@google.com | aca48f5 | 2008-08-26 15:44:38 +0900 | [diff] [blame] | 137 | TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 138 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 139 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 140 | return; |
| 141 | |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 142 | // Instigate tracking on a single tracked object, on our thread. |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 143 | const char kFunction[] = "TinyStartupShutdown"; |
| 144 | Location location(kFunction, kFile, kLineNumber, NULL); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 145 | Births* first_birth = ThreadData::TallyABirthIfActive(location); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 146 | |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 147 | ThreadData* data = ThreadData::first(); |
ajwong@chromium.org | 7211f7d | 2011-06-24 08:20:39 +0900 | [diff] [blame] | 148 | ASSERT_TRUE(data); |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 149 | EXPECT_FALSE(data->next()); |
jar@chromium.org | 79a58c3 | 2011-10-16 08:52:45 +0900 | [diff] [blame] | 150 | EXPECT_EQ(data, ThreadData::Get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 151 | ThreadData::BirthMap birth_map; |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 152 | ThreadData::DeathMap death_map; |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 153 | ThreadData::ParentChildSet parent_child_set; |
| 154 | data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 155 | EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 156 | EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 157 | EXPECT_EQ(0u, death_map.size()); // No deaths. |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 158 | EXPECT_EQ(0u, parent_child_set.size()); // No children. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 159 | |
| 160 | |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 161 | // Now instigate another birth, while we are timing the run of the first |
| 162 | // execution. |
isherman@chromium.org | 514b634 | 2012-04-13 10:48:35 +0900 | [diff] [blame] | 163 | ThreadData::NowForStartOfRun(first_birth); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 164 | // Create a child (using the same birth location). |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 165 | // TrackingInfo will call TallyABirth() during construction. |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 166 | base::TimeTicks kBogusBirthTime; |
| 167 | base::TrackingInfo pending_task(location, kBogusBirthTime); |
isherman@chromium.org | 514b634 | 2012-04-13 10:48:35 +0900 | [diff] [blame] | 168 | TrackedTime start_time(pending_task.time_posted); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 169 | // Finally conclude the outer run. |
| 170 | TrackedTime end_time = ThreadData::NowForEndOfRun(); |
| 171 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, start_time, |
| 172 | end_time); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 173 | |
| 174 | birth_map.clear(); |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 175 | death_map.clear(); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 176 | parent_child_set.clear(); |
| 177 | data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 178 | EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 179 | EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 180 | EXPECT_EQ(1u, death_map.size()); // 1 location. |
| 181 | EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 182 | if (ThreadData::TrackingParentChildStatus()) { |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 183 | EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 184 | EXPECT_EQ(parent_child_set.begin()->first, |
| 185 | parent_child_set.begin()->second); |
| 186 | } else { |
| 187 | EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
| 188 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 189 | |
| 190 | // The births were at the same location as the one known death. |
| 191 | EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
| 192 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 193 | ProcessDataSnapshot process_data; |
| 194 | ThreadData::Snapshot(false, &process_data); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 195 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 196 | const int32 time_elapsed = (end_time - start_time).InMilliseconds(); |
| 197 | ASSERT_EQ(1u, process_data.tasks.size()); |
| 198 | EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); |
| 199 | EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); |
| 200 | EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); |
| 201 | EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].birth.thread_name); |
| 202 | EXPECT_EQ(1, process_data.tasks[0].death_data.count); |
| 203 | EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sum); |
| 204 | EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_max); |
| 205 | EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sample); |
| 206 | EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_sum); |
| 207 | EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_max); |
| 208 | EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_sample); |
| 209 | EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].death_thread_name); |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 210 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 211 | if (ThreadData::TrackingParentChildStatus()) { |
| 212 | ASSERT_EQ(1u, process_data.descendants.size()); |
| 213 | EXPECT_EQ(kFile, process_data.descendants[0].parent.location.file_name); |
| 214 | EXPECT_EQ(kFunction, |
| 215 | process_data.descendants[0].parent.location.function_name); |
| 216 | EXPECT_EQ(kLineNumber, |
| 217 | process_data.descendants[0].parent.location.line_number); |
| 218 | EXPECT_EQ(kWorkerThreadName, |
| 219 | process_data.descendants[0].parent.thread_name); |
| 220 | EXPECT_EQ(kFile, process_data.descendants[0].child.location.file_name); |
| 221 | EXPECT_EQ(kFunction, |
| 222 | process_data.descendants[0].child.location.function_name); |
| 223 | EXPECT_EQ(kLineNumber, |
| 224 | process_data.descendants[0].child.location.line_number); |
| 225 | EXPECT_EQ(kWorkerThreadName, process_data.descendants[0].child.thread_name); |
| 226 | } else { |
| 227 | EXPECT_EQ(0u, process_data.descendants.size()); |
| 228 | } |
jar@chromium.org | b5c974b | 2011-12-14 10:36:48 +0900 | [diff] [blame] | 229 | } |
| 230 | |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 231 | TEST_F(TrackedObjectsTest, DeathDataTest) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 232 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 233 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 234 | return; |
| 235 | |
| 236 | scoped_ptr<DeathData> data(new DeathData()); |
| 237 | ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 238 | EXPECT_EQ(data->run_duration_sum(), 0); |
| 239 | EXPECT_EQ(data->run_duration_sample(), 0); |
| 240 | EXPECT_EQ(data->queue_duration_sum(), 0); |
| 241 | EXPECT_EQ(data->queue_duration_sample(), 0); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 242 | EXPECT_EQ(data->count(), 0); |
| 243 | |
isherman@chromium.org | 3306fc0 | 2012-03-25 07:17:18 +0900 | [diff] [blame] | 244 | int32 run_ms = 42; |
| 245 | int32 queue_ms = 8; |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 246 | |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 247 | const int kUnrandomInt = 0; // Fake random int that ensure we sample data. |
| 248 | data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 249 | EXPECT_EQ(data->run_duration_sum(), run_ms); |
| 250 | EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 251 | EXPECT_EQ(data->queue_duration_sum(), queue_ms); |
| 252 | EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 253 | EXPECT_EQ(data->count(), 1); |
| 254 | |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 255 | data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 256 | EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); |
| 257 | EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 258 | EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 259 | EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 260 | EXPECT_EQ(data->count(), 2); |
| 261 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 262 | DeathDataSnapshot snapshot(*data); |
| 263 | EXPECT_EQ(2, snapshot.count); |
| 264 | EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum); |
| 265 | EXPECT_EQ(run_ms, snapshot.run_duration_max); |
| 266 | EXPECT_EQ(run_ms, snapshot.run_duration_sample); |
| 267 | EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); |
| 268 | EXPECT_EQ(queue_ms, snapshot.queue_duration_max); |
| 269 | EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 270 | } |
| 271 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 272 | TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 273 | // Start in the deactivated state. |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 274 | if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 275 | return; |
| 276 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 277 | const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; |
| 278 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 279 | TallyABirth(location, std::string()); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 280 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 281 | ProcessDataSnapshot process_data; |
| 282 | ThreadData::Snapshot(false, &process_data); |
| 283 | EXPECT_EQ(0u, process_data.tasks.size()); |
| 284 | EXPECT_EQ(0u, process_data.descendants.size()); |
| 285 | EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 286 | } |
| 287 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 288 | TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { |
| 289 | // Start in the deactivated state. |
| 290 | if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 291 | return; |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 292 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 293 | const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; |
| 294 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 295 | TallyABirth(location, kMainThreadName); |
| 296 | |
| 297 | ProcessDataSnapshot process_data; |
| 298 | ThreadData::Snapshot(false, &process_data); |
| 299 | EXPECT_EQ(0u, process_data.tasks.size()); |
| 300 | EXPECT_EQ(0u, process_data.descendants.size()); |
| 301 | EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 302 | } |
| 303 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 304 | TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 305 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 306 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 307 | return; |
| 308 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 309 | const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; |
| 310 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 311 | TallyABirth(location, std::string()); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 312 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 313 | ProcessDataSnapshot process_data; |
| 314 | ThreadData::Snapshot(false, &process_data); |
| 315 | ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 316 | kStillAlive, 1, 0, 0); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 317 | } |
| 318 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 319 | TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 320 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 321 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 322 | return; |
| 323 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 324 | const char kFunction[] = "BirthOnlyToSnapshotMainThread"; |
| 325 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 326 | TallyABirth(location, kMainThreadName); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 327 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 328 | ProcessDataSnapshot process_data; |
| 329 | ThreadData::Snapshot(false, &process_data); |
| 330 | ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, |
| 331 | 1, 0, 0); |
| 332 | } |
| 333 | |
| 334 | TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
| 335 | if (!ThreadData::InitializeAndSetTrackingStatus( |
| 336 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 337 | return; |
| 338 | |
| 339 | const char kFunction[] = "LifeCycleToSnapshotMainThread"; |
| 340 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 341 | TallyABirth(location, kMainThreadName); |
| 342 | |
| 343 | const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 344 | base::TimeDelta::FromMilliseconds(1); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 345 | const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 346 | // TrackingInfo will call TallyABirth() during construction. |
| 347 | base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 348 | pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 349 | |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 350 | const TrackedTime kStartOfRun = TrackedTime() + |
| 351 | Duration::FromMilliseconds(5); |
| 352 | const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 353 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 354 | kStartOfRun, kEndOfRun); |
| 355 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 356 | ProcessDataSnapshot process_data; |
| 357 | ThreadData::Snapshot(false, &process_data); |
| 358 | ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 359 | kMainThreadName, 1, 2, 4); |
jar@chromium.org | 173e386 | 2011-10-30 12:44:25 +0900 | [diff] [blame] | 360 | } |
| 361 | |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 362 | // We will deactivate tracking after the birth, and before the death, and |
| 363 | // demonstrate that the lifecycle is completely tallied. This ensures that |
| 364 | // our tallied births are matched by tallied deaths (except for when the |
| 365 | // task is still running, or is queued). |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 366 | TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 367 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 368 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 173e386 | 2011-10-30 12:44:25 +0900 | [diff] [blame] | 369 | return; |
| 370 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 371 | const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
| 372 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 373 | TallyABirth(location, kMainThreadName); |
jar@chromium.org | 173e386 | 2011-10-30 12:44:25 +0900 | [diff] [blame] | 374 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 375 | const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 376 | base::TimeDelta::FromMilliseconds(1); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 377 | const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 378 | // TrackingInfo will call TallyABirth() during construction. |
| 379 | base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 380 | pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
jar@chromium.org | 173e386 | 2011-10-30 12:44:25 +0900 | [diff] [blame] | 381 | |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 382 | // Turn off tracking now that we have births. |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 383 | EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 384 | ThreadData::DEACTIVATED)); |
jar@chromium.org | 173e386 | 2011-10-30 12:44:25 +0900 | [diff] [blame] | 385 | |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 386 | const TrackedTime kStartOfRun = TrackedTime() + |
| 387 | Duration::FromMilliseconds(5); |
| 388 | const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 389 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 390 | kStartOfRun, kEndOfRun); |
| 391 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 392 | ProcessDataSnapshot process_data; |
| 393 | ThreadData::Snapshot(false, &process_data); |
| 394 | ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 395 | kMainThreadName, 1, 2, 4); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // We will deactivate tracking before starting a life cycle, and neither |
| 399 | // the birth nor the death will be recorded. |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 400 | TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { |
| 401 | // Start in the deactivated state. |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 402 | if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 403 | return; |
| 404 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 405 | const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; |
| 406 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 407 | TallyABirth(location, kMainThreadName); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 408 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 409 | const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 410 | base::TimeDelta::FromMilliseconds(1); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 411 | const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 412 | // TrackingInfo will call TallyABirth() during construction. |
| 413 | base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 414 | pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 415 | |
| 416 | const TrackedTime kStartOfRun = TrackedTime() + |
| 417 | Duration::FromMilliseconds(5); |
| 418 | const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 419 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 420 | kStartOfRun, kEndOfRun); |
| 421 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 422 | ProcessDataSnapshot process_data; |
| 423 | ThreadData::Snapshot(false, &process_data); |
| 424 | EXPECT_EQ(0u, process_data.tasks.size()); |
| 425 | EXPECT_EQ(0u, process_data.descendants.size()); |
| 426 | EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 427 | } |
| 428 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 429 | TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 430 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 431 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 432 | return; |
| 433 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 434 | const char kFunction[] = "LifeCycleToSnapshotWorkerThread"; |
| 435 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 436 | // Do not delete |birth|. We don't own it. |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 437 | Births* birth = ThreadData::TallyABirthIfActive(location); |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 438 | EXPECT_NE(reinterpret_cast<Births*>(NULL), birth); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 439 | |
| 440 | const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); |
| 441 | const TrackedTime kStartOfRun = TrackedTime() + |
| 442 | Duration::FromMilliseconds(5); |
| 443 | const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 444 | ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, |
| 445 | kStartOfRun, kEndOfRun); |
| 446 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 447 | // Call for the ToSnapshot, but tell it to not reset the maxes after scanning. |
| 448 | ProcessDataSnapshot process_data; |
| 449 | ThreadData::Snapshot(false, &process_data); |
| 450 | ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 451 | kWorkerThreadName, 1, 2, 4); |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 452 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 453 | // Call for the ToSnapshot, but tell it to reset the maxes after scanning. |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 454 | // We'll still get the same values, but the data will be reset (which we'll |
| 455 | // see in a moment). |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 456 | ProcessDataSnapshot process_data_pre_reset; |
| 457 | ThreadData::Snapshot(true, &process_data_pre_reset); |
| 458 | ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 459 | kWorkerThreadName, 1, 2, 4); |
jar@chromium.org | a026041 | 2011-12-04 16:19:10 +0900 | [diff] [blame] | 460 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 461 | // Call for the ToSnapshot, and now we'll see the result of the last |
| 462 | // translation, as the max will have been pushed back to zero. |
| 463 | ProcessDataSnapshot process_data_post_reset; |
| 464 | ThreadData::Snapshot(true, &process_data_post_reset); |
| 465 | ASSERT_EQ(1u, process_data_post_reset.tasks.size()); |
| 466 | EXPECT_EQ(kFile, process_data_post_reset.tasks[0].birth.location.file_name); |
| 467 | EXPECT_EQ(kFunction, |
| 468 | process_data_post_reset.tasks[0].birth.location.function_name); |
| 469 | EXPECT_EQ(kLineNumber, |
| 470 | process_data_post_reset.tasks[0].birth.location.line_number); |
| 471 | EXPECT_EQ(kWorkerThreadName, |
| 472 | process_data_post_reset.tasks[0].birth.thread_name); |
| 473 | EXPECT_EQ(1, process_data_post_reset.tasks[0].death_data.count); |
| 474 | EXPECT_EQ(2, process_data_post_reset.tasks[0].death_data.run_duration_sum); |
| 475 | EXPECT_EQ(0, process_data_post_reset.tasks[0].death_data.run_duration_max); |
| 476 | EXPECT_EQ(2, process_data_post_reset.tasks[0].death_data.run_duration_sample); |
| 477 | EXPECT_EQ(4, process_data_post_reset.tasks[0].death_data.queue_duration_sum); |
| 478 | EXPECT_EQ(0, process_data_post_reset.tasks[0].death_data.queue_duration_max); |
| 479 | EXPECT_EQ(4, |
| 480 | process_data_post_reset.tasks[0].death_data.queue_duration_sample); |
| 481 | EXPECT_EQ(kWorkerThreadName, |
| 482 | process_data_post_reset.tasks[0].death_thread_name); |
| 483 | EXPECT_EQ(0u, process_data_post_reset.descendants.size()); |
| 484 | EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | TEST_F(TrackedObjectsTest, TwoLives) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 488 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 489 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 490 | return; |
| 491 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 492 | const char kFunction[] = "TwoLives"; |
| 493 | Location location(kFunction, kFile, kLineNumber, NULL); |
| 494 | TallyABirth(location, kMainThreadName); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 495 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 496 | const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 497 | base::TimeDelta::FromMilliseconds(1); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 498 | const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 499 | // TrackingInfo will call TallyABirth() during construction. |
| 500 | base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 501 | pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 502 | |
| 503 | const TrackedTime kStartOfRun = TrackedTime() + |
| 504 | Duration::FromMilliseconds(5); |
| 505 | const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 506 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 507 | kStartOfRun, kEndOfRun); |
| 508 | |
| 509 | // TrackingInfo will call TallyABirth() during construction. |
| 510 | base::TrackingInfo pending_task2(location, kDelayedStartTime); |
| 511 | pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 512 | |
| 513 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, |
| 514 | kStartOfRun, kEndOfRun); |
| 515 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 516 | ProcessDataSnapshot process_data; |
| 517 | ThreadData::Snapshot(false, &process_data); |
| 518 | ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 519 | kMainThreadName, 2, 2, 4); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | TEST_F(TrackedObjectsTest, DifferentLives) { |
jar@chromium.org | 23b0072 | 2012-02-11 04:43:42 +0900 | [diff] [blame] | 523 | if (!ThreadData::InitializeAndSetTrackingStatus( |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 524 | ThreadData::PROFILING_CHILDREN_ACTIVE)) |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 525 | return; |
| 526 | |
| 527 | // Use a well named thread. |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 528 | ThreadData::InitializeThreadContext(kMainThreadName); |
| 529 | const char kFunction[] = "DifferentLives"; |
| 530 | Location location(kFunction, kFile, kLineNumber, NULL); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 531 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 532 | const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 533 | base::TimeDelta::FromMilliseconds(1); |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 534 | const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 535 | // TrackingInfo will call TallyABirth() during construction. |
| 536 | base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 537 | pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 538 | |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 539 | const TrackedTime kStartOfRun = TrackedTime() + |
| 540 | Duration::FromMilliseconds(5); |
| 541 | const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 542 | ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 543 | kStartOfRun, kEndOfRun); |
jar@chromium.org | 666ef9c | 2011-10-25 03:55:16 +0900 | [diff] [blame] | 544 | |
jar@chromium.org | 4be2cb0 | 2011-11-01 07:36:21 +0900 | [diff] [blame] | 545 | const int kSecondFakeLineNumber = 999; |
| 546 | Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 547 | |
| 548 | // TrackingInfo will call TallyABirth() during construction. |
| 549 | base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 550 | pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 551 | |
isherman@chromium.org | 98c10d2 | 2012-04-13 09:39:26 +0900 | [diff] [blame] | 552 | ProcessDataSnapshot process_data; |
| 553 | ThreadData::Snapshot(false, &process_data); |
| 554 | ASSERT_EQ(2u, process_data.tasks.size()); |
| 555 | EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); |
| 556 | EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); |
| 557 | EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); |
| 558 | EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name); |
| 559 | EXPECT_EQ(1, process_data.tasks[0].death_data.count); |
| 560 | EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sum); |
| 561 | EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_max); |
| 562 | EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sample); |
| 563 | EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sum); |
| 564 | EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_max); |
| 565 | EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sample); |
| 566 | EXPECT_EQ(kMainThreadName, process_data.tasks[0].death_thread_name); |
| 567 | EXPECT_EQ(kFile, process_data.tasks[1].birth.location.file_name); |
| 568 | EXPECT_EQ(kFunction, process_data.tasks[1].birth.location.function_name); |
| 569 | EXPECT_EQ(kSecondFakeLineNumber, |
| 570 | process_data.tasks[1].birth.location.line_number); |
| 571 | EXPECT_EQ(kMainThreadName, process_data.tasks[1].birth.thread_name); |
| 572 | EXPECT_EQ(1, process_data.tasks[1].death_data.count); |
| 573 | EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sum); |
| 574 | EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max); |
| 575 | EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sample); |
| 576 | EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sum); |
| 577 | EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_max); |
| 578 | EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample); |
| 579 | EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name); |
| 580 | EXPECT_EQ(0u, process_data.descendants.size()); |
| 581 | EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 582 | } |
| 583 | |
deanm@google.com | 11f192a | 2008-08-26 20:29:01 +0900 | [diff] [blame] | 584 | } // namespace tracked_objects |