| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 165 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 166 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 166 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 167 EXPECT_EQ(0u, death_map.size()); // No status yet. | 167 EXPECT_EQ(0u, death_map.size()); // No status yet. |
| 168 // Just like TinyStartupShutdown test. | 168 // Just like TinyStartupShutdown test. |
| 169 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 169 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 170 EXPECT_EQ(parent_child_set.begin()->first, | 170 EXPECT_EQ(parent_child_set.begin()->first, |
| 171 parent_child_set.begin()->second); | 171 parent_child_set.begin()->second); |
| 172 | 172 |
| 173 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 173 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 174 std::string json; | 174 std::string json; |
| 175 base::JSONWriter::Write(value.get(), false, &json); | 175 base::JSONWriter::Write(value.get(), &json); |
| 176 std::string birth_only_result = "{" | 176 std::string birth_only_result = "{" |
| 177 "\"descendants\":[" | 177 "\"descendants\":[" |
| 178 "{" | 178 "{" |
| 179 "\"child_location\":{" | 179 "\"child_location\":{" |
| 180 "\"file_name\":\"FixedUnitTestFileName\"," | 180 "\"file_name\":\"FixedUnitTestFileName\"," |
| 181 "\"function_name\":\"ParentChildTest\"," | 181 "\"function_name\":\"ParentChildTest\"," |
| 182 "\"line_number\":1776" | 182 "\"line_number\":1776" |
| 183 "}," | 183 "}," |
| 184 "\"child_thread\":\"WorkerThread-1\"," | 184 "\"child_thread\":\"WorkerThread-1\"," |
| 185 "\"parent_location\":{" | 185 "\"parent_location\":{" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 EXPECT_EQ(integer, run_ms); | 253 EXPECT_EQ(integer, run_ms); |
| 254 EXPECT_TRUE(dictionary->GetInteger("queue_ms", &integer)); | 254 EXPECT_TRUE(dictionary->GetInteger("queue_ms", &integer)); |
| 255 EXPECT_EQ(integer, 2 * queue_ms); | 255 EXPECT_EQ(integer, 2 * queue_ms); |
| 256 EXPECT_TRUE(dictionary->GetInteger("queue_ms_sample", &integer)); | 256 EXPECT_TRUE(dictionary->GetInteger("queue_ms_sample", &integer)); |
| 257 EXPECT_EQ(integer, queue_ms); | 257 EXPECT_EQ(integer, queue_ms); |
| 258 EXPECT_TRUE(dictionary->GetInteger("count", &integer)); | 258 EXPECT_TRUE(dictionary->GetInteger("count", &integer)); |
| 259 EXPECT_EQ(integer, 2); | 259 EXPECT_EQ(integer, 2); |
| 260 | 260 |
| 261 scoped_ptr<base::Value> value(data->ToValue()); | 261 scoped_ptr<base::Value> value(data->ToValue()); |
| 262 std::string json; | 262 std::string json; |
| 263 base::JSONWriter::Write(value.get(), false, &json); | 263 base::JSONWriter::Write(value.get(), &json); |
| 264 std::string birth_only_result = "{" | 264 std::string birth_only_result = "{" |
| 265 "\"count\":2," | 265 "\"count\":2," |
| 266 "\"queue_ms\":16," | 266 "\"queue_ms\":16," |
| 267 "\"queue_ms_max\":8," | 267 "\"queue_ms_max\":8," |
| 268 "\"queue_ms_sample\":8," | 268 "\"queue_ms_sample\":8," |
| 269 "\"run_ms\":84," | 269 "\"run_ms\":84," |
| 270 "\"run_ms_max\":42," | 270 "\"run_ms_max\":42," |
| 271 "\"run_ms_sample\":42" | 271 "\"run_ms_sample\":42" |
| 272 "}"; | 272 "}"; |
| 273 EXPECT_EQ(birth_only_result, json); | 273 EXPECT_EQ(birth_only_result, json); |
| 274 } | 274 } |
| 275 | 275 |
| 276 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueWorkerThread) { | 276 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueWorkerThread) { |
| 277 // Transition to Deactivated state before doing anything. | 277 // Transition to Deactivated state before doing anything. |
| 278 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 278 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
| 279 return; | 279 return; |
| 280 // 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 |
| 281 // thread. | 281 // thread. |
| 282 const int kFakeLineNumber = 173; | 282 const int kFakeLineNumber = 173; |
| 283 const char* kFile = "FixedFileName"; | 283 const char* kFile = "FixedFileName"; |
| 284 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 284 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
| 285 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 285 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 286 Births* birth = ThreadData::TallyABirthIfActive(location); | 286 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 287 // We should now see a NULL birth record. | 287 // We should now see a NULL birth record. |
| 288 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 288 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
| 289 | 289 |
| 290 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 290 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 291 std::string json; | 291 std::string json; |
| 292 base::JSONWriter::Write(value.get(), false, &json); | 292 base::JSONWriter::Write(value.get(), &json); |
| 293 std::string birth_only_result = "{" | 293 std::string birth_only_result = "{" |
| 294 "\"descendants\":[" | 294 "\"descendants\":[" |
| 295 "]," | 295 "]," |
| 296 "\"list\":[" | 296 "\"list\":[" |
| 297 "]" | 297 "]" |
| 298 "}"; | 298 "}"; |
| 299 EXPECT_EQ(json, birth_only_result); | 299 EXPECT_EQ(json, birth_only_result); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { | 302 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { |
| 303 // Start in the deactivated state. | 303 // Start in the deactivated state. |
| 304 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 304 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
| 305 return; | 305 return; |
| 306 | 306 |
| 307 // Use a well named thread. | 307 // Use a well named thread. |
| 308 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 308 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
| 309 const int kFakeLineNumber = 173; | 309 const int kFakeLineNumber = 173; |
| 310 const char* kFile = "FixedFileName"; | 310 const char* kFile = "FixedFileName"; |
| 311 const char* kFunction = "BirthOnlyToValueMainThread"; | 311 const char* kFunction = "BirthOnlyToValueMainThread"; |
| 312 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 312 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 313 // Do not delete birth. We don't own it. | 313 // Do not delete birth. We don't own it. |
| 314 Births* birth = ThreadData::TallyABirthIfActive(location); | 314 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 315 // We expect to not get a birth record. | 315 // We expect to not get a birth record. |
| 316 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 316 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
| 317 | 317 |
| 318 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 318 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 319 std::string json; | 319 std::string json; |
| 320 base::JSONWriter::Write(value.get(), false, &json); | 320 base::JSONWriter::Write(value.get(), &json); |
| 321 std::string birth_only_result = "{" | 321 std::string birth_only_result = "{" |
| 322 "\"descendants\":[" | 322 "\"descendants\":[" |
| 323 "]," | 323 "]," |
| 324 "\"list\":[" | 324 "\"list\":[" |
| 325 "]" | 325 "]" |
| 326 "}"; | 326 "}"; |
| 327 EXPECT_EQ(json, birth_only_result); | 327 EXPECT_EQ(json, birth_only_result); |
| 328 } | 328 } |
| 329 | 329 |
| 330 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { | 330 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { |
| 331 if (!ThreadData::InitializeAndSetTrackingStatus( | 331 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 332 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 332 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 333 return; | 333 return; |
| 334 // 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 |
| 335 // thread. | 335 // thread. |
| 336 const int kFakeLineNumber = 173; | 336 const int kFakeLineNumber = 173; |
| 337 const char* kFile = "FixedFileName"; | 337 const char* kFile = "FixedFileName"; |
| 338 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 338 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
| 339 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 339 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 340 Births* birth = ThreadData::TallyABirthIfActive(location); | 340 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 341 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 341 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 342 | 342 |
| 343 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 343 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 344 std::string json; | 344 std::string json; |
| 345 base::JSONWriter::Write(value.get(), false, &json); | 345 base::JSONWriter::Write(value.get(), &json); |
| 346 std::string birth_only_result = "{" | 346 std::string birth_only_result = "{" |
| 347 "\"descendants\":[" | 347 "\"descendants\":[" |
| 348 "]," | 348 "]," |
| 349 "\"list\":[" | 349 "\"list\":[" |
| 350 "{" | 350 "{" |
| 351 "\"birth_thread\":\"WorkerThread-1\"," | 351 "\"birth_thread\":\"WorkerThread-1\"," |
| 352 "\"death_data\":{" | 352 "\"death_data\":{" |
| 353 "\"count\":1," | 353 "\"count\":1," |
| 354 "\"queue_ms\":0," | 354 "\"queue_ms\":0," |
| 355 "\"queue_ms_max\":0," | 355 "\"queue_ms_max\":0," |
| (...skipping 24 matching lines...) Expand all Loading... |
| 380 const int kFakeLineNumber = 173; | 380 const int kFakeLineNumber = 173; |
| 381 const char* kFile = "FixedFileName"; | 381 const char* kFile = "FixedFileName"; |
| 382 const char* kFunction = "BirthOnlyToValueMainThread"; | 382 const char* kFunction = "BirthOnlyToValueMainThread"; |
| 383 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 383 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 384 // Do not delete birth. We don't own it. | 384 // Do not delete birth. We don't own it. |
| 385 Births* birth = ThreadData::TallyABirthIfActive(location); | 385 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 386 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 386 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 387 | 387 |
| 388 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 388 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 389 std::string json; | 389 std::string json; |
| 390 base::JSONWriter::Write(value.get(), false, &json); | 390 base::JSONWriter::Write(value.get(), &json); |
| 391 std::string birth_only_result = "{" | 391 std::string birth_only_result = "{" |
| 392 "\"descendants\":[" | 392 "\"descendants\":[" |
| 393 "]," | 393 "]," |
| 394 "\"list\":[" | 394 "\"list\":[" |
| 395 "{" | 395 "{" |
| 396 "\"birth_thread\":\"SomeMainThreadName\"," | 396 "\"birth_thread\":\"SomeMainThreadName\"," |
| 397 "\"death_data\":{" | 397 "\"death_data\":{" |
| 398 "\"count\":1," | 398 "\"count\":1," |
| 399 "\"queue_ms\":0," | 399 "\"queue_ms\":0," |
| 400 "\"queue_ms_max\":0," | 400 "\"queue_ms_max\":0," |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 438 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 439 | 439 |
| 440 const TrackedTime kStartOfRun = TrackedTime() + | 440 const TrackedTime kStartOfRun = TrackedTime() + |
| 441 Duration::FromMilliseconds(5); | 441 Duration::FromMilliseconds(5); |
| 442 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 442 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 443 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 443 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 444 kStartOfRun, kEndOfRun); | 444 kStartOfRun, kEndOfRun); |
| 445 | 445 |
| 446 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 446 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 447 std::string json; | 447 std::string json; |
| 448 base::JSONWriter::Write(value.get(), false, &json); | 448 base::JSONWriter::Write(value.get(), &json); |
| 449 std::string one_line_result = "{" | 449 std::string one_line_result = "{" |
| 450 "\"descendants\":[" | 450 "\"descendants\":[" |
| 451 "]," | 451 "]," |
| 452 "\"list\":[" | 452 "\"list\":[" |
| 453 "{" | 453 "{" |
| 454 "\"birth_thread\":\"SomeMainThreadName\"," | 454 "\"birth_thread\":\"SomeMainThreadName\"," |
| 455 "\"death_data\":{" | 455 "\"death_data\":{" |
| 456 "\"count\":1," | 456 "\"count\":1," |
| 457 "\"queue_ms\":4," | 457 "\"queue_ms\":4," |
| 458 "\"queue_ms_max\":4," | 458 "\"queue_ms_max\":4," |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 ThreadData::DEACTIVATED)); | 504 ThreadData::DEACTIVATED)); |
| 505 | 505 |
| 506 const TrackedTime kStartOfRun = TrackedTime() + | 506 const TrackedTime kStartOfRun = TrackedTime() + |
| 507 Duration::FromMilliseconds(5); | 507 Duration::FromMilliseconds(5); |
| 508 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 508 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 509 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 509 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 510 kStartOfRun, kEndOfRun); | 510 kStartOfRun, kEndOfRun); |
| 511 | 511 |
| 512 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 512 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 513 std::string json; | 513 std::string json; |
| 514 base::JSONWriter::Write(value.get(), false, &json); | 514 base::JSONWriter::Write(value.get(), &json); |
| 515 std::string one_line_result = "{" | 515 std::string one_line_result = "{" |
| 516 "\"descendants\":[" | 516 "\"descendants\":[" |
| 517 "]," | 517 "]," |
| 518 "\"list\":[" | 518 "\"list\":[" |
| 519 "{" | 519 "{" |
| 520 "\"birth_thread\":\"SomeMainThreadName\"," | 520 "\"birth_thread\":\"SomeMainThreadName\"," |
| 521 "\"death_data\":{" | 521 "\"death_data\":{" |
| 522 "\"count\":1," | 522 "\"count\":1," |
| 523 "\"queue_ms\":4," | 523 "\"queue_ms\":4," |
| 524 "\"queue_ms_max\":4," | 524 "\"queue_ms_max\":4," |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 563 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 564 | 564 |
| 565 const TrackedTime kStartOfRun = TrackedTime() + | 565 const TrackedTime kStartOfRun = TrackedTime() + |
| 566 Duration::FromMilliseconds(5); | 566 Duration::FromMilliseconds(5); |
| 567 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 567 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 568 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 568 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 569 kStartOfRun, kEndOfRun); | 569 kStartOfRun, kEndOfRun); |
| 570 | 570 |
| 571 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 571 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 572 std::string json; | 572 std::string json; |
| 573 base::JSONWriter::Write(value.get(), false, &json); | 573 base::JSONWriter::Write(value.get(), &json); |
| 574 std::string one_line_result = "{" | 574 std::string one_line_result = "{" |
| 575 "\"descendants\":[" | 575 "\"descendants\":[" |
| 576 "]," | 576 "]," |
| 577 "\"list\":[" | 577 "\"list\":[" |
| 578 "]" | 578 "]" |
| 579 "}"; | 579 "}"; |
| 580 EXPECT_EQ(one_line_result, json); | 580 EXPECT_EQ(one_line_result, json); |
| 581 } | 581 } |
| 582 | 582 |
| 583 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { | 583 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 599 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); | 599 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); |
| 600 const TrackedTime kStartOfRun = TrackedTime() + | 600 const TrackedTime kStartOfRun = TrackedTime() + |
| 601 Duration::FromMilliseconds(5); | 601 Duration::FromMilliseconds(5); |
| 602 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 602 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 603 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, | 603 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, |
| 604 kStartOfRun, kEndOfRun); | 604 kStartOfRun, kEndOfRun); |
| 605 | 605 |
| 606 // Call for the ToValue, but tell it to not the maxes after scanning. | 606 // Call for the ToValue, but tell it to not the maxes after scanning. |
| 607 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 607 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 608 std::string json; | 608 std::string json; |
| 609 base::JSONWriter::Write(value.get(), false, &json); | 609 base::JSONWriter::Write(value.get(), &json); |
| 610 std::string one_line_result = "{" | 610 std::string one_line_result = "{" |
| 611 "\"descendants\":[" | 611 "\"descendants\":[" |
| 612 "]," | 612 "]," |
| 613 "\"list\":[" | 613 "\"list\":[" |
| 614 "{" | 614 "{" |
| 615 "\"birth_thread\":\"WorkerThread-1\"," | 615 "\"birth_thread\":\"WorkerThread-1\"," |
| 616 "\"death_data\":{" | 616 "\"death_data\":{" |
| 617 "\"count\":1," | 617 "\"count\":1," |
| 618 "\"queue_ms\":4," | 618 "\"queue_ms\":4," |
| 619 "\"queue_ms_max\":4," | 619 "\"queue_ms_max\":4," |
| (...skipping 10 matching lines...) Expand all Loading... |
| 630 "}" | 630 "}" |
| 631 "}" | 631 "}" |
| 632 "]" | 632 "]" |
| 633 "}"; | 633 "}"; |
| 634 EXPECT_EQ(one_line_result, json); | 634 EXPECT_EQ(one_line_result, json); |
| 635 | 635 |
| 636 // Call for the ToValue, but tell it to reset the maxes after scanning. | 636 // Call for the ToValue, but tell it to reset the maxes after scanning. |
| 637 // We'll still get the same values, but the data will be reset (which we'll | 637 // We'll still get the same values, but the data will be reset (which we'll |
| 638 // see in a moment). | 638 // see in a moment). |
| 639 value.reset(ThreadData::ToValue(true)); | 639 value.reset(ThreadData::ToValue(true)); |
| 640 base::JSONWriter::Write(value.get(), false, &json); | 640 base::JSONWriter::Write(value.get(), &json); |
| 641 // Result should be unchanged. | 641 // Result should be unchanged. |
| 642 EXPECT_EQ(one_line_result, json); | 642 EXPECT_EQ(one_line_result, json); |
| 643 | 643 |
| 644 // Call for the ToValue, and now we'll see the result of the last translation, | 644 // Call for the ToValue, and now we'll see the result of the last translation, |
| 645 // as the max will have been pushed back to zero. | 645 // as the max will have been pushed back to zero. |
| 646 value.reset(ThreadData::ToValue(false)); | 646 value.reset(ThreadData::ToValue(false)); |
| 647 base::JSONWriter::Write(value.get(), false, &json); | 647 base::JSONWriter::Write(value.get(), &json); |
| 648 std::string one_line_result_with_zeros = "{" | 648 std::string one_line_result_with_zeros = "{" |
| 649 "\"descendants\":[" | 649 "\"descendants\":[" |
| 650 "]," | 650 "]," |
| 651 "\"list\":[" | 651 "\"list\":[" |
| 652 "{" | 652 "{" |
| 653 "\"birth_thread\":\"WorkerThread-1\"," | 653 "\"birth_thread\":\"WorkerThread-1\"," |
| 654 "\"death_data\":{" | 654 "\"death_data\":{" |
| 655 "\"count\":1," | 655 "\"count\":1," |
| 656 "\"queue_ms\":4," | 656 "\"queue_ms\":4," |
| 657 "\"queue_ms_max\":0," // Note zero here. | 657 "\"queue_ms_max\":0," // Note zero here. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 703 |
| 704 // TrackingInfo will call TallyABirth() during construction. | 704 // TrackingInfo will call TallyABirth() during construction. |
| 705 base::TrackingInfo pending_task2(location, kDelayedStartTime); | 705 base::TrackingInfo pending_task2(location, kDelayedStartTime); |
| 706 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 706 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 707 | 707 |
| 708 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, | 708 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, |
| 709 kStartOfRun, kEndOfRun); | 709 kStartOfRun, kEndOfRun); |
| 710 | 710 |
| 711 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 711 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 712 std::string json; | 712 std::string json; |
| 713 base::JSONWriter::Write(value.get(), false, &json); | 713 base::JSONWriter::Write(value.get(), &json); |
| 714 std::string one_line_result = "{" | 714 std::string one_line_result = "{" |
| 715 "\"descendants\":[" | 715 "\"descendants\":[" |
| 716 "]," | 716 "]," |
| 717 "\"list\":[" | 717 "\"list\":[" |
| 718 "{" | 718 "{" |
| 719 "\"birth_thread\":\"SomeFileThreadName\"," | 719 "\"birth_thread\":\"SomeFileThreadName\"," |
| 720 "\"death_data\":{" | 720 "\"death_data\":{" |
| 721 "\"count\":2," | 721 "\"count\":2," |
| 722 "\"queue_ms\":8," | 722 "\"queue_ms\":8," |
| 723 "\"queue_ms_max\":4," | 723 "\"queue_ms_max\":4," |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 | 765 |
| 766 const int kSecondFakeLineNumber = 999; | 766 const int kSecondFakeLineNumber = 999; |
| 767 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 767 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 768 | 768 |
| 769 // TrackingInfo will call TallyABirth() during construction. | 769 // TrackingInfo will call TallyABirth() during construction. |
| 770 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 770 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 771 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 771 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 772 | 772 |
| 773 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 773 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 774 std::string json; | 774 std::string json; |
| 775 base::JSONWriter::Write(value.get(), false, &json); | 775 base::JSONWriter::Write(value.get(), &json); |
| 776 std::string one_line_result = "{" | 776 std::string one_line_result = "{" |
| 777 "\"descendants\":[" | 777 "\"descendants\":[" |
| 778 "]," | 778 "]," |
| 779 "\"list\":[" | 779 "\"list\":[" |
| 780 "{" | 780 "{" |
| 781 "\"birth_thread\":\"SomeFileThreadName\"," | 781 "\"birth_thread\":\"SomeFileThreadName\"," |
| 782 "\"death_data\":{" | 782 "\"death_data\":{" |
| 783 "\"count\":1," | 783 "\"count\":1," |
| 784 "\"queue_ms\":4," | 784 "\"queue_ms\":4," |
| 785 "\"queue_ms_max\":4," | 785 "\"queue_ms_max\":4," |
| (...skipping 27 matching lines...) Expand all Loading... |
| 813 "\"line_number\":999" | 813 "\"line_number\":999" |
| 814 "}" | 814 "}" |
| 815 "}" | 815 "}" |
| 816 "]" | 816 "]" |
| 817 "}"; | 817 "}"; |
| 818 EXPECT_EQ(one_line_result, json); | 818 EXPECT_EQ(one_line_result, json); |
| 819 } | 819 } |
| 820 | 820 |
| 821 | 821 |
| 822 } // namespace tracked_objects | 822 } // namespace tracked_objects |
| OLD | NEW |