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