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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 445413003: Creating a framework for suppressing pollution of the profiler data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clarifying terminology Created 6 years, 3 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 | Annotate | Revision Log
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 EXPECT_EQ(0u, process_data.descendants.size()); 90 EXPECT_EQ(0u, process_data.descendants.size());
91 91
92 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 92 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
93 } 93 }
94 }; 94 };
95 95
96 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { 96 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) {
97 // Minimal test doesn't even create any tasks. 97 // Minimal test doesn't even create any tasks.
98 if (!ThreadData::InitializeAndSetTrackingStatus( 98 if (!ThreadData::InitializeAndSetTrackingStatus(
99 ThreadData::PROFILING_CHILDREN_ACTIVE)) 99 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
100 return; 100 return;
101 }
101 102
102 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 103 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
103 ThreadData* data = ThreadData::Get(); 104 ThreadData* data = ThreadData::Get();
104 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 105 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
105 ASSERT_TRUE(data); 106 ASSERT_TRUE(data);
106 EXPECT_FALSE(data->next()); 107 EXPECT_FALSE(data->next());
107 EXPECT_EQ(data, ThreadData::Get()); 108 EXPECT_EQ(data, ThreadData::Get());
108 ThreadData::BirthMap birth_map; 109 ThreadData::BirthMap birth_map;
109 ThreadData::DeathMap death_map; 110 ThreadData::DeathMap death_map;
110 ThreadData::ParentChildSet parent_child_set; 111 ThreadData::ParentChildSet parent_child_set;
(...skipping 18 matching lines...) Expand all
129 death_map.clear(); 130 death_map.clear();
130 parent_child_set.clear(); 131 parent_child_set.clear();
131 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 132 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
132 EXPECT_EQ(0u, birth_map.size()); 133 EXPECT_EQ(0u, birth_map.size());
133 EXPECT_EQ(0u, death_map.size()); 134 EXPECT_EQ(0u, death_map.size());
134 EXPECT_EQ(0u, parent_child_set.size()); 135 EXPECT_EQ(0u, parent_child_set.size());
135 } 136 }
136 137
137 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { 138 TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
138 if (!ThreadData::InitializeAndSetTrackingStatus( 139 if (!ThreadData::InitializeAndSetTrackingStatus(
139 ThreadData::PROFILING_CHILDREN_ACTIVE)) 140 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
140 return; 141 return;
142 }
141 143
142 // Instigate tracking on a single tracked object, on our thread. 144 // Instigate tracking on a single tracked object, on our thread.
143 const char kFunction[] = "TinyStartupShutdown"; 145 const char kFunction[] = "TinyStartupShutdown";
144 Location location(kFunction, kFile, kLineNumber, NULL); 146 Location location(kFunction, kFile, kLineNumber, NULL);
145 Births* first_birth = ThreadData::TallyABirthIfActive(location); 147 Births* first_birth = ThreadData::TallyABirthIfActive(location);
146 148
147 ThreadData* data = ThreadData::first(); 149 ThreadData* data = ThreadData::first();
148 ASSERT_TRUE(data); 150 ASSERT_TRUE(data);
149 EXPECT_FALSE(data->next()); 151 EXPECT_FALSE(data->next());
150 EXPECT_EQ(data, ThreadData::Get()); 152 EXPECT_EQ(data, ThreadData::Get());
(...skipping 10 matching lines...) Expand all
161 // Now instigate another birth, while we are timing the run of the first 163 // Now instigate another birth, while we are timing the run of the first
162 // execution. 164 // execution.
163 ThreadData::NowForStartOfRun(first_birth); 165 ThreadData::NowForStartOfRun(first_birth);
164 // Create a child (using the same birth location). 166 // Create a child (using the same birth location).
165 // TrackingInfo will call TallyABirth() during construction. 167 // TrackingInfo will call TallyABirth() during construction.
166 base::TimeTicks kBogusBirthTime; 168 base::TimeTicks kBogusBirthTime;
167 base::TrackingInfo pending_task(location, kBogusBirthTime); 169 base::TrackingInfo pending_task(location, kBogusBirthTime);
168 TrackedTime start_time(pending_task.time_posted); 170 TrackedTime start_time(pending_task.time_posted);
169 // Finally conclude the outer run. 171 // Finally conclude the outer run.
170 TrackedTime end_time = ThreadData::NowForEndOfRun(); 172 TrackedTime end_time = ThreadData::NowForEndOfRun();
171 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, start_time, 173 TaskStopwatch stopwatch;
172 end_time); 174 stopwatch.Start(start_time);
175 stopwatch.Stop(end_time);
176
177 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
173 178
174 birth_map.clear(); 179 birth_map.clear();
175 death_map.clear(); 180 death_map.clear();
176 parent_child_set.clear(); 181 parent_child_set.clear();
177 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 182 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
178 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 183 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
179 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. 184 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
180 EXPECT_EQ(1u, death_map.size()); // 1 location. 185 EXPECT_EQ(1u, death_map.size()); // 1 location.
181 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. 186 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death.
182 if (ThreadData::TrackingParentChildStatus()) { 187 if (ThreadData::TrackingParentChildStatus()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EXPECT_EQ(kLineNumber, 228 EXPECT_EQ(kLineNumber,
224 process_data.descendants[0].child.location.line_number); 229 process_data.descendants[0].child.location.line_number);
225 EXPECT_EQ(kWorkerThreadName, process_data.descendants[0].child.thread_name); 230 EXPECT_EQ(kWorkerThreadName, process_data.descendants[0].child.thread_name);
226 } else { 231 } else {
227 EXPECT_EQ(0u, process_data.descendants.size()); 232 EXPECT_EQ(0u, process_data.descendants.size());
228 } 233 }
229 } 234 }
230 235
231 TEST_F(TrackedObjectsTest, DeathDataTest) { 236 TEST_F(TrackedObjectsTest, DeathDataTest) {
232 if (!ThreadData::InitializeAndSetTrackingStatus( 237 if (!ThreadData::InitializeAndSetTrackingStatus(
233 ThreadData::PROFILING_CHILDREN_ACTIVE)) 238 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
234 return; 239 return;
240 }
235 241
236 scoped_ptr<DeathData> data(new DeathData()); 242 scoped_ptr<DeathData> data(new DeathData());
237 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); 243 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL));
238 EXPECT_EQ(data->run_duration_sum(), 0); 244 EXPECT_EQ(data->run_duration_sum(), 0);
239 EXPECT_EQ(data->run_duration_sample(), 0); 245 EXPECT_EQ(data->run_duration_sample(), 0);
240 EXPECT_EQ(data->queue_duration_sum(), 0); 246 EXPECT_EQ(data->queue_duration_sum(), 0);
241 EXPECT_EQ(data->queue_duration_sample(), 0); 247 EXPECT_EQ(data->queue_duration_sample(), 0);
242 EXPECT_EQ(data->count(), 0); 248 EXPECT_EQ(data->count(), 0);
243 249
244 int32 run_ms = 42; 250 int32 run_ms = 42;
(...skipping 19 matching lines...) Expand all
264 EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum); 270 EXPECT_EQ(2 * run_ms, snapshot.run_duration_sum);
265 EXPECT_EQ(run_ms, snapshot.run_duration_max); 271 EXPECT_EQ(run_ms, snapshot.run_duration_max);
266 EXPECT_EQ(run_ms, snapshot.run_duration_sample); 272 EXPECT_EQ(run_ms, snapshot.run_duration_sample);
267 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); 273 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum);
268 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); 274 EXPECT_EQ(queue_ms, snapshot.queue_duration_max);
269 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); 275 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample);
270 } 276 }
271 277
272 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { 278 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) {
273 // Start in the deactivated state. 279 // Start in the deactivated state.
274 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) 280 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
275 return; 281 return;
282 }
276 283
277 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; 284 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread";
278 Location location(kFunction, kFile, kLineNumber, NULL); 285 Location location(kFunction, kFile, kLineNumber, NULL);
279 TallyABirth(location, std::string()); 286 TallyABirth(location, std::string());
280 287
281 ProcessDataSnapshot process_data; 288 ProcessDataSnapshot process_data;
282 ThreadData::Snapshot(false, &process_data); 289 ThreadData::Snapshot(false, &process_data);
283 EXPECT_EQ(0u, process_data.tasks.size()); 290 EXPECT_EQ(0u, process_data.tasks.size());
284 EXPECT_EQ(0u, process_data.descendants.size()); 291 EXPECT_EQ(0u, process_data.descendants.size());
285 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 292 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
286 } 293 }
287 294
288 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { 295 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) {
289 // Start in the deactivated state. 296 // Start in the deactivated state.
290 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) 297 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
291 return; 298 return;
299 }
292 300
293 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; 301 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread";
294 Location location(kFunction, kFile, kLineNumber, NULL); 302 Location location(kFunction, kFile, kLineNumber, NULL);
295 TallyABirth(location, kMainThreadName); 303 TallyABirth(location, kMainThreadName);
296 304
297 ProcessDataSnapshot process_data; 305 ProcessDataSnapshot process_data;
298 ThreadData::Snapshot(false, &process_data); 306 ThreadData::Snapshot(false, &process_data);
299 EXPECT_EQ(0u, process_data.tasks.size()); 307 EXPECT_EQ(0u, process_data.tasks.size());
300 EXPECT_EQ(0u, process_data.descendants.size()); 308 EXPECT_EQ(0u, process_data.descendants.size());
301 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 309 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
302 } 310 }
303 311
304 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { 312 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) {
305 if (!ThreadData::InitializeAndSetTrackingStatus( 313 if (!ThreadData::InitializeAndSetTrackingStatus(
306 ThreadData::PROFILING_CHILDREN_ACTIVE)) 314 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
307 return; 315 return;
316 }
308 317
309 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; 318 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread";
310 Location location(kFunction, kFile, kLineNumber, NULL); 319 Location location(kFunction, kFile, kLineNumber, NULL);
311 TallyABirth(location, std::string()); 320 TallyABirth(location, std::string());
312 321
313 ProcessDataSnapshot process_data; 322 ProcessDataSnapshot process_data;
314 ThreadData::Snapshot(false, &process_data); 323 ThreadData::Snapshot(false, &process_data);
315 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 324 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
316 kStillAlive, 1, 0, 0); 325 kStillAlive, 1, 0, 0);
317 } 326 }
318 327
319 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { 328 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) {
320 if (!ThreadData::InitializeAndSetTrackingStatus( 329 if (!ThreadData::InitializeAndSetTrackingStatus(
321 ThreadData::PROFILING_CHILDREN_ACTIVE)) 330 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
322 return; 331 return;
332 }
323 333
324 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; 334 const char kFunction[] = "BirthOnlyToSnapshotMainThread";
325 Location location(kFunction, kFile, kLineNumber, NULL); 335 Location location(kFunction, kFile, kLineNumber, NULL);
326 TallyABirth(location, kMainThreadName); 336 TallyABirth(location, kMainThreadName);
327 337
328 ProcessDataSnapshot process_data; 338 ProcessDataSnapshot process_data;
329 ThreadData::Snapshot(false, &process_data); 339 ThreadData::Snapshot(false, &process_data);
330 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, 340 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive,
331 1, 0, 0); 341 1, 0, 0);
332 } 342 }
333 343
334 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { 344 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) {
335 if (!ThreadData::InitializeAndSetTrackingStatus( 345 if (!ThreadData::InitializeAndSetTrackingStatus(
336 ThreadData::PROFILING_CHILDREN_ACTIVE)) 346 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
337 return; 347 return;
348 }
338 349
339 const char kFunction[] = "LifeCycleToSnapshotMainThread"; 350 const char kFunction[] = "LifeCycleToSnapshotMainThread";
340 Location location(kFunction, kFile, kLineNumber, NULL); 351 Location location(kFunction, kFile, kLineNumber, NULL);
341 TallyABirth(location, kMainThreadName); 352 TallyABirth(location, kMainThreadName);
342 353
343 const base::TimeTicks kTimePosted = base::TimeTicks() + 354 const base::TimeTicks kTimePosted = base::TimeTicks() +
344 base::TimeDelta::FromMilliseconds(1); 355 base::TimeDelta::FromMilliseconds(1);
345 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 356 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
346 // TrackingInfo will call TallyABirth() during construction. 357 // TrackingInfo will call TallyABirth() during construction.
347 base::TrackingInfo pending_task(location, kDelayedStartTime); 358 base::TrackingInfo pending_task(location, kDelayedStartTime);
348 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 359 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
349 360
350 const TrackedTime kStartOfRun = TrackedTime() + 361 const TrackedTime kStartOfRun = TrackedTime() +
351 Duration::FromMilliseconds(5); 362 Duration::FromMilliseconds(5);
352 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 363 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
353 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 364 TaskStopwatch stopwatch;
354 kStartOfRun, kEndOfRun); 365 stopwatch.Start(kStartOfRun);
366 stopwatch.Stop(kEndOfRun);
367
368 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
355 369
356 ProcessDataSnapshot process_data; 370 ProcessDataSnapshot process_data;
357 ThreadData::Snapshot(false, &process_data); 371 ThreadData::Snapshot(false, &process_data);
358 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 372 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
359 kMainThreadName, 1, 2, 4); 373 kMainThreadName, 1, 2, 4);
360 } 374 }
361 375
362 // We will deactivate tracking after the birth, and before the death, and 376 // We will deactivate tracking after the birth, and before the death, and
363 // demonstrate that the lifecycle is completely tallied. This ensures that 377 // demonstrate that the lifecycle is completely tallied. This ensures that
364 // our tallied births are matched by tallied deaths (except for when the 378 // our tallied births are matched by tallied deaths (except for when the
365 // task is still running, or is queued). 379 // task is still running, or is queued).
366 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { 380 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) {
367 if (!ThreadData::InitializeAndSetTrackingStatus( 381 if (!ThreadData::InitializeAndSetTrackingStatus(
368 ThreadData::PROFILING_CHILDREN_ACTIVE)) 382 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
369 return; 383 return;
384 }
370 385
371 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; 386 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread";
372 Location location(kFunction, kFile, kLineNumber, NULL); 387 Location location(kFunction, kFile, kLineNumber, NULL);
373 TallyABirth(location, kMainThreadName); 388 TallyABirth(location, kMainThreadName);
374 389
375 const base::TimeTicks kTimePosted = base::TimeTicks() + 390 const base::TimeTicks kTimePosted = base::TimeTicks() +
376 base::TimeDelta::FromMilliseconds(1); 391 base::TimeDelta::FromMilliseconds(1);
377 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 392 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
378 // TrackingInfo will call TallyABirth() during construction. 393 // TrackingInfo will call TallyABirth() during construction.
379 base::TrackingInfo pending_task(location, kDelayedStartTime); 394 base::TrackingInfo pending_task(location, kDelayedStartTime);
380 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 395 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
381 396
382 // Turn off tracking now that we have births. 397 // Turn off tracking now that we have births.
383 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( 398 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus(
384 ThreadData::DEACTIVATED)); 399 ThreadData::DEACTIVATED));
385 400
386 const TrackedTime kStartOfRun = TrackedTime() + 401 const TrackedTime kStartOfRun = TrackedTime() +
387 Duration::FromMilliseconds(5); 402 Duration::FromMilliseconds(5);
388 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 403 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
389 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 404 TaskStopwatch stopwatch;
390 kStartOfRun, kEndOfRun); 405 stopwatch.Start(kStartOfRun);
406 stopwatch.Stop(kEndOfRun);
407
408 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
391 409
392 ProcessDataSnapshot process_data; 410 ProcessDataSnapshot process_data;
393 ThreadData::Snapshot(false, &process_data); 411 ThreadData::Snapshot(false, &process_data);
394 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 412 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
395 kMainThreadName, 1, 2, 4); 413 kMainThreadName, 1, 2, 4);
396 } 414 }
397 415
398 // We will deactivate tracking before starting a life cycle, and neither 416 // We will deactivate tracking before starting a life cycle, and neither
399 // the birth nor the death will be recorded. 417 // the birth nor the death will be recorded.
400 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { 418 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) {
401 // Start in the deactivated state. 419 // Start in the deactivated state.
402 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) 420 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
403 return; 421 return;
422 }
404 423
405 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; 424 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread";
406 Location location(kFunction, kFile, kLineNumber, NULL); 425 Location location(kFunction, kFile, kLineNumber, NULL);
407 TallyABirth(location, kMainThreadName); 426 TallyABirth(location, kMainThreadName);
408 427
409 const base::TimeTicks kTimePosted = base::TimeTicks() + 428 const base::TimeTicks kTimePosted = base::TimeTicks() +
410 base::TimeDelta::FromMilliseconds(1); 429 base::TimeDelta::FromMilliseconds(1);
411 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 430 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
412 // TrackingInfo will call TallyABirth() during construction. 431 // TrackingInfo will call TallyABirth() during construction.
413 base::TrackingInfo pending_task(location, kDelayedStartTime); 432 base::TrackingInfo pending_task(location, kDelayedStartTime);
414 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 433 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
415 434
416 const TrackedTime kStartOfRun = TrackedTime() + 435 const TrackedTime kStartOfRun = TrackedTime() +
417 Duration::FromMilliseconds(5); 436 Duration::FromMilliseconds(5);
418 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 437 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
419 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 438 TaskStopwatch stopwatch;
420 kStartOfRun, kEndOfRun); 439 stopwatch.Start(kStartOfRun);
440 stopwatch.Stop(kEndOfRun);
441
442 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
421 443
422 ProcessDataSnapshot process_data; 444 ProcessDataSnapshot process_data;
423 ThreadData::Snapshot(false, &process_data); 445 ThreadData::Snapshot(false, &process_data);
424 EXPECT_EQ(0u, process_data.tasks.size()); 446 EXPECT_EQ(0u, process_data.tasks.size());
425 EXPECT_EQ(0u, process_data.descendants.size()); 447 EXPECT_EQ(0u, process_data.descendants.size());
426 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 448 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
427 } 449 }
428 450
429 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) { 451 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) {
430 if (!ThreadData::InitializeAndSetTrackingStatus( 452 if (!ThreadData::InitializeAndSetTrackingStatus(
431 ThreadData::PROFILING_CHILDREN_ACTIVE)) 453 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
432 return; 454 return;
455 }
433 456
434 const char kFunction[] = "LifeCycleToSnapshotWorkerThread"; 457 const char kFunction[] = "LifeCycleToSnapshotWorkerThread";
435 Location location(kFunction, kFile, kLineNumber, NULL); 458 Location location(kFunction, kFile, kLineNumber, NULL);
436 // Do not delete |birth|. We don't own it. 459 // Do not delete |birth|. We don't own it.
437 Births* birth = ThreadData::TallyABirthIfActive(location); 460 Births* birth = ThreadData::TallyABirthIfActive(location);
438 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth); 461 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth);
439 462
440 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); 463 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1);
441 const TrackedTime kStartOfRun = TrackedTime() + 464 const TrackedTime kStartOfRun = TrackedTime() +
442 Duration::FromMilliseconds(5); 465 Duration::FromMilliseconds(5);
443 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 466 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
444 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, 467 TaskStopwatch stopwatch;
445 kStartOfRun, kEndOfRun); 468 stopwatch.Start(kStartOfRun);
469 stopwatch.Stop(kEndOfRun);
470
471 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, stopwatch);
446 472
447 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning. 473 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning.
448 ProcessDataSnapshot process_data; 474 ProcessDataSnapshot process_data;
449 ThreadData::Snapshot(false, &process_data); 475 ThreadData::Snapshot(false, &process_data);
450 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 476 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
451 kWorkerThreadName, 1, 2, 4); 477 kWorkerThreadName, 1, 2, 4);
452 478
453 // Call for the ToSnapshot, but tell it to reset the maxes after scanning. 479 // Call for the ToSnapshot, but tell it to reset the maxes after scanning.
454 // We'll still get the same values, but the data will be reset (which we'll 480 // We'll still get the same values, but the data will be reset (which we'll
455 // see in a moment). 481 // see in a moment).
(...skipping 23 matching lines...) Expand all
479 EXPECT_EQ(4, 505 EXPECT_EQ(4,
480 process_data_post_reset.tasks[0].death_data.queue_duration_sample); 506 process_data_post_reset.tasks[0].death_data.queue_duration_sample);
481 EXPECT_EQ(kWorkerThreadName, 507 EXPECT_EQ(kWorkerThreadName,
482 process_data_post_reset.tasks[0].death_thread_name); 508 process_data_post_reset.tasks[0].death_thread_name);
483 EXPECT_EQ(0u, process_data_post_reset.descendants.size()); 509 EXPECT_EQ(0u, process_data_post_reset.descendants.size());
484 EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id); 510 EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id);
485 } 511 }
486 512
487 TEST_F(TrackedObjectsTest, TwoLives) { 513 TEST_F(TrackedObjectsTest, TwoLives) {
488 if (!ThreadData::InitializeAndSetTrackingStatus( 514 if (!ThreadData::InitializeAndSetTrackingStatus(
489 ThreadData::PROFILING_CHILDREN_ACTIVE)) 515 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
490 return; 516 return;
517 }
491 518
492 const char kFunction[] = "TwoLives"; 519 const char kFunction[] = "TwoLives";
493 Location location(kFunction, kFile, kLineNumber, NULL); 520 Location location(kFunction, kFile, kLineNumber, NULL);
494 TallyABirth(location, kMainThreadName); 521 TallyABirth(location, kMainThreadName);
495 522
496 const base::TimeTicks kTimePosted = base::TimeTicks() + 523 const base::TimeTicks kTimePosted = base::TimeTicks() +
497 base::TimeDelta::FromMilliseconds(1); 524 base::TimeDelta::FromMilliseconds(1);
498 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 525 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
499 // TrackingInfo will call TallyABirth() during construction. 526 // TrackingInfo will call TallyABirth() during construction.
500 base::TrackingInfo pending_task(location, kDelayedStartTime); 527 base::TrackingInfo pending_task(location, kDelayedStartTime);
501 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 528 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
502 529
503 const TrackedTime kStartOfRun = TrackedTime() + 530 const TrackedTime kStartOfRun = TrackedTime() +
504 Duration::FromMilliseconds(5); 531 Duration::FromMilliseconds(5);
505 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 532 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 533 TaskStopwatch stopwatch;
507 kStartOfRun, kEndOfRun); 534 stopwatch.Start(kStartOfRun);
535 stopwatch.Stop(kEndOfRun);
536
537 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
508 538
509 // TrackingInfo will call TallyABirth() during construction. 539 // TrackingInfo will call TallyABirth() during construction.
510 base::TrackingInfo pending_task2(location, kDelayedStartTime); 540 base::TrackingInfo pending_task2(location, kDelayedStartTime);
511 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 541 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
542 stopwatch.Start(kStartOfRun);
543 stopwatch.Stop(kEndOfRun);
512 544
513 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, 545 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch);
514 kStartOfRun, kEndOfRun);
515 546
516 ProcessDataSnapshot process_data; 547 ProcessDataSnapshot process_data;
517 ThreadData::Snapshot(false, &process_data); 548 ThreadData::Snapshot(false, &process_data);
518 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 549 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
519 kMainThreadName, 2, 2, 4); 550 kMainThreadName, 2, 2, 4);
520 } 551 }
521 552
522 TEST_F(TrackedObjectsTest, DifferentLives) { 553 TEST_F(TrackedObjectsTest, DifferentLives) {
523 if (!ThreadData::InitializeAndSetTrackingStatus( 554 if (!ThreadData::InitializeAndSetTrackingStatus(
524 ThreadData::PROFILING_CHILDREN_ACTIVE)) 555 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
525 return; 556 return;
557 }
526 558
527 // Use a well named thread. 559 // Use a well named thread.
528 ThreadData::InitializeThreadContext(kMainThreadName); 560 ThreadData::InitializeThreadContext(kMainThreadName);
529 const char kFunction[] = "DifferentLives"; 561 const char kFunction[] = "DifferentLives";
530 Location location(kFunction, kFile, kLineNumber, NULL); 562 Location location(kFunction, kFile, kLineNumber, NULL);
531 563
532 const base::TimeTicks kTimePosted = base::TimeTicks() + 564 const base::TimeTicks kTimePosted = base::TimeTicks() +
533 base::TimeDelta::FromMilliseconds(1); 565 base::TimeDelta::FromMilliseconds(1);
534 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 566 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
535 // TrackingInfo will call TallyABirth() during construction. 567 // TrackingInfo will call TallyABirth() during construction.
536 base::TrackingInfo pending_task(location, kDelayedStartTime); 568 base::TrackingInfo pending_task(location, kDelayedStartTime);
537 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 569 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
538 570
539 const TrackedTime kStartOfRun = TrackedTime() + 571 const TrackedTime kStartOfRun = TrackedTime() +
540 Duration::FromMilliseconds(5); 572 Duration::FromMilliseconds(5);
541 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 573 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
542 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 574 TaskStopwatch stopwatch;
543 kStartOfRun, kEndOfRun); 575 stopwatch.Start(kStartOfRun);
576 stopwatch.Stop(kEndOfRun);
577
578 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
544 579
545 const int kSecondFakeLineNumber = 999; 580 const int kSecondFakeLineNumber = 999;
546 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); 581 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
547 582
548 // TrackingInfo will call TallyABirth() during construction. 583 // TrackingInfo will call TallyABirth() during construction.
549 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); 584 base::TrackingInfo pending_task2(second_location, kDelayedStartTime);
550 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 585 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
551 586
552 ProcessDataSnapshot process_data; 587 ProcessDataSnapshot process_data;
553 ThreadData::Snapshot(false, &process_data); 588 ThreadData::Snapshot(false, &process_data);
(...skipping 20 matching lines...) Expand all
574 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max); 609 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_max);
575 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sample); 610 EXPECT_EQ(0, process_data.tasks[1].death_data.run_duration_sample);
576 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sum); 611 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sum);
577 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_max); 612 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_max);
578 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample); 613 EXPECT_EQ(0, process_data.tasks[1].death_data.queue_duration_sample);
579 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name); 614 EXPECT_EQ(kStillAlive, process_data.tasks[1].death_thread_name);
580 EXPECT_EQ(0u, process_data.descendants.size()); 615 EXPECT_EQ(0u, process_data.descendants.size());
581 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 616 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
582 } 617 }
583 618
619 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) {
620 if (!ThreadData::InitializeAndSetTrackingStatus(
621 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
622 return;
623 }
624
625 const char kFunction[] = "TaskWithNestedExclusion";
626 Location location(kFunction, kFile, kLineNumber, NULL);
627 TallyABirth(location, kMainThreadName);
628
629 const base::TimeTicks kTimePosted = base::TimeTicks() +
630 base::TimeDelta::FromMilliseconds(1);
631 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
632 // TrackingInfo will call TallyABirth() during construction.
633 base::TrackingInfo pending_task(location, kDelayedStartTime);
634 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
635
636 const TrackedTime kStartOfRun = TrackedTime() +
637 Duration::FromMilliseconds(5);
638 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(15);
639 TaskStopwatch task_stopwatch;
640 task_stopwatch.Start(kStartOfRun);
641 {
642 TaskStopwatch exclusion_stopwatch;
643 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(8));
644 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(12));
645 }
646 task_stopwatch.Stop(kEndOfRun);
647
648 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
649
650 ProcessDataSnapshot process_data;
651 ThreadData::Snapshot(false, &process_data);
652 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
653 kMainThreadName, 1, 6, 4);
654 }
655
656 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) {
657 if (!ThreadData::InitializeAndSetTrackingStatus(
658 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
659 return;
660 }
661
662 const char kFunction[] = "TaskWith2NestedExclusions";
663 Location location(kFunction, kFile, kLineNumber, NULL);
664 TallyABirth(location, kMainThreadName);
665
666 const base::TimeTicks kTimePosted = base::TimeTicks() +
667 base::TimeDelta::FromMilliseconds(1);
668 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
669 // TrackingInfo will call TallyABirth() during construction.
670 base::TrackingInfo pending_task(location, kDelayedStartTime);
671 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
672
673 const TrackedTime kStartOfRun = TrackedTime() +
674 Duration::FromMilliseconds(5);
675 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(25);
676 TaskStopwatch task_stopwatch;
677 task_stopwatch.Start(kStartOfRun);
678 {
679 TaskStopwatch exclusion_stopwatch;
680 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(8));
681 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(12));
682
683 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(15));
684 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(18));
685 }
686 task_stopwatch.Stop(kEndOfRun);
687
688 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
689
690 ProcessDataSnapshot process_data;
691 ThreadData::Snapshot(false, &process_data);
692 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
693 kMainThreadName, 1, 13, 4);
694 }
695
696 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
697 if (!ThreadData::InitializeAndSetTrackingStatus(
698 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
699 return;
700 }
701
702 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask";
703 Location location(kFunction, kFile, kLineNumber, NULL);
704
705 const int kSecondFakeLineNumber = 999;
706
707 TallyABirth(location, kMainThreadName);
708
709 const base::TimeTicks kTimePosted = base::TimeTicks() +
710 base::TimeDelta::FromMilliseconds(1);
711 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
712 // TrackingInfo will call TallyABirth() during construction.
713 base::TrackingInfo pending_task(location, kDelayedStartTime);
714 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
715
716 const TrackedTime kStartOfRun = TrackedTime() +
717 Duration::FromMilliseconds(5);
718 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(15);
719 TaskStopwatch task_stopwatch;
720 task_stopwatch.Start(kStartOfRun);
721 {
722 TaskStopwatch exclusion_stopwatch;
723 exclusion_stopwatch.Start(TrackedTime() + Duration::FromMilliseconds(8));
724 {
725 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
726 base::TrackingInfo nested_task(second_location, kDelayedStartTime);
727 // Overwrite implied Now().
728 nested_task.time_posted =
729 base::TimeTicks() + base::TimeDelta::FromMilliseconds(8);
730 TaskStopwatch nested_task_stopwatch;
731 nested_task_stopwatch.Start(
732 TrackedTime() + Duration::FromMilliseconds(9));
733 nested_task_stopwatch.Stop(
734 TrackedTime() + Duration::FromMilliseconds(11));
735 ThreadData::TallyRunOnNamedThreadIfTracking(
736 nested_task, nested_task_stopwatch);
737 }
738 exclusion_stopwatch.Stop(TrackedTime() + Duration::FromMilliseconds(12));
739 }
740 task_stopwatch.Stop(kEndOfRun);
741
742 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
743
744 ProcessDataSnapshot process_data;
745 ThreadData::Snapshot(false, &process_data);
746 ASSERT_EQ(2u, process_data.tasks.size());
747 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name);
748 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name);
749 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number);
750 EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name);
751 EXPECT_EQ(1, process_data.tasks[0].death_data.count);
752 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_sum);
753 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_max);
754 EXPECT_EQ(6, process_data.tasks[0].death_data.run_duration_sample);
755 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sum);
756 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_max);
757 EXPECT_EQ(4, process_data.tasks[0].death_data.queue_duration_sample);
758 EXPECT_EQ(kMainThreadName, process_data.tasks[0].death_thread_name);
759 EXPECT_EQ(kFile, process_data.tasks[1].birth.location.file_name);
760 EXPECT_EQ(kFunction, process_data.tasks[1].birth.location.function_name);
761 EXPECT_EQ(kSecondFakeLineNumber,
762 process_data.tasks[1].birth.location.line_number);
763 EXPECT_EQ(kMainThreadName, process_data.tasks[1].birth.thread_name);
764 EXPECT_EQ(1, process_data.tasks[1].death_data.count);
765 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_sum);
766 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_max);
767 EXPECT_EQ(2, process_data.tasks[1].death_data.run_duration_sample);
768 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_sum);
769 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_max);
770 EXPECT_EQ(1, process_data.tasks[1].death_data.queue_duration_sample);
771 EXPECT_EQ(kMainThreadName, process_data.tasks[1].death_thread_name);
772 EXPECT_EQ(0u, process_data.descendants.size());
773 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
774 }
775
584 } // namespace tracked_objects 776 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698