| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Helper function to verify the most common test expectations. | 66 // Helper function to verify the most common test expectations. |
| 67 void ExpectSimpleProcessData(const ProcessDataSnapshot& process_data, | 67 void ExpectSimpleProcessData(const ProcessDataSnapshot& process_data, |
| 68 const std::string& function_name, | 68 const std::string& function_name, |
| 69 const std::string& birth_thread, | 69 const std::string& birth_thread, |
| 70 const std::string& death_thread, | 70 const std::string& death_thread, |
| 71 int count, | 71 int count, |
| 72 int run_ms, | 72 int run_ms, |
| 73 int queue_ms) { | 73 int queue_ms) { |
| 74 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 74 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 75 auto it = process_data.phased_process_data_snapshots.find(0); | 75 auto it = process_data.phased_snapshots.find(0); |
| 76 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 76 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 77 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 77 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 78 | 78 |
| 79 ASSERT_EQ(1u, process_data_phase.tasks.size()); | 79 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
| 80 | 80 |
| 81 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); | 81 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 82 EXPECT_EQ(function_name, | 82 EXPECT_EQ(function_name, |
| 83 process_data_phase.tasks[0].birth.location.function_name); | 83 process_data_phase.tasks[0].birth.location.function_name); |
| 84 EXPECT_EQ(kLineNumber, | 84 EXPECT_EQ(kLineNumber, |
| 85 process_data_phase.tasks[0].birth.location.line_number); | 85 process_data_phase.tasks[0].birth.location.line_number); |
| 86 | 86 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 116 // Test time in milliseconds. | 116 // Test time in milliseconds. |
| 117 static unsigned int test_time_; | 117 static unsigned int test_time_; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 // static | 120 // static |
| 121 unsigned int TrackedObjectsTest::test_time_; | 121 unsigned int TrackedObjectsTest::test_time_; |
| 122 | 122 |
| 123 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { | 123 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { |
| 124 if (!ThreadData::InitializeAndSetTrackingStatus( | 124 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 125 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 125 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 126 // Don't run the test if task tracking is not compiled in. |
| 126 return; | 127 return; |
| 127 } | 128 } |
| 128 | 129 |
| 129 // Check that creating and destroying a stopwatch without starting it doesn't | 130 // Check that creating and destroying a stopwatch without starting it doesn't |
| 130 // crash. | 131 // crash. |
| 131 TaskStopwatch stopwatch; | 132 TaskStopwatch stopwatch; |
| 132 } | 133 } |
| 133 | 134 |
| 134 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { | 135 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
| 135 // Minimal test doesn't even create any tasks. | 136 // Minimal test doesn't even create any tasks. |
| 136 if (!ThreadData::InitializeAndSetTrackingStatus( | 137 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 137 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 138 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 139 // Don't run the test if task tracking is not compiled in. |
| 138 return; | 140 return; |
| 139 } | 141 } |
| 140 | 142 |
| 141 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 143 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 142 ThreadData* data = ThreadData::Get(); | 144 ThreadData* data = ThreadData::Get(); |
| 143 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 145 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 144 ASSERT_TRUE(data); | 146 ASSERT_TRUE(data); |
| 145 EXPECT_FALSE(data->next()); | 147 EXPECT_FALSE(data->next()); |
| 146 EXPECT_EQ(data, ThreadData::Get()); | 148 EXPECT_EQ(data, ThreadData::Get()); |
| 147 ThreadData::BirthMap birth_map; | 149 ThreadData::BirthMap birth_map; |
| 148 ThreadData::DeathMap death_map; | 150 ThreadData::DeathsSnapshot deaths; |
| 149 ThreadData::ParentChildSet parent_child_set; | 151 ThreadData::ParentChildSet parent_child_set; |
| 150 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 152 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); |
| 151 EXPECT_EQ(0u, birth_map.size()); | 153 EXPECT_EQ(0u, birth_map.size()); |
| 152 EXPECT_EQ(0u, death_map.size()); | 154 EXPECT_EQ(0u, deaths.size()); |
| 153 EXPECT_EQ(0u, parent_child_set.size()); | 155 EXPECT_EQ(0u, parent_child_set.size()); |
| 154 | 156 |
| 155 // Clean up with no leaking. | 157 // Clean up with no leaking. |
| 156 Reset(); | 158 Reset(); |
| 157 | 159 |
| 158 // Do it again, just to be sure we reset state completely. | 160 // Do it again, just to be sure we reset state completely. |
| 159 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 161 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 160 ThreadData::PROFILING_CHILDREN_ACTIVE)); | 162 ThreadData::PROFILING_CHILDREN_ACTIVE)); |
| 161 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 163 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 162 data = ThreadData::Get(); | 164 data = ThreadData::Get(); |
| 163 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 165 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 164 ASSERT_TRUE(data); | 166 ASSERT_TRUE(data); |
| 165 EXPECT_FALSE(data->next()); | 167 EXPECT_FALSE(data->next()); |
| 166 EXPECT_EQ(data, ThreadData::Get()); | 168 EXPECT_EQ(data, ThreadData::Get()); |
| 167 birth_map.clear(); | 169 birth_map.clear(); |
| 168 death_map.clear(); | 170 deaths.clear(); |
| 169 parent_child_set.clear(); | 171 parent_child_set.clear(); |
| 170 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 172 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); |
| 171 EXPECT_EQ(0u, birth_map.size()); | 173 EXPECT_EQ(0u, birth_map.size()); |
| 172 EXPECT_EQ(0u, death_map.size()); | 174 EXPECT_EQ(0u, deaths.size()); |
| 173 EXPECT_EQ(0u, parent_child_set.size()); | 175 EXPECT_EQ(0u, parent_child_set.size()); |
| 174 } | 176 } |
| 175 | 177 |
| 176 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 178 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
| 177 if (!ThreadData::InitializeAndSetTrackingStatus( | 179 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 178 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 180 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 181 // Don't run the test if task tracking is not compiled in. |
| 179 return; | 182 return; |
| 180 } | 183 } |
| 181 | 184 |
| 182 // Instigate tracking on a single tracked object, on our thread. | 185 // Instigate tracking on a single tracked object, on our thread. |
| 183 const char kFunction[] = "TinyStartupShutdown"; | 186 const char kFunction[] = "TinyStartupShutdown"; |
| 184 Location location(kFunction, kFile, kLineNumber, NULL); | 187 Location location(kFunction, kFile, kLineNumber, NULL); |
| 185 Births* first_birth = ThreadData::TallyABirthIfActive(location); | 188 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
| 186 | 189 |
| 187 ThreadData* data = ThreadData::first(); | 190 ThreadData* data = ThreadData::first(); |
| 188 ASSERT_TRUE(data); | 191 ASSERT_TRUE(data); |
| 189 EXPECT_FALSE(data->next()); | 192 EXPECT_FALSE(data->next()); |
| 190 EXPECT_EQ(data, ThreadData::Get()); | 193 EXPECT_EQ(data, ThreadData::Get()); |
| 191 ThreadData::BirthMap birth_map; | 194 ThreadData::BirthMap birth_map; |
| 192 ThreadData::DeathMap death_map; | 195 ThreadData::DeathsSnapshot deaths; |
| 193 ThreadData::ParentChildSet parent_child_set; | 196 ThreadData::ParentChildSet parent_child_set; |
| 194 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 197 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); |
| 195 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 198 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 196 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 199 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 197 EXPECT_EQ(0u, death_map.size()); // No deaths. | 200 EXPECT_EQ(0u, deaths.size()); // No deaths. |
| 198 EXPECT_EQ(0u, parent_child_set.size()); // No children. | 201 EXPECT_EQ(0u, parent_child_set.size()); // No children. |
| 199 | 202 |
| 200 | 203 |
| 201 // Now instigate another birth, while we are timing the run of the first | 204 // Now instigate another birth, while we are timing the run of the first |
| 202 // execution. | 205 // execution. |
| 203 ThreadData::PrepareForStartOfRun(first_birth); | 206 ThreadData::PrepareForStartOfRun(first_birth); |
| 204 // Create a child (using the same birth location). | 207 // Create a child (using the same birth location). |
| 205 // TrackingInfo will call TallyABirth() during construction. | 208 // TrackingInfo will call TallyABirth() during construction. |
| 206 const int32 start_time = 1; | 209 const int32 start_time = 1; |
| 207 base::TimeTicks kBogusBirthTime = base::TimeTicks() + | 210 base::TimeTicks kBogusBirthTime = base::TimeTicks() + |
| 208 base::TimeDelta::FromMilliseconds(start_time); | 211 base::TimeDelta::FromMilliseconds(start_time); |
| 209 base::TrackingInfo pending_task(location, kBogusBirthTime); | 212 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 210 SetTestTime(1); | 213 SetTestTime(1); |
| 211 TaskStopwatch stopwatch; | 214 TaskStopwatch stopwatch; |
| 212 stopwatch.Start(); | 215 stopwatch.Start(); |
| 213 // Finally conclude the outer run. | 216 // Finally conclude the outer run. |
| 214 const int32 time_elapsed = 1000; | 217 const int32 time_elapsed = 1000; |
| 215 SetTestTime(start_time + time_elapsed); | 218 SetTestTime(start_time + time_elapsed); |
| 216 stopwatch.Stop(); | 219 stopwatch.Stop(); |
| 217 | 220 |
| 218 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 221 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 219 | 222 |
| 220 birth_map.clear(); | 223 birth_map.clear(); |
| 221 death_map.clear(); | 224 deaths.clear(); |
| 222 parent_child_set.clear(); | 225 parent_child_set.clear(); |
| 223 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 226 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); |
| 224 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 227 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 225 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 228 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 226 EXPECT_EQ(1u, death_map.size()); // 1 location. | 229 EXPECT_EQ(1u, deaths.size()); // 1 location. |
| 227 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 230 EXPECT_EQ(1, deaths.begin()->second.death_data.count); // 1 death. |
| 228 if (ThreadData::TrackingParentChildStatus()) { | 231 if (ThreadData::TrackingParentChildStatus()) { |
| 229 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 232 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 230 EXPECT_EQ(parent_child_set.begin()->first, | 233 EXPECT_EQ(parent_child_set.begin()->first, |
| 231 parent_child_set.begin()->second); | 234 parent_child_set.begin()->second); |
| 232 } else { | 235 } else { |
| 233 EXPECT_EQ(0u, parent_child_set.size()); // no stats. | 236 EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
| 234 } | 237 } |
| 235 | 238 |
| 236 // The births were at the same location as the one known death. | 239 // The births were at the same location as the one known death. |
| 237 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 240 EXPECT_EQ(birth_map.begin()->second, deaths.begin()->first); |
| 238 | 241 |
| 239 ProcessDataSnapshot process_data; | 242 ProcessDataSnapshot process_data; |
| 240 ThreadData::Snapshot(&process_data); | 243 ThreadData::Snapshot(0, &process_data); |
| 241 | 244 |
| 242 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 245 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 243 auto it = process_data.phased_process_data_snapshots.find(0); | 246 auto it = process_data.phased_snapshots.find(0); |
| 244 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 247 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 245 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 248 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 246 ASSERT_EQ(1u, process_data_phase.tasks.size()); | 249 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
| 247 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); | 250 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 248 EXPECT_EQ(kFunction, | 251 EXPECT_EQ(kFunction, |
| 249 process_data_phase.tasks[0].birth.location.function_name); | 252 process_data_phase.tasks[0].birth.location.function_name); |
| 250 EXPECT_EQ(kLineNumber, | 253 EXPECT_EQ(kLineNumber, |
| 251 process_data_phase.tasks[0].birth.location.line_number); | 254 process_data_phase.tasks[0].birth.location.line_number); |
| 252 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].birth.thread_name); | 255 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].birth.thread_name); |
| 253 EXPECT_EQ(1, process_data_phase.tasks[0].death_data.count); | 256 EXPECT_EQ(1, process_data_phase.tasks[0].death_data.count); |
| 254 EXPECT_EQ(time_elapsed, | 257 EXPECT_EQ(time_elapsed, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 281 EXPECT_EQ(kWorkerThreadName, | 284 EXPECT_EQ(kWorkerThreadName, |
| 282 process_data_phase.descendants[0].child.thread_name); | 285 process_data_phase.descendants[0].child.thread_name); |
| 283 } else { | 286 } else { |
| 284 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 287 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 285 } | 288 } |
| 286 } | 289 } |
| 287 | 290 |
| 288 TEST_F(TrackedObjectsTest, DeathDataTest) { | 291 TEST_F(TrackedObjectsTest, DeathDataTest) { |
| 289 if (!ThreadData::InitializeAndSetTrackingStatus( | 292 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 290 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 293 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 294 // Don't run the test if task tracking is not compiled in. |
| 291 return; | 295 return; |
| 292 } | 296 } |
| 293 | 297 |
| 294 scoped_ptr<DeathData> data(new DeathData()); | 298 scoped_ptr<DeathData> data(new DeathData()); |
| 295 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 299 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
| 296 EXPECT_EQ(data->run_duration_sum(), 0); | 300 EXPECT_EQ(data->run_duration_sum(), 0); |
| 301 EXPECT_EQ(data->run_duration_max(), 0); |
| 297 EXPECT_EQ(data->run_duration_sample(), 0); | 302 EXPECT_EQ(data->run_duration_sample(), 0); |
| 298 EXPECT_EQ(data->queue_duration_sum(), 0); | 303 EXPECT_EQ(data->queue_duration_sum(), 0); |
| 304 EXPECT_EQ(data->queue_duration_max(), 0); |
| 299 EXPECT_EQ(data->queue_duration_sample(), 0); | 305 EXPECT_EQ(data->queue_duration_sample(), 0); |
| 300 EXPECT_EQ(data->count(), 0); | 306 EXPECT_EQ(data->count(), 0); |
| 307 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 301 | 308 |
| 302 int32 run_ms = 42; | 309 int32 run_ms = 42; |
| 303 int32 queue_ms = 8; | 310 int32 queue_ms = 8; |
| 304 | 311 |
| 305 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. | 312 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. |
| 306 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 313 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 307 EXPECT_EQ(data->run_duration_sum(), run_ms); | 314 EXPECT_EQ(data->run_duration_sum(), run_ms); |
| 315 EXPECT_EQ(data->run_duration_max(), run_ms); |
| 308 EXPECT_EQ(data->run_duration_sample(), run_ms); | 316 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 309 EXPECT_EQ(data->queue_duration_sum(), queue_ms); | 317 EXPECT_EQ(data->queue_duration_sum(), queue_ms); |
| 318 EXPECT_EQ(data->queue_duration_max(), queue_ms); |
| 310 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 319 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 311 EXPECT_EQ(data->count(), 1); | 320 EXPECT_EQ(data->count(), 1); |
| 321 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 312 | 322 |
| 313 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 323 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 314 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); | 324 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); |
| 325 EXPECT_EQ(data->run_duration_max(), run_ms); |
| 315 EXPECT_EQ(data->run_duration_sample(), run_ms); | 326 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 316 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); | 327 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 328 EXPECT_EQ(data->queue_duration_max(), queue_ms); |
| 317 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 329 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 318 EXPECT_EQ(data->count(), 2); | 330 EXPECT_EQ(data->count(), 2); |
| 331 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 319 | 332 |
| 320 DeathDataSnapshot snapshot(*data); | 333 data->OnProfilingPhaseCompleted(123); |
| 321 EXPECT_EQ(2, snapshot.count); | 334 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); |
| 322 EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum); | 335 EXPECT_EQ(data->run_duration_max(), 0); |
| 323 EXPECT_EQ(run_ms, snapshot.run_duration_max); | 336 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 324 EXPECT_EQ(run_ms, snapshot.run_duration_sample); | 337 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 325 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); | 338 EXPECT_EQ(data->queue_duration_max(), 0); |
| 326 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); | 339 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 327 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); | 340 EXPECT_EQ(data->count(), 2); |
| 341 ASSERT_NE(nullptr, data->last_phase_snapshot()); |
| 342 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase); |
| 343 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count); |
| 344 EXPECT_EQ(2 * run_ms, |
| 345 data->last_phase_snapshot()->death_data.run_duration_sum); |
| 346 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max); |
| 347 EXPECT_EQ(run_ms, |
| 348 data->last_phase_snapshot()->death_data.run_duration_sample); |
| 349 EXPECT_EQ(2 * queue_ms, |
| 350 data->last_phase_snapshot()->death_data.queue_duration_sum); |
| 351 EXPECT_EQ(queue_ms, |
| 352 data->last_phase_snapshot()->death_data.queue_duration_max); |
| 353 EXPECT_EQ(queue_ms, |
| 354 data->last_phase_snapshot()->death_data.queue_duration_sample); |
| 355 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); |
| 356 |
| 357 int32 run_ms1 = 21; |
| 358 int32 queue_ms1 = 4; |
| 359 |
| 360 data->RecordDeath(queue_ms1, run_ms1, kUnrandomInt); |
| 361 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms + run_ms1); |
| 362 EXPECT_EQ(data->run_duration_max(), run_ms1); |
| 363 EXPECT_EQ(data->run_duration_sample(), run_ms1); |
| 364 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms + queue_ms1); |
| 365 EXPECT_EQ(data->queue_duration_max(), queue_ms1); |
| 366 EXPECT_EQ(data->queue_duration_sample(), queue_ms1); |
| 367 EXPECT_EQ(data->count(), 3); |
| 368 ASSERT_NE(nullptr, data->last_phase_snapshot()); |
| 369 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase); |
| 370 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count); |
| 371 EXPECT_EQ(2 * run_ms, |
| 372 data->last_phase_snapshot()->death_data.run_duration_sum); |
| 373 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max); |
| 374 EXPECT_EQ(run_ms, |
| 375 data->last_phase_snapshot()->death_data.run_duration_sample); |
| 376 EXPECT_EQ(2 * queue_ms, |
| 377 data->last_phase_snapshot()->death_data.queue_duration_sum); |
| 378 EXPECT_EQ(queue_ms, |
| 379 data->last_phase_snapshot()->death_data.queue_duration_max); |
| 380 EXPECT_EQ(queue_ms, |
| 381 data->last_phase_snapshot()->death_data.queue_duration_sample); |
| 382 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); |
| 383 } |
| 384 |
| 385 TEST_F(TrackedObjectsTest, Delta) { |
| 386 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 387 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 388 // Don't run the test if task tracking is not compiled in. |
| 389 return; |
| 390 } |
| 391 |
| 392 DeathDataSnapshot snapshot; |
| 393 snapshot.count = 10; |
| 394 snapshot.run_duration_sum = 100; |
| 395 snapshot.run_duration_max = 50; |
| 396 snapshot.run_duration_sample = 25; |
| 397 snapshot.queue_duration_sum = 200; |
| 398 snapshot.queue_duration_max = 101; |
| 399 snapshot.queue_duration_sample = 26; |
| 400 |
| 401 DeathDataSnapshot older_snapshot; |
| 402 older_snapshot.count = 2; |
| 403 older_snapshot.run_duration_sum = 95; |
| 404 older_snapshot.run_duration_max = 48; |
| 405 older_snapshot.run_duration_sample = 22; |
| 406 older_snapshot.queue_duration_sum = 190; |
| 407 older_snapshot.queue_duration_max = 99; |
| 408 older_snapshot.queue_duration_sample = 21; |
| 409 |
| 410 const DeathDataSnapshot& delta = snapshot.Delta(older_snapshot); |
| 411 EXPECT_EQ(8, delta.count); |
| 412 EXPECT_EQ(5, delta.run_duration_sum); |
| 413 EXPECT_EQ(50, delta.run_duration_max); |
| 414 EXPECT_EQ(25, delta.run_duration_sample); |
| 415 EXPECT_EQ(10, delta.queue_duration_sum); |
| 416 EXPECT_EQ(101, delta.queue_duration_max); |
| 417 EXPECT_EQ(26, delta.queue_duration_sample); |
| 328 } | 418 } |
| 329 | 419 |
| 330 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { | 420 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { |
| 331 // Start in the deactivated state. | 421 // Start in the deactivated state. |
| 332 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 422 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 423 // Don't run the test if task tracking is not compiled in. |
| 333 return; | 424 return; |
| 334 } | 425 } |
| 335 | 426 |
| 336 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; | 427 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; |
| 337 Location location(kFunction, kFile, kLineNumber, NULL); | 428 Location location(kFunction, kFile, kLineNumber, NULL); |
| 338 TallyABirth(location, std::string()); | 429 TallyABirth(location, std::string()); |
| 339 | 430 |
| 340 ProcessDataSnapshot process_data; | 431 ProcessDataSnapshot process_data; |
| 341 ThreadData::Snapshot(&process_data); | 432 ThreadData::Snapshot(0, &process_data); |
| 342 | 433 |
| 343 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 434 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 344 auto it = process_data.phased_process_data_snapshots.find(0); | |
| 345 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | |
| 346 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | |
| 347 | 435 |
| 348 EXPECT_EQ(0u, process_data_phase.tasks.size()); | 436 auto it0 = process_data.phased_snapshots.find(0); |
| 349 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 437 ASSERT_TRUE(it0 != process_data.phased_snapshots.end()); |
| 438 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 439 |
| 440 ASSERT_EQ(0u, process_data_phase0.tasks.size()); |
| 441 |
| 350 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 442 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 351 } | 443 } |
| 352 | 444 |
| 353 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { | 445 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { |
| 354 // Start in the deactivated state. | 446 // Start in the deactivated state. |
| 355 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 447 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 448 // Don't run the test if task tracking is not compiled in. |
| 356 return; | 449 return; |
| 357 } | 450 } |
| 358 | 451 |
| 359 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; | 452 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; |
| 360 Location location(kFunction, kFile, kLineNumber, NULL); | 453 Location location(kFunction, kFile, kLineNumber, NULL); |
| 361 TallyABirth(location, kMainThreadName); | 454 TallyABirth(location, kMainThreadName); |
| 362 | 455 |
| 363 ProcessDataSnapshot process_data; | 456 ProcessDataSnapshot process_data; |
| 364 ThreadData::Snapshot(&process_data); | 457 ThreadData::Snapshot(0, &process_data); |
| 365 | 458 |
| 366 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 459 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 367 auto it = process_data.phased_process_data_snapshots.find(0); | |
| 368 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | |
| 369 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | |
| 370 | 460 |
| 371 EXPECT_EQ(0u, process_data_phase.tasks.size()); | 461 auto it0 = process_data.phased_snapshots.find(0); |
| 372 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 462 ASSERT_TRUE(it0 != process_data.phased_snapshots.end()); |
| 463 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 464 |
| 465 ASSERT_EQ(0u, process_data_phase0.tasks.size()); |
| 466 |
| 373 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 467 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 374 } | 468 } |
| 375 | 469 |
| 376 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { | 470 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { |
| 377 if (!ThreadData::InitializeAndSetTrackingStatus( | 471 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 378 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 472 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 473 // Don't run the test if task tracking is not compiled in. |
| 379 return; | 474 return; |
| 380 } | 475 } |
| 381 | 476 |
| 382 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; | 477 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; |
| 383 Location location(kFunction, kFile, kLineNumber, NULL); | 478 Location location(kFunction, kFile, kLineNumber, NULL); |
| 384 TallyABirth(location, std::string()); | 479 TallyABirth(location, std::string()); |
| 385 | 480 |
| 386 ProcessDataSnapshot process_data; | 481 ProcessDataSnapshot process_data; |
| 387 ThreadData::Snapshot(&process_data); | 482 ThreadData::Snapshot(0, &process_data); |
| 388 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, | 483 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 389 kStillAlive, 1, 0, 0); | 484 kStillAlive, 1, 0, 0); |
| 390 } | 485 } |
| 391 | 486 |
| 392 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { | 487 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { |
| 393 if (!ThreadData::InitializeAndSetTrackingStatus( | 488 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 394 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 489 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 490 // Don't run the test if task tracking is not compiled in. |
| 395 return; | 491 return; |
| 396 } | 492 } |
| 397 | 493 |
| 398 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; | 494 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; |
| 399 Location location(kFunction, kFile, kLineNumber, NULL); | 495 Location location(kFunction, kFile, kLineNumber, NULL); |
| 400 TallyABirth(location, kMainThreadName); | 496 TallyABirth(location, kMainThreadName); |
| 401 | 497 |
| 402 ProcessDataSnapshot process_data; | 498 ProcessDataSnapshot process_data; |
| 403 ThreadData::Snapshot(&process_data); | 499 ThreadData::Snapshot(0, &process_data); |
| 404 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, | 500 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, |
| 405 1, 0, 0); | 501 1, 0, 0); |
| 406 } | 502 } |
| 407 | 503 |
| 408 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { | 504 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
| 409 if (!ThreadData::InitializeAndSetTrackingStatus( | 505 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 410 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 506 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 507 // Don't run the test if task tracking is not compiled in. |
| 411 return; | 508 return; |
| 412 } | 509 } |
| 413 | 510 |
| 414 const char kFunction[] = "LifeCycleToSnapshotMainThread"; | 511 const char kFunction[] = "LifeCycleToSnapshotMainThread"; |
| 415 Location location(kFunction, kFile, kLineNumber, NULL); | 512 Location location(kFunction, kFile, kLineNumber, NULL); |
| 416 TallyABirth(location, kMainThreadName); | 513 TallyABirth(location, kMainThreadName); |
| 417 | 514 |
| 418 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 515 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 419 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 516 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 420 // TrackingInfo will call TallyABirth() during construction. | 517 // TrackingInfo will call TallyABirth() during construction. |
| 421 base::TrackingInfo pending_task(location, kDelayedStartTime); | 518 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 422 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 519 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 423 | 520 |
| 424 const unsigned int kStartOfRun = 5; | 521 const unsigned int kStartOfRun = 5; |
| 425 const unsigned int kEndOfRun = 7; | 522 const unsigned int kEndOfRun = 7; |
| 426 SetTestTime(kStartOfRun); | 523 SetTestTime(kStartOfRun); |
| 427 TaskStopwatch stopwatch; | 524 TaskStopwatch stopwatch; |
| 428 stopwatch.Start(); | 525 stopwatch.Start(); |
| 429 SetTestTime(kEndOfRun); | 526 SetTestTime(kEndOfRun); |
| 430 stopwatch.Stop(); | 527 stopwatch.Stop(); |
| 431 | 528 |
| 432 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 529 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 433 | 530 |
| 434 ProcessDataSnapshot process_data; | 531 ProcessDataSnapshot process_data; |
| 435 ThreadData::Snapshot(&process_data); | 532 ThreadData::Snapshot(0, &process_data); |
| 436 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 533 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 437 kMainThreadName, 1, 2, 4); | 534 kMainThreadName, 1, 2, 4); |
| 438 } | 535 } |
| 439 | 536 |
| 537 TEST_F(TrackedObjectsTest, TwoPhases) { |
| 538 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 539 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 540 // Don't run the test if task tracking is not compiled in. |
| 541 return; |
| 542 } |
| 543 |
| 544 const char kFunction[] = "TwoPhases"; |
| 545 Location location(kFunction, kFile, kLineNumber, NULL); |
| 546 TallyABirth(location, kMainThreadName); |
| 547 |
| 548 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 549 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 550 // TrackingInfo will call TallyABirth() during construction. |
| 551 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 552 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 553 |
| 554 const unsigned int kStartOfRun = 5; |
| 555 const unsigned int kEndOfRun = 7; |
| 556 SetTestTime(kStartOfRun); |
| 557 TaskStopwatch stopwatch; |
| 558 stopwatch.Start(); |
| 559 SetTestTime(kEndOfRun); |
| 560 stopwatch.Stop(); |
| 561 |
| 562 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 563 |
| 564 ThreadData::OnProfilingPhaseCompleted(0); |
| 565 |
| 566 TallyABirth(location, kMainThreadName); |
| 567 |
| 568 const TrackedTime kTimePosted1 = TrackedTime::FromMilliseconds(9); |
| 569 const base::TimeTicks kDelayedStartTime1 = base::TimeTicks(); |
| 570 // TrackingInfo will call TallyABirth() during construction. |
| 571 base::TrackingInfo pending_task1(location, kDelayedStartTime1); |
| 572 pending_task1.time_posted = kTimePosted1; // Overwrite implied Now(). |
| 573 |
| 574 const unsigned int kStartOfRun1 = 11; |
| 575 const unsigned int kEndOfRun1 = 21; |
| 576 SetTestTime(kStartOfRun1); |
| 577 TaskStopwatch stopwatch1; |
| 578 stopwatch1.Start(); |
| 579 SetTestTime(kEndOfRun1); |
| 580 stopwatch1.Stop(); |
| 581 |
| 582 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task1, stopwatch1); |
| 583 |
| 584 ProcessDataSnapshot process_data; |
| 585 ThreadData::Snapshot(1, &process_data); |
| 586 |
| 587 ASSERT_EQ(2u, process_data.phased_snapshots.size()); |
| 588 |
| 589 auto it0 = process_data.phased_snapshots.find(0); |
| 590 ASSERT_TRUE(it0 != process_data.phased_snapshots.end()); |
| 591 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 592 |
| 593 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 594 |
| 595 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 596 EXPECT_EQ(kFunction, |
| 597 process_data_phase0.tasks[0].birth.location.function_name); |
| 598 EXPECT_EQ(kLineNumber, |
| 599 process_data_phase0.tasks[0].birth.location.line_number); |
| 600 |
| 601 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 602 |
| 603 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 604 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 605 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 606 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 607 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 608 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 609 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 610 |
| 611 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 612 |
| 613 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 614 |
| 615 auto it1 = process_data.phased_snapshots.find(1); |
| 616 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 617 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 618 |
| 619 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 620 |
| 621 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 622 EXPECT_EQ(kFunction, |
| 623 process_data_phase1.tasks[0].birth.location.function_name); |
| 624 EXPECT_EQ(kLineNumber, |
| 625 process_data_phase1.tasks[0].birth.location.line_number); |
| 626 |
| 627 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 628 |
| 629 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 630 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 631 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 632 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 633 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 634 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 635 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 636 |
| 637 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 638 |
| 639 EXPECT_EQ(0u, process_data_phase1.descendants.size()); |
| 640 |
| 641 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 642 } |
| 643 |
| 644 TEST_F(TrackedObjectsTest, ThreePhases) { |
| 645 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 646 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 647 // Don't run the test if task tracking is not compiled in. |
| 648 return; |
| 649 } |
| 650 |
| 651 const char kFunction[] = "ThreePhases"; |
| 652 Location location(kFunction, kFile, kLineNumber, NULL); |
| 653 |
| 654 // Phase 0 |
| 655 { |
| 656 TallyABirth(location, kMainThreadName); |
| 657 |
| 658 // TrackingInfo will call TallyABirth() during construction. |
| 659 SetTestTime(10); |
| 660 base::TrackingInfo pending_task(location, base::TimeTicks()); |
| 661 |
| 662 SetTestTime(17); |
| 663 TaskStopwatch stopwatch; |
| 664 stopwatch.Start(); |
| 665 SetTestTime(23); |
| 666 stopwatch.Stop(); |
| 667 |
| 668 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 669 } |
| 670 |
| 671 ThreadData::OnProfilingPhaseCompleted(0); |
| 672 |
| 673 // Phase 1 |
| 674 { |
| 675 TallyABirth(location, kMainThreadName); |
| 676 |
| 677 SetTestTime(30); |
| 678 base::TrackingInfo pending_task(location, base::TimeTicks()); |
| 679 |
| 680 SetTestTime(35); |
| 681 TaskStopwatch stopwatch; |
| 682 stopwatch.Start(); |
| 683 SetTestTime(39); |
| 684 stopwatch.Stop(); |
| 685 |
| 686 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 687 } |
| 688 |
| 689 ThreadData::OnProfilingPhaseCompleted(1); |
| 690 |
| 691 // Phase 2 |
| 692 { |
| 693 TallyABirth(location, kMainThreadName); |
| 694 |
| 695 // TrackingInfo will call TallyABirth() during construction. |
| 696 SetTestTime(40); |
| 697 base::TrackingInfo pending_task(location, base::TimeTicks()); |
| 698 |
| 699 SetTestTime(43); |
| 700 TaskStopwatch stopwatch; |
| 701 stopwatch.Start(); |
| 702 SetTestTime(45); |
| 703 stopwatch.Stop(); |
| 704 |
| 705 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 706 } |
| 707 |
| 708 // Snapshot and check results. |
| 709 ProcessDataSnapshot process_data; |
| 710 ThreadData::Snapshot(2, &process_data); |
| 711 |
| 712 ASSERT_EQ(3u, process_data.phased_snapshots.size()); |
| 713 |
| 714 auto it0 = process_data.phased_snapshots.find(0); |
| 715 ASSERT_TRUE(it0 != process_data.phased_snapshots.end()); |
| 716 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 717 |
| 718 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 719 |
| 720 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 721 EXPECT_EQ(kFunction, |
| 722 process_data_phase0.tasks[0].birth.location.function_name); |
| 723 EXPECT_EQ(kLineNumber, |
| 724 process_data_phase0.tasks[0].birth.location.line_number); |
| 725 |
| 726 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 727 |
| 728 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 729 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 730 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 731 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 732 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 733 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 734 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 735 |
| 736 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 737 |
| 738 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 739 |
| 740 auto it1 = process_data.phased_snapshots.find(1); |
| 741 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 742 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 743 |
| 744 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 745 |
| 746 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 747 EXPECT_EQ(kFunction, |
| 748 process_data_phase1.tasks[0].birth.location.function_name); |
| 749 EXPECT_EQ(kLineNumber, |
| 750 process_data_phase1.tasks[0].birth.location.line_number); |
| 751 |
| 752 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 753 |
| 754 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 755 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 756 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 757 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 758 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 759 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 760 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 761 |
| 762 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 763 |
| 764 EXPECT_EQ(0u, process_data_phase1.descendants.size()); |
| 765 |
| 766 auto it2 = process_data.phased_snapshots.find(2); |
| 767 ASSERT_TRUE(it2 != process_data.phased_snapshots.end()); |
| 768 const ProcessDataPhaseSnapshot& process_data_phase2 = it2->second; |
| 769 |
| 770 ASSERT_EQ(1u, process_data_phase2.tasks.size()); |
| 771 |
| 772 EXPECT_EQ(kFile, process_data_phase2.tasks[0].birth.location.file_name); |
| 773 EXPECT_EQ(kFunction, |
| 774 process_data_phase2.tasks[0].birth.location.function_name); |
| 775 EXPECT_EQ(kLineNumber, |
| 776 process_data_phase2.tasks[0].birth.location.line_number); |
| 777 |
| 778 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].birth.thread_name); |
| 779 |
| 780 EXPECT_EQ(1, process_data_phase2.tasks[0].death_data.count); |
| 781 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sum); |
| 782 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_max); |
| 783 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sample); |
| 784 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sum); |
| 785 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_max); |
| 786 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sample); |
| 787 |
| 788 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].death_thread_name); |
| 789 |
| 790 EXPECT_EQ(0u, process_data_phase2.descendants.size()); |
| 791 |
| 792 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 793 } |
| 794 |
| 795 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) { |
| 796 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 797 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 798 // Don't run the test if task tracking is not compiled in. |
| 799 return; |
| 800 } |
| 801 |
| 802 const char kFunction[] = "TwoPhasesSecondEmpty"; |
| 803 Location location(kFunction, kFile, kLineNumber, NULL); |
| 804 ThreadData::InitializeThreadContext(kMainThreadName); |
| 805 |
| 806 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 807 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 808 // TrackingInfo will call TallyABirth() during construction. |
| 809 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 810 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 811 |
| 812 const unsigned int kStartOfRun = 5; |
| 813 const unsigned int kEndOfRun = 7; |
| 814 SetTestTime(kStartOfRun); |
| 815 TaskStopwatch stopwatch; |
| 816 stopwatch.Start(); |
| 817 SetTestTime(kEndOfRun); |
| 818 stopwatch.Stop(); |
| 819 |
| 820 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 821 |
| 822 ThreadData::OnProfilingPhaseCompleted(0); |
| 823 |
| 824 ProcessDataSnapshot process_data; |
| 825 ThreadData::Snapshot(1, &process_data); |
| 826 |
| 827 ASSERT_EQ(2u, process_data.phased_snapshots.size()); |
| 828 |
| 829 auto it0 = process_data.phased_snapshots.find(0); |
| 830 ASSERT_TRUE(it0 != process_data.phased_snapshots.end()); |
| 831 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 832 |
| 833 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 834 |
| 835 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 836 EXPECT_EQ(kFunction, |
| 837 process_data_phase0.tasks[0].birth.location.function_name); |
| 838 EXPECT_EQ(kLineNumber, |
| 839 process_data_phase0.tasks[0].birth.location.line_number); |
| 840 |
| 841 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 842 |
| 843 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 844 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 845 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 846 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 847 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 848 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 849 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 850 |
| 851 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 852 |
| 853 auto it1 = process_data.phased_snapshots.find(1); |
| 854 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 855 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 856 |
| 857 ASSERT_EQ(0u, process_data_phase1.tasks.size()); |
| 858 |
| 859 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 860 |
| 861 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 862 } |
| 863 |
| 864 TEST_F(TrackedObjectsTest, TwoPhasesFirstEmpty) { |
| 865 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 866 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 867 // Don't run the test if task tracking is not compiled in. |
| 868 return; |
| 869 } |
| 870 |
| 871 ThreadData::OnProfilingPhaseCompleted(0); |
| 872 |
| 873 const char kFunction[] = "TwoPhasesSecondEmpty"; |
| 874 Location location(kFunction, kFile, kLineNumber, NULL); |
| 875 ThreadData::InitializeThreadContext(kMainThreadName); |
| 876 |
| 877 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 878 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 879 // TrackingInfo will call TallyABirth() during construction. |
| 880 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 881 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 882 |
| 883 const unsigned int kStartOfRun = 5; |
| 884 const unsigned int kEndOfRun = 7; |
| 885 SetTestTime(kStartOfRun); |
| 886 TaskStopwatch stopwatch; |
| 887 stopwatch.Start(); |
| 888 SetTestTime(kEndOfRun); |
| 889 stopwatch.Stop(); |
| 890 |
| 891 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 892 |
| 893 ProcessDataSnapshot process_data; |
| 894 ThreadData::Snapshot(1, &process_data); |
| 895 |
| 896 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 897 |
| 898 auto it1 = process_data.phased_snapshots.find(1); |
| 899 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 900 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 901 |
| 902 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 903 |
| 904 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 905 EXPECT_EQ(kFunction, |
| 906 process_data_phase1.tasks[0].birth.location.function_name); |
| 907 EXPECT_EQ(kLineNumber, |
| 908 process_data_phase1.tasks[0].birth.location.line_number); |
| 909 |
| 910 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 911 |
| 912 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 913 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 914 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 915 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 916 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 917 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 918 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 919 |
| 920 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 921 |
| 922 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 923 } |
| 924 |
| 440 // We will deactivate tracking after the birth, and before the death, and | 925 // We will deactivate tracking after the birth, and before the death, and |
| 441 // demonstrate that the lifecycle is completely tallied. This ensures that | 926 // demonstrate that the lifecycle is completely tallied. This ensures that |
| 442 // our tallied births are matched by tallied deaths (except for when the | 927 // our tallied births are matched by tallied deaths (except for when the |
| 443 // task is still running, or is queued). | 928 // task is still running, or is queued). |
| 444 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { | 929 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
| 445 if (!ThreadData::InitializeAndSetTrackingStatus( | 930 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 446 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 931 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 932 // Don't run the test if task tracking is not compiled in. |
| 447 return; | 933 return; |
| 448 } | 934 } |
| 449 | 935 |
| 450 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; | 936 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
| 451 Location location(kFunction, kFile, kLineNumber, NULL); | 937 Location location(kFunction, kFile, kLineNumber, NULL); |
| 452 TallyABirth(location, kMainThreadName); | 938 TallyABirth(location, kMainThreadName); |
| 453 | 939 |
| 454 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 940 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 455 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 941 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 456 // TrackingInfo will call TallyABirth() during construction. | 942 // TrackingInfo will call TallyABirth() during construction. |
| 457 base::TrackingInfo pending_task(location, kDelayedStartTime); | 943 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 458 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 944 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 459 | 945 |
| 460 // Turn off tracking now that we have births. | 946 // Turn off tracking now that we have births. |
| 461 EXPECT_TRUE( | 947 EXPECT_TRUE( |
| 462 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)); | 948 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)); |
| 463 | 949 |
| 464 const unsigned int kStartOfRun = 5; | 950 const unsigned int kStartOfRun = 5; |
| 465 const unsigned int kEndOfRun = 7; | 951 const unsigned int kEndOfRun = 7; |
| 466 SetTestTime(kStartOfRun); | 952 SetTestTime(kStartOfRun); |
| 467 TaskStopwatch stopwatch; | 953 TaskStopwatch stopwatch; |
| 468 stopwatch.Start(); | 954 stopwatch.Start(); |
| 469 SetTestTime(kEndOfRun); | 955 SetTestTime(kEndOfRun); |
| 470 stopwatch.Stop(); | 956 stopwatch.Stop(); |
| 471 | 957 |
| 472 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 958 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 473 | 959 |
| 474 ProcessDataSnapshot process_data; | 960 ProcessDataSnapshot process_data; |
| 475 ThreadData::Snapshot(&process_data); | 961 ThreadData::Snapshot(0, &process_data); |
| 476 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 962 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 477 kMainThreadName, 1, 2, 4); | 963 kMainThreadName, 1, 2, 4); |
| 478 } | 964 } |
| 479 | 965 |
| 480 // We will deactivate tracking before starting a life cycle, and neither | 966 // We will deactivate tracking before starting a life cycle, and neither |
| 481 // the birth nor the death will be recorded. | 967 // the birth nor the death will be recorded. |
| 482 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { | 968 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { |
| 483 // Start in the deactivated state. | 969 // Start in the deactivated state. |
| 484 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 970 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 971 // Don't run the test if task tracking is not compiled in. |
| 485 return; | 972 return; |
| 486 } | 973 } |
| 487 | 974 |
| 488 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; | 975 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; |
| 489 Location location(kFunction, kFile, kLineNumber, NULL); | 976 Location location(kFunction, kFile, kLineNumber, NULL); |
| 490 TallyABirth(location, kMainThreadName); | 977 TallyABirth(location, kMainThreadName); |
| 491 | 978 |
| 492 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 979 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 493 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 980 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 494 // TrackingInfo will call TallyABirth() during construction. | 981 // TrackingInfo will call TallyABirth() during construction. |
| 495 base::TrackingInfo pending_task(location, kDelayedStartTime); | 982 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 496 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 983 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 497 | 984 |
| 498 const unsigned int kStartOfRun = 5; | 985 const unsigned int kStartOfRun = 5; |
| 499 const unsigned int kEndOfRun = 7; | 986 const unsigned int kEndOfRun = 7; |
| 500 SetTestTime(kStartOfRun); | 987 SetTestTime(kStartOfRun); |
| 501 TaskStopwatch stopwatch; | 988 TaskStopwatch stopwatch; |
| 502 stopwatch.Start(); | 989 stopwatch.Start(); |
| 503 SetTestTime(kEndOfRun); | 990 SetTestTime(kEndOfRun); |
| 504 stopwatch.Stop(); | 991 stopwatch.Stop(); |
| 505 | 992 |
| 506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 993 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 507 | 994 |
| 508 ProcessDataSnapshot process_data; | 995 ProcessDataSnapshot process_data; |
| 509 ThreadData::Snapshot(&process_data); | 996 ThreadData::Snapshot(0, &process_data); |
| 510 | 997 |
| 511 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 998 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 512 auto it = process_data.phased_process_data_snapshots.find(0); | |
| 513 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | |
| 514 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | |
| 515 | 999 |
| 516 EXPECT_EQ(0u, process_data_phase.tasks.size()); | 1000 auto it0 = process_data.phased_snapshots.find(0); |
| 517 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 1001 ASSERT_TRUE(it0 != process_data.phased_snapshots.end()); |
| 1002 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 1003 |
| 1004 ASSERT_EQ(0u, process_data_phase0.tasks.size()); |
| 1005 |
| 518 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1006 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 519 } | 1007 } |
| 520 | 1008 |
| 521 TEST_F(TrackedObjectsTest, TwoLives) { | 1009 TEST_F(TrackedObjectsTest, TwoLives) { |
| 522 if (!ThreadData::InitializeAndSetTrackingStatus( | 1010 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 523 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1011 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 1012 // Don't run the test if task tracking is not compiled in. |
| 524 return; | 1013 return; |
| 525 } | 1014 } |
| 526 | 1015 |
| 527 const char kFunction[] = "TwoLives"; | 1016 const char kFunction[] = "TwoLives"; |
| 528 Location location(kFunction, kFile, kLineNumber, NULL); | 1017 Location location(kFunction, kFile, kLineNumber, NULL); |
| 529 TallyABirth(location, kMainThreadName); | 1018 TallyABirth(location, kMainThreadName); |
| 530 | 1019 |
| 531 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1020 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 532 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 1021 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 533 // TrackingInfo will call TallyABirth() during construction. | 1022 // TrackingInfo will call TallyABirth() during construction. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 549 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 1038 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 550 SetTestTime(kStartOfRun); | 1039 SetTestTime(kStartOfRun); |
| 551 TaskStopwatch stopwatch2; | 1040 TaskStopwatch stopwatch2; |
| 552 stopwatch2.Start(); | 1041 stopwatch2.Start(); |
| 553 SetTestTime(kEndOfRun); | 1042 SetTestTime(kEndOfRun); |
| 554 stopwatch2.Stop(); | 1043 stopwatch2.Stop(); |
| 555 | 1044 |
| 556 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); | 1045 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); |
| 557 | 1046 |
| 558 ProcessDataSnapshot process_data; | 1047 ProcessDataSnapshot process_data; |
| 559 ThreadData::Snapshot(&process_data); | 1048 ThreadData::Snapshot(0, &process_data); |
| 560 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 1049 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 561 kMainThreadName, 2, 2, 4); | 1050 kMainThreadName, 2, 2, 4); |
| 562 } | 1051 } |
| 563 | 1052 |
| 564 TEST_F(TrackedObjectsTest, DifferentLives) { | 1053 TEST_F(TrackedObjectsTest, DifferentLives) { |
| 565 if (!ThreadData::InitializeAndSetTrackingStatus( | 1054 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 566 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1055 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 1056 // Don't run the test if task tracking is not compiled in. |
| 567 return; | 1057 return; |
| 568 } | 1058 } |
| 569 | 1059 |
| 570 // Use a well named thread. | 1060 // Use a well named thread. |
| 571 ThreadData::InitializeThreadContext(kMainThreadName); | 1061 ThreadData::InitializeThreadContext(kMainThreadName); |
| 572 const char kFunction[] = "DifferentLives"; | 1062 const char kFunction[] = "DifferentLives"; |
| 573 Location location(kFunction, kFile, kLineNumber, NULL); | 1063 Location location(kFunction, kFile, kLineNumber, NULL); |
| 574 | 1064 |
| 575 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1065 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 576 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 1066 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 589 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 1079 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 590 | 1080 |
| 591 const int kSecondFakeLineNumber = 999; | 1081 const int kSecondFakeLineNumber = 999; |
| 592 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 1082 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 593 | 1083 |
| 594 // TrackingInfo will call TallyABirth() during construction. | 1084 // TrackingInfo will call TallyABirth() during construction. |
| 595 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 1085 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 596 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 1086 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 597 | 1087 |
| 598 ProcessDataSnapshot process_data; | 1088 ProcessDataSnapshot process_data; |
| 599 ThreadData::Snapshot(&process_data); | 1089 ThreadData::Snapshot(0, &process_data); |
| 600 | 1090 |
| 601 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 1091 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 602 auto it = process_data.phased_process_data_snapshots.find(0); | 1092 auto it = process_data.phased_snapshots.find(0); |
| 603 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 1093 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 604 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 1094 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 605 | 1095 |
| 606 ASSERT_EQ(2u, process_data_phase.tasks.size()); | 1096 ASSERT_EQ(2u, process_data_phase.tasks.size()); |
| 607 | 1097 |
| 608 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); | 1098 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 609 EXPECT_EQ(kFunction, | 1099 EXPECT_EQ(kFunction, |
| 610 process_data_phase.tasks[0].birth.location.function_name); | 1100 process_data_phase.tasks[0].birth.location.function_name); |
| 611 EXPECT_EQ(kLineNumber, | 1101 EXPECT_EQ(kLineNumber, |
| 612 process_data_phase.tasks[0].birth.location.line_number); | 1102 process_data_phase.tasks[0].birth.location.line_number); |
| 613 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[0].birth.thread_name); | 1103 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[0].birth.thread_name); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 633 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); | 1123 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); |
| 634 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); | 1124 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); |
| 635 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); | 1125 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); |
| 636 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 1126 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 637 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1127 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 638 } | 1128 } |
| 639 | 1129 |
| 640 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { | 1130 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { |
| 641 if (!ThreadData::InitializeAndSetTrackingStatus( | 1131 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 642 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1132 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 1133 // Don't run the test if task tracking is not compiled in. |
| 643 return; | 1134 return; |
| 644 } | 1135 } |
| 645 | 1136 |
| 646 const char kFunction[] = "TaskWithNestedExclusion"; | 1137 const char kFunction[] = "TaskWithNestedExclusion"; |
| 647 Location location(kFunction, kFile, kLineNumber, NULL); | 1138 Location location(kFunction, kFile, kLineNumber, NULL); |
| 648 TallyABirth(location, kMainThreadName); | 1139 TallyABirth(location, kMainThreadName); |
| 649 | 1140 |
| 650 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1141 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 651 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 1142 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 652 // TrackingInfo will call TallyABirth() during construction. | 1143 // TrackingInfo will call TallyABirth() during construction. |
| 653 base::TrackingInfo pending_task(location, kDelayedStartTime); | 1144 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 654 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 1145 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 655 | 1146 |
| 656 SetTestTime(5); | 1147 SetTestTime(5); |
| 657 TaskStopwatch task_stopwatch; | 1148 TaskStopwatch task_stopwatch; |
| 658 task_stopwatch.Start(); | 1149 task_stopwatch.Start(); |
| 659 { | 1150 { |
| 660 SetTestTime(8); | 1151 SetTestTime(8); |
| 661 TaskStopwatch exclusion_stopwatch; | 1152 TaskStopwatch exclusion_stopwatch; |
| 662 exclusion_stopwatch.Start(); | 1153 exclusion_stopwatch.Start(); |
| 663 SetTestTime(12); | 1154 SetTestTime(12); |
| 664 exclusion_stopwatch.Stop(); | 1155 exclusion_stopwatch.Stop(); |
| 665 } | 1156 } |
| 666 SetTestTime(15); | 1157 SetTestTime(15); |
| 667 task_stopwatch.Stop(); | 1158 task_stopwatch.Stop(); |
| 668 | 1159 |
| 669 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 1160 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 670 | 1161 |
| 671 ProcessDataSnapshot process_data; | 1162 ProcessDataSnapshot process_data; |
| 672 ThreadData::Snapshot(&process_data); | 1163 ThreadData::Snapshot(0, &process_data); |
| 673 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 1164 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 674 kMainThreadName, 1, 6, 4); | 1165 kMainThreadName, 1, 6, 4); |
| 675 } | 1166 } |
| 676 | 1167 |
| 677 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { | 1168 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { |
| 678 if (!ThreadData::InitializeAndSetTrackingStatus( | 1169 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 679 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1170 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 1171 // Don't run the test if task tracking is not compiled in. |
| 680 return; | 1172 return; |
| 681 } | 1173 } |
| 682 | 1174 |
| 683 const char kFunction[] = "TaskWith2NestedExclusions"; | 1175 const char kFunction[] = "TaskWith2NestedExclusions"; |
| 684 Location location(kFunction, kFile, kLineNumber, NULL); | 1176 Location location(kFunction, kFile, kLineNumber, NULL); |
| 685 TallyABirth(location, kMainThreadName); | 1177 TallyABirth(location, kMainThreadName); |
| 686 | 1178 |
| 687 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1179 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 688 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 1180 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 689 // TrackingInfo will call TallyABirth() during construction. | 1181 // TrackingInfo will call TallyABirth() during construction. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 705 exclusion_stopwatch2.Start(); | 1197 exclusion_stopwatch2.Start(); |
| 706 SetTestTime(18); | 1198 SetTestTime(18); |
| 707 exclusion_stopwatch2.Stop(); | 1199 exclusion_stopwatch2.Stop(); |
| 708 } | 1200 } |
| 709 SetTestTime(25); | 1201 SetTestTime(25); |
| 710 task_stopwatch.Stop(); | 1202 task_stopwatch.Stop(); |
| 711 | 1203 |
| 712 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 1204 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 713 | 1205 |
| 714 ProcessDataSnapshot process_data; | 1206 ProcessDataSnapshot process_data; |
| 715 ThreadData::Snapshot(&process_data); | 1207 ThreadData::Snapshot(0, &process_data); |
| 716 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 1208 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 717 kMainThreadName, 1, 13, 4); | 1209 kMainThreadName, 1, 13, 4); |
| 718 } | 1210 } |
| 719 | 1211 |
| 720 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { | 1212 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { |
| 721 if (!ThreadData::InitializeAndSetTrackingStatus( | 1213 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 722 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1214 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 1215 // Don't run the test if task tracking is not compiled in. |
| 723 return; | 1216 return; |
| 724 } | 1217 } |
| 725 | 1218 |
| 726 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; | 1219 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; |
| 727 Location location(kFunction, kFile, kLineNumber, NULL); | 1220 Location location(kFunction, kFile, kLineNumber, NULL); |
| 728 | 1221 |
| 729 const int kSecondFakeLineNumber = 999; | 1222 const int kSecondFakeLineNumber = 999; |
| 730 | 1223 |
| 731 TallyABirth(location, kMainThreadName); | 1224 TallyABirth(location, kMainThreadName); |
| 732 | 1225 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 758 } | 1251 } |
| 759 SetTestTime(12); | 1252 SetTestTime(12); |
| 760 exclusion_stopwatch.Stop(); | 1253 exclusion_stopwatch.Stop(); |
| 761 } | 1254 } |
| 762 SetTestTime(15); | 1255 SetTestTime(15); |
| 763 task_stopwatch.Stop(); | 1256 task_stopwatch.Stop(); |
| 764 | 1257 |
| 765 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 1258 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 766 | 1259 |
| 767 ProcessDataSnapshot process_data; | 1260 ProcessDataSnapshot process_data; |
| 768 ThreadData::Snapshot(&process_data); | 1261 ThreadData::Snapshot(0, &process_data); |
| 769 | 1262 |
| 770 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 1263 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 771 auto it = process_data.phased_process_data_snapshots.find(0); | 1264 auto it = process_data.phased_snapshots.find(0); |
| 772 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 1265 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 773 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 1266 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 774 | 1267 |
| 775 // The order in which the two task follow is platform-dependent. | 1268 // The order in which the two task follow is platform-dependent. |
| 776 int t0 = | 1269 int t0 = |
| 777 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) | 1270 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) |
| 778 ? 0 | 1271 ? 0 |
| 779 : 1; | 1272 : 1; |
| 780 int t1 = 1 - t0; | 1273 int t1 = 1 - t0; |
| 781 | 1274 |
| 782 ASSERT_EQ(2u, process_data_phase.tasks.size()); | 1275 ASSERT_EQ(2u, process_data_phase.tasks.size()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 806 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); | 1299 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); |
| 807 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); | 1300 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); |
| 808 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); | 1301 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); |
| 809 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); | 1302 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); |
| 810 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); | 1303 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); |
| 811 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 1304 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 812 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1305 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 813 } | 1306 } |
| 814 | 1307 |
| 815 } // namespace tracked_objects | 1308 } // namespace tracked_objects |
| OLD | NEW |