| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 process_data_phase.tasks[0].death_data.run_duration_sample); | 94 process_data_phase.tasks[0].death_data.run_duration_sample); |
| 95 EXPECT_EQ(count * queue_ms, | 95 EXPECT_EQ(count * queue_ms, |
| 96 process_data_phase.tasks[0].death_data.queue_duration_sum); | 96 process_data_phase.tasks[0].death_data.queue_duration_sum); |
| 97 EXPECT_EQ(queue_ms, | 97 EXPECT_EQ(queue_ms, |
| 98 process_data_phase.tasks[0].death_data.queue_duration_max); | 98 process_data_phase.tasks[0].death_data.queue_duration_max); |
| 99 EXPECT_EQ(queue_ms, | 99 EXPECT_EQ(queue_ms, |
| 100 process_data_phase.tasks[0].death_data.queue_duration_sample); | 100 process_data_phase.tasks[0].death_data.queue_duration_sample); |
| 101 | 101 |
| 102 EXPECT_EQ(death_thread, process_data_phase.tasks[0].death_thread_name); | 102 EXPECT_EQ(death_thread, process_data_phase.tasks[0].death_thread_name); |
| 103 | 103 |
| 104 EXPECT_EQ(0u, process_data_phase.descendants.size()); | |
| 105 | |
| 106 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 104 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 107 } | 105 } |
| 108 | 106 |
| 109 // Sets time that will be returned by ThreadData::Now(). | 107 // Sets time that will be returned by ThreadData::Now(). |
| 110 static void SetTestTime(unsigned int test_time) { test_time_ = test_time; } | 108 static void SetTestTime(unsigned int test_time) { test_time_ = test_time; } |
| 111 | 109 |
| 112 private: | 110 private: |
| 113 // Returns test time in milliseconds. | 111 // Returns test time in milliseconds. |
| 114 static unsigned int GetTestTime() { return test_time_; } | 112 static unsigned int GetTestTime() { return test_time_; } |
| 115 | 113 |
| 116 // Test time in milliseconds. | 114 // Test time in milliseconds. |
| 117 static unsigned int test_time_; | 115 static unsigned int test_time_; |
| 118 }; | 116 }; |
| 119 | 117 |
| 120 // static | 118 // static |
| 121 unsigned int TrackedObjectsTest::test_time_; | 119 unsigned int TrackedObjectsTest::test_time_; |
| 122 | 120 |
| 123 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { | 121 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { |
| 124 if (!ThreadData::InitializeAndSetTrackingStatus( | 122 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 125 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 123 ThreadData::PROFILING_ACTIVE)) { |
| 126 // Don't run the test if task tracking is not compiled in. | 124 // Don't run the test if task tracking is not compiled in. |
| 127 return; | 125 return; |
| 128 } | 126 } |
| 129 | 127 |
| 130 // Check that creating and destroying a stopwatch without starting it doesn't | 128 // Check that creating and destroying a stopwatch without starting it doesn't |
| 131 // crash. | 129 // crash. |
| 132 TaskStopwatch stopwatch; | 130 TaskStopwatch stopwatch; |
| 133 } | 131 } |
| 134 | 132 |
| 135 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { | 133 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
| 136 // Minimal test doesn't even create any tasks. | 134 // Minimal test doesn't even create any tasks. |
| 137 if (!ThreadData::InitializeAndSetTrackingStatus( | 135 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 138 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 136 ThreadData::PROFILING_ACTIVE)) { |
| 139 // Don't run the test if task tracking is not compiled in. | 137 // Don't run the test if task tracking is not compiled in. |
| 140 return; | 138 return; |
| 141 } | 139 } |
| 142 | 140 |
| 143 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 141 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 144 ThreadData* data = ThreadData::Get(); | 142 ThreadData* data = ThreadData::Get(); |
| 145 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 143 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 146 ASSERT_TRUE(data); | 144 ASSERT_TRUE(data); |
| 147 EXPECT_FALSE(data->next()); | 145 EXPECT_FALSE(data->next()); |
| 148 EXPECT_EQ(data, ThreadData::Get()); | 146 EXPECT_EQ(data, ThreadData::Get()); |
| 149 ThreadData::BirthMap birth_map; | 147 ThreadData::BirthMap birth_map; |
| 150 ThreadData::DeathsSnapshot deaths; | 148 ThreadData::DeathsSnapshot deaths; |
| 151 ThreadData::ParentChildSet parent_child_set; | 149 data->SnapshotMaps(0, &birth_map, &deaths); |
| 152 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); | |
| 153 EXPECT_EQ(0u, birth_map.size()); | 150 EXPECT_EQ(0u, birth_map.size()); |
| 154 EXPECT_EQ(0u, deaths.size()); | 151 EXPECT_EQ(0u, deaths.size()); |
| 155 EXPECT_EQ(0u, parent_child_set.size()); | |
| 156 | 152 |
| 157 // Clean up with no leaking. | 153 // Clean up with no leaking. |
| 158 Reset(); | 154 Reset(); |
| 159 | 155 |
| 160 // Do it again, just to be sure we reset state completely. | 156 // Do it again, just to be sure we reset state completely. |
| 161 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 157 EXPECT_TRUE( |
| 162 ThreadData::PROFILING_CHILDREN_ACTIVE)); | 158 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE)); |
| 163 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 159 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 164 data = ThreadData::Get(); | 160 data = ThreadData::Get(); |
| 165 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 161 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 166 ASSERT_TRUE(data); | 162 ASSERT_TRUE(data); |
| 167 EXPECT_FALSE(data->next()); | 163 EXPECT_FALSE(data->next()); |
| 168 EXPECT_EQ(data, ThreadData::Get()); | 164 EXPECT_EQ(data, ThreadData::Get()); |
| 169 birth_map.clear(); | 165 birth_map.clear(); |
| 170 deaths.clear(); | 166 deaths.clear(); |
| 171 parent_child_set.clear(); | 167 data->SnapshotMaps(0, &birth_map, &deaths); |
| 172 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); | |
| 173 EXPECT_EQ(0u, birth_map.size()); | 168 EXPECT_EQ(0u, birth_map.size()); |
| 174 EXPECT_EQ(0u, deaths.size()); | 169 EXPECT_EQ(0u, deaths.size()); |
| 175 EXPECT_EQ(0u, parent_child_set.size()); | |
| 176 } | 170 } |
| 177 | 171 |
| 178 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 172 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
| 179 if (!ThreadData::InitializeAndSetTrackingStatus( | 173 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 180 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 174 ThreadData::PROFILING_ACTIVE)) { |
| 181 // Don't run the test if task tracking is not compiled in. | 175 // Don't run the test if task tracking is not compiled in. |
| 182 return; | 176 return; |
| 183 } | 177 } |
| 184 | 178 |
| 185 // Instigate tracking on a single tracked object, on our thread. | 179 // Instigate tracking on a single tracked object, on our thread. |
| 186 const char kFunction[] = "TinyStartupShutdown"; | 180 const char kFunction[] = "TinyStartupShutdown"; |
| 187 Location location(kFunction, kFile, kLineNumber, NULL); | 181 Location location(kFunction, kFile, kLineNumber, NULL); |
| 188 Births* first_birth = ThreadData::TallyABirthIfActive(location); | 182 ThreadData::TallyABirthIfActive(location); |
| 189 | 183 |
| 190 ThreadData* data = ThreadData::first(); | 184 ThreadData* data = ThreadData::first(); |
| 191 ASSERT_TRUE(data); | 185 ASSERT_TRUE(data); |
| 192 EXPECT_FALSE(data->next()); | 186 EXPECT_FALSE(data->next()); |
| 193 EXPECT_EQ(data, ThreadData::Get()); | 187 EXPECT_EQ(data, ThreadData::Get()); |
| 194 ThreadData::BirthMap birth_map; | 188 ThreadData::BirthMap birth_map; |
| 195 ThreadData::DeathsSnapshot deaths; | 189 ThreadData::DeathsSnapshot deaths; |
| 196 ThreadData::ParentChildSet parent_child_set; | 190 data->SnapshotMaps(0, &birth_map, &deaths); |
| 197 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); | |
| 198 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 191 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 199 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 192 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 200 EXPECT_EQ(0u, deaths.size()); // No deaths. | 193 EXPECT_EQ(0u, deaths.size()); // No deaths. |
| 201 EXPECT_EQ(0u, parent_child_set.size()); // No children. | |
| 202 | 194 |
| 203 | 195 |
| 204 // Now instigate another birth, while we are timing the run of the first | 196 // Now instigate another birth, while we are timing the run of the first |
| 205 // execution. | 197 // execution. |
| 206 ThreadData::PrepareForStartOfRun(first_birth); | |
| 207 // Create a child (using the same birth location). | 198 // Create a child (using the same birth location). |
| 208 // TrackingInfo will call TallyABirth() during construction. | 199 // TrackingInfo will call TallyABirth() during construction. |
| 209 const int32 start_time = 1; | 200 const int32 start_time = 1; |
| 210 base::TimeTicks kBogusBirthTime = base::TimeTicks() + | 201 base::TimeTicks kBogusBirthTime = base::TimeTicks() + |
| 211 base::TimeDelta::FromMilliseconds(start_time); | 202 base::TimeDelta::FromMilliseconds(start_time); |
| 212 base::TrackingInfo pending_task(location, kBogusBirthTime); | 203 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 213 SetTestTime(1); | 204 SetTestTime(1); |
| 214 TaskStopwatch stopwatch; | 205 TaskStopwatch stopwatch; |
| 215 stopwatch.Start(); | 206 stopwatch.Start(); |
| 216 // Finally conclude the outer run. | 207 // Finally conclude the outer run. |
| 217 const int32 time_elapsed = 1000; | 208 const int32 time_elapsed = 1000; |
| 218 SetTestTime(start_time + time_elapsed); | 209 SetTestTime(start_time + time_elapsed); |
| 219 stopwatch.Stop(); | 210 stopwatch.Stop(); |
| 220 | 211 |
| 221 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 212 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 222 | 213 |
| 223 birth_map.clear(); | 214 birth_map.clear(); |
| 224 deaths.clear(); | 215 deaths.clear(); |
| 225 parent_child_set.clear(); | 216 data->SnapshotMaps(0, &birth_map, &deaths); |
| 226 data->SnapshotMaps(0, &birth_map, &deaths, &parent_child_set); | |
| 227 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 217 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 228 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 218 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 229 EXPECT_EQ(1u, deaths.size()); // 1 location. | 219 EXPECT_EQ(1u, deaths.size()); // 1 location. |
| 230 EXPECT_EQ(1, deaths.begin()->second.death_data.count); // 1 death. | 220 EXPECT_EQ(1, deaths.begin()->second.death_data.count); // 1 death. |
| 231 if (ThreadData::TrackingParentChildStatus()) { | |
| 232 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | |
| 233 EXPECT_EQ(parent_child_set.begin()->first, | |
| 234 parent_child_set.begin()->second); | |
| 235 } else { | |
| 236 EXPECT_EQ(0u, parent_child_set.size()); // no stats. | |
| 237 } | |
| 238 | 221 |
| 239 // The births were at the same location as the one known death. | 222 // The births were at the same location as the one known death. |
| 240 EXPECT_EQ(birth_map.begin()->second, deaths.begin()->first); | 223 EXPECT_EQ(birth_map.begin()->second, deaths.begin()->first); |
| 241 | 224 |
| 242 ProcessDataSnapshot process_data; | 225 ProcessDataSnapshot process_data; |
| 243 ThreadData::Snapshot(0, &process_data); | 226 ThreadData::Snapshot(0, &process_data); |
| 244 | 227 |
| 245 ASSERT_EQ(1u, process_data.phased_snapshots.size()); | 228 ASSERT_EQ(1u, process_data.phased_snapshots.size()); |
| 246 auto it = process_data.phased_snapshots.find(0); | 229 auto it = process_data.phased_snapshots.find(0); |
| 247 ASSERT_TRUE(it != process_data.phased_snapshots.end()); | 230 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 248 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 231 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 249 ASSERT_EQ(1u, process_data_phase.tasks.size()); | 232 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
| 250 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); | 233 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 251 EXPECT_EQ(kFunction, | 234 EXPECT_EQ(kFunction, |
| 252 process_data_phase.tasks[0].birth.location.function_name); | 235 process_data_phase.tasks[0].birth.location.function_name); |
| 253 EXPECT_EQ(kLineNumber, | 236 EXPECT_EQ(kLineNumber, |
| 254 process_data_phase.tasks[0].birth.location.line_number); | 237 process_data_phase.tasks[0].birth.location.line_number); |
| 255 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].birth.thread_name); | 238 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].birth.thread_name); |
| 256 EXPECT_EQ(1, process_data_phase.tasks[0].death_data.count); | 239 EXPECT_EQ(1, process_data_phase.tasks[0].death_data.count); |
| 257 EXPECT_EQ(time_elapsed, | 240 EXPECT_EQ(time_elapsed, |
| 258 process_data_phase.tasks[0].death_data.run_duration_sum); | 241 process_data_phase.tasks[0].death_data.run_duration_sum); |
| 259 EXPECT_EQ(time_elapsed, | 242 EXPECT_EQ(time_elapsed, |
| 260 process_data_phase.tasks[0].death_data.run_duration_max); | 243 process_data_phase.tasks[0].death_data.run_duration_max); |
| 261 EXPECT_EQ(time_elapsed, | 244 EXPECT_EQ(time_elapsed, |
| 262 process_data_phase.tasks[0].death_data.run_duration_sample); | 245 process_data_phase.tasks[0].death_data.run_duration_sample); |
| 263 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); | 246 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); |
| 264 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); | 247 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); |
| 265 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); | 248 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); |
| 266 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); | 249 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); |
| 267 | |
| 268 if (ThreadData::TrackingParentChildStatus()) { | |
| 269 ASSERT_EQ(1u, process_data_phase.descendants.size()); | |
| 270 EXPECT_EQ(kFile, | |
| 271 process_data_phase.descendants[0].parent.location.file_name); | |
| 272 EXPECT_EQ(kFunction, | |
| 273 process_data_phase.descendants[0].parent.location.function_name); | |
| 274 EXPECT_EQ(kLineNumber, | |
| 275 process_data_phase.descendants[0].parent.location.line_number); | |
| 276 EXPECT_EQ(kWorkerThreadName, | |
| 277 process_data_phase.descendants[0].parent.thread_name); | |
| 278 EXPECT_EQ(kFile, | |
| 279 process_data_phase.descendants[0].child.location.file_name); | |
| 280 EXPECT_EQ(kFunction, | |
| 281 process_data_phase.descendants[0].child.location.function_name); | |
| 282 EXPECT_EQ(kLineNumber, | |
| 283 process_data_phase.descendants[0].child.location.line_number); | |
| 284 EXPECT_EQ(kWorkerThreadName, | |
| 285 process_data_phase.descendants[0].child.thread_name); | |
| 286 } else { | |
| 287 EXPECT_EQ(0u, process_data_phase.descendants.size()); | |
| 288 } | |
| 289 } | 250 } |
| 290 | 251 |
| 291 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) { | 252 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) { |
| 292 if (!ThreadData::InitializeAndSetTrackingStatus( | 253 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 293 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 254 ThreadData::PROFILING_ACTIVE)) { |
| 294 // Don't run the test if task tracking is not compiled in. | 255 // Don't run the test if task tracking is not compiled in. |
| 295 return; | 256 return; |
| 296 } | 257 } |
| 297 | 258 |
| 298 scoped_ptr<DeathData> data(new DeathData()); | 259 scoped_ptr<DeathData> data(new DeathData()); |
| 299 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 260 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
| 300 EXPECT_EQ(data->run_duration_sum(), 0); | 261 EXPECT_EQ(data->run_duration_sum(), 0); |
| 301 EXPECT_EQ(data->run_duration_max(), 0); | 262 EXPECT_EQ(data->run_duration_max(), 0); |
| 302 EXPECT_EQ(data->run_duration_sample(), 0); | 263 EXPECT_EQ(data->run_duration_sample(), 0); |
| 303 EXPECT_EQ(data->queue_duration_sum(), 0); | 264 EXPECT_EQ(data->queue_duration_sum(), 0); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 326 EXPECT_EQ(data->run_duration_sample(), run_ms); | 287 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 327 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); | 288 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 328 EXPECT_EQ(data->queue_duration_max(), queue_ms); | 289 EXPECT_EQ(data->queue_duration_max(), queue_ms); |
| 329 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 290 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 330 EXPECT_EQ(data->count(), 2); | 291 EXPECT_EQ(data->count(), 2); |
| 331 EXPECT_EQ(nullptr, data->last_phase_snapshot()); | 292 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 332 } | 293 } |
| 333 | 294 |
| 334 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { | 295 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { |
| 335 if (!ThreadData::InitializeAndSetTrackingStatus( | 296 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 336 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 297 ThreadData::PROFILING_ACTIVE)) { |
| 337 // Don't run the test if task tracking is not compiled in. | 298 // Don't run the test if task tracking is not compiled in. |
| 338 return; | 299 return; |
| 339 } | 300 } |
| 340 | 301 |
| 341 scoped_ptr<DeathData> data(new DeathData()); | 302 scoped_ptr<DeathData> data(new DeathData()); |
| 342 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 303 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
| 343 | 304 |
| 344 int32 run_ms = 42; | 305 int32 run_ms = 42; |
| 345 int32 queue_ms = 8; | 306 int32 queue_ms = 8; |
| 346 | 307 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 data->last_phase_snapshot()->death_data.queue_duration_sum); | 356 data->last_phase_snapshot()->death_data.queue_duration_sum); |
| 396 EXPECT_EQ(queue_ms, | 357 EXPECT_EQ(queue_ms, |
| 397 data->last_phase_snapshot()->death_data.queue_duration_max); | 358 data->last_phase_snapshot()->death_data.queue_duration_max); |
| 398 EXPECT_EQ(queue_ms, | 359 EXPECT_EQ(queue_ms, |
| 399 data->last_phase_snapshot()->death_data.queue_duration_sample); | 360 data->last_phase_snapshot()->death_data.queue_duration_sample); |
| 400 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); | 361 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); |
| 401 } | 362 } |
| 402 | 363 |
| 403 TEST_F(TrackedObjectsTest, Delta) { | 364 TEST_F(TrackedObjectsTest, Delta) { |
| 404 if (!ThreadData::InitializeAndSetTrackingStatus( | 365 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 405 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 366 ThreadData::PROFILING_ACTIVE)) { |
| 406 // Don't run the test if task tracking is not compiled in. | 367 // Don't run the test if task tracking is not compiled in. |
| 407 return; | 368 return; |
| 408 } | 369 } |
| 409 | 370 |
| 410 DeathDataSnapshot snapshot; | 371 DeathDataSnapshot snapshot; |
| 411 snapshot.count = 10; | 372 snapshot.count = 10; |
| 412 snapshot.run_duration_sum = 100; | 373 snapshot.run_duration_sum = 100; |
| 413 snapshot.run_duration_max = 50; | 374 snapshot.run_duration_max = 50; |
| 414 snapshot.run_duration_sample = 25; | 375 snapshot.run_duration_sample = 25; |
| 415 snapshot.queue_duration_sum = 200; | 376 snapshot.queue_duration_sum = 200; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 ASSERT_TRUE(it != process_data.phased_snapshots.end()); | 441 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 481 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 442 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 482 | 443 |
| 483 ASSERT_EQ(0u, process_data_phase.tasks.size()); | 444 ASSERT_EQ(0u, process_data_phase.tasks.size()); |
| 484 | 445 |
| 485 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 446 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 486 } | 447 } |
| 487 | 448 |
| 488 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { | 449 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { |
| 489 if (!ThreadData::InitializeAndSetTrackingStatus( | 450 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 490 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 451 ThreadData::PROFILING_ACTIVE)) { |
| 491 // Don't run the test if task tracking is not compiled in. | 452 // Don't run the test if task tracking is not compiled in. |
| 492 return; | 453 return; |
| 493 } | 454 } |
| 494 | 455 |
| 495 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; | 456 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; |
| 496 Location location(kFunction, kFile, kLineNumber, NULL); | 457 Location location(kFunction, kFile, kLineNumber, NULL); |
| 497 TallyABirth(location, std::string()); | 458 TallyABirth(location, std::string()); |
| 498 | 459 |
| 499 ProcessDataSnapshot process_data; | 460 ProcessDataSnapshot process_data; |
| 500 ThreadData::Snapshot(0, &process_data); | 461 ThreadData::Snapshot(0, &process_data); |
| 501 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, | 462 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 502 kStillAlive, 1, 0, 0); | 463 kStillAlive, 1, 0, 0); |
| 503 } | 464 } |
| 504 | 465 |
| 505 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { | 466 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { |
| 506 if (!ThreadData::InitializeAndSetTrackingStatus( | 467 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 507 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 468 ThreadData::PROFILING_ACTIVE)) { |
| 508 // Don't run the test if task tracking is not compiled in. | 469 // Don't run the test if task tracking is not compiled in. |
| 509 return; | 470 return; |
| 510 } | 471 } |
| 511 | 472 |
| 512 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; | 473 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; |
| 513 Location location(kFunction, kFile, kLineNumber, NULL); | 474 Location location(kFunction, kFile, kLineNumber, NULL); |
| 514 TallyABirth(location, kMainThreadName); | 475 TallyABirth(location, kMainThreadName); |
| 515 | 476 |
| 516 ProcessDataSnapshot process_data; | 477 ProcessDataSnapshot process_data; |
| 517 ThreadData::Snapshot(0, &process_data); | 478 ThreadData::Snapshot(0, &process_data); |
| 518 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, | 479 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, |
| 519 1, 0, 0); | 480 1, 0, 0); |
| 520 } | 481 } |
| 521 | 482 |
| 522 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { | 483 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
| 523 if (!ThreadData::InitializeAndSetTrackingStatus( | 484 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 524 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 485 ThreadData::PROFILING_ACTIVE)) { |
| 525 // Don't run the test if task tracking is not compiled in. | 486 // Don't run the test if task tracking is not compiled in. |
| 526 return; | 487 return; |
| 527 } | 488 } |
| 528 | 489 |
| 529 const char kFunction[] = "LifeCycleToSnapshotMainThread"; | 490 const char kFunction[] = "LifeCycleToSnapshotMainThread"; |
| 530 Location location(kFunction, kFile, kLineNumber, NULL); | 491 Location location(kFunction, kFile, kLineNumber, NULL); |
| 531 TallyABirth(location, kMainThreadName); | 492 TallyABirth(location, kMainThreadName); |
| 532 | 493 |
| 533 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 494 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 534 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 495 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 547 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 508 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 548 | 509 |
| 549 ProcessDataSnapshot process_data; | 510 ProcessDataSnapshot process_data; |
| 550 ThreadData::Snapshot(0, &process_data); | 511 ThreadData::Snapshot(0, &process_data); |
| 551 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 512 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 552 kMainThreadName, 1, 2, 4); | 513 kMainThreadName, 1, 2, 4); |
| 553 } | 514 } |
| 554 | 515 |
| 555 TEST_F(TrackedObjectsTest, TwoPhases) { | 516 TEST_F(TrackedObjectsTest, TwoPhases) { |
| 556 if (!ThreadData::InitializeAndSetTrackingStatus( | 517 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 557 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 518 ThreadData::PROFILING_ACTIVE)) { |
| 558 // Don't run the test if task tracking is not compiled in. | 519 // Don't run the test if task tracking is not compiled in. |
| 559 return; | 520 return; |
| 560 } | 521 } |
| 561 | 522 |
| 562 const char kFunction[] = "TwoPhases"; | 523 const char kFunction[] = "TwoPhases"; |
| 563 Location location(kFunction, kFile, kLineNumber, NULL); | 524 Location location(kFunction, kFile, kLineNumber, NULL); |
| 564 TallyABirth(location, kMainThreadName); | 525 TallyABirth(location, kMainThreadName); |
| 565 | 526 |
| 566 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 527 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 567 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 528 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); | 582 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 622 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); | 583 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 623 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); | 584 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 624 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); | 585 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 625 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); | 586 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 626 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); | 587 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 627 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); | 588 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 628 | 589 |
| 629 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); | 590 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 630 | 591 |
| 631 EXPECT_EQ(0u, process_data_phase0.descendants.size()); | |
| 632 | |
| 633 auto it1 = process_data.phased_snapshots.find(1); | 592 auto it1 = process_data.phased_snapshots.find(1); |
| 634 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); | 593 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 635 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; | 594 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 636 | 595 |
| 637 ASSERT_EQ(1u, process_data_phase1.tasks.size()); | 596 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 638 | 597 |
| 639 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); | 598 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 640 EXPECT_EQ(kFunction, | 599 EXPECT_EQ(kFunction, |
| 641 process_data_phase1.tasks[0].birth.location.function_name); | 600 process_data_phase1.tasks[0].birth.location.function_name); |
| 642 EXPECT_EQ(kLineNumber, | 601 EXPECT_EQ(kLineNumber, |
| 643 process_data_phase1.tasks[0].birth.location.line_number); | 602 process_data_phase1.tasks[0].birth.location.line_number); |
| 644 | 603 |
| 645 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); | 604 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 646 | 605 |
| 647 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); | 606 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 648 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum); | 607 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 649 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max); | 608 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 650 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample); | 609 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 651 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum); | 610 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 652 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max); | 611 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 653 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample); | 612 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 654 | 613 |
| 655 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); | 614 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 656 | 615 |
| 657 EXPECT_EQ(0u, process_data_phase1.descendants.size()); | |
| 658 | |
| 659 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 616 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 660 } | 617 } |
| 661 | 618 |
| 662 TEST_F(TrackedObjectsTest, ThreePhases) { | 619 TEST_F(TrackedObjectsTest, ThreePhases) { |
| 663 if (!ThreadData::InitializeAndSetTrackingStatus( | 620 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 664 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 621 ThreadData::PROFILING_ACTIVE)) { |
| 665 // Don't run the test if task tracking is not compiled in. | 622 // Don't run the test if task tracking is not compiled in. |
| 666 return; | 623 return; |
| 667 } | 624 } |
| 668 | 625 |
| 669 const char kFunction[] = "ThreePhases"; | 626 const char kFunction[] = "ThreePhases"; |
| 670 Location location(kFunction, kFile, kLineNumber, NULL); | 627 Location location(kFunction, kFile, kLineNumber, NULL); |
| 671 | 628 |
| 672 // Phase 0 | 629 // Phase 0 |
| 673 { | 630 { |
| 674 TallyABirth(location, kMainThreadName); | 631 TallyABirth(location, kMainThreadName); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); | 703 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 747 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sum); | 704 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 748 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_max); | 705 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 749 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sample); | 706 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 750 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sum); | 707 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 751 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_max); | 708 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 752 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sample); | 709 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 753 | 710 |
| 754 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); | 711 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 755 | 712 |
| 756 EXPECT_EQ(0u, process_data_phase0.descendants.size()); | |
| 757 | |
| 758 auto it1 = process_data.phased_snapshots.find(1); | 713 auto it1 = process_data.phased_snapshots.find(1); |
| 759 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); | 714 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 760 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; | 715 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 761 | 716 |
| 762 ASSERT_EQ(1u, process_data_phase1.tasks.size()); | 717 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 763 | 718 |
| 764 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); | 719 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 765 EXPECT_EQ(kFunction, | 720 EXPECT_EQ(kFunction, |
| 766 process_data_phase1.tasks[0].birth.location.function_name); | 721 process_data_phase1.tasks[0].birth.location.function_name); |
| 767 EXPECT_EQ(kLineNumber, | 722 EXPECT_EQ(kLineNumber, |
| 768 process_data_phase1.tasks[0].birth.location.line_number); | 723 process_data_phase1.tasks[0].birth.location.line_number); |
| 769 | 724 |
| 770 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); | 725 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 771 | 726 |
| 772 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); | 727 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 773 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sum); | 728 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 774 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_max); | 729 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 775 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sample); | 730 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 776 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sum); | 731 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 777 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_max); | 732 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 778 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sample); | 733 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 779 | 734 |
| 780 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); | 735 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 781 | 736 |
| 782 EXPECT_EQ(0u, process_data_phase1.descendants.size()); | |
| 783 | |
| 784 auto it2 = process_data.phased_snapshots.find(2); | 737 auto it2 = process_data.phased_snapshots.find(2); |
| 785 ASSERT_TRUE(it2 != process_data.phased_snapshots.end()); | 738 ASSERT_TRUE(it2 != process_data.phased_snapshots.end()); |
| 786 const ProcessDataPhaseSnapshot& process_data_phase2 = it2->second; | 739 const ProcessDataPhaseSnapshot& process_data_phase2 = it2->second; |
| 787 | 740 |
| 788 ASSERT_EQ(1u, process_data_phase2.tasks.size()); | 741 ASSERT_EQ(1u, process_data_phase2.tasks.size()); |
| 789 | 742 |
| 790 EXPECT_EQ(kFile, process_data_phase2.tasks[0].birth.location.file_name); | 743 EXPECT_EQ(kFile, process_data_phase2.tasks[0].birth.location.file_name); |
| 791 EXPECT_EQ(kFunction, | 744 EXPECT_EQ(kFunction, |
| 792 process_data_phase2.tasks[0].birth.location.function_name); | 745 process_data_phase2.tasks[0].birth.location.function_name); |
| 793 EXPECT_EQ(kLineNumber, | 746 EXPECT_EQ(kLineNumber, |
| 794 process_data_phase2.tasks[0].birth.location.line_number); | 747 process_data_phase2.tasks[0].birth.location.line_number); |
| 795 | 748 |
| 796 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].birth.thread_name); | 749 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].birth.thread_name); |
| 797 | 750 |
| 798 EXPECT_EQ(1, process_data_phase2.tasks[0].death_data.count); | 751 EXPECT_EQ(1, process_data_phase2.tasks[0].death_data.count); |
| 799 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sum); | 752 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sum); |
| 800 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_max); | 753 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_max); |
| 801 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sample); | 754 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sample); |
| 802 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sum); | 755 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sum); |
| 803 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_max); | 756 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_max); |
| 804 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sample); | 757 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sample); |
| 805 | 758 |
| 806 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].death_thread_name); | 759 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].death_thread_name); |
| 807 | 760 |
| 808 EXPECT_EQ(0u, process_data_phase2.descendants.size()); | |
| 809 | |
| 810 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 761 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 811 } | 762 } |
| 812 | 763 |
| 813 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) { | 764 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) { |
| 814 if (!ThreadData::InitializeAndSetTrackingStatus( | 765 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 815 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 766 ThreadData::PROFILING_ACTIVE)) { |
| 816 // Don't run the test if task tracking is not compiled in. | 767 // Don't run the test if task tracking is not compiled in. |
| 817 return; | 768 return; |
| 818 } | 769 } |
| 819 | 770 |
| 820 const char kFunction[] = "TwoPhasesSecondEmpty"; | 771 const char kFunction[] = "TwoPhasesSecondEmpty"; |
| 821 Location location(kFunction, kFile, kLineNumber, NULL); | 772 Location location(kFunction, kFile, kLineNumber, NULL); |
| 822 ThreadData::InitializeThreadContext(kMainThreadName); | 773 ThreadData::InitializeThreadContext(kMainThreadName); |
| 823 | 774 |
| 824 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 775 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 825 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 776 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); | 818 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 868 | 819 |
| 869 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); | 820 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 870 | 821 |
| 871 auto it1 = process_data.phased_snapshots.find(1); | 822 auto it1 = process_data.phased_snapshots.find(1); |
| 872 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); | 823 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); |
| 873 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; | 824 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 874 | 825 |
| 875 ASSERT_EQ(0u, process_data_phase1.tasks.size()); | 826 ASSERT_EQ(0u, process_data_phase1.tasks.size()); |
| 876 | 827 |
| 877 EXPECT_EQ(0u, process_data_phase0.descendants.size()); | |
| 878 | |
| 879 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 828 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 880 } | 829 } |
| 881 | 830 |
| 882 TEST_F(TrackedObjectsTest, TwoPhasesFirstEmpty) { | 831 TEST_F(TrackedObjectsTest, TwoPhasesFirstEmpty) { |
| 883 if (!ThreadData::InitializeAndSetTrackingStatus( | 832 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 884 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 833 ThreadData::PROFILING_ACTIVE)) { |
| 885 // Don't run the test if task tracking is not compiled in. | 834 // Don't run the test if task tracking is not compiled in. |
| 886 return; | 835 return; |
| 887 } | 836 } |
| 888 | 837 |
| 889 ThreadData::OnProfilingPhaseCompleted(0); | 838 ThreadData::OnProfilingPhaseCompleted(0); |
| 890 | 839 |
| 891 const char kFunction[] = "TwoPhasesSecondEmpty"; | 840 const char kFunction[] = "TwoPhasesSecondEmpty"; |
| 892 Location location(kFunction, kFile, kLineNumber, NULL); | 841 Location location(kFunction, kFile, kLineNumber, NULL); |
| 893 ThreadData::InitializeThreadContext(kMainThreadName); | 842 ThreadData::InitializeThreadContext(kMainThreadName); |
| 894 | 843 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 | 888 |
| 940 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 889 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 941 } | 890 } |
| 942 | 891 |
| 943 // We will deactivate tracking after the birth, and before the death, and | 892 // We will deactivate tracking after the birth, and before the death, and |
| 944 // demonstrate that the lifecycle is completely tallied. This ensures that | 893 // demonstrate that the lifecycle is completely tallied. This ensures that |
| 945 // our tallied births are matched by tallied deaths (except for when the | 894 // our tallied births are matched by tallied deaths (except for when the |
| 946 // task is still running, or is queued). | 895 // task is still running, or is queued). |
| 947 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { | 896 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
| 948 if (!ThreadData::InitializeAndSetTrackingStatus( | 897 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 949 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 898 ThreadData::PROFILING_ACTIVE)) { |
| 950 // Don't run the test if task tracking is not compiled in. | 899 // Don't run the test if task tracking is not compiled in. |
| 951 return; | 900 return; |
| 952 } | 901 } |
| 953 | 902 |
| 954 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; | 903 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
| 955 Location location(kFunction, kFile, kLineNumber, NULL); | 904 Location location(kFunction, kFile, kLineNumber, NULL); |
| 956 TallyABirth(location, kMainThreadName); | 905 TallyABirth(location, kMainThreadName); |
| 957 | 906 |
| 958 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 907 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 959 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 908 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 ASSERT_TRUE(it != process_data.phased_snapshots.end()); | 968 ASSERT_TRUE(it != process_data.phased_snapshots.end()); |
| 1020 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 969 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 1021 | 970 |
| 1022 ASSERT_EQ(0u, process_data_phase.tasks.size()); | 971 ASSERT_EQ(0u, process_data_phase.tasks.size()); |
| 1023 | 972 |
| 1024 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 973 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 1025 } | 974 } |
| 1026 | 975 |
| 1027 TEST_F(TrackedObjectsTest, TwoLives) { | 976 TEST_F(TrackedObjectsTest, TwoLives) { |
| 1028 if (!ThreadData::InitializeAndSetTrackingStatus( | 977 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 1029 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 978 ThreadData::PROFILING_ACTIVE)) { |
| 1030 // Don't run the test if task tracking is not compiled in. | 979 // Don't run the test if task tracking is not compiled in. |
| 1031 return; | 980 return; |
| 1032 } | 981 } |
| 1033 | 982 |
| 1034 const char kFunction[] = "TwoLives"; | 983 const char kFunction[] = "TwoLives"; |
| 1035 Location location(kFunction, kFile, kLineNumber, NULL); | 984 Location location(kFunction, kFile, kLineNumber, NULL); |
| 1036 TallyABirth(location, kMainThreadName); | 985 TallyABirth(location, kMainThreadName); |
| 1037 | 986 |
| 1038 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 987 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 1039 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 988 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1063 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); | 1012 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); |
| 1064 | 1013 |
| 1065 ProcessDataSnapshot process_data; | 1014 ProcessDataSnapshot process_data; |
| 1066 ThreadData::Snapshot(0, &process_data); | 1015 ThreadData::Snapshot(0, &process_data); |
| 1067 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 1016 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 1068 kMainThreadName, 2, 2, 4); | 1017 kMainThreadName, 2, 2, 4); |
| 1069 } | 1018 } |
| 1070 | 1019 |
| 1071 TEST_F(TrackedObjectsTest, DifferentLives) { | 1020 TEST_F(TrackedObjectsTest, DifferentLives) { |
| 1072 if (!ThreadData::InitializeAndSetTrackingStatus( | 1021 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 1073 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1022 ThreadData::PROFILING_ACTIVE)) { |
| 1074 // Don't run the test if task tracking is not compiled in. | 1023 // Don't run the test if task tracking is not compiled in. |
| 1075 return; | 1024 return; |
| 1076 } | 1025 } |
| 1077 | 1026 |
| 1078 // Use a well named thread. | 1027 // Use a well named thread. |
| 1079 ThreadData::InitializeThreadContext(kMainThreadName); | 1028 ThreadData::InitializeThreadContext(kMainThreadName); |
| 1080 const char kFunction[] = "DifferentLives"; | 1029 const char kFunction[] = "DifferentLives"; |
| 1081 Location location(kFunction, kFile, kLineNumber, NULL); | 1030 Location location(kFunction, kFile, kLineNumber, NULL); |
| 1082 | 1031 |
| 1083 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1032 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 process_data_phase.tasks[1].birth.location.line_number); | 1083 process_data_phase.tasks[1].birth.location.line_number); |
| 1135 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[1].birth.thread_name); | 1084 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[1].birth.thread_name); |
| 1136 EXPECT_EQ(1, process_data_phase.tasks[1].death_data.count); | 1085 EXPECT_EQ(1, process_data_phase.tasks[1].death_data.count); |
| 1137 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sum); | 1086 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sum); |
| 1138 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_max); | 1087 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_max); |
| 1139 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sample); | 1088 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sample); |
| 1140 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sum); | 1089 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sum); |
| 1141 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); | 1090 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); |
| 1142 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); | 1091 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); |
| 1143 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); | 1092 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); |
| 1144 EXPECT_EQ(0u, process_data_phase.descendants.size()); | |
| 1145 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1093 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 1146 } | 1094 } |
| 1147 | 1095 |
| 1148 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { | 1096 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { |
| 1149 if (!ThreadData::InitializeAndSetTrackingStatus( | 1097 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 1150 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1098 ThreadData::PROFILING_ACTIVE)) { |
| 1151 // Don't run the test if task tracking is not compiled in. | 1099 // Don't run the test if task tracking is not compiled in. |
| 1152 return; | 1100 return; |
| 1153 } | 1101 } |
| 1154 | 1102 |
| 1155 const char kFunction[] = "TaskWithNestedExclusion"; | 1103 const char kFunction[] = "TaskWithNestedExclusion"; |
| 1156 Location location(kFunction, kFile, kLineNumber, NULL); | 1104 Location location(kFunction, kFile, kLineNumber, NULL); |
| 1157 TallyABirth(location, kMainThreadName); | 1105 TallyABirth(location, kMainThreadName); |
| 1158 | 1106 |
| 1159 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1107 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 1160 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 1108 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1178 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 1126 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 1179 | 1127 |
| 1180 ProcessDataSnapshot process_data; | 1128 ProcessDataSnapshot process_data; |
| 1181 ThreadData::Snapshot(0, &process_data); | 1129 ThreadData::Snapshot(0, &process_data); |
| 1182 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 1130 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 1183 kMainThreadName, 1, 6, 4); | 1131 kMainThreadName, 1, 6, 4); |
| 1184 } | 1132 } |
| 1185 | 1133 |
| 1186 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { | 1134 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { |
| 1187 if (!ThreadData::InitializeAndSetTrackingStatus( | 1135 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 1188 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1136 ThreadData::PROFILING_ACTIVE)) { |
| 1189 // Don't run the test if task tracking is not compiled in. | 1137 // Don't run the test if task tracking is not compiled in. |
| 1190 return; | 1138 return; |
| 1191 } | 1139 } |
| 1192 | 1140 |
| 1193 const char kFunction[] = "TaskWith2NestedExclusions"; | 1141 const char kFunction[] = "TaskWith2NestedExclusions"; |
| 1194 Location location(kFunction, kFile, kLineNumber, NULL); | 1142 Location location(kFunction, kFile, kLineNumber, NULL); |
| 1195 TallyABirth(location, kMainThreadName); | 1143 TallyABirth(location, kMainThreadName); |
| 1196 | 1144 |
| 1197 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 1145 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 1198 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 1146 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1222 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 1170 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 1223 | 1171 |
| 1224 ProcessDataSnapshot process_data; | 1172 ProcessDataSnapshot process_data; |
| 1225 ThreadData::Snapshot(0, &process_data); | 1173 ThreadData::Snapshot(0, &process_data); |
| 1226 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 1174 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 1227 kMainThreadName, 1, 13, 4); | 1175 kMainThreadName, 1, 13, 4); |
| 1228 } | 1176 } |
| 1229 | 1177 |
| 1230 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { | 1178 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { |
| 1231 if (!ThreadData::InitializeAndSetTrackingStatus( | 1179 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 1232 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 1180 ThreadData::PROFILING_ACTIVE)) { |
| 1233 // Don't run the test if task tracking is not compiled in. | 1181 // Don't run the test if task tracking is not compiled in. |
| 1234 return; | 1182 return; |
| 1235 } | 1183 } |
| 1236 | 1184 |
| 1237 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; | 1185 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; |
| 1238 Location location(kFunction, kFile, kLineNumber, NULL); | 1186 Location location(kFunction, kFile, kLineNumber, NULL); |
| 1239 | 1187 |
| 1240 const int kSecondFakeLineNumber = 999; | 1188 const int kSecondFakeLineNumber = 999; |
| 1241 | 1189 |
| 1242 TallyABirth(location, kMainThreadName); | 1190 TallyABirth(location, kMainThreadName); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 process_data_phase.tasks[t1].birth.location.line_number); | 1260 process_data_phase.tasks[t1].birth.location.line_number); |
| 1313 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].birth.thread_name); | 1261 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].birth.thread_name); |
| 1314 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.count); | 1262 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.count); |
| 1315 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sum); | 1263 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sum); |
| 1316 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); | 1264 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); |
| 1317 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); | 1265 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); |
| 1318 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); | 1266 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); |
| 1319 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); | 1267 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); |
| 1320 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); | 1268 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); |
| 1321 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); | 1269 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); |
| 1322 EXPECT_EQ(0u, process_data_phase.descendants.size()); | |
| 1323 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1270 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 1324 } | 1271 } |
| 1325 | 1272 |
| 1326 } // namespace tracked_objects | 1273 } // namespace tracked_objects |
| OLD | NEW |