Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 1021053003: Delivering the FIRST_NONEMPTY_PAINT phase changing event to base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@phase_splitting
Patch Set: More comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 23 matching lines...) Expand all
278 process_data_phase.descendants[0].child.location.function_name); 281 process_data_phase.descendants[0].child.location.function_name);
279 EXPECT_EQ(kLineNumber, 282 EXPECT_EQ(kLineNumber,
280 process_data_phase.descendants[0].child.location.line_number); 283 process_data_phase.descendants[0].child.location.line_number);
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, DeathDataTestRecordDeath) {
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());
332 }
319 333
320 DeathDataSnapshot snapshot(*data); 334 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) {
321 EXPECT_EQ(2, snapshot.count); 335 if (!ThreadData::InitializeAndSetTrackingStatus(
322 EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum); 336 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
323 EXPECT_EQ(run_ms, snapshot.run_duration_max); 337 // Don't run the test if task tracking is not compiled in.
324 EXPECT_EQ(run_ms, snapshot.run_duration_sample); 338 return;
325 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); 339 }
326 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); 340
327 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); 341 scoped_ptr<DeathData> data(new DeathData());
342 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL));
343
344 int32 run_ms = 42;
345 int32 queue_ms = 8;
346
347 const int kUnrandomInt = 0; // Fake random int that ensure we sample data.
348 data->RecordDeath(queue_ms, run_ms, kUnrandomInt);
349 data->RecordDeath(queue_ms, run_ms, kUnrandomInt);
350
351 data->OnProfilingPhaseCompleted(123);
352 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms);
353 EXPECT_EQ(data->run_duration_max(), 0);
354 EXPECT_EQ(data->run_duration_sample(), run_ms);
355 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms);
356 EXPECT_EQ(data->queue_duration_max(), 0);
357 EXPECT_EQ(data->queue_duration_sample(), queue_ms);
358 EXPECT_EQ(data->count(), 2);
359 ASSERT_NE(nullptr, data->last_phase_snapshot());
360 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase);
361 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count);
362 EXPECT_EQ(2 * run_ms,
363 data->last_phase_snapshot()->death_data.run_duration_sum);
364 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max);
365 EXPECT_EQ(run_ms,
366 data->last_phase_snapshot()->death_data.run_duration_sample);
367 EXPECT_EQ(2 * queue_ms,
368 data->last_phase_snapshot()->death_data.queue_duration_sum);
369 EXPECT_EQ(queue_ms,
370 data->last_phase_snapshot()->death_data.queue_duration_max);
371 EXPECT_EQ(queue_ms,
372 data->last_phase_snapshot()->death_data.queue_duration_sample);
373 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev);
374
375 int32 run_ms1 = 21;
376 int32 queue_ms1 = 4;
377
378 data->RecordDeath(queue_ms1, run_ms1, kUnrandomInt);
379 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms + run_ms1);
380 EXPECT_EQ(data->run_duration_max(), run_ms1);
381 EXPECT_EQ(data->run_duration_sample(), run_ms1);
382 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms + queue_ms1);
383 EXPECT_EQ(data->queue_duration_max(), queue_ms1);
384 EXPECT_EQ(data->queue_duration_sample(), queue_ms1);
385 EXPECT_EQ(data->count(), 3);
386 ASSERT_NE(nullptr, data->last_phase_snapshot());
387 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase);
388 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count);
389 EXPECT_EQ(2 * run_ms,
390 data->last_phase_snapshot()->death_data.run_duration_sum);
391 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max);
392 EXPECT_EQ(run_ms,
393 data->last_phase_snapshot()->death_data.run_duration_sample);
394 EXPECT_EQ(2 * queue_ms,
395 data->last_phase_snapshot()->death_data.queue_duration_sum);
396 EXPECT_EQ(queue_ms,
397 data->last_phase_snapshot()->death_data.queue_duration_max);
398 EXPECT_EQ(queue_ms,
399 data->last_phase_snapshot()->death_data.queue_duration_sample);
400 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev);
401 }
402
403 TEST_F(TrackedObjectsTest, Delta) {
404 if (!ThreadData::InitializeAndSetTrackingStatus(
405 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
406 // Don't run the test if task tracking is not compiled in.
407 return;
408 }
409
410 DeathDataSnapshot snapshot;
411 snapshot.count = 10;
412 snapshot.run_duration_sum = 100;
413 snapshot.run_duration_max = 50;
414 snapshot.run_duration_sample = 25;
415 snapshot.queue_duration_sum = 200;
416 snapshot.queue_duration_max = 101;
417 snapshot.queue_duration_sample = 26;
418
419 DeathDataSnapshot older_snapshot;
420 older_snapshot.count = 2;
421 older_snapshot.run_duration_sum = 95;
422 older_snapshot.run_duration_max = 48;
423 older_snapshot.run_duration_sample = 22;
424 older_snapshot.queue_duration_sum = 190;
425 older_snapshot.queue_duration_max = 99;
426 older_snapshot.queue_duration_sample = 21;
427
428 const DeathDataSnapshot& delta = snapshot.Delta(older_snapshot);
429 EXPECT_EQ(8, delta.count);
430 EXPECT_EQ(5, delta.run_duration_sum);
431 EXPECT_EQ(50, delta.run_duration_max);
432 EXPECT_EQ(25, delta.run_duration_sample);
433 EXPECT_EQ(10, delta.queue_duration_sum);
434 EXPECT_EQ(101, delta.queue_duration_max);
435 EXPECT_EQ(26, delta.queue_duration_sample);
328 } 436 }
329 437
330 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { 438 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) {
331 // Start in the deactivated state. 439 // Start in the deactivated state.
332 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 440 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
441 // Don't run the test if task tracking is not compiled in.
333 return; 442 return;
334 } 443 }
335 444
336 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; 445 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread";
337 Location location(kFunction, kFile, kLineNumber, NULL); 446 Location location(kFunction, kFile, kLineNumber, NULL);
338 TallyABirth(location, std::string()); 447 TallyABirth(location, std::string());
339 448
340 ProcessDataSnapshot process_data; 449 ProcessDataSnapshot process_data;
341 ThreadData::Snapshot(&process_data); 450 ThreadData::Snapshot(0, &process_data);
342 451
343 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 452 ASSERT_EQ(1u, process_data.phased_snapshots.size());
344 auto it = process_data.phased_process_data_snapshots.find(0); 453
345 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 454 auto it = process_data.phased_snapshots.find(0);
455 ASSERT_TRUE(it != process_data.phased_snapshots.end());
346 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 456 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
347 457
348 EXPECT_EQ(0u, process_data_phase.tasks.size()); 458 ASSERT_EQ(0u, process_data_phase.tasks.size());
349 EXPECT_EQ(0u, process_data_phase.descendants.size()); 459
350 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 460 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
351 } 461 }
352 462
353 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { 463 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) {
354 // Start in the deactivated state. 464 // Start in the deactivated state.
355 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 465 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
466 // Don't run the test if task tracking is not compiled in.
356 return; 467 return;
357 } 468 }
358 469
359 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; 470 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread";
360 Location location(kFunction, kFile, kLineNumber, NULL); 471 Location location(kFunction, kFile, kLineNumber, NULL);
361 TallyABirth(location, kMainThreadName); 472 TallyABirth(location, kMainThreadName);
362 473
363 ProcessDataSnapshot process_data; 474 ProcessDataSnapshot process_data;
364 ThreadData::Snapshot(&process_data); 475 ThreadData::Snapshot(0, &process_data);
365 476
366 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 477 ASSERT_EQ(1u, process_data.phased_snapshots.size());
367 auto it = process_data.phased_process_data_snapshots.find(0); 478
368 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 479 auto it = process_data.phased_snapshots.find(0);
480 ASSERT_TRUE(it != process_data.phased_snapshots.end());
369 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 481 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
370 482
371 EXPECT_EQ(0u, process_data_phase.tasks.size()); 483 ASSERT_EQ(0u, process_data_phase.tasks.size());
372 EXPECT_EQ(0u, process_data_phase.descendants.size()); 484
373 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 485 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
374 } 486 }
375 487
376 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { 488 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) {
377 if (!ThreadData::InitializeAndSetTrackingStatus( 489 if (!ThreadData::InitializeAndSetTrackingStatus(
378 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 490 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
491 // Don't run the test if task tracking is not compiled in.
379 return; 492 return;
380 } 493 }
381 494
382 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; 495 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread";
383 Location location(kFunction, kFile, kLineNumber, NULL); 496 Location location(kFunction, kFile, kLineNumber, NULL);
384 TallyABirth(location, std::string()); 497 TallyABirth(location, std::string());
385 498
386 ProcessDataSnapshot process_data; 499 ProcessDataSnapshot process_data;
387 ThreadData::Snapshot(&process_data); 500 ThreadData::Snapshot(0, &process_data);
388 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 501 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
389 kStillAlive, 1, 0, 0); 502 kStillAlive, 1, 0, 0);
390 } 503 }
391 504
392 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { 505 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) {
393 if (!ThreadData::InitializeAndSetTrackingStatus( 506 if (!ThreadData::InitializeAndSetTrackingStatus(
394 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 507 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
508 // Don't run the test if task tracking is not compiled in.
395 return; 509 return;
396 } 510 }
397 511
398 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; 512 const char kFunction[] = "BirthOnlyToSnapshotMainThread";
399 Location location(kFunction, kFile, kLineNumber, NULL); 513 Location location(kFunction, kFile, kLineNumber, NULL);
400 TallyABirth(location, kMainThreadName); 514 TallyABirth(location, kMainThreadName);
401 515
402 ProcessDataSnapshot process_data; 516 ProcessDataSnapshot process_data;
403 ThreadData::Snapshot(&process_data); 517 ThreadData::Snapshot(0, &process_data);
404 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, 518 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive,
405 1, 0, 0); 519 1, 0, 0);
406 } 520 }
407 521
408 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { 522 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) {
409 if (!ThreadData::InitializeAndSetTrackingStatus( 523 if (!ThreadData::InitializeAndSetTrackingStatus(
410 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 524 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
525 // Don't run the test if task tracking is not compiled in.
411 return; 526 return;
412 } 527 }
413 528
414 const char kFunction[] = "LifeCycleToSnapshotMainThread"; 529 const char kFunction[] = "LifeCycleToSnapshotMainThread";
415 Location location(kFunction, kFile, kLineNumber, NULL); 530 Location location(kFunction, kFile, kLineNumber, NULL);
416 TallyABirth(location, kMainThreadName); 531 TallyABirth(location, kMainThreadName);
417 532
418 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 533 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
419 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 534 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
420 // TrackingInfo will call TallyABirth() during construction. 535 // TrackingInfo will call TallyABirth() during construction.
421 base::TrackingInfo pending_task(location, kDelayedStartTime); 536 base::TrackingInfo pending_task(location, kDelayedStartTime);
422 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 537 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
423 538
424 const unsigned int kStartOfRun = 5; 539 const unsigned int kStartOfRun = 5;
425 const unsigned int kEndOfRun = 7; 540 const unsigned int kEndOfRun = 7;
426 SetTestTime(kStartOfRun); 541 SetTestTime(kStartOfRun);
427 TaskStopwatch stopwatch; 542 TaskStopwatch stopwatch;
428 stopwatch.Start(); 543 stopwatch.Start();
429 SetTestTime(kEndOfRun); 544 SetTestTime(kEndOfRun);
430 stopwatch.Stop(); 545 stopwatch.Stop();
431 546
432 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 547 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
433 548
434 ProcessDataSnapshot process_data; 549 ProcessDataSnapshot process_data;
435 ThreadData::Snapshot(&process_data); 550 ThreadData::Snapshot(0, &process_data);
436 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 551 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
437 kMainThreadName, 1, 2, 4); 552 kMainThreadName, 1, 2, 4);
438 } 553 }
439 554
555 TEST_F(TrackedObjectsTest, TwoPhases) {
556 if (!ThreadData::InitializeAndSetTrackingStatus(
557 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
558 // Don't run the test if task tracking is not compiled in.
559 return;
560 }
561
562 const char kFunction[] = "TwoPhases";
563 Location location(kFunction, kFile, kLineNumber, NULL);
564 TallyABirth(location, kMainThreadName);
565
566 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
567 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
568 // TrackingInfo will call TallyABirth() during construction.
569 base::TrackingInfo pending_task(location, kDelayedStartTime);
570 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
571
572 const unsigned int kStartOfRun = 5;
573 const unsigned int kEndOfRun = 7;
574 SetTestTime(kStartOfRun);
575 TaskStopwatch stopwatch;
576 stopwatch.Start();
577 SetTestTime(kEndOfRun);
578 stopwatch.Stop();
579
580 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
581
582 ThreadData::OnProfilingPhaseCompleted(0);
583
584 TallyABirth(location, kMainThreadName);
585
586 const TrackedTime kTimePosted1 = TrackedTime::FromMilliseconds(9);
587 const base::TimeTicks kDelayedStartTime1 = base::TimeTicks();
588 // TrackingInfo will call TallyABirth() during construction.
589 base::TrackingInfo pending_task1(location, kDelayedStartTime1);
590 pending_task1.time_posted = kTimePosted1; // Overwrite implied Now().
591
592 const unsigned int kStartOfRun1 = 11;
593 const unsigned int kEndOfRun1 = 21;
594 SetTestTime(kStartOfRun1);
595 TaskStopwatch stopwatch1;
596 stopwatch1.Start();
597 SetTestTime(kEndOfRun1);
598 stopwatch1.Stop();
599
600 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task1, stopwatch1);
601
602 ProcessDataSnapshot process_data;
603 ThreadData::Snapshot(1, &process_data);
604
605 ASSERT_EQ(2u, process_data.phased_snapshots.size());
606
607 auto it0 = process_data.phased_snapshots.find(0);
608 ASSERT_TRUE(it0 != process_data.phased_snapshots.end());
609 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second;
610
611 ASSERT_EQ(1u, process_data_phase0.tasks.size());
612
613 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name);
614 EXPECT_EQ(kFunction,
615 process_data_phase0.tasks[0].birth.location.function_name);
616 EXPECT_EQ(kLineNumber,
617 process_data_phase0.tasks[0].birth.location.line_number);
618
619 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name);
620
621 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count);
622 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum);
623 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max);
624 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample);
625 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum);
626 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max);
627 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample);
628
629 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name);
630
631 EXPECT_EQ(0u, process_data_phase0.descendants.size());
632
633 auto it1 = process_data.phased_snapshots.find(1);
634 ASSERT_TRUE(it1 != process_data.phased_snapshots.end());
635 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
636
637 ASSERT_EQ(1u, process_data_phase1.tasks.size());
638
639 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name);
640 EXPECT_EQ(kFunction,
641 process_data_phase1.tasks[0].birth.location.function_name);
642 EXPECT_EQ(kLineNumber,
643 process_data_phase1.tasks[0].birth.location.line_number);
644
645 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name);
646
647 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count);
648 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum);
649 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max);
650 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample);
651 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum);
652 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max);
653 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample);
654
655 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name);
656
657 EXPECT_EQ(0u, process_data_phase1.descendants.size());
658
659 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
660 }
661
662 TEST_F(TrackedObjectsTest, ThreePhases) {
663 if (!ThreadData::InitializeAndSetTrackingStatus(
664 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
665 // Don't run the test if task tracking is not compiled in.
666 return;
667 }
668
669 const char kFunction[] = "ThreePhases";
670 Location location(kFunction, kFile, kLineNumber, NULL);
671
672 // Phase 0
673 {
674 TallyABirth(location, kMainThreadName);
675
676 // TrackingInfo will call TallyABirth() during construction.
677 SetTestTime(10);
678 base::TrackingInfo pending_task(location, base::TimeTicks());
679
680 SetTestTime(17);
681 TaskStopwatch stopwatch;
682 stopwatch.Start();
683 SetTestTime(23);
684 stopwatch.Stop();
685
686 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
687 }
688
689 ThreadData::OnProfilingPhaseCompleted(0);
690
691 // Phase 1
692 {
693 TallyABirth(location, kMainThreadName);
694
695 SetTestTime(30);
696 base::TrackingInfo pending_task(location, base::TimeTicks());
697
698 SetTestTime(35);
699 TaskStopwatch stopwatch;
700 stopwatch.Start();
701 SetTestTime(39);
702 stopwatch.Stop();
703
704 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
705 }
706
707 ThreadData::OnProfilingPhaseCompleted(1);
708
709 // Phase 2
710 {
711 TallyABirth(location, kMainThreadName);
712
713 // TrackingInfo will call TallyABirth() during construction.
714 SetTestTime(40);
715 base::TrackingInfo pending_task(location, base::TimeTicks());
716
717 SetTestTime(43);
718 TaskStopwatch stopwatch;
719 stopwatch.Start();
720 SetTestTime(45);
721 stopwatch.Stop();
722
723 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
724 }
725
726 // Snapshot and check results.
727 ProcessDataSnapshot process_data;
728 ThreadData::Snapshot(2, &process_data);
729
730 ASSERT_EQ(3u, process_data.phased_snapshots.size());
731
732 auto it0 = process_data.phased_snapshots.find(0);
733 ASSERT_TRUE(it0 != process_data.phased_snapshots.end());
734 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second;
735
736 ASSERT_EQ(1u, process_data_phase0.tasks.size());
737
738 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name);
739 EXPECT_EQ(kFunction,
740 process_data_phase0.tasks[0].birth.location.function_name);
741 EXPECT_EQ(kLineNumber,
742 process_data_phase0.tasks[0].birth.location.line_number);
743
744 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name);
745
746 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count);
747 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sum);
748 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_max);
749 EXPECT_EQ(6, process_data_phase0.tasks[0].death_data.run_duration_sample);
750 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sum);
751 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_max);
752 EXPECT_EQ(7, process_data_phase0.tasks[0].death_data.queue_duration_sample);
753
754 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name);
755
756 EXPECT_EQ(0u, process_data_phase0.descendants.size());
757
758 auto it1 = process_data.phased_snapshots.find(1);
759 ASSERT_TRUE(it1 != process_data.phased_snapshots.end());
760 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
761
762 ASSERT_EQ(1u, process_data_phase1.tasks.size());
763
764 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name);
765 EXPECT_EQ(kFunction,
766 process_data_phase1.tasks[0].birth.location.function_name);
767 EXPECT_EQ(kLineNumber,
768 process_data_phase1.tasks[0].birth.location.line_number);
769
770 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name);
771
772 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count);
773 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sum);
774 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_max);
775 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.run_duration_sample);
776 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sum);
777 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_max);
778 EXPECT_EQ(5, process_data_phase1.tasks[0].death_data.queue_duration_sample);
779
780 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name);
781
782 EXPECT_EQ(0u, process_data_phase1.descendants.size());
783
784 auto it2 = process_data.phased_snapshots.find(2);
785 ASSERT_TRUE(it2 != process_data.phased_snapshots.end());
786 const ProcessDataPhaseSnapshot& process_data_phase2 = it2->second;
787
788 ASSERT_EQ(1u, process_data_phase2.tasks.size());
789
790 EXPECT_EQ(kFile, process_data_phase2.tasks[0].birth.location.file_name);
791 EXPECT_EQ(kFunction,
792 process_data_phase2.tasks[0].birth.location.function_name);
793 EXPECT_EQ(kLineNumber,
794 process_data_phase2.tasks[0].birth.location.line_number);
795
796 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].birth.thread_name);
797
798 EXPECT_EQ(1, process_data_phase2.tasks[0].death_data.count);
799 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sum);
800 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_max);
801 EXPECT_EQ(2, process_data_phase2.tasks[0].death_data.run_duration_sample);
802 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sum);
803 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_max);
804 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sample);
805
806 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].death_thread_name);
807
808 EXPECT_EQ(0u, process_data_phase2.descendants.size());
809
810 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
811 }
812
813 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) {
814 if (!ThreadData::InitializeAndSetTrackingStatus(
815 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
816 // Don't run the test if task tracking is not compiled in.
817 return;
818 }
819
820 const char kFunction[] = "TwoPhasesSecondEmpty";
821 Location location(kFunction, kFile, kLineNumber, NULL);
822 ThreadData::InitializeThreadContext(kMainThreadName);
823
824 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
825 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
826 // TrackingInfo will call TallyABirth() during construction.
827 base::TrackingInfo pending_task(location, kDelayedStartTime);
828 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
829
830 const unsigned int kStartOfRun = 5;
831 const unsigned int kEndOfRun = 7;
832 SetTestTime(kStartOfRun);
833 TaskStopwatch stopwatch;
834 stopwatch.Start();
835 SetTestTime(kEndOfRun);
836 stopwatch.Stop();
837
838 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
839
840 ThreadData::OnProfilingPhaseCompleted(0);
841
842 ProcessDataSnapshot process_data;
843 ThreadData::Snapshot(1, &process_data);
844
845 ASSERT_EQ(2u, process_data.phased_snapshots.size());
846
847 auto it0 = process_data.phased_snapshots.find(0);
848 ASSERT_TRUE(it0 != process_data.phased_snapshots.end());
849 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second;
850
851 ASSERT_EQ(1u, process_data_phase0.tasks.size());
852
853 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name);
854 EXPECT_EQ(kFunction,
855 process_data_phase0.tasks[0].birth.location.function_name);
856 EXPECT_EQ(kLineNumber,
857 process_data_phase0.tasks[0].birth.location.line_number);
858
859 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name);
860
861 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count);
862 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum);
863 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max);
864 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample);
865 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum);
866 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max);
867 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample);
868
869 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name);
870
871 auto it1 = process_data.phased_snapshots.find(1);
872 ASSERT_TRUE(it1 != process_data.phased_snapshots.end());
873 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
874
875 ASSERT_EQ(0u, process_data_phase1.tasks.size());
876
877 EXPECT_EQ(0u, process_data_phase0.descendants.size());
878
879 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
880 }
881
882 TEST_F(TrackedObjectsTest, TwoPhasesFirstEmpty) {
883 if (!ThreadData::InitializeAndSetTrackingStatus(
884 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
885 // Don't run the test if task tracking is not compiled in.
886 return;
887 }
888
889 ThreadData::OnProfilingPhaseCompleted(0);
890
891 const char kFunction[] = "TwoPhasesSecondEmpty";
892 Location location(kFunction, kFile, kLineNumber, NULL);
893 ThreadData::InitializeThreadContext(kMainThreadName);
894
895 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
896 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
897 // TrackingInfo will call TallyABirth() during construction.
898 base::TrackingInfo pending_task(location, kDelayedStartTime);
899 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
900
901 const unsigned int kStartOfRun = 5;
902 const unsigned int kEndOfRun = 7;
903 SetTestTime(kStartOfRun);
904 TaskStopwatch stopwatch;
905 stopwatch.Start();
906 SetTestTime(kEndOfRun);
907 stopwatch.Stop();
908
909 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
910
911 ProcessDataSnapshot process_data;
912 ThreadData::Snapshot(1, &process_data);
913
914 ASSERT_EQ(1u, process_data.phased_snapshots.size());
915
916 auto it1 = process_data.phased_snapshots.find(1);
917 ASSERT_TRUE(it1 != process_data.phased_snapshots.end());
918 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
919
920 ASSERT_EQ(1u, process_data_phase1.tasks.size());
921
922 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name);
923 EXPECT_EQ(kFunction,
924 process_data_phase1.tasks[0].birth.location.function_name);
925 EXPECT_EQ(kLineNumber,
926 process_data_phase1.tasks[0].birth.location.line_number);
927
928 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name);
929
930 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count);
931 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.run_duration_sum);
932 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.run_duration_max);
933 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.run_duration_sample);
934 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.queue_duration_sum);
935 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.queue_duration_max);
936 EXPECT_EQ(4, process_data_phase1.tasks[0].death_data.queue_duration_sample);
937
938 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name);
939
940 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
941 }
942
440 // We will deactivate tracking after the birth, and before the death, and 943 // We will deactivate tracking after the birth, and before the death, and
441 // demonstrate that the lifecycle is completely tallied. This ensures that 944 // demonstrate that the lifecycle is completely tallied. This ensures that
442 // our tallied births are matched by tallied deaths (except for when the 945 // our tallied births are matched by tallied deaths (except for when the
443 // task is still running, or is queued). 946 // task is still running, or is queued).
444 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { 947 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) {
445 if (!ThreadData::InitializeAndSetTrackingStatus( 948 if (!ThreadData::InitializeAndSetTrackingStatus(
446 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 949 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
950 // Don't run the test if task tracking is not compiled in.
447 return; 951 return;
448 } 952 }
449 953
450 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; 954 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread";
451 Location location(kFunction, kFile, kLineNumber, NULL); 955 Location location(kFunction, kFile, kLineNumber, NULL);
452 TallyABirth(location, kMainThreadName); 956 TallyABirth(location, kMainThreadName);
453 957
454 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 958 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
455 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 959 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
456 // TrackingInfo will call TallyABirth() during construction. 960 // TrackingInfo will call TallyABirth() during construction.
457 base::TrackingInfo pending_task(location, kDelayedStartTime); 961 base::TrackingInfo pending_task(location, kDelayedStartTime);
458 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 962 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
459 963
460 // Turn off tracking now that we have births. 964 // Turn off tracking now that we have births.
461 EXPECT_TRUE( 965 EXPECT_TRUE(
462 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)); 966 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED));
463 967
464 const unsigned int kStartOfRun = 5; 968 const unsigned int kStartOfRun = 5;
465 const unsigned int kEndOfRun = 7; 969 const unsigned int kEndOfRun = 7;
466 SetTestTime(kStartOfRun); 970 SetTestTime(kStartOfRun);
467 TaskStopwatch stopwatch; 971 TaskStopwatch stopwatch;
468 stopwatch.Start(); 972 stopwatch.Start();
469 SetTestTime(kEndOfRun); 973 SetTestTime(kEndOfRun);
470 stopwatch.Stop(); 974 stopwatch.Stop();
471 975
472 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 976 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
473 977
474 ProcessDataSnapshot process_data; 978 ProcessDataSnapshot process_data;
475 ThreadData::Snapshot(&process_data); 979 ThreadData::Snapshot(0, &process_data);
476 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 980 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
477 kMainThreadName, 1, 2, 4); 981 kMainThreadName, 1, 2, 4);
478 } 982 }
479 983
480 // We will deactivate tracking before starting a life cycle, and neither 984 // We will deactivate tracking before starting a life cycle, and neither
481 // the birth nor the death will be recorded. 985 // the birth nor the death will be recorded.
482 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { 986 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) {
483 // Start in the deactivated state. 987 // Start in the deactivated state.
484 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 988 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
989 // Don't run the test if task tracking is not compiled in.
485 return; 990 return;
486 } 991 }
487 992
488 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; 993 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread";
489 Location location(kFunction, kFile, kLineNumber, NULL); 994 Location location(kFunction, kFile, kLineNumber, NULL);
490 TallyABirth(location, kMainThreadName); 995 TallyABirth(location, kMainThreadName);
491 996
492 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 997 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
493 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 998 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
494 // TrackingInfo will call TallyABirth() during construction. 999 // TrackingInfo will call TallyABirth() during construction.
495 base::TrackingInfo pending_task(location, kDelayedStartTime); 1000 base::TrackingInfo pending_task(location, kDelayedStartTime);
496 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 1001 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
497 1002
498 const unsigned int kStartOfRun = 5; 1003 const unsigned int kStartOfRun = 5;
499 const unsigned int kEndOfRun = 7; 1004 const unsigned int kEndOfRun = 7;
500 SetTestTime(kStartOfRun); 1005 SetTestTime(kStartOfRun);
501 TaskStopwatch stopwatch; 1006 TaskStopwatch stopwatch;
502 stopwatch.Start(); 1007 stopwatch.Start();
503 SetTestTime(kEndOfRun); 1008 SetTestTime(kEndOfRun);
504 stopwatch.Stop(); 1009 stopwatch.Stop();
505 1010
506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 1011 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
507 1012
508 ProcessDataSnapshot process_data; 1013 ProcessDataSnapshot process_data;
509 ThreadData::Snapshot(&process_data); 1014 ThreadData::Snapshot(0, &process_data);
510 1015
511 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 1016 ASSERT_EQ(1u, process_data.phased_snapshots.size());
512 auto it = process_data.phased_process_data_snapshots.find(0); 1017
513 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 1018 auto it = process_data.phased_snapshots.find(0);
1019 ASSERT_TRUE(it != process_data.phased_snapshots.end());
514 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 1020 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
515 1021
516 EXPECT_EQ(0u, process_data_phase.tasks.size()); 1022 ASSERT_EQ(0u, process_data_phase.tasks.size());
517 EXPECT_EQ(0u, process_data_phase.descendants.size()); 1023
518 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 1024 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
519 } 1025 }
520 1026
521 TEST_F(TrackedObjectsTest, TwoLives) { 1027 TEST_F(TrackedObjectsTest, TwoLives) {
522 if (!ThreadData::InitializeAndSetTrackingStatus( 1028 if (!ThreadData::InitializeAndSetTrackingStatus(
523 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 1029 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
1030 // Don't run the test if task tracking is not compiled in.
524 return; 1031 return;
525 } 1032 }
526 1033
527 const char kFunction[] = "TwoLives"; 1034 const char kFunction[] = "TwoLives";
528 Location location(kFunction, kFile, kLineNumber, NULL); 1035 Location location(kFunction, kFile, kLineNumber, NULL);
529 TallyABirth(location, kMainThreadName); 1036 TallyABirth(location, kMainThreadName);
530 1037
531 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1038 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
532 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1039 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
533 // TrackingInfo will call TallyABirth() during construction. 1040 // TrackingInfo will call TallyABirth() during construction.
(...skipping 15 matching lines...) Expand all
549 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 1056 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
550 SetTestTime(kStartOfRun); 1057 SetTestTime(kStartOfRun);
551 TaskStopwatch stopwatch2; 1058 TaskStopwatch stopwatch2;
552 stopwatch2.Start(); 1059 stopwatch2.Start();
553 SetTestTime(kEndOfRun); 1060 SetTestTime(kEndOfRun);
554 stopwatch2.Stop(); 1061 stopwatch2.Stop();
555 1062
556 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); 1063 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2);
557 1064
558 ProcessDataSnapshot process_data; 1065 ProcessDataSnapshot process_data;
559 ThreadData::Snapshot(&process_data); 1066 ThreadData::Snapshot(0, &process_data);
560 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 1067 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
561 kMainThreadName, 2, 2, 4); 1068 kMainThreadName, 2, 2, 4);
562 } 1069 }
563 1070
564 TEST_F(TrackedObjectsTest, DifferentLives) { 1071 TEST_F(TrackedObjectsTest, DifferentLives) {
565 if (!ThreadData::InitializeAndSetTrackingStatus( 1072 if (!ThreadData::InitializeAndSetTrackingStatus(
566 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 1073 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
1074 // Don't run the test if task tracking is not compiled in.
567 return; 1075 return;
568 } 1076 }
569 1077
570 // Use a well named thread. 1078 // Use a well named thread.
571 ThreadData::InitializeThreadContext(kMainThreadName); 1079 ThreadData::InitializeThreadContext(kMainThreadName);
572 const char kFunction[] = "DifferentLives"; 1080 const char kFunction[] = "DifferentLives";
573 Location location(kFunction, kFile, kLineNumber, NULL); 1081 Location location(kFunction, kFile, kLineNumber, NULL);
574 1082
575 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1083 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
576 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1084 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
(...skipping 12 matching lines...) Expand all
589 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 1097 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
590 1098
591 const int kSecondFakeLineNumber = 999; 1099 const int kSecondFakeLineNumber = 999;
592 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); 1100 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
593 1101
594 // TrackingInfo will call TallyABirth() during construction. 1102 // TrackingInfo will call TallyABirth() during construction.
595 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); 1103 base::TrackingInfo pending_task2(second_location, kDelayedStartTime);
596 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 1104 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
597 1105
598 ProcessDataSnapshot process_data; 1106 ProcessDataSnapshot process_data;
599 ThreadData::Snapshot(&process_data); 1107 ThreadData::Snapshot(0, &process_data);
600 1108
601 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 1109 ASSERT_EQ(1u, process_data.phased_snapshots.size());
602 auto it = process_data.phased_process_data_snapshots.find(0); 1110 auto it = process_data.phased_snapshots.find(0);
603 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 1111 ASSERT_TRUE(it != process_data.phased_snapshots.end());
604 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 1112 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
605 1113
606 ASSERT_EQ(2u, process_data_phase.tasks.size()); 1114 ASSERT_EQ(2u, process_data_phase.tasks.size());
607 1115
608 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); 1116 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name);
609 EXPECT_EQ(kFunction, 1117 EXPECT_EQ(kFunction,
610 process_data_phase.tasks[0].birth.location.function_name); 1118 process_data_phase.tasks[0].birth.location.function_name);
611 EXPECT_EQ(kLineNumber, 1119 EXPECT_EQ(kLineNumber,
612 process_data_phase.tasks[0].birth.location.line_number); 1120 process_data_phase.tasks[0].birth.location.line_number);
613 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[0].birth.thread_name); 1121 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[0].birth.thread_name);
(...skipping 19 matching lines...) Expand all
633 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); 1141 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); 1142 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); 1143 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name);
636 EXPECT_EQ(0u, process_data_phase.descendants.size()); 1144 EXPECT_EQ(0u, process_data_phase.descendants.size());
637 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 1145 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
638 } 1146 }
639 1147
640 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { 1148 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) {
641 if (!ThreadData::InitializeAndSetTrackingStatus( 1149 if (!ThreadData::InitializeAndSetTrackingStatus(
642 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 1150 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
1151 // Don't run the test if task tracking is not compiled in.
643 return; 1152 return;
644 } 1153 }
645 1154
646 const char kFunction[] = "TaskWithNestedExclusion"; 1155 const char kFunction[] = "TaskWithNestedExclusion";
647 Location location(kFunction, kFile, kLineNumber, NULL); 1156 Location location(kFunction, kFile, kLineNumber, NULL);
648 TallyABirth(location, kMainThreadName); 1157 TallyABirth(location, kMainThreadName);
649 1158
650 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1159 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
651 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1160 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
652 // TrackingInfo will call TallyABirth() during construction. 1161 // TrackingInfo will call TallyABirth() during construction.
653 base::TrackingInfo pending_task(location, kDelayedStartTime); 1162 base::TrackingInfo pending_task(location, kDelayedStartTime);
654 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 1163 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
655 1164
656 SetTestTime(5); 1165 SetTestTime(5);
657 TaskStopwatch task_stopwatch; 1166 TaskStopwatch task_stopwatch;
658 task_stopwatch.Start(); 1167 task_stopwatch.Start();
659 { 1168 {
660 SetTestTime(8); 1169 SetTestTime(8);
661 TaskStopwatch exclusion_stopwatch; 1170 TaskStopwatch exclusion_stopwatch;
662 exclusion_stopwatch.Start(); 1171 exclusion_stopwatch.Start();
663 SetTestTime(12); 1172 SetTestTime(12);
664 exclusion_stopwatch.Stop(); 1173 exclusion_stopwatch.Stop();
665 } 1174 }
666 SetTestTime(15); 1175 SetTestTime(15);
667 task_stopwatch.Stop(); 1176 task_stopwatch.Stop();
668 1177
669 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 1178 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
670 1179
671 ProcessDataSnapshot process_data; 1180 ProcessDataSnapshot process_data;
672 ThreadData::Snapshot(&process_data); 1181 ThreadData::Snapshot(0, &process_data);
673 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 1182 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
674 kMainThreadName, 1, 6, 4); 1183 kMainThreadName, 1, 6, 4);
675 } 1184 }
676 1185
677 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { 1186 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) {
678 if (!ThreadData::InitializeAndSetTrackingStatus( 1187 if (!ThreadData::InitializeAndSetTrackingStatus(
679 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 1188 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
1189 // Don't run the test if task tracking is not compiled in.
680 return; 1190 return;
681 } 1191 }
682 1192
683 const char kFunction[] = "TaskWith2NestedExclusions"; 1193 const char kFunction[] = "TaskWith2NestedExclusions";
684 Location location(kFunction, kFile, kLineNumber, NULL); 1194 Location location(kFunction, kFile, kLineNumber, NULL);
685 TallyABirth(location, kMainThreadName); 1195 TallyABirth(location, kMainThreadName);
686 1196
687 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1197 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
688 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1198 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
689 // TrackingInfo will call TallyABirth() during construction. 1199 // TrackingInfo will call TallyABirth() during construction.
(...skipping 15 matching lines...) Expand all
705 exclusion_stopwatch2.Start(); 1215 exclusion_stopwatch2.Start();
706 SetTestTime(18); 1216 SetTestTime(18);
707 exclusion_stopwatch2.Stop(); 1217 exclusion_stopwatch2.Stop();
708 } 1218 }
709 SetTestTime(25); 1219 SetTestTime(25);
710 task_stopwatch.Stop(); 1220 task_stopwatch.Stop();
711 1221
712 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 1222 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
713 1223
714 ProcessDataSnapshot process_data; 1224 ProcessDataSnapshot process_data;
715 ThreadData::Snapshot(&process_data); 1225 ThreadData::Snapshot(0, &process_data);
716 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 1226 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
717 kMainThreadName, 1, 13, 4); 1227 kMainThreadName, 1, 13, 4);
718 } 1228 }
719 1229
720 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { 1230 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
721 if (!ThreadData::InitializeAndSetTrackingStatus( 1231 if (!ThreadData::InitializeAndSetTrackingStatus(
722 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 1232 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
1233 // Don't run the test if task tracking is not compiled in.
723 return; 1234 return;
724 } 1235 }
725 1236
726 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; 1237 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask";
727 Location location(kFunction, kFile, kLineNumber, NULL); 1238 Location location(kFunction, kFile, kLineNumber, NULL);
728 1239
729 const int kSecondFakeLineNumber = 999; 1240 const int kSecondFakeLineNumber = 999;
730 1241
731 TallyABirth(location, kMainThreadName); 1242 TallyABirth(location, kMainThreadName);
732 1243
(...skipping 25 matching lines...) Expand all
758 } 1269 }
759 SetTestTime(12); 1270 SetTestTime(12);
760 exclusion_stopwatch.Stop(); 1271 exclusion_stopwatch.Stop();
761 } 1272 }
762 SetTestTime(15); 1273 SetTestTime(15);
763 task_stopwatch.Stop(); 1274 task_stopwatch.Stop();
764 1275
765 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 1276 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
766 1277
767 ProcessDataSnapshot process_data; 1278 ProcessDataSnapshot process_data;
768 ThreadData::Snapshot(&process_data); 1279 ThreadData::Snapshot(0, &process_data);
769 1280
770 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); 1281 ASSERT_EQ(1u, process_data.phased_snapshots.size());
771 auto it = process_data.phased_process_data_snapshots.find(0); 1282 auto it = process_data.phased_snapshots.find(0);
772 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); 1283 ASSERT_TRUE(it != process_data.phased_snapshots.end());
773 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 1284 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
774 1285
775 // The order in which the two task follow is platform-dependent. 1286 // The order in which the two task follow is platform-dependent.
776 int t0 = 1287 int t0 =
777 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) 1288 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber)
778 ? 0 1289 ? 0
779 : 1; 1290 : 1;
780 int t1 = 1 - t0; 1291 int t1 = 1 - t0;
781 1292
782 ASSERT_EQ(2u, process_data_phase.tasks.size()); 1293 ASSERT_EQ(2u, process_data_phase.tasks.size());
(...skipping 23 matching lines...) Expand all
806 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); 1317 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); 1318 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); 1319 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); 1320 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); 1321 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name);
811 EXPECT_EQ(0u, process_data_phase.descendants.size()); 1322 EXPECT_EQ(0u, process_data_phase.descendants.size());
812 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 1323 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
813 } 1324 }
814 1325
815 } // namespace tracked_objects 1326 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698