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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress Created 5 years, 9 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
« no previous file with comments | « base/tracked_objects.cc ('k') | base/value_conversions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 132 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
133 ThreadData* data = ThreadData::Get(); 133 ThreadData* data = ThreadData::Get();
134 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 134 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
135 ASSERT_TRUE(data); 135 ASSERT_TRUE(data);
136 EXPECT_FALSE(data->next()); 136 EXPECT_FALSE(data->next());
137 EXPECT_EQ(data, ThreadData::Get()); 137 EXPECT_EQ(data, ThreadData::Get());
138 ThreadData::BirthMap birth_map; 138 ThreadData::BirthMap birth_map;
139 ThreadData::DeathMap death_map; 139 ThreadData::DeathMap death_map;
140 ThreadData::ParentChildSet parent_child_set; 140 ThreadData::ParentChildSet parent_child_set;
141 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 141 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
142 EXPECT_EQ(0u, birth_map.size()); 142 EXPECT_EQ(0u, birth_map.size());
143 EXPECT_EQ(0u, death_map.size()); 143 EXPECT_EQ(0u, death_map.size());
144 EXPECT_EQ(0u, parent_child_set.size()); 144 EXPECT_EQ(0u, parent_child_set.size());
145 145
146 // Clean up with no leaking. 146 // Clean up with no leaking.
147 Reset(); 147 Reset();
148 148
149 // Do it again, just to be sure we reset state completely. 149 // Do it again, just to be sure we reset state completely.
150 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( 150 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus(
151 ThreadData::PROFILING_CHILDREN_ACTIVE)); 151 ThreadData::PROFILING_CHILDREN_ACTIVE));
152 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 152 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
153 data = ThreadData::Get(); 153 data = ThreadData::Get();
154 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 154 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
155 ASSERT_TRUE(data); 155 ASSERT_TRUE(data);
156 EXPECT_FALSE(data->next()); 156 EXPECT_FALSE(data->next());
157 EXPECT_EQ(data, ThreadData::Get()); 157 EXPECT_EQ(data, ThreadData::Get());
158 birth_map.clear(); 158 birth_map.clear();
159 death_map.clear(); 159 death_map.clear();
160 parent_child_set.clear(); 160 parent_child_set.clear();
161 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 161 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
162 EXPECT_EQ(0u, birth_map.size()); 162 EXPECT_EQ(0u, birth_map.size());
163 EXPECT_EQ(0u, death_map.size()); 163 EXPECT_EQ(0u, death_map.size());
164 EXPECT_EQ(0u, parent_child_set.size()); 164 EXPECT_EQ(0u, parent_child_set.size());
165 } 165 }
166 166
167 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { 167 TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
168 if (!ThreadData::InitializeAndSetTrackingStatus( 168 if (!ThreadData::InitializeAndSetTrackingStatus(
169 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 169 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
170 return; 170 return;
171 } 171 }
172 172
173 // Instigate tracking on a single tracked object, on our thread. 173 // Instigate tracking on a single tracked object, on our thread.
174 const char kFunction[] = "TinyStartupShutdown"; 174 const char kFunction[] = "TinyStartupShutdown";
175 Location location(kFunction, kFile, kLineNumber, NULL); 175 Location location(kFunction, kFile, kLineNumber, NULL);
176 Births* first_birth = ThreadData::TallyABirthIfActive(location); 176 Births* first_birth = ThreadData::TallyABirthIfActive(location);
177 177
178 ThreadData* data = ThreadData::first(); 178 ThreadData* data = ThreadData::first();
179 ASSERT_TRUE(data); 179 ASSERT_TRUE(data);
180 EXPECT_FALSE(data->next()); 180 EXPECT_FALSE(data->next());
181 EXPECT_EQ(data, ThreadData::Get()); 181 EXPECT_EQ(data, ThreadData::Get());
182 ThreadData::BirthMap birth_map; 182 ThreadData::BirthMap birth_map;
183 ThreadData::DeathMap death_map; 183 ThreadData::DeathMap death_map;
184 ThreadData::ParentChildSet parent_child_set; 184 ThreadData::ParentChildSet parent_child_set;
185 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 185 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
186 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 186 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
187 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. 187 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth.
188 EXPECT_EQ(0u, death_map.size()); // No deaths. 188 EXPECT_EQ(0u, death_map.size()); // No deaths.
189 EXPECT_EQ(0u, parent_child_set.size()); // No children. 189 EXPECT_EQ(0u, parent_child_set.size()); // No children.
190 190
191 191
192 // Now instigate another birth, while we are timing the run of the first 192 // Now instigate another birth, while we are timing the run of the first
193 // execution. 193 // execution.
194 ThreadData::PrepareForStartOfRun(first_birth); 194 ThreadData::PrepareForStartOfRun(first_birth);
195 // Create a child (using the same birth location). 195 // Create a child (using the same birth location).
196 // TrackingInfo will call TallyABirth() during construction. 196 // TrackingInfo will call TallyABirth() during construction.
197 const int32 start_time = 1; 197 const int32 start_time = 1;
198 base::TimeTicks kBogusBirthTime = base::TimeTicks() + 198 base::TimeTicks kBogusBirthTime = base::TimeTicks() +
199 base::TimeDelta::FromMilliseconds(start_time); 199 base::TimeDelta::FromMilliseconds(start_time);
200 base::TrackingInfo pending_task(location, kBogusBirthTime); 200 base::TrackingInfo pending_task(location, kBogusBirthTime);
201 SetTestTime(1); 201 SetTestTime(1);
202 TaskStopwatch stopwatch; 202 TaskStopwatch stopwatch;
203 stopwatch.Start(); 203 stopwatch.Start();
204 // Finally conclude the outer run. 204 // Finally conclude the outer run.
205 const int32 time_elapsed = 1000; 205 const int32 time_elapsed = 1000;
206 SetTestTime(start_time + time_elapsed); 206 SetTestTime(start_time + time_elapsed);
207 stopwatch.Stop(); 207 stopwatch.Stop();
208 208
209 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 209 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
210 210
211 birth_map.clear(); 211 birth_map.clear();
212 death_map.clear(); 212 death_map.clear();
213 parent_child_set.clear(); 213 parent_child_set.clear();
214 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); 214 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
215 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 215 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
216 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. 216 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
217 EXPECT_EQ(1u, death_map.size()); // 1 location. 217 EXPECT_EQ(1u, death_map.size()); // 1 location.
218 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. 218 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death.
219 if (ThreadData::TrackingParentChildStatus()) { 219 if (ThreadData::TrackingParentChildStatus()) {
220 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. 220 EXPECT_EQ(1u, parent_child_set.size()); // 1 child.
221 EXPECT_EQ(parent_child_set.begin()->first, 221 EXPECT_EQ(parent_child_set.begin()->first,
222 parent_child_set.begin()->second); 222 parent_child_set.begin()->second);
223 } else { 223 } else {
224 EXPECT_EQ(0u, parent_child_set.size()); // no stats. 224 EXPECT_EQ(0u, parent_child_set.size()); // no stats.
225 } 225 }
226 226
227 // The births were at the same location as the one known death. 227 // The births were at the same location as the one known death.
228 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); 228 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first);
229 229
230 ProcessDataSnapshot process_data; 230 ProcessDataSnapshot process_data;
231 ThreadData::Snapshot(false, &process_data); 231 ThreadData::Snapshot(&process_data);
232 232
233 ASSERT_EQ(1u, process_data.tasks.size()); 233 ASSERT_EQ(1u, process_data.tasks.size());
234 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); 234 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name);
235 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); 235 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name);
236 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); 236 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number);
237 EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].birth.thread_name); 237 EXPECT_EQ(kWorkerThreadName, process_data.tasks[0].birth.thread_name);
238 EXPECT_EQ(1, process_data.tasks[0].death_data.count); 238 EXPECT_EQ(1, process_data.tasks[0].death_data.count);
239 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sum); 239 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sum);
240 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_max); 240 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_max);
241 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sample); 241 EXPECT_EQ(time_elapsed, process_data.tasks[0].death_data.run_duration_sample);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // Start in the deactivated state. 310 // Start in the deactivated state.
311 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 311 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
312 return; 312 return;
313 } 313 }
314 314
315 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; 315 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread";
316 Location location(kFunction, kFile, kLineNumber, NULL); 316 Location location(kFunction, kFile, kLineNumber, NULL);
317 TallyABirth(location, std::string()); 317 TallyABirth(location, std::string());
318 318
319 ProcessDataSnapshot process_data; 319 ProcessDataSnapshot process_data;
320 ThreadData::Snapshot(false, &process_data); 320 ThreadData::Snapshot(&process_data);
321 EXPECT_EQ(0u, process_data.tasks.size()); 321 EXPECT_EQ(0u, process_data.tasks.size());
322 EXPECT_EQ(0u, process_data.descendants.size()); 322 EXPECT_EQ(0u, process_data.descendants.size());
323 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 323 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
324 } 324 }
325 325
326 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { 326 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) {
327 // Start in the deactivated state. 327 // Start in the deactivated state.
328 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 328 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
329 return; 329 return;
330 } 330 }
331 331
332 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; 332 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread";
333 Location location(kFunction, kFile, kLineNumber, NULL); 333 Location location(kFunction, kFile, kLineNumber, NULL);
334 TallyABirth(location, kMainThreadName); 334 TallyABirth(location, kMainThreadName);
335 335
336 ProcessDataSnapshot process_data; 336 ProcessDataSnapshot process_data;
337 ThreadData::Snapshot(false, &process_data); 337 ThreadData::Snapshot(&process_data);
338 EXPECT_EQ(0u, process_data.tasks.size()); 338 EXPECT_EQ(0u, process_data.tasks.size());
339 EXPECT_EQ(0u, process_data.descendants.size()); 339 EXPECT_EQ(0u, process_data.descendants.size());
340 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 340 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
341 } 341 }
342 342
343 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { 343 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) {
344 if (!ThreadData::InitializeAndSetTrackingStatus( 344 if (!ThreadData::InitializeAndSetTrackingStatus(
345 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 345 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
346 return; 346 return;
347 } 347 }
348 348
349 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; 349 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread";
350 Location location(kFunction, kFile, kLineNumber, NULL); 350 Location location(kFunction, kFile, kLineNumber, NULL);
351 TallyABirth(location, std::string()); 351 TallyABirth(location, std::string());
352 352
353 ProcessDataSnapshot process_data; 353 ProcessDataSnapshot process_data;
354 ThreadData::Snapshot(false, &process_data); 354 ThreadData::Snapshot(&process_data);
355 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 355 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
356 kStillAlive, 1, 0, 0); 356 kStillAlive, 1, 0, 0);
357 } 357 }
358 358
359 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { 359 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) {
360 if (!ThreadData::InitializeAndSetTrackingStatus( 360 if (!ThreadData::InitializeAndSetTrackingStatus(
361 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 361 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
362 return; 362 return;
363 } 363 }
364 364
365 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; 365 const char kFunction[] = "BirthOnlyToSnapshotMainThread";
366 Location location(kFunction, kFile, kLineNumber, NULL); 366 Location location(kFunction, kFile, kLineNumber, NULL);
367 TallyABirth(location, kMainThreadName); 367 TallyABirth(location, kMainThreadName);
368 368
369 ProcessDataSnapshot process_data; 369 ProcessDataSnapshot process_data;
370 ThreadData::Snapshot(false, &process_data); 370 ThreadData::Snapshot(&process_data);
371 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, 371 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive,
372 1, 0, 0); 372 1, 0, 0);
373 } 373 }
374 374
375 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { 375 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) {
376 if (!ThreadData::InitializeAndSetTrackingStatus( 376 if (!ThreadData::InitializeAndSetTrackingStatus(
377 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 377 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
378 return; 378 return;
379 } 379 }
380 380
(...skipping 11 matching lines...) Expand all
392 const unsigned int kEndOfRun = 7; 392 const unsigned int kEndOfRun = 7;
393 SetTestTime(kStartOfRun); 393 SetTestTime(kStartOfRun);
394 TaskStopwatch stopwatch; 394 TaskStopwatch stopwatch;
395 stopwatch.Start(); 395 stopwatch.Start();
396 SetTestTime(kEndOfRun); 396 SetTestTime(kEndOfRun);
397 stopwatch.Stop(); 397 stopwatch.Stop();
398 398
399 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 399 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
400 400
401 ProcessDataSnapshot process_data; 401 ProcessDataSnapshot process_data;
402 ThreadData::Snapshot(false, &process_data); 402 ThreadData::Snapshot(&process_data);
403 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 403 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
404 kMainThreadName, 1, 2, 4); 404 kMainThreadName, 1, 2, 4);
405 } 405 }
406 406
407 // We will deactivate tracking after the birth, and before the death, and 407 // We will deactivate tracking after the birth, and before the death, and
408 // demonstrate that the lifecycle is completely tallied. This ensures that 408 // demonstrate that the lifecycle is completely tallied. This ensures that
409 // our tallied births are matched by tallied deaths (except for when the 409 // our tallied births are matched by tallied deaths (except for when the
410 // task is still running, or is queued). 410 // task is still running, or is queued).
411 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { 411 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) {
412 if (!ThreadData::InitializeAndSetTrackingStatus( 412 if (!ThreadData::InitializeAndSetTrackingStatus(
(...skipping 19 matching lines...) Expand all
432 const unsigned int kEndOfRun = 7; 432 const unsigned int kEndOfRun = 7;
433 SetTestTime(kStartOfRun); 433 SetTestTime(kStartOfRun);
434 TaskStopwatch stopwatch; 434 TaskStopwatch stopwatch;
435 stopwatch.Start(); 435 stopwatch.Start();
436 SetTestTime(kEndOfRun); 436 SetTestTime(kEndOfRun);
437 stopwatch.Stop(); 437 stopwatch.Stop();
438 438
439 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 439 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
440 440
441 ProcessDataSnapshot process_data; 441 ProcessDataSnapshot process_data;
442 ThreadData::Snapshot(false, &process_data); 442 ThreadData::Snapshot(&process_data);
443 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 443 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
444 kMainThreadName, 1, 2, 4); 444 kMainThreadName, 1, 2, 4);
445 } 445 }
446 446
447 // We will deactivate tracking before starting a life cycle, and neither 447 // We will deactivate tracking before starting a life cycle, and neither
448 // the birth nor the death will be recorded. 448 // the birth nor the death will be recorded.
449 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { 449 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) {
450 // Start in the deactivated state. 450 // Start in the deactivated state.
451 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 451 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) {
452 return; 452 return;
(...skipping 13 matching lines...) Expand all
466 const unsigned int kEndOfRun = 7; 466 const unsigned int kEndOfRun = 7;
467 SetTestTime(kStartOfRun); 467 SetTestTime(kStartOfRun);
468 TaskStopwatch stopwatch; 468 TaskStopwatch stopwatch;
469 stopwatch.Start(); 469 stopwatch.Start();
470 SetTestTime(kEndOfRun); 470 SetTestTime(kEndOfRun);
471 stopwatch.Stop(); 471 stopwatch.Stop();
472 472
473 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 473 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
474 474
475 ProcessDataSnapshot process_data; 475 ProcessDataSnapshot process_data;
476 ThreadData::Snapshot(false, &process_data); 476 ThreadData::Snapshot(&process_data);
477 EXPECT_EQ(0u, process_data.tasks.size()); 477 EXPECT_EQ(0u, process_data.tasks.size());
478 EXPECT_EQ(0u, process_data.descendants.size()); 478 EXPECT_EQ(0u, process_data.descendants.size());
479 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 479 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
480 } 480 }
481 481
482 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) {
483 if (!ThreadData::InitializeAndSetTrackingStatus(
484 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
485 return;
486 }
487
488 const char kFunction[] = "LifeCycleToSnapshotWorkerThread";
489 Location location(kFunction, kFile, kLineNumber, NULL);
490 // Do not delete |birth|. We don't own it.
491 Births* birth = ThreadData::TallyABirthIfActive(location);
492 EXPECT_NE(reinterpret_cast<Births*>(NULL), birth);
493
494 const unsigned int kTimePosted = 1;
495 const unsigned int kStartOfRun = 5;
496 const unsigned int kEndOfRun = 7;
497 SetTestTime(kStartOfRun);
498 TaskStopwatch stopwatch;
499 stopwatch.Start();
500 SetTestTime(kEndOfRun);
501 stopwatch.Stop();
502
503 ThreadData::TallyRunOnWorkerThreadIfTracking(
504 birth, TrackedTime() + Duration::FromMilliseconds(kTimePosted), stopwatch);
505
506 // Call for the ToSnapshot, but tell it to not reset the maxes after scanning.
507 ProcessDataSnapshot process_data;
508 ThreadData::Snapshot(false, &process_data);
509 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
510 kWorkerThreadName, 1, 2, 4);
511
512 // Call for the ToSnapshot, but tell it to reset the maxes after scanning.
513 // We'll still get the same values, but the data will be reset (which we'll
514 // see in a moment).
515 ProcessDataSnapshot process_data_pre_reset;
516 ThreadData::Snapshot(true, &process_data_pre_reset);
517 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
518 kWorkerThreadName, 1, 2, 4);
519
520 // Call for the ToSnapshot, and now we'll see the result of the last
521 // translation, as the max will have been pushed back to zero.
522 ProcessDataSnapshot process_data_post_reset;
523 ThreadData::Snapshot(true, &process_data_post_reset);
524 ASSERT_EQ(1u, process_data_post_reset.tasks.size());
525 EXPECT_EQ(kFile, process_data_post_reset.tasks[0].birth.location.file_name);
526 EXPECT_EQ(kFunction,
527 process_data_post_reset.tasks[0].birth.location.function_name);
528 EXPECT_EQ(kLineNumber,
529 process_data_post_reset.tasks[0].birth.location.line_number);
530 EXPECT_EQ(kWorkerThreadName,
531 process_data_post_reset.tasks[0].birth.thread_name);
532 EXPECT_EQ(1, process_data_post_reset.tasks[0].death_data.count);
533 EXPECT_EQ(2, process_data_post_reset.tasks[0].death_data.run_duration_sum);
534 EXPECT_EQ(0, process_data_post_reset.tasks[0].death_data.run_duration_max);
535 EXPECT_EQ(2, process_data_post_reset.tasks[0].death_data.run_duration_sample);
536 EXPECT_EQ(4, process_data_post_reset.tasks[0].death_data.queue_duration_sum);
537 EXPECT_EQ(0, process_data_post_reset.tasks[0].death_data.queue_duration_max);
538 EXPECT_EQ(4,
539 process_data_post_reset.tasks[0].death_data.queue_duration_sample);
540 EXPECT_EQ(kWorkerThreadName,
541 process_data_post_reset.tasks[0].death_thread_name);
542 EXPECT_EQ(0u, process_data_post_reset.descendants.size());
543 EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id);
544 }
545
546 TEST_F(TrackedObjectsTest, TwoLives) { 482 TEST_F(TrackedObjectsTest, TwoLives) {
547 if (!ThreadData::InitializeAndSetTrackingStatus( 483 if (!ThreadData::InitializeAndSetTrackingStatus(
548 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 484 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
549 return; 485 return;
550 } 486 }
551 487
552 const char kFunction[] = "TwoLives"; 488 const char kFunction[] = "TwoLives";
553 Location location(kFunction, kFile, kLineNumber, NULL); 489 Location location(kFunction, kFile, kLineNumber, NULL);
554 TallyABirth(location, kMainThreadName); 490 TallyABirth(location, kMainThreadName);
555 491
(...skipping 18 matching lines...) Expand all
574 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 510 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
575 SetTestTime(kStartOfRun); 511 SetTestTime(kStartOfRun);
576 TaskStopwatch stopwatch2; 512 TaskStopwatch stopwatch2;
577 stopwatch2.Start(); 513 stopwatch2.Start();
578 SetTestTime(kEndOfRun); 514 SetTestTime(kEndOfRun);
579 stopwatch2.Stop(); 515 stopwatch2.Stop();
580 516
581 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); 517 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2);
582 518
583 ProcessDataSnapshot process_data; 519 ProcessDataSnapshot process_data;
584 ThreadData::Snapshot(false, &process_data); 520 ThreadData::Snapshot(&process_data);
585 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 521 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
586 kMainThreadName, 2, 2, 4); 522 kMainThreadName, 2, 2, 4);
587 } 523 }
588 524
589 TEST_F(TrackedObjectsTest, DifferentLives) { 525 TEST_F(TrackedObjectsTest, DifferentLives) {
590 if (!ThreadData::InitializeAndSetTrackingStatus( 526 if (!ThreadData::InitializeAndSetTrackingStatus(
591 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 527 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
592 return; 528 return;
593 } 529 }
594 530
(...skipping 19 matching lines...) Expand all
614 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 550 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
615 551
616 const int kSecondFakeLineNumber = 999; 552 const int kSecondFakeLineNumber = 999;
617 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); 553 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
618 554
619 // TrackingInfo will call TallyABirth() during construction. 555 // TrackingInfo will call TallyABirth() during construction.
620 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); 556 base::TrackingInfo pending_task2(second_location, kDelayedStartTime);
621 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 557 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
622 558
623 ProcessDataSnapshot process_data; 559 ProcessDataSnapshot process_data;
624 ThreadData::Snapshot(false, &process_data); 560 ThreadData::Snapshot(&process_data);
625 ASSERT_EQ(2u, process_data.tasks.size()); 561 ASSERT_EQ(2u, process_data.tasks.size());
626 562
627 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name); 563 EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name);
628 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name); 564 EXPECT_EQ(kFunction, process_data.tasks[0].birth.location.function_name);
629 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number); 565 EXPECT_EQ(kLineNumber, process_data.tasks[0].birth.location.line_number);
630 EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name); 566 EXPECT_EQ(kMainThreadName, process_data.tasks[0].birth.thread_name);
631 EXPECT_EQ(1, process_data.tasks[0].death_data.count); 567 EXPECT_EQ(1, process_data.tasks[0].death_data.count);
632 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sum); 568 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sum);
633 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_max); 569 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_max);
634 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sample); 570 EXPECT_EQ(2, process_data.tasks[0].death_data.run_duration_sample);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 exclusion_stopwatch.Start(); 614 exclusion_stopwatch.Start();
679 SetTestTime(12); 615 SetTestTime(12);
680 exclusion_stopwatch.Stop(); 616 exclusion_stopwatch.Stop();
681 } 617 }
682 SetTestTime(15); 618 SetTestTime(15);
683 task_stopwatch.Stop(); 619 task_stopwatch.Stop();
684 620
685 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 621 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
686 622
687 ProcessDataSnapshot process_data; 623 ProcessDataSnapshot process_data;
688 ThreadData::Snapshot(false, &process_data); 624 ThreadData::Snapshot(&process_data);
689 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 625 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
690 kMainThreadName, 1, 6, 4); 626 kMainThreadName, 1, 6, 4);
691 } 627 }
692 628
693 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { 629 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) {
694 if (!ThreadData::InitializeAndSetTrackingStatus( 630 if (!ThreadData::InitializeAndSetTrackingStatus(
695 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 631 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
696 return; 632 return;
697 } 633 }
698 634
(...skipping 22 matching lines...) Expand all
721 exclusion_stopwatch2.Start(); 657 exclusion_stopwatch2.Start();
722 SetTestTime(18); 658 SetTestTime(18);
723 exclusion_stopwatch2.Stop(); 659 exclusion_stopwatch2.Stop();
724 } 660 }
725 SetTestTime(25); 661 SetTestTime(25);
726 task_stopwatch.Stop(); 662 task_stopwatch.Stop();
727 663
728 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 664 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
729 665
730 ProcessDataSnapshot process_data; 666 ProcessDataSnapshot process_data;
731 ThreadData::Snapshot(false, &process_data); 667 ThreadData::Snapshot(&process_data);
732 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 668 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
733 kMainThreadName, 1, 13, 4); 669 kMainThreadName, 1, 13, 4);
734 } 670 }
735 671
736 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { 672 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
737 if (!ThreadData::InitializeAndSetTrackingStatus( 673 if (!ThreadData::InitializeAndSetTrackingStatus(
738 ThreadData::PROFILING_CHILDREN_ACTIVE)) { 674 ThreadData::PROFILING_CHILDREN_ACTIVE)) {
739 return; 675 return;
740 } 676 }
741 677
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } 710 }
775 SetTestTime(12); 711 SetTestTime(12);
776 exclusion_stopwatch.Stop(); 712 exclusion_stopwatch.Stop();
777 } 713 }
778 SetTestTime(15); 714 SetTestTime(15);
779 task_stopwatch.Stop(); 715 task_stopwatch.Stop();
780 716
781 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 717 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
782 718
783 ProcessDataSnapshot process_data; 719 ProcessDataSnapshot process_data;
784 ThreadData::Snapshot(false, &process_data); 720 ThreadData::Snapshot(&process_data);
785 721
786 // The order in which the two task follow is platform-dependent. 722 // The order in which the two task follow is platform-dependent.
787 int t0 = (process_data.tasks[0].birth.location.line_number == kLineNumber) ? 723 int t0 = (process_data.tasks[0].birth.location.line_number == kLineNumber) ?
788 0 : 1; 724 0 : 1;
789 int t1 = 1 - t0; 725 int t1 = 1 - t0;
790 726
791 ASSERT_EQ(2u, process_data.tasks.size()); 727 ASSERT_EQ(2u, process_data.tasks.size());
792 EXPECT_EQ(kFile, process_data.tasks[t0].birth.location.file_name); 728 EXPECT_EQ(kFile, process_data.tasks[t0].birth.location.file_name);
793 EXPECT_EQ(kFunction, process_data.tasks[t0].birth.location.function_name); 729 EXPECT_EQ(kFunction, process_data.tasks[t0].birth.location.function_name);
794 EXPECT_EQ(kLineNumber, process_data.tasks[t0].birth.location.line_number); 730 EXPECT_EQ(kLineNumber, process_data.tasks[t0].birth.location.line_number);
(...skipping 17 matching lines...) Expand all
812 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_sample); 748 EXPECT_EQ(2, process_data.tasks[t1].death_data.run_duration_sample);
813 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sum); 749 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sum);
814 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_max); 750 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_max);
815 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sample); 751 EXPECT_EQ(1, process_data.tasks[t1].death_data.queue_duration_sample);
816 EXPECT_EQ(kMainThreadName, process_data.tasks[t1].death_thread_name); 752 EXPECT_EQ(kMainThreadName, process_data.tasks[t1].death_thread_name);
817 EXPECT_EQ(0u, process_data.descendants.size()); 753 EXPECT_EQ(0u, process_data.descendants.size());
818 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 754 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
819 } 755 }
820 756
821 } // namespace tracked_objects 757 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/tracked_objects.cc ('k') | base/value_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698