OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
6 | 6 |
7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 // Provide access, since this class is a friend of ThreadData. | 30 // Provide access, since this class is a friend of ThreadData. |
31 void ShutdownSingleThreadedCleanup(bool leak) { | 31 void ShutdownSingleThreadedCleanup(bool leak) { |
32 ThreadData::ShutdownSingleThreadedCleanup(leak); | 32 ThreadData::ShutdownSingleThreadedCleanup(leak); |
33 } | 33 } |
34 }; | 34 }; |
35 | 35 |
36 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { | 36 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
37 // Minimal test doesn't even create any tasks. | 37 // Minimal test doesn't even create any tasks. |
38 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 38 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 39 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
39 return; | 40 return; |
40 | 41 |
41 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 42 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
42 ThreadData* data = ThreadData::Get(); | 43 ThreadData* data = ThreadData::Get(); |
43 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 44 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
44 EXPECT_TRUE(data); | 45 EXPECT_TRUE(data); |
45 EXPECT_TRUE(!data->next()); | 46 EXPECT_TRUE(!data->next()); |
46 EXPECT_EQ(data, ThreadData::Get()); | 47 EXPECT_EQ(data, ThreadData::Get()); |
47 ThreadData::BirthMap birth_map; | 48 ThreadData::BirthMap birth_map; |
48 ThreadData::DeathMap death_map; | 49 ThreadData::DeathMap death_map; |
49 ThreadData::ParentChildSet parent_child_set; | 50 ThreadData::ParentChildSet parent_child_set; |
50 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 51 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
51 EXPECT_EQ(0u, birth_map.size()); | 52 EXPECT_EQ(0u, birth_map.size()); |
52 EXPECT_EQ(0u, death_map.size()); | 53 EXPECT_EQ(0u, death_map.size()); |
53 EXPECT_EQ(0u, parent_child_set.size()); | 54 EXPECT_EQ(0u, parent_child_set.size()); |
54 // Cleanup with no leaking. | 55 // Cleanup with no leaking. |
55 ShutdownSingleThreadedCleanup(false); | 56 ShutdownSingleThreadedCleanup(false); |
56 | 57 |
57 // Do it again, just to be sure we reset state completely. | 58 // Do it again, just to be sure we reset state completely. |
58 ThreadData::InitializeAndSetTrackingStatus(true); | 59 ThreadData::InitializeAndSetTrackingStatus( |
| 60 ThreadData::PROFILING_CHILDREN_ACTIVE); |
59 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 61 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
60 data = ThreadData::Get(); | 62 data = ThreadData::Get(); |
61 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 63 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
62 EXPECT_TRUE(data); | 64 EXPECT_TRUE(data); |
63 EXPECT_TRUE(!data->next()); | 65 EXPECT_TRUE(!data->next()); |
64 EXPECT_EQ(data, ThreadData::Get()); | 66 EXPECT_EQ(data, ThreadData::Get()); |
65 birth_map.clear(); | 67 birth_map.clear(); |
66 death_map.clear(); | 68 death_map.clear(); |
67 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 69 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
68 EXPECT_EQ(0u, birth_map.size()); | 70 EXPECT_EQ(0u, birth_map.size()); |
69 EXPECT_EQ(0u, death_map.size()); | 71 EXPECT_EQ(0u, death_map.size()); |
70 EXPECT_EQ(0u, parent_child_set.size()); | 72 EXPECT_EQ(0u, parent_child_set.size()); |
71 } | 73 } |
72 | 74 |
73 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 75 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
74 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 76 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 77 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
75 return; | 78 return; |
76 | 79 |
77 // Instigate tracking on a single tracked object, on our thread. | 80 // Instigate tracking on a single tracked object, on our thread. |
78 const Location& location = FROM_HERE; | 81 const Location& location = FROM_HERE; |
79 Births* first_birth = ThreadData::TallyABirthIfActive(location); | 82 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
80 | 83 |
81 ThreadData* data = ThreadData::first(); | 84 ThreadData* data = ThreadData::first(); |
82 ASSERT_TRUE(data); | 85 ASSERT_TRUE(data); |
83 EXPECT_TRUE(!data->next()); | 86 EXPECT_TRUE(!data->next()); |
84 EXPECT_EQ(data, ThreadData::Get()); | 87 EXPECT_EQ(data, ThreadData::Get()); |
(...skipping 21 matching lines...) Expand all Loading... |
106 end_time); | 109 end_time); |
107 | 110 |
108 birth_map.clear(); | 111 birth_map.clear(); |
109 death_map.clear(); | 112 death_map.clear(); |
110 parent_child_set.clear(); | 113 parent_child_set.clear(); |
111 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 114 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
112 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 115 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
113 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 116 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
114 EXPECT_EQ(1u, death_map.size()); // 1 location. | 117 EXPECT_EQ(1u, death_map.size()); // 1 location. |
115 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 118 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
116 if (ThreadData::tracking_parent_child_status()) { | 119 if (ThreadData::TrackingParentChildStatus()) { |
117 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 120 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
118 EXPECT_EQ(parent_child_set.begin()->first, | 121 EXPECT_EQ(parent_child_set.begin()->first, |
119 parent_child_set.begin()->second); | 122 parent_child_set.begin()->second); |
120 } else { | 123 } else { |
121 EXPECT_EQ(0u, parent_child_set.size()); // no stats. | 124 EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
122 } | 125 } |
123 | 126 |
124 // The births were at the same location as the one known death. | 127 // The births were at the same location as the one known death. |
125 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 128 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
126 } | 129 } |
127 | 130 |
128 TEST_F(TrackedObjectsTest, ParentChildTest) { | 131 TEST_F(TrackedObjectsTest, ParentChildTest) { |
129 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 132 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 133 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
130 return; | 134 return; |
131 if (!ThreadData::tracking_parent_child_status()) | 135 if (!ThreadData::TrackingParentChildStatus()) |
132 return; // Feature not compiled in. | 136 return; // Feature not compiled in. |
133 | 137 |
134 // Instigate tracking on a single tracked object, on our thread. | 138 // Instigate tracking on a single tracked object, on our thread. |
135 const int kFakeLineNumber = 1776; | 139 const int kFakeLineNumber = 1776; |
136 const char* kFile = "FixedUnitTestFileName"; | 140 const char* kFile = "FixedUnitTestFileName"; |
137 const char* kFunction = "ParentChildTest"; | 141 const char* kFunction = "ParentChildTest"; |
138 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 142 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
139 | 143 |
140 // Now instigate another birth, while we are timing the run of the first | 144 // Now instigate another birth, while we are timing the run of the first |
141 // execution. | 145 // execution. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 "\"function_name\":\"ParentChildTest\"," | 208 "\"function_name\":\"ParentChildTest\"," |
205 "\"line_number\":1776" | 209 "\"line_number\":1776" |
206 "}" | 210 "}" |
207 "}" | 211 "}" |
208 "]" | 212 "]" |
209 "}"; | 213 "}"; |
210 EXPECT_EQ(json, birth_only_result); | 214 EXPECT_EQ(json, birth_only_result); |
211 } | 215 } |
212 | 216 |
213 TEST_F(TrackedObjectsTest, DeathDataTest) { | 217 TEST_F(TrackedObjectsTest, DeathDataTest) { |
214 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 218 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 219 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
215 return; | 220 return; |
216 | 221 |
217 scoped_ptr<DeathData> data(new DeathData()); | 222 scoped_ptr<DeathData> data(new DeathData()); |
218 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 223 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
219 EXPECT_EQ(data->run_duration_sum(), 0); | 224 EXPECT_EQ(data->run_duration_sum(), 0); |
220 EXPECT_EQ(data->run_duration_sample(), 0); | 225 EXPECT_EQ(data->run_duration_sample(), 0); |
221 EXPECT_EQ(data->queue_duration_sum(), 0); | 226 EXPECT_EQ(data->queue_duration_sum(), 0); |
222 EXPECT_EQ(data->queue_duration_sample(), 0); | 227 EXPECT_EQ(data->queue_duration_sample(), 0); |
223 EXPECT_EQ(data->count(), 0); | 228 EXPECT_EQ(data->count(), 0); |
224 | 229 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 "\"queue_ms_sample\":8," | 268 "\"queue_ms_sample\":8," |
264 "\"run_ms\":84," | 269 "\"run_ms\":84," |
265 "\"run_ms_max\":42," | 270 "\"run_ms_max\":42," |
266 "\"run_ms_sample\":42" | 271 "\"run_ms_sample\":42" |
267 "}"; | 272 "}"; |
268 EXPECT_EQ(birth_only_result, json); | 273 EXPECT_EQ(birth_only_result, json); |
269 } | 274 } |
270 | 275 |
271 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueWorkerThread) { | 276 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueWorkerThread) { |
272 // Transition to Deactivated state before doing anything. | 277 // Transition to Deactivated state before doing anything. |
273 if (!ThreadData::InitializeAndSetTrackingStatus(false)) | 278 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
274 return; | 279 return; |
275 // We don't initialize system with a thread name, so we're viewed as a worker | 280 // We don't initialize system with a thread name, so we're viewed as a worker |
276 // thread. | 281 // thread. |
277 const int kFakeLineNumber = 173; | 282 const int kFakeLineNumber = 173; |
278 const char* kFile = "FixedFileName"; | 283 const char* kFile = "FixedFileName"; |
279 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 284 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
280 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 285 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
281 Births* birth = ThreadData::TallyABirthIfActive(location); | 286 Births* birth = ThreadData::TallyABirthIfActive(location); |
282 // We should now see a NULL birth record. | 287 // We should now see a NULL birth record. |
283 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 288 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
284 | 289 |
285 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 290 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
286 std::string json; | 291 std::string json; |
287 base::JSONWriter::Write(value.get(), false, &json); | 292 base::JSONWriter::Write(value.get(), false, &json); |
288 std::string birth_only_result = "{" | 293 std::string birth_only_result = "{" |
289 "\"descendants\":[" | 294 "\"descendants\":[" |
290 "]," | 295 "]," |
291 "\"list\":[" | 296 "\"list\":[" |
292 "]" | 297 "]" |
293 "}"; | 298 "}"; |
294 EXPECT_EQ(json, birth_only_result); | 299 EXPECT_EQ(json, birth_only_result); |
295 } | 300 } |
296 | 301 |
297 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { | 302 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { |
298 // Start in the deactivated state. | 303 // Start in the deactivated state. |
299 if (!ThreadData::InitializeAndSetTrackingStatus(false)) | 304 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
300 return; | 305 return; |
301 | 306 |
302 // Use a well named thread. | 307 // Use a well named thread. |
303 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 308 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
304 const int kFakeLineNumber = 173; | 309 const int kFakeLineNumber = 173; |
305 const char* kFile = "FixedFileName"; | 310 const char* kFile = "FixedFileName"; |
306 const char* kFunction = "BirthOnlyToValueMainThread"; | 311 const char* kFunction = "BirthOnlyToValueMainThread"; |
307 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 312 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
308 // Do not delete birth. We don't own it. | 313 // Do not delete birth. We don't own it. |
309 Births* birth = ThreadData::TallyABirthIfActive(location); | 314 Births* birth = ThreadData::TallyABirthIfActive(location); |
310 // We expect to not get a birth record. | 315 // We expect to not get a birth record. |
311 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 316 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
312 | 317 |
313 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 318 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
314 std::string json; | 319 std::string json; |
315 base::JSONWriter::Write(value.get(), false, &json); | 320 base::JSONWriter::Write(value.get(), false, &json); |
316 std::string birth_only_result = "{" | 321 std::string birth_only_result = "{" |
317 "\"descendants\":[" | 322 "\"descendants\":[" |
318 "]," | 323 "]," |
319 "\"list\":[" | 324 "\"list\":[" |
320 "]" | 325 "]" |
321 "}"; | 326 "}"; |
322 EXPECT_EQ(json, birth_only_result); | 327 EXPECT_EQ(json, birth_only_result); |
323 } | 328 } |
324 | 329 |
325 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { | 330 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { |
326 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 331 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 332 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
327 return; | 333 return; |
328 // We don't initialize system with a thread name, so we're viewed as a worker | 334 // We don't initialize system with a thread name, so we're viewed as a worker |
329 // thread. | 335 // thread. |
330 const int kFakeLineNumber = 173; | 336 const int kFakeLineNumber = 173; |
331 const char* kFile = "FixedFileName"; | 337 const char* kFile = "FixedFileName"; |
332 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 338 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
333 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 339 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
334 Births* birth = ThreadData::TallyABirthIfActive(location); | 340 Births* birth = ThreadData::TallyABirthIfActive(location); |
335 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 341 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
336 | 342 |
(...skipping 21 matching lines...) Expand all Loading... |
358 "\"function_name\":\"BirthOnlyToValueWorkerThread\"," | 364 "\"function_name\":\"BirthOnlyToValueWorkerThread\"," |
359 "\"line_number\":173" | 365 "\"line_number\":173" |
360 "}" | 366 "}" |
361 "}" | 367 "}" |
362 "]" | 368 "]" |
363 "}"; | 369 "}"; |
364 EXPECT_EQ(json, birth_only_result); | 370 EXPECT_EQ(json, birth_only_result); |
365 } | 371 } |
366 | 372 |
367 TEST_F(TrackedObjectsTest, BirthOnlyToValueMainThread) { | 373 TEST_F(TrackedObjectsTest, BirthOnlyToValueMainThread) { |
368 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 374 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 375 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
369 return; | 376 return; |
370 | 377 |
371 // Use a well named thread. | 378 // Use a well named thread. |
372 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 379 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
373 const int kFakeLineNumber = 173; | 380 const int kFakeLineNumber = 173; |
374 const char* kFile = "FixedFileName"; | 381 const char* kFile = "FixedFileName"; |
375 const char* kFunction = "BirthOnlyToValueMainThread"; | 382 const char* kFunction = "BirthOnlyToValueMainThread"; |
376 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 383 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
377 // Do not delete birth. We don't own it. | 384 // Do not delete birth. We don't own it. |
378 Births* birth = ThreadData::TallyABirthIfActive(location); | 385 Births* birth = ThreadData::TallyABirthIfActive(location); |
(...skipping 23 matching lines...) Expand all Loading... |
402 "\"function_name\":\"BirthOnlyToValueMainThread\"," | 409 "\"function_name\":\"BirthOnlyToValueMainThread\"," |
403 "\"line_number\":173" | 410 "\"line_number\":173" |
404 "}" | 411 "}" |
405 "}" | 412 "}" |
406 "]" | 413 "]" |
407 "}"; | 414 "}"; |
408 EXPECT_EQ(json, birth_only_result); | 415 EXPECT_EQ(json, birth_only_result); |
409 } | 416 } |
410 | 417 |
411 TEST_F(TrackedObjectsTest, LifeCycleToValueMainThread) { | 418 TEST_F(TrackedObjectsTest, LifeCycleToValueMainThread) { |
412 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 419 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 420 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
413 return; | 421 return; |
414 | 422 |
415 // Use a well named thread. | 423 // Use a well named thread. |
416 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 424 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
417 const int kFakeLineNumber = 236; | 425 const int kFakeLineNumber = 236; |
418 const char* kFile = "FixedFileName"; | 426 const char* kFile = "FixedFileName"; |
419 const char* kFunction = "LifeCycleToValueMainThread"; | 427 const char* kFunction = "LifeCycleToValueMainThread"; |
420 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 428 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
421 // Do not delete birth. We don't own it. | 429 // Do not delete birth. We don't own it. |
422 Births* birth = ThreadData::TallyABirthIfActive(location); | 430 Births* birth = ThreadData::TallyABirthIfActive(location); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 "]" | 471 "]" |
464 "}"; | 472 "}"; |
465 EXPECT_EQ(one_line_result, json); | 473 EXPECT_EQ(one_line_result, json); |
466 } | 474 } |
467 | 475 |
468 // We will deactivate tracking after the birth, and before the death, and | 476 // We will deactivate tracking after the birth, and before the death, and |
469 // demonstrate that the lifecycle is completely tallied. This ensures that | 477 // demonstrate that the lifecycle is completely tallied. This ensures that |
470 // our tallied births are matched by tallied deaths (except for when the | 478 // our tallied births are matched by tallied deaths (except for when the |
471 // task is still running, or is queued). | 479 // task is still running, or is queued). |
472 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToValueMainThread) { | 480 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToValueMainThread) { |
473 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 481 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 482 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
474 return; | 483 return; |
475 | 484 |
476 // Use a well named thread. | 485 // Use a well named thread. |
477 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 486 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
478 const int kFakeLineNumber = 236; | 487 const int kFakeLineNumber = 236; |
479 const char* kFile = "FixedFileName"; | 488 const char* kFile = "FixedFileName"; |
480 const char* kFunction = "LifeCycleToValueMainThread"; | 489 const char* kFunction = "LifeCycleToValueMainThread"; |
481 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 490 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
482 // Do not delete birth. We don't own it. | 491 // Do not delete birth. We don't own it. |
483 Births* birth = ThreadData::TallyABirthIfActive(location); | 492 Births* birth = ThreadData::TallyABirthIfActive(location); |
484 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 493 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
485 | 494 |
486 const base::TimeTicks kTimePosted = base::TimeTicks() | 495 const base::TimeTicks kTimePosted = base::TimeTicks() |
487 + base::TimeDelta::FromMilliseconds(1); | 496 + base::TimeDelta::FromMilliseconds(1); |
488 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 497 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
489 // TrackingInfo will call TallyABirth() during construction. | 498 // TrackingInfo will call TallyABirth() during construction. |
490 base::TrackingInfo pending_task(location, kDelayedStartTime); | 499 base::TrackingInfo pending_task(location, kDelayedStartTime); |
491 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 500 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
492 | 501 |
493 // Turn off tracking now that we have births. | 502 // Turn off tracking now that we have births. |
494 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus(false)); | 503 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 504 ThreadData::DEACTIVATED)); |
495 | 505 |
496 const TrackedTime kStartOfRun = TrackedTime() + | 506 const TrackedTime kStartOfRun = TrackedTime() + |
497 Duration::FromMilliseconds(5); | 507 Duration::FromMilliseconds(5); |
498 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 508 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
499 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 509 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
500 kStartOfRun, kEndOfRun); | 510 kStartOfRun, kEndOfRun); |
501 | 511 |
502 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 512 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
503 std::string json; | 513 std::string json; |
504 base::JSONWriter::Write(value.get(), false, &json); | 514 base::JSONWriter::Write(value.get(), false, &json); |
(...skipping 20 matching lines...) Expand all Loading... |
525 "}" | 535 "}" |
526 "}" | 536 "}" |
527 "]" | 537 "]" |
528 "}"; | 538 "}"; |
529 EXPECT_EQ(one_line_result, json); | 539 EXPECT_EQ(one_line_result, json); |
530 } | 540 } |
531 | 541 |
532 // We will deactivate tracking before starting a life cycle, and neither | 542 // We will deactivate tracking before starting a life cycle, and neither |
533 // the birth nor the death will be recorded. | 543 // the birth nor the death will be recorded. |
534 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToValueMainThread) { | 544 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToValueMainThread) { |
535 if (!ThreadData::InitializeAndSetTrackingStatus(false)) | 545 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
536 return; | 546 return; |
537 | 547 |
538 // Use a well named thread. | 548 // Use a well named thread. |
539 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 549 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
540 const int kFakeLineNumber = 236; | 550 const int kFakeLineNumber = 236; |
541 const char* kFile = "FixedFileName"; | 551 const char* kFile = "FixedFileName"; |
542 const char* kFunction = "LifeCycleToValueMainThread"; | 552 const char* kFunction = "LifeCycleToValueMainThread"; |
543 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 553 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
544 // Do not delete birth. We don't own it. | 554 // Do not delete birth. We don't own it. |
545 Births* birth = ThreadData::TallyABirthIfActive(location); | 555 Births* birth = ThreadData::TallyABirthIfActive(location); |
(...skipping 18 matching lines...) Expand all Loading... |
564 std::string one_line_result = "{" | 574 std::string one_line_result = "{" |
565 "\"descendants\":[" | 575 "\"descendants\":[" |
566 "]," | 576 "]," |
567 "\"list\":[" | 577 "\"list\":[" |
568 "]" | 578 "]" |
569 "}"; | 579 "}"; |
570 EXPECT_EQ(one_line_result, json); | 580 EXPECT_EQ(one_line_result, json); |
571 } | 581 } |
572 | 582 |
573 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { | 583 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { |
574 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 584 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 585 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
575 return; | 586 return; |
576 | 587 |
577 // Don't initialize thread, so that we appear as a worker thread. | 588 // Don't initialize thread, so that we appear as a worker thread. |
578 // ThreadData::InitializeThreadContext("SomeMainThreadName"); | 589 // ThreadData::InitializeThreadContext("SomeMainThreadName"); |
579 | 590 |
580 const int kFakeLineNumber = 236; | 591 const int kFakeLineNumber = 236; |
581 const char* kFile = "FixedFileName"; | 592 const char* kFile = "FixedFileName"; |
582 const char* kFunction = "LifeCycleToValueWorkerThread"; | 593 const char* kFunction = "LifeCycleToValueWorkerThread"; |
583 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 594 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
584 // Do not delete birth. We don't own it. | 595 // Do not delete birth. We don't own it. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 "\"function_name\":\"LifeCycleToValueWorkerThread\"," | 666 "\"function_name\":\"LifeCycleToValueWorkerThread\"," |
656 "\"line_number\":236" | 667 "\"line_number\":236" |
657 "}" | 668 "}" |
658 "}" | 669 "}" |
659 "]" | 670 "]" |
660 "}"; | 671 "}"; |
661 EXPECT_EQ(one_line_result_with_zeros, json); | 672 EXPECT_EQ(one_line_result_with_zeros, json); |
662 } | 673 } |
663 | 674 |
664 TEST_F(TrackedObjectsTest, TwoLives) { | 675 TEST_F(TrackedObjectsTest, TwoLives) { |
665 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 676 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 677 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
666 return; | 678 return; |
667 | 679 |
668 // Use a well named thread. | 680 // Use a well named thread. |
669 ThreadData::InitializeThreadContext("SomeFileThreadName"); | 681 ThreadData::InitializeThreadContext("SomeFileThreadName"); |
670 const int kFakeLineNumber = 222; | 682 const int kFakeLineNumber = 222; |
671 const char* kFile = "AnotherFileName"; | 683 const char* kFile = "AnotherFileName"; |
672 const char* kFunction = "TwoLives"; | 684 const char* kFunction = "TwoLives"; |
673 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 685 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
674 // Do not delete birth. We don't own it. | 686 // Do not delete birth. We don't own it. |
675 Births* birth = ThreadData::TallyABirthIfActive(location); | 687 Births* birth = ThreadData::TallyABirthIfActive(location); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 "\"function_name\":\"TwoLives\"," | 732 "\"function_name\":\"TwoLives\"," |
721 "\"line_number\":222" | 733 "\"line_number\":222" |
722 "}" | 734 "}" |
723 "}" | 735 "}" |
724 "]" | 736 "]" |
725 "}"; | 737 "}"; |
726 EXPECT_EQ(one_line_result, json); | 738 EXPECT_EQ(one_line_result, json); |
727 } | 739 } |
728 | 740 |
729 TEST_F(TrackedObjectsTest, DifferentLives) { | 741 TEST_F(TrackedObjectsTest, DifferentLives) { |
730 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 742 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 743 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
731 return; | 744 return; |
732 | 745 |
733 // Use a well named thread. | 746 // Use a well named thread. |
734 ThreadData::InitializeThreadContext("SomeFileThreadName"); | 747 ThreadData::InitializeThreadContext("SomeFileThreadName"); |
735 const int kFakeLineNumber = 567; | 748 const int kFakeLineNumber = 567; |
736 const char* kFile = "AnotherFileName"; | 749 const char* kFile = "AnotherFileName"; |
737 const char* kFunction = "DifferentLives"; | 750 const char* kFunction = "DifferentLives"; |
738 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 751 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
739 | 752 |
740 const base::TimeTicks kTimePosted = base::TimeTicks() | 753 const base::TimeTicks kTimePosted = base::TimeTicks() |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 "\"line_number\":999" | 813 "\"line_number\":999" |
801 "}" | 814 "}" |
802 "}" | 815 "}" |
803 "]" | 816 "]" |
804 "}"; | 817 "}"; |
805 EXPECT_EQ(one_line_result, json); | 818 EXPECT_EQ(one_line_result, json); |
806 } | 819 } |
807 | 820 |
808 | 821 |
809 } // namespace tracked_objects | 822 } // namespace tracked_objects |
OLD | NEW |