| 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.tasks.size()); | 74 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 75 const PhasedProcessDataSnapshots::const_iterator it = |
| 76 process_data.phased_process_data_snapshots.find(0); |
| 77 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 78 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 75 | 79 |
| 76 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); | 80 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
| 81 |
| 82 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 77 EXPECT_EQ(function_name, | 83 EXPECT_EQ(function_name, |
| 78 process_data.tasks[0].birth.location.function_name); | 84 process_data_phase.tasks[0].birth.location.function_name); |
| 79 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); | 85 EXPECT_EQ(kLineNumber, |
| 86 process_data_phase.tasks[0].birth.location.line_number); |
| 80 | 87 |
| 81 EXPECT_EQ(birth_thread, process_data.tasks[0].birth.thread_name); | 88 EXPECT_EQ(birth_thread, process_data_phase.tasks[0].birth.thread_name); |
| 82 | 89 |
| 83 EXPECT_EQ(count, process_data.tasks[0].death_data.count); | 90 EXPECT_EQ(count, process_data_phase.tasks[0].death_data.count); |
| 84 EXPECT_EQ(count * run_ms, | 91 EXPECT_EQ(count * run_ms, |
| 85 process_data.tasks[0].death_data.run_duration_sum); | 92 process_data_phase.tasks[0].death_data.run_duration_sum); |
| 86 EXPECT_EQ(run_ms, process_data.tasks[0].death_data.run_duration_max); | 93 EXPECT_EQ(run_ms, process_data_phase.tasks[0].death_data.run_duration_max); |
| 87 EXPECT_EQ(run_ms, process_data.tasks[0].death_data.run_duration_sample); | 94 EXPECT_EQ(run_ms, |
| 95 process_data_phase.tasks[0].death_data.run_duration_sample); |
| 88 EXPECT_EQ(count * queue_ms, | 96 EXPECT_EQ(count * queue_ms, |
| 89 process_data.tasks[0].death_data.queue_duration_sum); | 97 process_data_phase.tasks[0].death_data.queue_duration_sum); |
| 90 EXPECT_EQ(queue_ms, process_data.tasks[0].death_data.queue_duration_max); | 98 EXPECT_EQ(queue_ms, |
| 91 EXPECT_EQ(queue_ms, process_data.tasks[0].death_data.queue_duration_sample); | 99 process_data_phase.tasks[0].death_data.queue_duration_max); |
| 100 EXPECT_EQ(queue_ms, |
| 101 process_data_phase.tasks[0].death_data.queue_duration_sample); |
| 92 | 102 |
| 93 EXPECT_EQ(death_thread, process_data.tasks[0].death_thread_name); | 103 EXPECT_EQ(death_thread, process_data_phase.tasks[0].death_thread_name); |
| 94 | 104 |
| 95 EXPECT_EQ(0u, process_data.descendants.size()); | 105 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 96 | 106 |
| 97 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 107 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 98 } | 108 } |
| 99 | 109 |
| 100 // Sets time that will be returned by ThreadData::Now(). | 110 // Sets time that will be returned by ThreadData::Now(). |
| 101 static void SetTestTime(unsigned int test_time) { test_time_ = test_time; } | 111 static void SetTestTime(unsigned int test_time) { test_time_ = test_time; } |
| 102 | 112 |
| 103 private: | 113 private: |
| 104 // Returns test time in milliseconds. | 114 // Returns test time in milliseconds. |
| 105 static unsigned int GetTestTime() { return test_time_; } | 115 static unsigned int GetTestTime() { return test_time_; } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 131 | 141 |
| 132 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 142 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 133 ThreadData* data = ThreadData::Get(); | 143 ThreadData* data = ThreadData::Get(); |
| 134 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 144 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 135 ASSERT_TRUE(data); | 145 ASSERT_TRUE(data); |
| 136 EXPECT_FALSE(data->next()); | 146 EXPECT_FALSE(data->next()); |
| 137 EXPECT_EQ(data, ThreadData::Get()); | 147 EXPECT_EQ(data, ThreadData::Get()); |
| 138 ThreadData::BirthMap birth_map; | 148 ThreadData::BirthMap birth_map; |
| 139 ThreadData::DeathMap death_map; | 149 ThreadData::DeathMap death_map; |
| 140 ThreadData::ParentChildSet parent_child_set; | 150 ThreadData::ParentChildSet parent_child_set; |
| 141 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 151 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 142 EXPECT_EQ(0u, birth_map.size()); | 152 EXPECT_EQ(0u, birth_map.size()); |
| 143 EXPECT_EQ(0u, death_map.size()); | 153 EXPECT_EQ(0u, death_map.size()); |
| 144 EXPECT_EQ(0u, parent_child_set.size()); | 154 EXPECT_EQ(0u, parent_child_set.size()); |
| 145 | 155 |
| 146 // Clean up with no leaking. | 156 // Clean up with no leaking. |
| 147 Reset(); | 157 Reset(); |
| 148 | 158 |
| 149 // Do it again, just to be sure we reset state completely. | 159 // Do it again, just to be sure we reset state completely. |
| 150 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 160 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 151 ThreadData::PROFILING_CHILDREN_ACTIVE)); | 161 ThreadData::PROFILING_CHILDREN_ACTIVE)); |
| 152 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 162 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 153 data = ThreadData::Get(); | 163 data = ThreadData::Get(); |
| 154 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 164 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 155 ASSERT_TRUE(data); | 165 ASSERT_TRUE(data); |
| 156 EXPECT_FALSE(data->next()); | 166 EXPECT_FALSE(data->next()); |
| 157 EXPECT_EQ(data, ThreadData::Get()); | 167 EXPECT_EQ(data, ThreadData::Get()); |
| 158 birth_map.clear(); | 168 birth_map.clear(); |
| 159 death_map.clear(); | 169 death_map.clear(); |
| 160 parent_child_set.clear(); | 170 parent_child_set.clear(); |
| 161 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 171 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 162 EXPECT_EQ(0u, birth_map.size()); | 172 EXPECT_EQ(0u, birth_map.size()); |
| 163 EXPECT_EQ(0u, death_map.size()); | 173 EXPECT_EQ(0u, death_map.size()); |
| 164 EXPECT_EQ(0u, parent_child_set.size()); | 174 EXPECT_EQ(0u, parent_child_set.size()); |
| 165 } | 175 } |
| 166 | 176 |
| 167 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 177 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
| 168 if (!ThreadData::InitializeAndSetTrackingStatus( | 178 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 169 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 179 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 170 return; | 180 return; |
| 171 } | 181 } |
| 172 | 182 |
| 173 // Instigate tracking on a single tracked object, on our thread. | 183 // Instigate tracking on a single tracked object, on our thread. |
| 174 const char kFunction[] = "TinyStartupShutdown"; | 184 const char kFunction[] = "TinyStartupShutdown"; |
| 175 Location location(kFunction, kFile, kLineNumber, NULL); | 185 Location location(kFunction, kFile, kLineNumber, NULL); |
| 176 Births* first_birth = ThreadData::TallyABirthIfActive(location); | 186 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
| 177 | 187 |
| 178 ThreadData* data = ThreadData::first(); | 188 ThreadData* data = ThreadData::first(); |
| 179 ASSERT_TRUE(data); | 189 ASSERT_TRUE(data); |
| 180 EXPECT_FALSE(data->next()); | 190 EXPECT_FALSE(data->next()); |
| 181 EXPECT_EQ(data, ThreadData::Get()); | 191 EXPECT_EQ(data, ThreadData::Get()); |
| 182 ThreadData::BirthMap birth_map; | 192 ThreadData::BirthMap birth_map; |
| 183 ThreadData::DeathMap death_map; | 193 ThreadData::DeathMap death_map; |
| 184 ThreadData::ParentChildSet parent_child_set; | 194 ThreadData::ParentChildSet parent_child_set; |
| 185 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 195 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 186 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 196 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 187 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 197 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 188 EXPECT_EQ(0u, death_map.size()); // No deaths. | 198 EXPECT_EQ(0u, death_map.size()); // No deaths. |
| 189 EXPECT_EQ(0u, parent_child_set.size()); // No children. | 199 EXPECT_EQ(0u, parent_child_set.size()); // No children. |
| 190 | 200 |
| 191 | 201 |
| 192 // Now instigate another birth, while we are timing the run of the first | 202 // Now instigate another birth, while we are timing the run of the first |
| 193 // execution. | 203 // execution. |
| 194 ThreadData::PrepareForStartOfRun(first_birth); | 204 ThreadData::PrepareForStartOfRun(first_birth); |
| 195 // Create a child (using the same birth location). | 205 // Create a child (using the same birth location). |
| 196 // TrackingInfo will call TallyABirth() during construction. | 206 // TrackingInfo will call TallyABirth() during construction. |
| 197 const int32 start_time = 1; | 207 const int32 start_time = 1; |
| 198 base::TimeTicks kBogusBirthTime = base::TimeTicks() + | 208 base::TimeTicks kBogusBirthTime = base::TimeTicks() + |
| 199 base::TimeDelta::FromMilliseconds(start_time); | 209 base::TimeDelta::FromMilliseconds(start_time); |
| 200 base::TrackingInfo pending_task(location, kBogusBirthTime); | 210 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 201 SetTestTime(1); | 211 SetTestTime(1); |
| 202 TaskStopwatch stopwatch; | 212 TaskStopwatch stopwatch; |
| 203 stopwatch.Start(); | 213 stopwatch.Start(); |
| 204 // Finally conclude the outer run. | 214 // Finally conclude the outer run. |
| 205 const int32 time_elapsed = 1000; | 215 const int32 time_elapsed = 1000; |
| 206 SetTestTime(start_time + time_elapsed); | 216 SetTestTime(start_time + time_elapsed); |
| 207 stopwatch.Stop(); | 217 stopwatch.Stop(); |
| 208 | 218 |
| 209 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 219 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 210 | 220 |
| 211 birth_map.clear(); | 221 birth_map.clear(); |
| 212 death_map.clear(); | 222 death_map.clear(); |
| 213 parent_child_set.clear(); | 223 parent_child_set.clear(); |
| 214 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 224 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 215 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 225 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 216 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 226 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 217 EXPECT_EQ(1u, death_map.size()); // 1 location. | 227 EXPECT_EQ(1u, death_map.size()); // 1 location. |
| 218 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 228 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
| 219 if (ThreadData::TrackingParentChildStatus()) { | 229 if (ThreadData::TrackingParentChildStatus()) { |
| 220 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 230 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 221 EXPECT_EQ(parent_child_set.begin()->first, | 231 EXPECT_EQ(parent_child_set.begin()->first, |
| 222 parent_child_set.begin()->second); | 232 parent_child_set.begin()->second); |
| 223 } else { | 233 } else { |
| 224 EXPECT_EQ(0u, parent_child_set.size()); // no stats. | 234 EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
| 225 } | 235 } |
| 226 | 236 |
| 227 // The births were at the same location as the one known death. | 237 // The births were at the same location as the one known death. |
| 228 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 238 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
| 229 | 239 |
| 230 ProcessDataSnapshot process_data; | 240 ProcessDataSnapshot process_data; |
| 231 ThreadData::Snapshot(&process_data); | 241 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 232 | 242 |
| 233 ASSERT_EQ(1u, process_data.tasks.size()); | 243 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 234 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); | 244 const PhasedProcessDataSnapshots::const_iterator it = |
| 235 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); | 245 process_data.phased_process_data_snapshots.find(0); |
| 236 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); | 246 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 237 EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].birth.thread_name); | 247 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 238 EXPECT_EQ(1, process_data.tasks[0].death_data.count); | 248 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
| 239 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sum); | 249 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 240 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_max); | 250 EXPECT_EQ(kFunction, |
| 241 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sample); | 251 process_data_phase.tasks[0].birth.location.function_name); |
| 242 EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_sum); | 252 EXPECT_EQ(kLineNumber, |
| 243 EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_max); | 253 process_data_phase.tasks[0].birth.location.line_number); |
| 244 EXPECT_EQ(0, process_data.tasks[0].death_data.queue_duration_sample); | 254 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].birth.thread_name); |
| 245 EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].death_thread_name); | 255 EXPECT_EQ(1, process_data_phase.tasks[0].death_data.count); |
| 256 EXPECT_EQ(time_elapsed, |
| 257 process_data_phase.tasks[0].death_data.run_duration_sum); |
| 258 EXPECT_EQ(time_elapsed, |
| 259 process_data_phase.tasks[0].death_data.run_duration_max); |
| 260 EXPECT_EQ(time_elapsed, |
| 261 process_data_phase.tasks[0].death_data.run_duration_sample); |
| 262 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); |
| 263 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); |
| 264 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); |
| 265 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); |
| 246 | 266 |
| 247 if (ThreadData::TrackingParentChildStatus()) { | 267 if (ThreadData::TrackingParentChildStatus()) { |
| 248 ASSERT_EQ(1u, process_data.descendants.size()); | 268 ASSERT_EQ(1u, process_data_phase.descendants.size()); |
| 249 EXPECT_EQ(kFile, process_data.descendants[0].parent.location.file_name); | 269 EXPECT_EQ(kFile, |
| 270 process_data_phase.descendants[0].parent.location.file_name); |
| 250 EXPECT_EQ(kFunction, | 271 EXPECT_EQ(kFunction, |
| 251 process_data.descendants[0].parent.location.function_name); | 272 process_data_phase.descendants[0].parent.location.function_name); |
| 252 EXPECT_EQ(kLineNumber, | 273 EXPECT_EQ(kLineNumber, |
| 253 process_data.descendants[0].parent.location.line_number); | 274 process_data_phase.descendants[0].parent.location.line_number); |
| 254 EXPECT_EQ(kWorkerThreadName, | 275 EXPECT_EQ(kWorkerThreadName, |
| 255 process_data.descendants[0].parent.thread_name); | 276 process_data_phase.descendants[0].parent.thread_name); |
| 256 EXPECT_EQ(kFile, process_data.descendants[0].child.location.file_name); | 277 EXPECT_EQ(kFile, |
| 278 process_data_phase.descendants[0].child.location.file_name); |
| 257 EXPECT_EQ(kFunction, | 279 EXPECT_EQ(kFunction, |
| 258 process_data.descendants[0].child.location.function_name); | 280 process_data_phase.descendants[0].child.location.function_name); |
| 259 EXPECT_EQ(kLineNumber, | 281 EXPECT_EQ(kLineNumber, |
| 260 process_data.descendants[0].child.location.line_number); | 282 process_data_phase.descendants[0].child.location.line_number); |
| 261 EXPECT_EQ(kWorkerThreadName, process_data.descendants[0].child.thread_name); | 283 EXPECT_EQ(kWorkerThreadName, |
| 284 process_data_phase.descendants[0].child.thread_name); |
| 262 } else { | 285 } else { |
| 263 EXPECT_EQ(0u, process_data.descendants.size()); | 286 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 264 } | 287 } |
| 265 } | 288 } |
| 266 | 289 |
| 267 TEST_F(TrackedObjectsTest, DeathDataTest) { | 290 TEST_F(TrackedObjectsTest, DeathDataTest) { |
| 268 if (!ThreadData::InitializeAndSetTrackingStatus( | 291 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 269 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 292 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 270 return; | 293 return; |
| 271 } | 294 } |
| 272 | 295 |
| 273 scoped_ptr<DeathData> data(new DeathData()); | 296 scoped_ptr<DeathData> data(new DeathData()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // Start in the deactivated state. | 333 // Start in the deactivated state. |
| 311 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 334 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 312 return; | 335 return; |
| 313 } | 336 } |
| 314 | 337 |
| 315 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; | 338 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; |
| 316 Location location(kFunction, kFile, kLineNumber, NULL); | 339 Location location(kFunction, kFile, kLineNumber, NULL); |
| 317 TallyABirth(location, std::string()); | 340 TallyABirth(location, std::string()); |
| 318 | 341 |
| 319 ProcessDataSnapshot process_data; | 342 ProcessDataSnapshot process_data; |
| 320 ThreadData::Snapshot(&process_data); | 343 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 321 EXPECT_EQ(0u, process_data.tasks.size()); | 344 |
| 322 EXPECT_EQ(0u, process_data.descendants.size()); | 345 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 346 const PhasedProcessDataSnapshots::const_iterator it = |
| 347 process_data.phased_process_data_snapshots.find(0); |
| 348 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 349 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 350 |
| 351 EXPECT_EQ(0u, process_data_phase.tasks.size()); |
| 352 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 323 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 353 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 324 } | 354 } |
| 325 | 355 |
| 326 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { | 356 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { |
| 327 // Start in the deactivated state. | 357 // Start in the deactivated state. |
| 328 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 358 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 329 return; | 359 return; |
| 330 } | 360 } |
| 331 | 361 |
| 332 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; | 362 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; |
| 333 Location location(kFunction, kFile, kLineNumber, NULL); | 363 Location location(kFunction, kFile, kLineNumber, NULL); |
| 334 TallyABirth(location, kMainThreadName); | 364 TallyABirth(location, kMainThreadName); |
| 335 | 365 |
| 336 ProcessDataSnapshot process_data; | 366 ProcessDataSnapshot process_data; |
| 337 ThreadData::Snapshot(&process_data); | 367 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 338 EXPECT_EQ(0u, process_data.tasks.size()); | 368 |
| 339 EXPECT_EQ(0u, process_data.descendants.size()); | 369 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 370 const PhasedProcessDataSnapshots::const_iterator it = |
| 371 process_data.phased_process_data_snapshots.find(0); |
| 372 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 373 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 374 |
| 375 EXPECT_EQ(0u, process_data_phase.tasks.size()); |
| 376 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 340 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 377 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 341 } | 378 } |
| 342 | 379 |
| 343 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { | 380 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { |
| 344 if (!ThreadData::InitializeAndSetTrackingStatus( | 381 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 345 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 382 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 346 return; | 383 return; |
| 347 } | 384 } |
| 348 | 385 |
| 349 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; | 386 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; |
| 350 Location location(kFunction, kFile, kLineNumber, NULL); | 387 Location location(kFunction, kFile, kLineNumber, NULL); |
| 351 TallyABirth(location, std::string()); | 388 TallyABirth(location, std::string()); |
| 352 | 389 |
| 353 ProcessDataSnapshot process_data; | 390 ProcessDataSnapshot process_data; |
| 354 ThreadData::Snapshot(&process_data); | 391 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 355 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, | 392 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
| 356 kStillAlive, 1, 0, 0); | 393 kStillAlive, 1, 0, 0); |
| 357 } | 394 } |
| 358 | 395 |
| 359 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { | 396 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { |
| 360 if (!ThreadData::InitializeAndSetTrackingStatus( | 397 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 361 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 398 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 362 return; | 399 return; |
| 363 } | 400 } |
| 364 | 401 |
| 365 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; | 402 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; |
| 366 Location location(kFunction, kFile, kLineNumber, NULL); | 403 Location location(kFunction, kFile, kLineNumber, NULL); |
| 367 TallyABirth(location, kMainThreadName); | 404 TallyABirth(location, kMainThreadName); |
| 368 | 405 |
| 369 ProcessDataSnapshot process_data; | 406 ProcessDataSnapshot process_data; |
| 370 ThreadData::Snapshot(&process_data); | 407 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 371 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, | 408 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, |
| 372 1, 0, 0); | 409 1, 0, 0); |
| 373 } | 410 } |
| 374 | 411 |
| 375 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { | 412 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
| 376 if (!ThreadData::InitializeAndSetTrackingStatus( | 413 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 377 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 414 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 378 return; | 415 return; |
| 379 } | 416 } |
| 380 | 417 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 392 const unsigned int kEndOfRun = 7; | 429 const unsigned int kEndOfRun = 7; |
| 393 SetTestTime(kStartOfRun); | 430 SetTestTime(kStartOfRun); |
| 394 TaskStopwatch stopwatch; | 431 TaskStopwatch stopwatch; |
| 395 stopwatch.Start(); | 432 stopwatch.Start(); |
| 396 SetTestTime(kEndOfRun); | 433 SetTestTime(kEndOfRun); |
| 397 stopwatch.Stop(); | 434 stopwatch.Stop(); |
| 398 | 435 |
| 399 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 436 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 400 | 437 |
| 401 ProcessDataSnapshot process_data; | 438 ProcessDataSnapshot process_data; |
| 402 ThreadData::Snapshot(&process_data); | 439 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 403 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 440 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 404 kMainThreadName, 1, 2, 4); | 441 kMainThreadName, 1, 2, 4); |
| 405 } | 442 } |
| 406 | 443 |
| 444 TEST_F(TrackedObjectsTest, TwoPhases) { |
| 445 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 446 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 447 return; |
| 448 } |
| 449 |
| 450 const char kFunction[] = "TwoPhases"; |
| 451 Location location(kFunction, kFile, kLineNumber, NULL); |
| 452 TallyABirth(location, kMainThreadName); |
| 453 |
| 454 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 455 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 456 // TrackingInfo will call TallyABirth() during construction. |
| 457 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 458 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 459 |
| 460 const unsigned int kStartOfRun = 5; |
| 461 const unsigned int kEndOfRun = 7; |
| 462 SetTestTime(kStartOfRun); |
| 463 TaskStopwatch stopwatch; |
| 464 stopwatch.Start(); |
| 465 SetTestTime(kEndOfRun); |
| 466 stopwatch.Stop(); |
| 467 |
| 468 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 469 |
| 470 ThreadData::OnProfilingPhaseCompletion(0); |
| 471 |
| 472 TallyABirth(location, kMainThreadName); |
| 473 |
| 474 const TrackedTime kTimePosted1 = TrackedTime::FromMilliseconds(9); |
| 475 const base::TimeTicks kDelayedStartTime1 = base::TimeTicks(); |
| 476 // TrackingInfo will call TallyABirth() during construction. |
| 477 base::TrackingInfo pending_task1(location, kDelayedStartTime1); |
| 478 pending_task1.time_posted = kTimePosted1; // Overwrite implied Now(). |
| 479 |
| 480 const unsigned int kStartOfRun1 = 11; |
| 481 const unsigned int kEndOfRun1 = 21; |
| 482 SetTestTime(kStartOfRun1); |
| 483 TaskStopwatch stopwatch1; |
| 484 stopwatch1.Start(); |
| 485 SetTestTime(kEndOfRun1); |
| 486 stopwatch1.Stop(); |
| 487 |
| 488 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task1, stopwatch1); |
| 489 |
| 490 ProcessDataSnapshot process_data; |
| 491 ThreadData::GetProcessDataSnapshot(1, &process_data); |
| 492 |
| 493 ASSERT_EQ(2, process_data.phased_process_data_snapshots.size()); |
| 494 |
| 495 const PhasedProcessDataSnapshots::const_iterator it0 = |
| 496 process_data.phased_process_data_snapshots.find(0); |
| 497 ASSERT_TRUE(it0 != process_data.phased_process_data_snapshots.end()); |
| 498 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 499 |
| 500 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 501 |
| 502 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 503 EXPECT_EQ(kFunction, |
| 504 process_data_phase0.tasks[0].birth.location.function_name); |
| 505 EXPECT_EQ(kLineNumber, |
| 506 process_data_phase0.tasks[0].birth.location.line_number); |
| 507 |
| 508 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 509 |
| 510 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 511 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 512 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 513 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 514 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 515 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 516 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 517 |
| 518 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 519 |
| 520 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 521 |
| 522 const PhasedProcessDataSnapshots::const_iterator it1 = |
| 523 process_data.phased_process_data_snapshots.find(1); |
| 524 ASSERT_TRUE(it1 != process_data.phased_process_data_snapshots.end()); |
| 525 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 526 |
| 527 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 528 |
| 529 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 530 EXPECT_EQ(kFunction, |
| 531 process_data_phase1.tasks[0].birth.location.function_name); |
| 532 EXPECT_EQ(kLineNumber, |
| 533 process_data_phase1.tasks[0].birth.location.line_number); |
| 534 |
| 535 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 536 |
| 537 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 538 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 539 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 540 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 541 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 542 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 543 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 544 |
| 545 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 546 |
| 547 EXPECT_EQ(0u, process_data_phase1.descendants.size()); |
| 548 |
| 549 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 550 } |
| 551 |
| 552 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) { |
| 553 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 554 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 555 return; |
| 556 } |
| 557 |
| 558 const char kFunction[] = "TwoPhasesSecondEmpty"; |
| 559 Location location(kFunction, kFile, kLineNumber, NULL); |
| 560 ThreadData::InitializeThreadContext(kMainThreadName); |
| 561 |
| 562 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 563 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 564 // TrackingInfo will call TallyABirth() during construction. |
| 565 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 566 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 567 |
| 568 const unsigned int kStartOfRun = 5; |
| 569 const unsigned int kEndOfRun = 7; |
| 570 SetTestTime(kStartOfRun); |
| 571 TaskStopwatch stopwatch; |
| 572 stopwatch.Start(); |
| 573 SetTestTime(kEndOfRun); |
| 574 stopwatch.Stop(); |
| 575 |
| 576 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 577 |
| 578 ThreadData::OnProfilingPhaseCompletion(0); |
| 579 |
| 580 ProcessDataSnapshot process_data; |
| 581 ThreadData::GetProcessDataSnapshot(1, &process_data); |
| 582 |
| 583 ASSERT_EQ(2, process_data.phased_process_data_snapshots.size()); |
| 584 |
| 585 const PhasedProcessDataSnapshots::const_iterator it0 = |
| 586 process_data.phased_process_data_snapshots.find(0); |
| 587 ASSERT_TRUE(it0 != process_data.phased_process_data_snapshots.end()); |
| 588 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 589 |
| 590 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 591 |
| 592 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 593 EXPECT_EQ(kFunction, |
| 594 process_data_phase0.tasks[0].birth.location.function_name); |
| 595 EXPECT_EQ(kLineNumber, |
| 596 process_data_phase0.tasks[0].birth.location.line_number); |
| 597 |
| 598 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 599 |
| 600 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 601 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 602 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 603 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 604 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 605 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 606 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 607 |
| 608 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 609 |
| 610 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 611 |
| 612 const PhasedProcessDataSnapshots::const_iterator it1 = |
| 613 process_data.phased_process_data_snapshots.find(1); |
| 614 ASSERT_TRUE(it1 != process_data.phased_process_data_snapshots.end()); |
| 615 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 616 |
| 617 ASSERT_EQ(0u, process_data_phase1.tasks.size()); |
| 618 |
| 619 EXPECT_EQ(0u, process_data_phase1.descendants.size()); |
| 620 |
| 621 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 622 } |
| 623 |
| 407 // We will deactivate tracking after the birth, and before the death, and | 624 // We will deactivate tracking after the birth, and before the death, and |
| 408 // demonstrate that the lifecycle is completely tallied. This ensures that | 625 // demonstrate that the lifecycle is completely tallied. This ensures that |
| 409 // our tallied births are matched by tallied deaths (except for when the | 626 // our tallied births are matched by tallied deaths (except for when the |
| 410 // task is still running, or is queued). | 627 // task is still running, or is queued). |
| 411 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { | 628 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
| 412 if (!ThreadData::InitializeAndSetTrackingStatus( | 629 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 413 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 630 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 414 return; | 631 return; |
| 415 } | 632 } |
| 416 | 633 |
| 417 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; | 634 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
| 418 Location location(kFunction, kFile, kLineNumber, NULL); | 635 Location location(kFunction, kFile, kLineNumber, NULL); |
| 419 TallyABirth(location, kMainThreadName); | 636 TallyABirth(location, kMainThreadName); |
| 420 | 637 |
| 421 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 638 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 422 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 639 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 423 // TrackingInfo will call TallyABirth() during construction. | 640 // TrackingInfo will call TallyABirth() during construction. |
| 424 base::TrackingInfo pending_task(location, kDelayedStartTime); | 641 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 425 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 642 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 426 | 643 |
| 427 // Turn off tracking now that we have births. | 644 // Turn off tracking now that we have births. |
| 428 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 645 EXPECT_TRUE( |
| 429 ThreadData::DEACTIVATED)); | 646 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)); |
| 430 | 647 |
| 431 const unsigned int kStartOfRun = 5; | 648 const unsigned int kStartOfRun = 5; |
| 432 const unsigned int kEndOfRun = 7; | 649 const unsigned int kEndOfRun = 7; |
| 433 SetTestTime(kStartOfRun); | 650 SetTestTime(kStartOfRun); |
| 434 TaskStopwatch stopwatch; | 651 TaskStopwatch stopwatch; |
| 435 stopwatch.Start(); | 652 stopwatch.Start(); |
| 436 SetTestTime(kEndOfRun); | 653 SetTestTime(kEndOfRun); |
| 437 stopwatch.Stop(); | 654 stopwatch.Stop(); |
| 438 | 655 |
| 439 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 656 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 440 | 657 |
| 441 ProcessDataSnapshot process_data; | 658 ProcessDataSnapshot process_data; |
| 442 ThreadData::Snapshot(&process_data); | 659 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 443 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 660 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 444 kMainThreadName, 1, 2, 4); | 661 kMainThreadName, 1, 2, 4); |
| 445 } | 662 } |
| 446 | 663 |
| 447 // We will deactivate tracking before starting a life cycle, and neither | 664 // We will deactivate tracking before starting a life cycle, and neither |
| 448 // the birth nor the death will be recorded. | 665 // the birth nor the death will be recorded. |
| 449 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { | 666 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { |
| 450 // Start in the deactivated state. | 667 // Start in the deactivated state. |
| 451 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 668 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 452 return; | 669 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 466 const unsigned int kEndOfRun = 7; | 683 const unsigned int kEndOfRun = 7; |
| 467 SetTestTime(kStartOfRun); | 684 SetTestTime(kStartOfRun); |
| 468 TaskStopwatch stopwatch; | 685 TaskStopwatch stopwatch; |
| 469 stopwatch.Start(); | 686 stopwatch.Start(); |
| 470 SetTestTime(kEndOfRun); | 687 SetTestTime(kEndOfRun); |
| 471 stopwatch.Stop(); | 688 stopwatch.Stop(); |
| 472 | 689 |
| 473 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 690 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 474 | 691 |
| 475 ProcessDataSnapshot process_data; | 692 ProcessDataSnapshot process_data; |
| 476 ThreadData::Snapshot(&process_data); | 693 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 477 EXPECT_EQ(0u, process_data.tasks.size()); | 694 |
| 478 EXPECT_EQ(0u, process_data.descendants.size()); | 695 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 696 const PhasedProcessDataSnapshots::const_iterator it = |
| 697 process_data.phased_process_data_snapshots.find(0); |
| 698 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 699 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 700 |
| 701 EXPECT_EQ(0u, process_data_phase.tasks.size()); |
| 702 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 479 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 703 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 480 } | 704 } |
| 481 | 705 |
| 482 TEST_F(TrackedObjectsTest, TwoLives) { | 706 TEST_F(TrackedObjectsTest, TwoLives) { |
| 483 if (!ThreadData::InitializeAndSetTrackingStatus( | 707 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 484 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 708 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 485 return; | 709 return; |
| 486 } | 710 } |
| 487 | 711 |
| 488 const char kFunction[] = "TwoLives"; | 712 const char kFunction[] = "TwoLives"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 510 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 734 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 511 SetTestTime(kStartOfRun); | 735 SetTestTime(kStartOfRun); |
| 512 TaskStopwatch stopwatch2; | 736 TaskStopwatch stopwatch2; |
| 513 stopwatch2.Start(); | 737 stopwatch2.Start(); |
| 514 SetTestTime(kEndOfRun); | 738 SetTestTime(kEndOfRun); |
| 515 stopwatch2.Stop(); | 739 stopwatch2.Stop(); |
| 516 | 740 |
| 517 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); | 741 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); |
| 518 | 742 |
| 519 ProcessDataSnapshot process_data; | 743 ProcessDataSnapshot process_data; |
| 520 ThreadData::Snapshot(&process_data); | 744 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 521 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 745 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 522 kMainThreadName, 2, 2, 4); | 746 kMainThreadName, 2, 2, 4); |
| 523 } | 747 } |
| 524 | 748 |
| 525 TEST_F(TrackedObjectsTest, DifferentLives) { | 749 TEST_F(TrackedObjectsTest, DifferentLives) { |
| 526 if (!ThreadData::InitializeAndSetTrackingStatus( | 750 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 527 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 751 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 528 return; | 752 return; |
| 529 } | 753 } |
| 530 | 754 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 550 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 774 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 551 | 775 |
| 552 const int kSecondFakeLineNumber = 999; | 776 const int kSecondFakeLineNumber = 999; |
| 553 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 777 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 554 | 778 |
| 555 // TrackingInfo will call TallyABirth() during construction. | 779 // TrackingInfo will call TallyABirth() during construction. |
| 556 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 780 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 557 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 781 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 558 | 782 |
| 559 ProcessDataSnapshot process_data; | 783 ProcessDataSnapshot process_data; |
| 560 ThreadData::Snapshot(&process_data); | 784 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 561 ASSERT_EQ(2u, process_data.tasks.size()); | |
| 562 | 785 |
| 563 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); | 786 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 564 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); | 787 const PhasedProcessDataSnapshots::const_iterator it = |
| 565 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); | 788 process_data.phased_process_data_snapshots.find(0); |
| 566 EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name); | 789 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 567 EXPECT_EQ(1, process_data.tasks[0].death_data.count); | 790 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 568 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sum); | 791 |
| 569 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_max); | 792 ASSERT_EQ(2u, process_data_phase.tasks.size()); |
| 570 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sample); | 793 |
| 571 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sum); | 794 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
| 572 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_max); | 795 EXPECT_EQ(kFunction, |
| 573 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sample); | 796 process_data_phase.tasks[0].birth.location.function_name); |
| 574 EXPECT_EQ(kMainThreadName, process_data.tasks[0].death_thread_name); | 797 EXPECT_EQ(kLineNumber, |
| 575 EXPECT_EQ(kFile, process_data.tasks[1].birth.location.file_name); | 798 process_data_phase.tasks[0].birth.location.line_number); |
| 576 EXPECT_EQ(kFunction, process_data.tasks[1].birth.location.function_name); | 799 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[0].birth.thread_name); |
| 800 EXPECT_EQ(1, process_data_phase.tasks[0].death_data.count); |
| 801 EXPECT_EQ(2, process_data_phase.tasks[0].death_data.run_duration_sum); |
| 802 EXPECT_EQ(2, process_data_phase.tasks[0].death_data.run_duration_max); |
| 803 EXPECT_EQ(2, process_data_phase.tasks[0].death_data.run_duration_sample); |
| 804 EXPECT_EQ(4, process_data_phase.tasks[0].death_data.queue_duration_sum); |
| 805 EXPECT_EQ(4, process_data_phase.tasks[0].death_data.queue_duration_max); |
| 806 EXPECT_EQ(4, process_data_phase.tasks[0].death_data.queue_duration_sample); |
| 807 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[0].death_thread_name); |
| 808 EXPECT_EQ(kFile, process_data_phase.tasks[1].birth.location.file_name); |
| 809 EXPECT_EQ(kFunction, |
| 810 process_data_phase.tasks[1].birth.location.function_name); |
| 577 EXPECT_EQ(kSecondFakeLineNumber, | 811 EXPECT_EQ(kSecondFakeLineNumber, |
| 578 process_data.tasks[1].birth.location.line_number); | 812 process_data_phase.tasks[1].birth.location.line_number); |
| 579 EXPECT_EQ(kMainThreadName, process_data.tasks[1].birth.thread_name); | 813 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[1].birth.thread_name); |
| 580 EXPECT_EQ(1, process_data.tasks[1].death_data.count); | 814 EXPECT_EQ(1, process_data_phase.tasks[1].death_data.count); |
| 581 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sum); | 815 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sum); |
| 582 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max); | 816 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_max); |
| 583 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sample); | 817 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sample); |
| 584 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sum); | 818 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sum); |
| 585 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_max); | 819 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); |
| 586 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample); | 820 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); |
| 587 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name); | 821 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); |
| 588 EXPECT_EQ(0u, process_data.descendants.size()); | 822 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 589 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 823 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 590 } | 824 } |
| 591 | 825 |
| 592 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { | 826 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { |
| 593 if (!ThreadData::InitializeAndSetTrackingStatus( | 827 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 594 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 828 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 595 return; | 829 return; |
| 596 } | 830 } |
| 597 | 831 |
| 598 const char kFunction[] = "TaskWithNestedExclusion"; | 832 const char kFunction[] = "TaskWithNestedExclusion"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 614 exclusion_stopwatch.Start(); | 848 exclusion_stopwatch.Start(); |
| 615 SetTestTime(12); | 849 SetTestTime(12); |
| 616 exclusion_stopwatch.Stop(); | 850 exclusion_stopwatch.Stop(); |
| 617 } | 851 } |
| 618 SetTestTime(15); | 852 SetTestTime(15); |
| 619 task_stopwatch.Stop(); | 853 task_stopwatch.Stop(); |
| 620 | 854 |
| 621 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 855 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 622 | 856 |
| 623 ProcessDataSnapshot process_data; | 857 ProcessDataSnapshot process_data; |
| 624 ThreadData::Snapshot(&process_data); | 858 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 625 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 859 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 626 kMainThreadName, 1, 6, 4); | 860 kMainThreadName, 1, 6, 4); |
| 627 } | 861 } |
| 628 | 862 |
| 629 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { | 863 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { |
| 630 if (!ThreadData::InitializeAndSetTrackingStatus( | 864 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 631 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 865 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 632 return; | 866 return; |
| 633 } | 867 } |
| 634 | 868 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 657 exclusion_stopwatch2.Start(); | 891 exclusion_stopwatch2.Start(); |
| 658 SetTestTime(18); | 892 SetTestTime(18); |
| 659 exclusion_stopwatch2.Stop(); | 893 exclusion_stopwatch2.Stop(); |
| 660 } | 894 } |
| 661 SetTestTime(25); | 895 SetTestTime(25); |
| 662 task_stopwatch.Stop(); | 896 task_stopwatch.Stop(); |
| 663 | 897 |
| 664 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 898 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 665 | 899 |
| 666 ProcessDataSnapshot process_data; | 900 ProcessDataSnapshot process_data; |
| 667 ThreadData::Snapshot(&process_data); | 901 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 668 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 902 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
| 669 kMainThreadName, 1, 13, 4); | 903 kMainThreadName, 1, 13, 4); |
| 670 } | 904 } |
| 671 | 905 |
| 672 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { | 906 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { |
| 673 if (!ThreadData::InitializeAndSetTrackingStatus( | 907 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 674 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 908 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 675 return; | 909 return; |
| 676 } | 910 } |
| 677 | 911 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 } | 944 } |
| 711 SetTestTime(12); | 945 SetTestTime(12); |
| 712 exclusion_stopwatch.Stop(); | 946 exclusion_stopwatch.Stop(); |
| 713 } | 947 } |
| 714 SetTestTime(15); | 948 SetTestTime(15); |
| 715 task_stopwatch.Stop(); | 949 task_stopwatch.Stop(); |
| 716 | 950 |
| 717 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 951 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
| 718 | 952 |
| 719 ProcessDataSnapshot process_data; | 953 ProcessDataSnapshot process_data; |
| 720 ThreadData::Snapshot(&process_data); | 954 ThreadData::GetProcessDataSnapshot(0, &process_data); |
| 955 |
| 956 ASSERT_EQ(1, process_data.phased_process_data_snapshots.size()); |
| 957 const PhasedProcessDataSnapshots::const_iterator it = |
| 958 process_data.phased_process_data_snapshots.find(0); |
| 959 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
| 960 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
| 721 | 961 |
| 722 // The order in which the two task follow is platform-dependent. | 962 // The order in which the two task follow is platform-dependent. |
| 723 int t0 = (process_data.tasks[0].birth.location.line_number == kLineNumber) ? | 963 int t0 = |
| 724 0 : 1; | 964 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) |
| 965 ? 0 |
| 966 : 1; |
| 725 int t1 = 1 - t0; | 967 int t1 = 1 - t0; |
| 726 | 968 |
| 727 ASSERT_EQ(2u, process_data.tasks.size()); | 969 ASSERT_EQ(2u, process_data_phase.tasks.size()); |
| 728 EXPECT_EQ(kFile, process_data.tasks[t0].birth.location.file_name); | 970 EXPECT_EQ(kFile, process_data_phase.tasks[t0].birth.location.file_name); |
| 729 EXPECT_EQ(kFunction, process_data.tasks[t0].birth.location.function_name); | 971 EXPECT_EQ(kFunction, |
| 730 EXPECT_EQ(kLineNumber, process_data.tasks[t0].birth.location.line_number); | 972 process_data_phase.tasks[t0].birth.location.function_name); |
| 731 EXPECT_EQ(kMainThreadName, process_data.tasks[t0].birth.thread_name); | 973 EXPECT_EQ(kLineNumber, |
| 732 EXPECT_EQ(1, process_data.tasks[t0].death_data.count); | 974 process_data_phase.tasks[t0].birth.location.line_number); |
| 733 EXPECT_EQ(6, process_data.tasks[t0].death_data.run_duration_sum); | 975 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t0].birth.thread_name); |
| 734 EXPECT_EQ(6, process_data.tasks[t0].death_data.run_duration_max); | 976 EXPECT_EQ(1, process_data_phase.tasks[t0].death_data.count); |
| 735 EXPECT_EQ(6, process_data.tasks[t0].death_data.run_duration_sample); | 977 EXPECT_EQ(6, process_data_phase.tasks[t0].death_data.run_duration_sum); |
| 736 EXPECT_EQ(4, process_data.tasks[t0].death_data.queue_duration_sum); | 978 EXPECT_EQ(6, process_data_phase.tasks[t0].death_data.run_duration_max); |
| 737 EXPECT_EQ(4, process_data.tasks[t0].death_data.queue_duration_max); | 979 EXPECT_EQ(6, process_data_phase.tasks[t0].death_data.run_duration_sample); |
| 738 EXPECT_EQ(4, process_data.tasks[t0].death_data.queue_duration_sample); | 980 EXPECT_EQ(4, process_data_phase.tasks[t0].death_data.queue_duration_sum); |
| 739 EXPECT_EQ(kMainThreadName, process_data.tasks[t0].death_thread_name); | 981 EXPECT_EQ(4, process_data_phase.tasks[t0].death_data.queue_duration_max); |
| 740 EXPECT_EQ(kFile, process_data.tasks[t1].birth.location.file_name); | 982 EXPECT_EQ(4, process_data_phase.tasks[t0].death_data.queue_duration_sample); |
| 741 EXPECT_EQ(kFunction, process_data.tasks[t1].birth.location.function_name); | 983 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t0].death_thread_name); |
| 984 EXPECT_EQ(kFile, process_data_phase.tasks[t1].birth.location.file_name); |
| 985 EXPECT_EQ(kFunction, |
| 986 process_data_phase.tasks[t1].birth.location.function_name); |
| 742 EXPECT_EQ(kSecondFakeLineNumber, | 987 EXPECT_EQ(kSecondFakeLineNumber, |
| 743 process_data.tasks[t1].birth.location.line_number); | 988 process_data_phase.tasks[t1].birth.location.line_number); |
| 744 EXPECT_EQ(kMainThreadName, process_data.tasks[t1].birth.thread_name); | 989 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].birth.thread_name); |
| 745 EXPECT_EQ(1, process_data.tasks[t1].death_data.count); | 990 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.count); |
| 746 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_sum); | 991 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sum); |
| 747 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_max); | 992 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); |
| 748 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_sample); | 993 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); |
| 749 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sum); | 994 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); |
| 750 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_max); | 995 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); |
| 751 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sample); | 996 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); |
| 752 EXPECT_EQ(kMainThreadName, process_data.tasks[t1].death_thread_name); | 997 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); |
| 753 EXPECT_EQ(0u, process_data.descendants.size()); | 998 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
| 754 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 999 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 755 } | 1000 } |
| 756 | 1001 |
| 757 } // namespace tracked_objects | 1002 } // namespace tracked_objects |
| OLD | NEW |