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 | 8 |
9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 } | 851 } |
852 | 852 |
853 void GlobalActivityTracker::ReleaseUserDataMemory( | 853 void GlobalActivityTracker::ReleaseUserDataMemory( |
854 PersistentMemoryAllocator::Reference* reference) { | 854 PersistentMemoryAllocator::Reference* reference) { |
855 DCHECK(*reference); | 855 DCHECK(*reference); |
856 base::AutoLock autolock(user_data_allocator_lock_); | 856 base::AutoLock autolock(user_data_allocator_lock_); |
857 user_data_allocator_.ReleaseObjectReference(*reference); | 857 user_data_allocator_.ReleaseObjectReference(*reference); |
858 *reference = PersistentMemoryAllocator::kReferenceNull; | 858 *reference = PersistentMemoryAllocator::kReferenceNull; |
859 } | 859 } |
860 | 860 |
| 861 void GlobalActivityTracker::RecordLogMessage(StringPiece message) { |
| 862 // Allocate at least one extra byte so the string is NUL terminated. All |
| 863 // memory returned by the allocator is guaranteed to be zeroed. |
| 864 PersistentMemoryAllocator::Reference ref = |
| 865 allocator_->Allocate(message.size() + 1, kTypeIdGlobalLogMessage); |
| 866 char* memory = allocator_->GetAsArray<char>(ref, kTypeIdGlobalLogMessage, |
| 867 message.size() + 1); |
| 868 if (memory) { |
| 869 memcpy(memory, message.data(), message.size()); |
| 870 allocator_->MakeIterable(ref); |
| 871 } |
| 872 } |
| 873 |
861 GlobalActivityTracker::GlobalActivityTracker( | 874 GlobalActivityTracker::GlobalActivityTracker( |
862 std::unique_ptr<PersistentMemoryAllocator> allocator, | 875 std::unique_ptr<PersistentMemoryAllocator> allocator, |
863 int stack_depth) | 876 int stack_depth) |
864 : allocator_(std::move(allocator)), | 877 : allocator_(std::move(allocator)), |
865 stack_memory_size_(ThreadActivityTracker::SizeForStackDepth(stack_depth)), | 878 stack_memory_size_(ThreadActivityTracker::SizeForStackDepth(stack_depth)), |
866 this_thread_tracker_(&OnTLSDestroy), | 879 this_thread_tracker_(&OnTLSDestroy), |
867 thread_tracker_count_(0), | 880 thread_tracker_count_(0), |
868 thread_tracker_allocator_(allocator_.get(), | 881 thread_tracker_allocator_(allocator_.get(), |
869 kTypeIdActivityTracker, | 882 kTypeIdActivityTracker, |
870 kTypeIdActivityTrackerFree, | 883 kTypeIdActivityTrackerFree, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 : GlobalActivityTracker::ScopedThreadActivity( | 1010 : GlobalActivityTracker::ScopedThreadActivity( |
998 program_counter, | 1011 program_counter, |
999 nullptr, | 1012 nullptr, |
1000 Activity::ACT_PROCESS_WAIT, | 1013 Activity::ACT_PROCESS_WAIT, |
1001 ActivityData::ForProcess(process->Pid()), | 1014 ActivityData::ForProcess(process->Pid()), |
1002 /*lock_allowed=*/true) {} | 1015 /*lock_allowed=*/true) {} |
1003 #endif | 1016 #endif |
1004 | 1017 |
1005 } // namespace debug | 1018 } // namespace debug |
1006 } // namespace base | 1019 } // namespace base |
OLD | NEW |