Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "base/debug/activity_tracker.h" | 5 #include "base/debug/activity_tracker.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 size_t GetGlobalUserDataMemoryCacheUsed() { | 83 size_t GetGlobalUserDataMemoryCacheUsed() { |
| 84 return GlobalActivityTracker::Get()->user_data_allocator_.cache_used(); | 84 return GlobalActivityTracker::Get()->user_data_allocator_.cache_used(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void HandleProcessExit(int64_t id, | 87 void HandleProcessExit(int64_t id, |
| 88 int64_t stamp, | 88 int64_t stamp, |
| 89 int code, | 89 int code, |
| 90 GlobalActivityTracker::ProcessPhase phase, | 90 GlobalActivityTracker::ProcessPhase phase, |
| 91 std::string&& command, | 91 std::string&& command, |
| 92 ActivityUserData::Snapshot&& data) { | 92 ActivityUserData::Snapshot&& data) { |
| 93 exit_id = id; | 93 exit_id_ = id; |
| 94 exit_stamp = stamp; | 94 exit_stamp_ = stamp; |
| 95 exit_code = code; | 95 exit_code_ = code; |
| 96 exit_phase = phase; | 96 exit_phase_ = phase; |
| 97 exit_command = std::move(command); | 97 exit_command_ = std::move(command); |
| 98 exit_data = std::move(data); | 98 exit_data_ = std::move(data); |
| 99 } | 99 } |
| 100 | 100 |
| 101 static void DoNothing() {} | 101 static void DoNothing() {} |
| 102 | 102 |
| 103 int64_t exit_id = 0; | 103 int64_t exit_id_ = 0; |
| 104 int64_t exit_stamp; | 104 int64_t exit_stamp_; |
| 105 int exit_code; | 105 int exit_code_; |
| 106 GlobalActivityTracker::ProcessPhase exit_phase; | 106 GlobalActivityTracker::ProcessPhase exit_phase_; |
| 107 std::string exit_command; | 107 std::string exit_command_; |
| 108 ActivityUserData::Snapshot exit_data; | 108 ActivityUserData::Snapshot exit_data_; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 TEST_F(ActivityTrackerTest, UserDataTest) { | 111 TEST_F(ActivityTrackerTest, UserDataTest) { |
| 112 char buffer[256]; | 112 char buffer[256]; |
| 113 memset(buffer, 0, sizeof(buffer)); | 113 memset(buffer, 0, sizeof(buffer)); |
| 114 ActivityUserData data(buffer, sizeof(buffer)); | 114 ActivityUserData data(buffer, sizeof(buffer)); |
| 115 size_t space = sizeof(buffer) - sizeof(ActivityUserData::MemoryHeader); | 115 size_t space = sizeof(buffer) - sizeof(ActivityUserData::MemoryHeader); |
| 116 ASSERT_EQ(space, data.available_); | 116 ASSERT_EQ(space, data.available_); |
| 117 | 117 |
| 118 data.SetInt("foo", 1); | 118 data.SetInt("foo", 1); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 t2.WaitReady(); | 387 t2.WaitReady(); |
| 388 EXPECT_EQ(starting_active + 1, GetGlobalActiveTrackerCount()); | 388 EXPECT_EQ(starting_active + 1, GetGlobalActiveTrackerCount()); |
| 389 EXPECT_EQ(starting_inactive, GetGlobalInactiveTrackerCount()); | 389 EXPECT_EQ(starting_inactive, GetGlobalInactiveTrackerCount()); |
| 390 | 390 |
| 391 t2.Exit(); | 391 t2.Exit(); |
| 392 t2.Join(); | 392 t2.Join(); |
| 393 EXPECT_EQ(starting_active, GetGlobalActiveTrackerCount()); | 393 EXPECT_EQ(starting_active, GetGlobalActiveTrackerCount()); |
| 394 EXPECT_EQ(starting_inactive + 1, GetGlobalInactiveTrackerCount()); | 394 EXPECT_EQ(starting_inactive + 1, GetGlobalInactiveTrackerCount()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // This test fails roughly 10% of runs on Android tablets. | 397 TEST_F(ActivityTrackerTest, ProcessDeathTest) { |
| 398 // See http://crbug.com/723060 for details. | |
| 399 #if defined(OS_ANDROID) | |
| 400 #define MAYBE_ProcessDeathTest DISABLED_ProcessDeathTest | |
| 401 #else | |
| 402 #define MAYBE_ProcessDeathTest ProcessDeathTest | |
| 403 #endif | |
| 404 | |
| 405 TEST_F(ActivityTrackerTest, MAYBE_ProcessDeathTest) { | |
| 406 // This doesn't actually create and destroy a process. Instead, it uses for- | 398 // This doesn't actually create and destroy a process. Instead, it uses for- |
| 407 // testing interfaces to simulate data created by other processes. | 399 // testing interfaces to simulate data created by other processes. |
| 408 const ProcessId other_process_id = GetCurrentProcId() + 1; | 400 const ProcessId other_process_id = GetCurrentProcId() + 1; |
| 409 | 401 |
| 410 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0); | 402 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0); |
| 411 GlobalActivityTracker* global = GlobalActivityTracker::Get(); | 403 GlobalActivityTracker* global = GlobalActivityTracker::Get(); |
| 412 ThreadActivityTracker* thread = global->GetOrCreateTrackerForCurrentThread(); | 404 ThreadActivityTracker* thread = global->GetOrCreateTrackerForCurrentThread(); |
| 413 | 405 |
| 414 // Get callbacks for process exit. | 406 // Get callbacks for process exit. |
| 415 global->SetProcessExitCallback( | 407 global->SetProcessExitCallback( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 ASSERT_TRUE(ActivityUserData::GetOwningProcessId( | 456 ASSERT_TRUE(ActivityUserData::GetOwningProcessId( |
| 465 global->process_data().GetBaseAddress(), &owning_id, &stamp)); | 457 global->process_data().GetBaseAddress(), &owning_id, &stamp)); |
| 466 EXPECT_EQ(other_process_id, owning_id); | 458 EXPECT_EQ(other_process_id, owning_id); |
| 467 ASSERT_TRUE(ThreadActivityTracker::GetOwningProcessId( | 459 ASSERT_TRUE(ThreadActivityTracker::GetOwningProcessId( |
| 468 thread->GetBaseAddress(), &owning_id, &stamp)); | 460 thread->GetBaseAddress(), &owning_id, &stamp)); |
| 469 EXPECT_EQ(other_process_id, owning_id); | 461 EXPECT_EQ(other_process_id, owning_id); |
| 470 ASSERT_TRUE(ActivityUserData::GetOwningProcessId(user_data.GetBaseAddress(), | 462 ASSERT_TRUE(ActivityUserData::GetOwningProcessId(user_data.GetBaseAddress(), |
| 471 &owning_id, &stamp)); | 463 &owning_id, &stamp)); |
| 472 EXPECT_EQ(other_process_id, owning_id); | 464 EXPECT_EQ(other_process_id, owning_id); |
| 473 | 465 |
| 466 // Wait for the current time to advance beyond the creation stamp. | |
| 467 while (Time::Now().ToInternalValue() <= stamp) | |
|
manzagop (departed)
2017/05/19 17:35:21
Could you instead use a timestamp in the past when
bcwhite
2017/05/19 18:04:07
Done.
| |
| 468 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | |
| 469 | |
| 474 // Check that process exit will perform callback and free the allocations. | 470 // Check that process exit will perform callback and free the allocations. |
| 475 ASSERT_EQ(0, exit_id); | 471 ASSERT_EQ(0, exit_id_); |
| 476 ASSERT_EQ(GlobalActivityTracker::kTypeIdProcessDataRecord, | 472 ASSERT_EQ(GlobalActivityTracker::kTypeIdProcessDataRecord, |
| 477 global->allocator()->GetType(proc_data_ref)); | 473 global->allocator()->GetType(proc_data_ref)); |
| 478 ASSERT_EQ(GlobalActivityTracker::kTypeIdActivityTracker, | 474 ASSERT_EQ(GlobalActivityTracker::kTypeIdActivityTracker, |
| 479 global->allocator()->GetType(tracker_ref)); | 475 global->allocator()->GetType(tracker_ref)); |
| 480 ASSERT_EQ(GlobalActivityTracker::kTypeIdUserDataRecord, | 476 ASSERT_EQ(GlobalActivityTracker::kTypeIdUserDataRecord, |
| 481 global->allocator()->GetType(user_data_ref)); | 477 global->allocator()->GetType(user_data_ref)); |
| 482 global->RecordProcessExit(other_process_id, 0); | 478 global->RecordProcessExit(other_process_id, 0); |
| 483 EXPECT_EQ(other_process_id, exit_id); | 479 EXPECT_EQ(other_process_id, exit_id_); |
| 484 EXPECT_EQ("foo --bar", exit_command); | 480 EXPECT_EQ("foo --bar", exit_command_); |
| 485 EXPECT_EQ(GlobalActivityTracker::kTypeIdProcessDataRecordFree, | 481 EXPECT_EQ(GlobalActivityTracker::kTypeIdProcessDataRecordFree, |
| 486 global->allocator()->GetType(proc_data_ref)); | 482 global->allocator()->GetType(proc_data_ref)); |
| 487 EXPECT_EQ(GlobalActivityTracker::kTypeIdActivityTrackerFree, | 483 EXPECT_EQ(GlobalActivityTracker::kTypeIdActivityTrackerFree, |
| 488 global->allocator()->GetType(tracker_ref)); | 484 global->allocator()->GetType(tracker_ref)); |
| 489 EXPECT_EQ(GlobalActivityTracker::kTypeIdUserDataRecordFree, | 485 EXPECT_EQ(GlobalActivityTracker::kTypeIdUserDataRecordFree, |
| 490 global->allocator()->GetType(user_data_ref)); | 486 global->allocator()->GetType(user_data_ref)); |
| 491 | 487 |
| 492 // Restore memory contents and types so things don't crash when doing real | 488 // Restore memory contents and types so things don't crash when doing real |
| 493 // process clean-up. | 489 // process clean-up. |
| 494 memcpy(const_cast<void*>(thread->GetBaseAddress()), tracker_copy.get(), | 490 memcpy(const_cast<void*>(thread->GetBaseAddress()), tracker_copy.get(), |
| 495 tracker_size); | 491 tracker_size); |
| 496 global->allocator()->ChangeType( | 492 global->allocator()->ChangeType( |
| 497 proc_data_ref, GlobalActivityTracker::kTypeIdProcessDataRecord, | 493 proc_data_ref, GlobalActivityTracker::kTypeIdProcessDataRecord, |
| 498 GlobalActivityTracker::kTypeIdUserDataRecordFree, false); | 494 GlobalActivityTracker::kTypeIdUserDataRecordFree, false); |
| 499 global->allocator()->ChangeType( | 495 global->allocator()->ChangeType( |
| 500 tracker_ref, GlobalActivityTracker::kTypeIdActivityTracker, | 496 tracker_ref, GlobalActivityTracker::kTypeIdActivityTracker, |
| 501 GlobalActivityTracker::kTypeIdActivityTrackerFree, false); | 497 GlobalActivityTracker::kTypeIdActivityTrackerFree, false); |
| 502 global->allocator()->ChangeType( | 498 global->allocator()->ChangeType( |
| 503 user_data_ref, GlobalActivityTracker::kTypeIdUserDataRecord, | 499 user_data_ref, GlobalActivityTracker::kTypeIdUserDataRecord, |
| 504 GlobalActivityTracker::kTypeIdUserDataRecordFree, false); | 500 GlobalActivityTracker::kTypeIdUserDataRecordFree, false); |
| 505 } | 501 } |
| 506 | 502 |
| 507 } // namespace debug | 503 } // namespace debug |
| 508 } // namespace base | 504 } // namespace base |
| OLD | NEW |