| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // The minimum depth a stack should support. | 34 // The minimum depth a stack should support. |
| 35 const int kMinStackDepth = 2; | 35 const int kMinStackDepth = 2; |
| 36 | 36 |
| 37 // The amount of memory set aside for holding arbitrary user data (key/value | 37 // The amount of memory set aside for holding arbitrary user data (key/value |
| 38 // pairs) globally or associated with ActivityData entries. | 38 // pairs) globally or associated with ActivityData entries. |
| 39 const size_t kUserDataSize = 1 << 10; // 1 KiB | 39 const size_t kUserDataSize = 1 << 10; // 1 KiB |
| 40 const size_t kProcessDataSize = 4 << 10; // 4 KiB | 40 const size_t kProcessDataSize = 4 << 10; // 4 KiB |
| 41 const size_t kGlobalDataSize = 16 << 10; // 16 KiB | |
| 42 const size_t kMaxUserDataNameLength = | 41 const size_t kMaxUserDataNameLength = |
| 43 static_cast<size_t>(std::numeric_limits<uint8_t>::max()); | 42 static_cast<size_t>(std::numeric_limits<uint8_t>::max()); |
| 44 | 43 |
| 45 // A constant used to indicate that module information is changing. | 44 // A constant used to indicate that module information is changing. |
| 46 const uint32_t kModuleInformationChanging = 0x80000000; | 45 const uint32_t kModuleInformationChanging = 0x80000000; |
| 47 | 46 |
| 48 // The key used to record process information. | 47 // The key used to record process information. |
| 49 const char kProcessPhaseDataKey[] = "process-phase"; | 48 const char kProcessPhaseDataKey[] = "process-phase"; |
| 50 | 49 |
| 51 // An atomically incrementing number, used to check for recreations of objects | 50 // An atomically incrementing number, used to check for recreations of objects |
| (...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 | 1591 |
| 1593 bool success = record->EncodeFrom(info, required_size); | 1592 bool success = record->EncodeFrom(info, required_size); |
| 1594 DCHECK(success); | 1593 DCHECK(success); |
| 1595 allocator_->MakeIterable(record); | 1594 allocator_->MakeIterable(record); |
| 1596 modules_.insert(std::make_pair(info.file, record)); | 1595 modules_.insert(std::make_pair(info.file, record)); |
| 1597 } | 1596 } |
| 1598 | 1597 |
| 1599 void GlobalActivityTracker::RecordFieldTrial(const std::string& trial_name, | 1598 void GlobalActivityTracker::RecordFieldTrial(const std::string& trial_name, |
| 1600 StringPiece group_name) { | 1599 StringPiece group_name) { |
| 1601 const std::string key = std::string("FieldTrial.") + trial_name; | 1600 const std::string key = std::string("FieldTrial.") + trial_name; |
| 1602 global_data_.SetString(key, group_name); | 1601 process_data_.SetString(key, group_name); |
| 1603 } | 1602 } |
| 1604 | 1603 |
| 1605 GlobalActivityTracker::GlobalActivityTracker( | 1604 GlobalActivityTracker::GlobalActivityTracker( |
| 1606 std::unique_ptr<PersistentMemoryAllocator> allocator, | 1605 std::unique_ptr<PersistentMemoryAllocator> allocator, |
| 1607 int stack_depth, | 1606 int stack_depth, |
| 1608 int64_t process_id) | 1607 int64_t process_id) |
| 1609 : allocator_(std::move(allocator)), | 1608 : allocator_(std::move(allocator)), |
| 1610 stack_memory_size_(ThreadActivityTracker::SizeForStackDepth(stack_depth)), | 1609 stack_memory_size_(ThreadActivityTracker::SizeForStackDepth(stack_depth)), |
| 1611 process_id_(process_id == 0 ? GetCurrentProcId() : process_id), | 1610 process_id_(process_id == 0 ? GetCurrentProcId() : process_id), |
| 1612 this_thread_tracker_(&OnTLSDestroy), | 1611 this_thread_tracker_(&OnTLSDestroy), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1624 kCachedUserDataMemories, | 1623 kCachedUserDataMemories, |
| 1625 /*make_iterable=*/true), | 1624 /*make_iterable=*/true), |
| 1626 process_data_(allocator_->GetAsArray<char>( | 1625 process_data_(allocator_->GetAsArray<char>( |
| 1627 AllocateFrom(allocator_.get(), | 1626 AllocateFrom(allocator_.get(), |
| 1628 kTypeIdProcessDataRecordFree, | 1627 kTypeIdProcessDataRecordFree, |
| 1629 kProcessDataSize, | 1628 kProcessDataSize, |
| 1630 kTypeIdProcessDataRecord), | 1629 kTypeIdProcessDataRecord), |
| 1631 kTypeIdProcessDataRecord, | 1630 kTypeIdProcessDataRecord, |
| 1632 kProcessDataSize), | 1631 kProcessDataSize), |
| 1633 kProcessDataSize, | 1632 kProcessDataSize, |
| 1634 process_id_), | 1633 process_id_) { |
| 1635 global_data_( | |
| 1636 allocator_->GetAsArray<char>( | |
| 1637 allocator_->Allocate(kGlobalDataSize, kTypeIdGlobalDataRecord), | |
| 1638 kTypeIdGlobalDataRecord, | |
| 1639 kGlobalDataSize), | |
| 1640 kGlobalDataSize, | |
| 1641 process_id_) { | |
| 1642 DCHECK_NE(0, process_id_); | 1634 DCHECK_NE(0, process_id_); |
| 1643 | 1635 |
| 1644 // Ensure that there is no other global object and then make this one such. | 1636 // Ensure that there is no other global object and then make this one such. |
| 1645 DCHECK(!g_tracker_); | 1637 DCHECK(!g_tracker_); |
| 1646 subtle::Release_Store(&g_tracker_, reinterpret_cast<uintptr_t>(this)); | 1638 subtle::Release_Store(&g_tracker_, reinterpret_cast<uintptr_t>(this)); |
| 1647 | 1639 |
| 1648 // The data records must be iterable in order to be found by an analyzer. | 1640 // The data records must be iterable in order to be found by an analyzer. |
| 1649 allocator_->MakeIterable(allocator_->GetAsReference( | 1641 allocator_->MakeIterable(allocator_->GetAsReference( |
| 1650 process_data_.GetBaseAddress(), kTypeIdProcessDataRecord)); | 1642 process_data_.GetBaseAddress(), kTypeIdProcessDataRecord)); |
| 1651 allocator_->MakeIterable(allocator_->GetAsReference( | |
| 1652 global_data_.GetBaseAddress(), kTypeIdGlobalDataRecord)); | |
| 1653 | 1643 |
| 1654 // Note that this process has launched. | 1644 // Note that this process has launched. |
| 1655 SetProcessPhase(PROCESS_LAUNCHED); | 1645 SetProcessPhase(PROCESS_LAUNCHED); |
| 1656 | 1646 |
| 1657 // Fetch and record all activated field trials. | 1647 // Fetch and record all activated field trials. |
| 1658 FieldTrial::ActiveGroups active_groups; | 1648 FieldTrial::ActiveGroups active_groups; |
| 1659 FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | 1649 FieldTrialList::GetActiveFieldTrialGroups(&active_groups); |
| 1660 for (auto& group : active_groups) | 1650 for (auto& group : active_groups) |
| 1661 RecordFieldTrial(group.trial_name, group.group_name); | 1651 RecordFieldTrial(group.trial_name, group.group_name); |
| 1662 } | 1652 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 : GlobalActivityTracker::ScopedThreadActivity( | 1773 : GlobalActivityTracker::ScopedThreadActivity( |
| 1784 program_counter, | 1774 program_counter, |
| 1785 nullptr, | 1775 nullptr, |
| 1786 Activity::ACT_PROCESS_WAIT, | 1776 Activity::ACT_PROCESS_WAIT, |
| 1787 ActivityData::ForProcess(process->Pid()), | 1777 ActivityData::ForProcess(process->Pid()), |
| 1788 /*lock_allowed=*/true) {} | 1778 /*lock_allowed=*/true) {} |
| 1789 #endif | 1779 #endif |
| 1790 | 1780 |
| 1791 } // namespace debug | 1781 } // namespace debug |
| 1792 } // namespace base | 1782 } // namespace base |
| OLD | NEW |