| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
| 6 | 6 |
| 7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 const char kStillAlive[] = "Still_Alive"; | 21 const char kStillAlive[] = "Still_Alive"; |
| 22 | 22 |
| 23 namespace tracked_objects { | 23 namespace tracked_objects { |
| 24 | 24 |
| 25 class TrackedObjectsTest : public testing::Test { | 25 class TrackedObjectsTest : public testing::Test { |
| 26 protected: | 26 protected: |
| 27 TrackedObjectsTest() { | 27 TrackedObjectsTest() { |
| 28 // On entry, leak any database structures in case they are still in use by | 28 // On entry, leak any database structures in case they are still in use by |
| 29 // prior threads. | 29 // prior threads. |
| 30 ThreadData::ShutdownSingleThreadedCleanup(true); | 30 ThreadData::ShutdownSingleThreadedCleanup(true); |
| 31 |
| 32 test_time_ = 0; |
| 33 ThreadData::SetAlternateTimeSource(&TrackedObjectsTest::GetTestTime); |
| 34 ThreadData::now_function_is_time_ = true; |
| 31 } | 35 } |
| 32 | 36 |
| 33 virtual ~TrackedObjectsTest() { | 37 virtual ~TrackedObjectsTest() { |
| 34 // We should not need to leak any structures we create, since we are | 38 // We should not need to leak any structures we create, since we are |
| 35 // single threaded, and carefully accounting for items. | 39 // single threaded, and carefully accounting for items. |
| 36 ThreadData::ShutdownSingleThreadedCleanup(false); | 40 ThreadData::ShutdownSingleThreadedCleanup(false); |
| 37 } | 41 } |
| 38 | 42 |
| 39 // Reset the profiler state. | 43 // Reset the profiler state. |
| 40 void Reset() { | 44 void Reset() { |
| 41 ThreadData::ShutdownSingleThreadedCleanup(false); | 45 ThreadData::ShutdownSingleThreadedCleanup(false); |
| 46 test_time_ = 0; |
| 42 } | 47 } |
| 43 | 48 |
| 44 // Simulate a birth on the thread named |thread_name|, at the given | 49 // Simulate a birth on the thread named |thread_name|, at the given |
| 45 // |location|. | 50 // |location|. |
| 46 void TallyABirth(const Location& location, const std::string& thread_name) { | 51 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 | 52 // If the |thread_name| is empty, we don't initialize system with a thread |
| 48 // name, so we're viewed as a worker thread. | 53 // name, so we're viewed as a worker thread. |
| 49 if (!thread_name.empty()) | 54 if (!thread_name.empty()) |
| 50 ThreadData::InitializeThreadContext(kMainThreadName); | 55 ThreadData::InitializeThreadContext(kMainThreadName); |
| 51 | 56 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 process_data.tasks[0].death_data.queue_duration_sum); | 89 process_data.tasks[0].death_data.queue_duration_sum); |
| 85 EXPECT_EQ(queue_ms, process_data.tasks[0].death_data.queue_duration_max); | 90 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); | 91 EXPECT_EQ(queue_ms, process_data.tasks[0].death_data.queue_duration_sample); |
| 87 | 92 |
| 88 EXPECT_EQ(death_thread, process_data.tasks[0].death_thread_name); | 93 EXPECT_EQ(death_thread, process_data.tasks[0].death_thread_name); |
| 89 | 94 |
| 90 EXPECT_EQ(0u, process_data.descendants.size()); | 95 EXPECT_EQ(0u, process_data.descendants.size()); |
| 91 | 96 |
| 92 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 97 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 93 } | 98 } |
| 99 |
| 100 // Sets time that will be returned by ThreadData::Now(). |
| 101 static void SetTestTime(unsigned int test_time) { test_time_ = test_time; } |
| 102 |
| 103 private: |
| 104 // Returns test time in milliseconds. |
| 105 static unsigned int GetTestTime() { return test_time_; } |
| 106 |
| 107 // Test time in milliseconds. |
| 108 static unsigned int test_time_; |
| 94 }; | 109 }; |
| 95 | 110 |
| 111 // static |
| 112 unsigned int TrackedObjectsTest::test_time_; |
| 113 |
| 114 |
| 96 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { | 115 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
| 97 // Minimal test doesn't even create any tasks. | 116 // Minimal test doesn't even create any tasks. |
| 98 if (!ThreadData::InitializeAndSetTrackingStatus( | 117 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 99 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 118 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 100 return; | 119 return; |
| 120 } |
| 101 | 121 |
| 102 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 122 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 103 ThreadData* data = ThreadData::Get(); | 123 ThreadData* data = ThreadData::Get(); |
| 104 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 124 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 105 ASSERT_TRUE(data); | 125 ASSERT_TRUE(data); |
| 106 EXPECT_FALSE(data->next()); | 126 EXPECT_FALSE(data->next()); |
| 107 EXPECT_EQ(data, ThreadData::Get()); | 127 EXPECT_EQ(data, ThreadData::Get()); |
| 108 ThreadData::BirthMap birth_map; | 128 ThreadData::BirthMap birth_map; |
| 109 ThreadData::DeathMap death_map; | 129 ThreadData::DeathMap death_map; |
| 110 ThreadData::ParentChildSet parent_child_set; | 130 ThreadData::ParentChildSet parent_child_set; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 death_map.clear(); | 149 death_map.clear(); |
| 130 parent_child_set.clear(); | 150 parent_child_set.clear(); |
| 131 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 151 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 132 EXPECT_EQ(0u, birth_map.size()); | 152 EXPECT_EQ(0u, birth_map.size()); |
| 133 EXPECT_EQ(0u, death_map.size()); | 153 EXPECT_EQ(0u, death_map.size()); |
| 134 EXPECT_EQ(0u, parent_child_set.size()); | 154 EXPECT_EQ(0u, parent_child_set.size()); |
| 135 } | 155 } |
| 136 | 156 |
| 137 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 157 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
| 138 if (!ThreadData::InitializeAndSetTrackingStatus( | 158 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 139 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 159 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 140 return; | 160 return; |
| 161 } |
| 141 | 162 |
| 142 // Instigate tracking on a single tracked object, on our thread. | 163 // Instigate tracking on a single tracked object, on our thread. |
| 143 const char kFunction[] = "TinyStartupShutdown"; | 164 const char kFunction[] = "TinyStartupShutdown"; |
| 144 Location location(kFunction, kFile, kLineNumber, NULL); | 165 Location location(kFunction, kFile, kLineNumber, NULL); |
| 145 Births* first_birth = ThreadData::TallyABirthIfActive(location); | 166 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
| 146 | 167 |
| 147 ThreadData* data = ThreadData::first(); | 168 ThreadData* data = ThreadData::first(); |
| 148 ASSERT_TRUE(data); | 169 ASSERT_TRUE(data); |
| 149 EXPECT_FALSE(data->next()); | 170 EXPECT_FALSE(data->next()); |
| 150 EXPECT_EQ(data, ThreadData::Get()); | 171 EXPECT_EQ(data, ThreadData::Get()); |
| 151 ThreadData::BirthMap birth_map; | 172 ThreadData::BirthMap birth_map; |
| 152 ThreadData::DeathMap death_map; | 173 ThreadData::DeathMap death_map; |
| 153 ThreadData::ParentChildSet parent_child_set; | 174 ThreadData::ParentChildSet parent_child_set; |
| 154 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 175 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 155 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 176 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 156 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 177 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 157 EXPECT_EQ(0u, death_map.size()); // No deaths. | 178 EXPECT_EQ(0u, death_map.size()); // No deaths. |
| 158 EXPECT_EQ(0u, parent_child_set.size()); // No children. | 179 EXPECT_EQ(0u, parent_child_set.size()); // No children. |
| 159 | 180 |
| 160 | 181 |
| 161 // Now instigate another birth, while we are timing the run of the first | 182 // Now instigate another birth, while we are timing the run of the first |
| 162 // execution. | 183 // execution. |
| 163 ThreadData::NowForStartOfRun(first_birth); | 184 ThreadData::PrepareForStartOfRun(first_birth); |
| 164 // Create a child (using the same birth location). | 185 // Create a child (using the same birth location). |
| 165 // TrackingInfo will call TallyABirth() during construction. | 186 // TrackingInfo will call TallyABirth() during construction. |
| 166 base::TimeTicks kBogusBirthTime; | 187 const int32 start_time = 1; |
| 188 base::TimeTicks kBogusBirthTime = base::TimeTicks() + |
| 189 base::TimeDelta::FromMilliseconds(start_time); |
| 167 base::TrackingInfo pending_task(location, kBogusBirthTime); | 190 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 168 TrackedTime start_time(pending_task.time_posted); | 191 SetTestTime(1); |
| 192 TaskStopwatch stopwatch; |
| 169 // Finally conclude the outer run. | 193 // Finally conclude the outer run. |
| 170 TrackedTime end_time = ThreadData::NowForEndOfRun(); | 194 const int32 time_elapsed = 1000; |
| 171 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, start_time, | 195 SetTestTime(start_time + time_elapsed); |
| 172 end_time); | 196 stopwatch.Stop(); |
| 197 |
| 198 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 173 | 199 |
| 174 birth_map.clear(); | 200 birth_map.clear(); |
| 175 death_map.clear(); | 201 death_map.clear(); |
| 176 parent_child_set.clear(); | 202 parent_child_set.clear(); |
| 177 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 203 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 178 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 204 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 179 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 205 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 180 EXPECT_EQ(1u, death_map.size()); // 1 location. | 206 EXPECT_EQ(1u, death_map.size()); // 1 location. |
| 181 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 207 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
| 182 if (ThreadData::TrackingParentChildStatus()) { | 208 if (ThreadData::TrackingParentChildStatus()) { |
| 183 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 209 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 184 EXPECT_EQ(parent_child_set.begin()->first, | 210 EXPECT_EQ(parent_child_set.begin()->first, |
| 185 parent_child_set.begin()->second); | 211 parent_child_set.begin()->second); |
| 186 } else { | 212 } else { |
| 187 EXPECT_EQ(0u, parent_child_set.size()); // no stats. | 213 EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
| 188 } | 214 } |
| 189 | 215 |
| 190 // The births were at the same location as the one known death. | 216 // The births were at the same location as the one known death. |
| 191 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 217 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
| 192 | 218 |
| 193 ProcessDataSnapshot process_data; | 219 ProcessDataSnapshot process_data; |
| 194 ThreadData::Snapshot(false, &process_data); | 220 ThreadData::Snapshot(false, &process_data); |
| 195 | 221 |
| 196 const int32 time_elapsed = (end_time - start_time).InMilliseconds(); | |
| 197 ASSERT_EQ(1u, process_data.tasks.size()); | 222 ASSERT_EQ(1u, process_data.tasks.size()); |
| 198 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); | 223 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); |
| 199 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); | 224 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); |
| 200 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); | 225 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); |
| 201 EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].birth.thread_name); | 226 EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].birth.thread_name); |
| 202 EXPECT_EQ(1, process_data.tasks[0].death_data.count); | 227 EXPECT_EQ(1, process_data.tasks[0].death_data.count); |
| 203 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sum); | 228 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); | 229 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); | 230 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); | 231 EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_sum); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 223 EXPECT_EQ(kLineNumber, | 248 EXPECT_EQ(kLineNumber, |
| 224 process_data.descendants[0].child.location.line_number); | 249 process_data.descendants[0].child.location.line_number); |
| 225 EXPECT_EQ(kWorkerThreadName, process_data.descendants[0].child.thread_name); | 250 EXPECT_EQ(kWorkerThreadName, process_data.descendants[0].child.thread_name); |
| 226 } else { | 251 } else { |
| 227 EXPECT_EQ(0u, process_data.descendants.size()); | 252 EXPECT_EQ(0u, process_data.descendants.size()); |
| 228 } | 253 } |
| 229 } | 254 } |
| 230 | 255 |
| 231 TEST_F(TrackedObjectsTest, DeathDataTest) { | 256 TEST_F(TrackedObjectsTest, DeathDataTest) { |
| 232 if (!ThreadData::InitializeAndSetTrackingStatus( | 257 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 233 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 258 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 234 return; | 259 return; |
| 260 } |
| 235 | 261 |
| 236 scoped_ptr<DeathData> data(new DeathData()); | 262 scoped_ptr<DeathData> data(new DeathData()); |
| 237 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 263 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
| 238 EXPECT_EQ(data->run_duration_sum(), 0); | 264 EXPECT_EQ(data->run_duration_sum(), 0); |
| 239 EXPECT_EQ(data->run_duration_sample(), 0); | 265 EXPECT_EQ(data->run_duration_sample(), 0); |
| 240 EXPECT_EQ(data->queue_duration_sum(), 0); | 266 EXPECT_EQ(data->queue_duration_sum(), 0); |
| 241 EXPECT_EQ(data->queue_duration_sample(), 0); | 267 EXPECT_EQ(data->queue_duration_sample(), 0); |
| 242 EXPECT_EQ(data->count(), 0); | 268 EXPECT_EQ(data->count(), 0); |
| 243 | 269 |
| 244 int32 run_ms = 42; | 270 int32 run_ms = 42; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 264 EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum); | 290 EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum); |
| 265 EXPECT_EQ(run_ms, snapshot.run_duration_max); | 291 EXPECT_EQ(run_ms, snapshot.run_duration_max); |
| 266 EXPECT_EQ(run_ms, snapshot.run_duration_sample); | 292 EXPECT_EQ(run_ms, snapshot.run_duration_sample); |
| 267 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); | 293 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); |
| 268 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); | 294 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); |
| 269 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); | 295 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); |
| 270 } | 296 } |
| 271 | 297 |
| 272 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { | 298 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { |
| 273 // Start in the deactivated state. | 299 // Start in the deactivated state. |
| 274 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 300 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 275 return; | 301 return; |
| 302 } |
| 276 | 303 |
| 277 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; | 304 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; |
| 278 Location location(kFunction, kFile, kLineNumber, NULL); | 305 Location location(kFunction, kFile, kLineNumber, NULL); |
| 279 TallyABirth(location, std::string()); | 306 TallyABirth(location, std::string()); |
| 280 | 307 |
| 281 ProcessDataSnapshot process_data; | 308 ProcessDataSnapshot process_data; |
| 282 ThreadData::Snapshot(false, &process_data); | 309 ThreadData::Snapshot(false, &process_data); |
| 283 EXPECT_EQ(0u, process_data.tasks.size()); | 310 EXPECT_EQ(0u, process_data.tasks.size()); |
| 284 EXPECT_EQ(0u, process_data.descendants.size()); | 311 EXPECT_EQ(0u, process_data.descendants.size()); |
| 285 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 312 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 286 } | 313 } |
| 287 | 314 |
| 288 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { | 315 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { |
| 289 // Start in the deactivated state. | 316 // Start in the deactivated state. |
| 290 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 317 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 291 return; | 318 return; |
| 319 } |
| 292 | 320 |
| 293 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; | 321 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; |
| 294 Location location(kFunction, kFile, kLineNumber, NULL); | 322 Location location(kFunction, kFile, kLineNumber, NULL); |
| 295 TallyABirth(location, kMainThreadName); | 323 TallyABirth(location, kMainThreadName); |
| 296 | 324 |
| 297 ProcessDataSnapshot process_data; | 325 ProcessDataSnapshot process_data; |
| 298 ThreadData::Snapshot(false, &process_data); | 326 ThreadData::Snapshot(false, &process_data); |
| 299 EXPECT_EQ(0u, process_data.tasks.size()); | 327 EXPECT_EQ(0u, process_data.tasks.size()); |
| 300 EXPECT_EQ(0u, process_data.descendants.size()); | 328 EXPECT_EQ(0u, process_data.descendants.size()); |
| 301 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 329 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 302 } | 330 } |
| 303 | 331 |
| 304 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { | 332 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { |
| 305 if (!ThreadData::InitializeAndSetTrackingStatus( | 333 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 306 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 334 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 307 return; | 335 return; |
| 336 } |
| 308 | 337 |
| 309 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; | 338 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; |
| 310 Location location(kFunction, kFile, kLineNumber, NULL); | 339 Location location(kFunction, kFile, kLineNumber, NULL); |
| 311 TallyABirth(location, std::string()); | 340 TallyABirth(location, std::string()); |
| 312 | 341 |
| 313 ProcessDataSnapshot process_data; | 342 ProcessDataSnapshot process_data; |
| 314 ThreadData::Snapshot(false, &process_data); | 343 ThreadData::Snapshot(false, &process_data); |
| 315 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, | 344 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 316 kStillAlive, 1, 0, 0); | 345 kStillAlive, 1, 0, 0); |
| 317 } | 346 } |
| 318 | 347 |
| 319 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { | 348 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { |
| 320 if (!ThreadData::InitializeAndSetTrackingStatus( | 349 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 321 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 350 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 322 return; | 351 return; |
| 352 } |
| 323 | 353 |
| 324 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; | 354 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; |
| 325 Location location(kFunction, kFile, kLineNumber, NULL); | 355 Location location(kFunction, kFile, kLineNumber, NULL); |
| 326 TallyABirth(location, kMainThreadName); | 356 TallyABirth(location, kMainThreadName); |
| 327 | 357 |
| 328 ProcessDataSnapshot process_data; | 358 ProcessDataSnapshot process_data; |
| 329 ThreadData::Snapshot(false, &process_data); | 359 ThreadData::Snapshot(false, &process_data); |
| 330 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, | 360 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, |
| 331 1, 0, 0); | 361 1, 0, 0); |
| 332 } | 362 } |
| 333 | 363 |
| 334 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { | 364 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
| 335 if (!ThreadData::InitializeAndSetTrackingStatus( | 365 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 336 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 366 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 337 return; | 367 return; |
| 368 } |
| 338 | 369 |
| 339 const char kFunction[] = "LifeCycleToSnapshotMainThread"; | 370 const char kFunction[] = "LifeCycleToSnapshotMainThread"; |
| 340 Location location(kFunction, kFile, kLineNumber, NULL); | 371 Location location(kFunction, kFile, kLineNumber, NULL); |
| 341 TallyABirth(location, kMainThreadName); | 372 TallyABirth(location, kMainThreadName); |
| 342 | 373 |
| 343 const base::TimeTicks kTimePosted = base::TimeTicks() + | 374 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 344 base::TimeDelta::FromMilliseconds(1); | 375 base::TimeDelta::FromMilliseconds(1); |
| 345 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 376 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 346 // TrackingInfo will call TallyABirth() during construction. | 377 // TrackingInfo will call TallyABirth() during construction. |
| 347 base::TrackingInfo pending_task(location, kDelayedStartTime); | 378 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 348 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 379 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 349 | 380 |
| 350 const TrackedTime kStartOfRun = TrackedTime() + | 381 const unsigned int kStartOfRun = 5; |
| 351 Duration::FromMilliseconds(5); | 382 const unsigned int kEndOfRun = 7; |
| 352 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 383 SetTestTime(kStartOfRun); |
| 353 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 384 TaskStopwatch stopwatch; |
| 354 kStartOfRun, kEndOfRun); | 385 SetTestTime(kEndOfRun); |
| 386 stopwatch.Stop(); |
| 387 |
| 388 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 355 | 389 |
| 356 ProcessDataSnapshot process_data; | 390 ProcessDataSnapshot process_data; |
| 357 ThreadData::Snapshot(false, &process_data); | 391 ThreadData::Snapshot(false, &process_data); |
| 358 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 392 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 359 kMainThreadName, 1, 2, 4); | 393 kMainThreadName, 1, 2, 4); |
| 360 } | 394 } |
| 361 | 395 |
| 362 // We will deactivate tracking after the birth, and before the death, and | 396 // We will deactivate tracking after the birth, and before the death, and |
| 363 // demonstrate that the lifecycle is completely tallied. This ensures that | 397 // demonstrate that the lifecycle is completely tallied. This ensures that |
| 364 // our tallied births are matched by tallied deaths (except for when the | 398 // our tallied births are matched by tallied deaths (except for when the |
| 365 // task is still running, or is queued). | 399 // task is still running, or is queued). |
| 366 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { | 400 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
| 367 if (!ThreadData::InitializeAndSetTrackingStatus( | 401 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 368 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 402 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 369 return; | 403 return; |
| 404 } |
| 370 | 405 |
| 371 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; | 406 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
| 372 Location location(kFunction, kFile, kLineNumber, NULL); | 407 Location location(kFunction, kFile, kLineNumber, NULL); |
| 373 TallyABirth(location, kMainThreadName); | 408 TallyABirth(location, kMainThreadName); |
| 374 | 409 |
| 375 const base::TimeTicks kTimePosted = base::TimeTicks() + | 410 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 376 base::TimeDelta::FromMilliseconds(1); | 411 base::TimeDelta::FromMilliseconds(1); |
| 377 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 412 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 378 // TrackingInfo will call TallyABirth() during construction. | 413 // TrackingInfo will call TallyABirth() during construction. |
| 379 base::TrackingInfo pending_task(location, kDelayedStartTime); | 414 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 380 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 415 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 381 | 416 |
| 382 // Turn off tracking now that we have births. | 417 // Turn off tracking now that we have births. |
| 383 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 418 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 384 ThreadData::DEACTIVATED)); | 419 ThreadData::DEACTIVATED)); |
| 385 | 420 |
| 386 const TrackedTime kStartOfRun = TrackedTime() + | 421 const unsigned int kStartOfRun = 5; |
| 387 Duration::FromMilliseconds(5); | 422 const unsigned int kEndOfRun = 7; |
| 388 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 423 SetTestTime(kStartOfRun); |
| 389 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 424 TaskStopwatch stopwatch; |
| 390 kStartOfRun, kEndOfRun); | 425 SetTestTime(kEndOfRun); |
| 426 stopwatch.Stop(); |
| 427 |
| 428 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 391 | 429 |
| 392 ProcessDataSnapshot process_data; | 430 ProcessDataSnapshot process_data; |
| 393 ThreadData::Snapshot(false, &process_data); | 431 ThreadData::Snapshot(false, &process_data); |
| 394 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 432 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 395 kMainThreadName, 1, 2, 4); | 433 kMainThreadName, 1, 2, 4); |
| 396 } | 434 } |
| 397 | 435 |
| 398 // We will deactivate tracking before starting a life cycle, and neither | 436 // We will deactivate tracking before starting a life cycle, and neither |
| 399 // the birth nor the death will be recorded. | 437 // the birth nor the death will be recorded. |
| 400 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { | 438 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { |
| 401 // Start in the deactivated state. | 439 // Start in the deactivated state. |
| 402 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 440 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 403 return; | 441 return; |
| 442 } |
| 404 | 443 |
| 405 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; | 444 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; |
| 406 Location location(kFunction, kFile, kLineNumber, NULL); | 445 Location location(kFunction, kFile, kLineNumber, NULL); |
| 407 TallyABirth(location, kMainThreadName); | 446 TallyABirth(location, kMainThreadName); |
| 408 | 447 |
| 409 const base::TimeTicks kTimePosted = base::TimeTicks() + | 448 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 410 base::TimeDelta::FromMilliseconds(1); | 449 base::TimeDelta::FromMilliseconds(1); |
| 411 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 450 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 412 // TrackingInfo will call TallyABirth() during construction. | 451 // TrackingInfo will call TallyABirth() during construction. |
| 413 base::TrackingInfo pending_task(location, kDelayedStartTime); | 452 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 414 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 453 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 415 | 454 |
| 416 const TrackedTime kStartOfRun = TrackedTime() + | 455 const unsigned int kStartOfRun = 5; |
| 417 Duration::FromMilliseconds(5); | 456 const unsigned int kEndOfRun = 7; |
| 418 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 457 SetTestTime(kStartOfRun); |
| 419 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 458 TaskStopwatch stopwatch; |
| 420 kStartOfRun, kEndOfRun); | 459 SetTestTime(kEndOfRun); |
| 460 stopwatch.Stop(); |
| 461 |
| 462 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 421 | 463 |
| 422 ProcessDataSnapshot process_data; | 464 ProcessDataSnapshot process_data; |
| 423 ThreadData::Snapshot(false, &process_data); | 465 ThreadData::Snapshot(false, &process_data); |
| 424 EXPECT_EQ(0u, process_data.tasks.size()); | 466 EXPECT_EQ(0u, process_data.tasks.size()); |
| 425 EXPECT_EQ(0u, process_data.descendants.size()); | 467 EXPECT_EQ(0u, process_data.descendants.size()); |
| 426 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 468 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 427 } | 469 } |
| 428 | 470 |
| 429 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) { | 471 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) { |
| 430 if (!ThreadData::InitializeAndSetTrackingStatus( | 472 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 431 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 473 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 432 return; | 474 return; |
| 475 } |
| 433 | 476 |
| 434 const char kFunction[] = "LifeCycleToSnapshotWorkerThread"; | 477 const char kFunction[] = "LifeCycleToSnapshotWorkerThread"; |
| 435 Location location(kFunction, kFile, kLineNumber, NULL); | 478 Location location(kFunction, kFile, kLineNumber, NULL); |
| 436 // Do not delete |birth|. We don't own it. | 479 // Do not delete |birth|. We don't own it. |
| 437 Births* birth = ThreadData::TallyABirthIfActive(location); | 480 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 438 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth); | 481 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth); |
| 439 | 482 |
| 440 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); | 483 const unsigned int kTimePosted = 1; |
| 441 const TrackedTime kStartOfRun = TrackedTime() + | 484 const unsigned int kStartOfRun = 5; |
| 442 Duration::FromMilliseconds(5); | 485 const unsigned int kEndOfRun = 7; |
| 443 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 486 SetTestTime(kStartOfRun); |
| 444 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, | 487 TaskStopwatch stopwatch; |
| 445 kStartOfRun, kEndOfRun); | 488 SetTestTime(kEndOfRun); |
| 489 stopwatch.Stop(); |
| 490 |
| 491 ThreadData::TallyRunOnWorkerThreadIfTracking( |
| 492 birth, TrackedTime() + Duration::FromMilliseconds(kTimePosted), stopwatch); |
| 446 | 493 |
| 447 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning. | 494 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning. |
| 448 ProcessDataSnapshot process_data; | 495 ProcessDataSnapshot process_data; |
| 449 ThreadData::Snapshot(false, &process_data); | 496 ThreadData::Snapshot(false, &process_data); |
| 450 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, | 497 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 451 kWorkerThreadName, 1, 2, 4); | 498 kWorkerThreadName, 1, 2, 4); |
| 452 | 499 |
| 453 // Call for the ToSnapshot, but tell it to reset the maxes after scanning. | 500 // Call for the ToSnapshot, but tell it to reset the maxes after scanning. |
| 454 // We'll still get the same values, but the data will be reset (which we'll | 501 // We'll still get the same values, but the data will be reset (which we'll |
| 455 // see in a moment). | 502 // see in a moment). |
| (...skipping 23 matching lines...) Expand all Loading... |
| 479 EXPECT_EQ(4, | 526 EXPECT_EQ(4, |
| 480 process_data_post_reset.tasks[0].death_data.queue_duration_sample); | 527 process_data_post_reset.tasks[0].death_data.queue_duration_sample); |
| 481 EXPECT_EQ(kWorkerThreadName, | 528 EXPECT_EQ(kWorkerThreadName, |
| 482 process_data_post_reset.tasks[0].death_thread_name); | 529 process_data_post_reset.tasks[0].death_thread_name); |
| 483 EXPECT_EQ(0u, process_data_post_reset.descendants.size()); | 530 EXPECT_EQ(0u, process_data_post_reset.descendants.size()); |
| 484 EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id); | 531 EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id); |
| 485 } | 532 } |
| 486 | 533 |
| 487 TEST_F(TrackedObjectsTest, TwoLives) { | 534 TEST_F(TrackedObjectsTest, TwoLives) { |
| 488 if (!ThreadData::InitializeAndSetTrackingStatus( | 535 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 489 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 536 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 490 return; | 537 return; |
| 538 } |
| 491 | 539 |
| 492 const char kFunction[] = "TwoLives"; | 540 const char kFunction[] = "TwoLives"; |
| 493 Location location(kFunction, kFile, kLineNumber, NULL); | 541 Location location(kFunction, kFile, kLineNumber, NULL); |
| 494 TallyABirth(location, kMainThreadName); | 542 TallyABirth(location, kMainThreadName); |
| 495 | 543 |
| 496 const base::TimeTicks kTimePosted = base::TimeTicks() + | 544 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 497 base::TimeDelta::FromMilliseconds(1); | 545 base::TimeDelta::FromMilliseconds(1); |
| 498 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 546 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 499 // TrackingInfo will call TallyABirth() during construction. | 547 // TrackingInfo will call TallyABirth() during construction. |
| 500 base::TrackingInfo pending_task(location, kDelayedStartTime); | 548 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 501 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 549 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 502 | 550 |
| 503 const TrackedTime kStartOfRun = TrackedTime() + | 551 const unsigned int kStartOfRun = 5; |
| 504 Duration::FromMilliseconds(5); | 552 const unsigned int kEndOfRun = 7; |
| 505 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 553 SetTestTime(kStartOfRun); |
| 506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 554 TaskStopwatch stopwatch; |
| 507 kStartOfRun, kEndOfRun); | 555 SetTestTime(kEndOfRun); |
| 556 stopwatch.Stop(); |
| 557 |
| 558 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 508 | 559 |
| 509 // TrackingInfo will call TallyABirth() during construction. | 560 // TrackingInfo will call TallyABirth() during construction. |
| 510 base::TrackingInfo pending_task2(location, kDelayedStartTime); | 561 base::TrackingInfo pending_task2(location, kDelayedStartTime); |
| 511 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 562 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 563 SetTestTime(kStartOfRun); |
| 564 TaskStopwatch stopwatch2; |
| 565 SetTestTime(kEndOfRun); |
| 566 stopwatch2.Stop(); |
| 512 | 567 |
| 513 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, | 568 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); |
| 514 kStartOfRun, kEndOfRun); | |
| 515 | 569 |
| 516 ProcessDataSnapshot process_data; | 570 ProcessDataSnapshot process_data; |
| 517 ThreadData::Snapshot(false, &process_data); | 571 ThreadData::Snapshot(false, &process_data); |
| 518 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 572 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 519 kMainThreadName, 2, 2, 4); | 573 kMainThreadName, 2, 2, 4); |
| 520 } | 574 } |
| 521 | 575 |
| 522 TEST_F(TrackedObjectsTest, DifferentLives) { | 576 TEST_F(TrackedObjectsTest, DifferentLives) { |
| 523 if (!ThreadData::InitializeAndSetTrackingStatus( | 577 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 524 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 578 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 525 return; | 579 return; |
| 580 } |
| 526 | 581 |
| 527 // Use a well named thread. | 582 // Use a well named thread. |
| 528 ThreadData::InitializeThreadContext(kMainThreadName); | 583 ThreadData::InitializeThreadContext(kMainThreadName); |
| 529 const char kFunction[] = "DifferentLives"; | 584 const char kFunction[] = "DifferentLives"; |
| 530 Location location(kFunction, kFile, kLineNumber, NULL); | 585 Location location(kFunction, kFile, kLineNumber, NULL); |
| 531 | 586 |
| 532 const base::TimeTicks kTimePosted = base::TimeTicks() + | 587 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 533 base::TimeDelta::FromMilliseconds(1); | 588 base::TimeDelta::FromMilliseconds(1); |
| 534 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 589 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 535 // TrackingInfo will call TallyABirth() during construction. | 590 // TrackingInfo will call TallyABirth() during construction. |
| 536 base::TrackingInfo pending_task(location, kDelayedStartTime); | 591 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 537 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 592 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 538 | 593 |
| 539 const TrackedTime kStartOfRun = TrackedTime() + | 594 const unsigned int kStartOfRun = 5; |
| 540 Duration::FromMilliseconds(5); | 595 const unsigned int kEndOfRun = 7; |
| 541 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 596 SetTestTime(kStartOfRun); |
| 542 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 597 TaskStopwatch stopwatch; |
| 543 kStartOfRun, kEndOfRun); | 598 SetTestTime(kEndOfRun); |
| 599 stopwatch.Stop(); |
| 600 |
| 601 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 544 | 602 |
| 545 const int kSecondFakeLineNumber = 999; | 603 const int kSecondFakeLineNumber = 999; |
| 546 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 604 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 547 | 605 |
| 548 // TrackingInfo will call TallyABirth() during construction. | 606 // TrackingInfo will call TallyABirth() during construction. |
| 549 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 607 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 550 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 608 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 551 | 609 |
| 552 ProcessDataSnapshot process_data; | 610 ProcessDataSnapshot process_data; |
| 553 ThreadData::Snapshot(false, &process_data); | 611 ThreadData::Snapshot(false, &process_data); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 574 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max); | 632 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); | 633 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); | 634 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); | 635 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); | 636 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample); |
| 579 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name); | 637 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name); |
| 580 EXPECT_EQ(0u, process_data.descendants.size()); | 638 EXPECT_EQ(0u, process_data.descendants.size()); |
| 581 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 639 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 582 } | 640 } |
| 583 | 641 |
| 642 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { |
| 643 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 644 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 645 return; |
| 646 } |
| 647 |
| 648 const char kFunction[] = "TaskWithNestedExclusion"; |
| 649 Location location(kFunction, kFile, kLineNumber, NULL); |
| 650 TallyABirth(location, kMainThreadName); |
| 651 |
| 652 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 653 base::TimeDelta::FromMilliseconds(1); |
| 654 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 655 // TrackingInfo will call TallyABirth() during construction. |
| 656 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 657 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 658 |
| 659 SetTestTime(5); |
| 660 TaskStopwatch task_stopwatch; |
| 661 { |
| 662 SetTestTime(8); |
| 663 TaskStopwatch exclusion_stopwatch; |
| 664 SetTestTime(12); |
| 665 exclusion_stopwatch.Stop(); |
| 666 } |
| 667 SetTestTime(15); |
| 668 task_stopwatch.Stop(); |
| 669 |
| 670 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 671 |
| 672 ProcessDataSnapshot process_data; |
| 673 ThreadData::Snapshot(false, &process_data); |
| 674 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 675 kMainThreadName, 1, 6, 4); |
| 676 } |
| 677 |
| 678 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { |
| 679 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 680 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 681 return; |
| 682 } |
| 683 |
| 684 const char kFunction[] = "TaskWith2NestedExclusions"; |
| 685 Location location(kFunction, kFile, kLineNumber, NULL); |
| 686 TallyABirth(location, kMainThreadName); |
| 687 |
| 688 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 689 base::TimeDelta::FromMilliseconds(1); |
| 690 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 691 // TrackingInfo will call TallyABirth() during construction. |
| 692 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 693 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 694 |
| 695 SetTestTime(5); |
| 696 TaskStopwatch task_stopwatch; |
| 697 { |
| 698 SetTestTime(8); |
| 699 TaskStopwatch exclusion_stopwatch; |
| 700 SetTestTime(12); |
| 701 exclusion_stopwatch.Stop(); |
| 702 |
| 703 SetTestTime(15); |
| 704 TaskStopwatch exclusion_stopwatch2; |
| 705 SetTestTime(18); |
| 706 exclusion_stopwatch2.Stop(); |
| 707 } |
| 708 SetTestTime(25); |
| 709 task_stopwatch.Stop(); |
| 710 |
| 711 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 712 |
| 713 ProcessDataSnapshot process_data; |
| 714 ThreadData::Snapshot(false, &process_data); |
| 715 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 716 kMainThreadName, 1, 13, 4); |
| 717 } |
| 718 |
| 719 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { |
| 720 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 721 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 722 return; |
| 723 } |
| 724 |
| 725 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; |
| 726 Location location(kFunction, kFile, kLineNumber, NULL); |
| 727 |
| 728 const int kSecondFakeLineNumber = 999; |
| 729 |
| 730 TallyABirth(location, kMainThreadName); |
| 731 |
| 732 const base::TimeTicks kTimePosted = base::TimeTicks() + |
| 733 base::TimeDelta::FromMilliseconds(1); |
| 734 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 735 // TrackingInfo will call TallyABirth() during construction. |
| 736 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 737 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 738 |
| 739 SetTestTime(5); |
| 740 TaskStopwatch task_stopwatch; |
| 741 { |
| 742 SetTestTime(8); |
| 743 TaskStopwatch exclusion_stopwatch; |
| 744 { |
| 745 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 746 base::TrackingInfo nested_task(second_location, kDelayedStartTime); |
| 747 // Overwrite implied Now(). |
| 748 nested_task.time_posted = |
| 749 base::TimeTicks() + base::TimeDelta::FromMilliseconds(8); |
| 750 SetTestTime(9); |
| 751 TaskStopwatch nested_task_stopwatch; |
| 752 SetTestTime(11); |
| 753 nested_task_stopwatch.Stop(); |
| 754 ThreadData::TallyRunOnNamedThreadIfTracking( |
| 755 nested_task, nested_task_stopwatch); |
| 756 } |
| 757 SetTestTime(12); |
| 758 exclusion_stopwatch.Stop(); |
| 759 } |
| 760 SetTestTime(15); |
| 761 task_stopwatch.Stop(); |
| 762 |
| 763 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 764 |
| 765 ProcessDataSnapshot process_data; |
| 766 ThreadData::Snapshot(false, &process_data); |
| 767 ASSERT_EQ(2u, process_data.tasks.size()); |
| 768 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); |
| 769 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); |
| 770 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); |
| 771 EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name); |
| 772 EXPECT_EQ(1, process_data.tasks[0].death_data.count); |
| 773 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_sum); |
| 774 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_max); |
| 775 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_sample); |
| 776 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sum); |
| 777 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_max); |
| 778 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sample); |
| 779 EXPECT_EQ(kMainThreadName, process_data.tasks[0].death_thread_name); |
| 780 EXPECT_EQ(kFile, process_data.tasks[1].birth.location.file_name); |
| 781 EXPECT_EQ(kFunction, process_data.tasks[1].birth.location.function_name); |
| 782 EXPECT_EQ(kSecondFakeLineNumber, |
| 783 process_data.tasks[1].birth.location.line_number); |
| 784 EXPECT_EQ(kMainThreadName, process_data.tasks[1].birth.thread_name); |
| 785 EXPECT_EQ(1, process_data.tasks[1].death_data.count); |
| 786 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_sum); |
| 787 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_max); |
| 788 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_sample); |
| 789 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_sum); |
| 790 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_max); |
| 791 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_sample); |
| 792 EXPECT_EQ(kMainThreadName, process_data.tasks[1].death_thread_name); |
| 793 EXPECT_EQ(0u, process_data.descendants.size()); |
| 794 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 795 } |
| 796 |
| 584 } // namespace tracked_objects | 797 } // namespace tracked_objects |
| OLD | NEW |