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