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 // Activity tracking provides a low-overhead method of collecting information | 5 // Activity tracking provides a low-overhead method of collecting information |
6 // about the state of the application for analysis both while it is running | 6 // about the state of the application for analysis both while it is running |
7 // and after it has terminated unexpectedly. Its primary purpose is to help | 7 // and after it has terminated unexpectedly. Its primary purpose is to help |
8 // locate reasons the browser becomes unresponsive by providing insight into | 8 // locate reasons the browser becomes unresponsive by providing insight into |
9 // what all the various threads and processes are (or were) doing. | 9 // what all the various threads and processes are (or were) doing. |
10 | 10 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 } | 125 } |
126 }; | 126 }; |
127 | 127 |
128 // A "null" activity-data that can be passed to indicate "do not change". | 128 // A "null" activity-data that can be passed to indicate "do not change". |
129 extern const ActivityData kNullActivityData; | 129 extern const ActivityData kNullActivityData; |
130 | 130 |
131 | 131 |
132 // A helper class that is used for managing memory allocations within a | 132 // A helper class that is used for managing memory allocations within a |
133 // persistent memory allocator. Instances of this class are NOT thread-safe. | 133 // persistent memory allocator. Instances of this class are NOT thread-safe. |
134 // Use from a single thread or protect access with a lock. | 134 // Use from a single thread or protect access with a lock. |
135 class ActivityTrackerMemoryAllocator { | 135 class BASE_EXPORT ActivityTrackerMemoryAllocator { |
136 public: | 136 public: |
137 using Reference = PersistentMemoryAllocator::Reference; | 137 using Reference = PersistentMemoryAllocator::Reference; |
138 | 138 |
139 // Creates a instance for allocating objects of a fixed |object_type|, a | 139 // Creates a instance for allocating objects of a fixed |object_type|, a |
140 // corresponding |object_free| type, and the |object_size|. An internal | 140 // corresponding |object_free| type, and the |object_size|. An internal |
141 // cache of the last |cache_size| released references will be kept for | 141 // cache of the last |cache_size| released references will be kept for |
142 // quick future fetches. If |make_iterable| then allocated objects will | 142 // quick future fetches. If |make_iterable| then allocated objects will |
143 // be marked "iterable" in the allocator. | 143 // be marked "iterable" in the allocator. |
144 ActivityTrackerMemoryAllocator(PersistentMemoryAllocator* allocator, | 144 ActivityTrackerMemoryAllocator(PersistentMemoryAllocator* allocator, |
145 uint32_t object_type, | 145 uint32_t object_type, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 SIGNED_VALUE, | 300 SIGNED_VALUE, |
301 UNSIGNED_VALUE, | 301 UNSIGNED_VALUE, |
302 }; | 302 }; |
303 | 303 |
304 class BASE_EXPORT TypedValue { | 304 class BASE_EXPORT TypedValue { |
305 public: | 305 public: |
306 TypedValue(); | 306 TypedValue(); |
307 TypedValue(const TypedValue& other); | 307 TypedValue(const TypedValue& other); |
308 ~TypedValue(); | 308 ~TypedValue(); |
309 | 309 |
310 ValueType type() const { return type_; } | |
311 | |
310 // These methods return the extracted value in the correct format. | 312 // These methods return the extracted value in the correct format. |
311 StringPiece Get() const; | 313 StringPiece Get() const; |
312 StringPiece GetString() const; | 314 StringPiece GetString() const; |
313 bool GetBool() const; | 315 bool GetBool() const; |
314 char GetChar() const; | 316 char GetChar() const; |
315 int64_t GetInt() const; | 317 int64_t GetInt() const; |
316 uint64_t GetUint() const; | 318 uint64_t GetUint() const; |
317 | 319 |
318 // These methods return references to process memory as originally provided | 320 // These methods return references to process memory as originally provided |
319 // to corresponding Set calls. USE WITH CAUTION! There is no guarantee that | 321 // to corresponding Set calls. USE WITH CAUTION! There is no guarantee that |
320 // the referenced memory is assessible or useful. It's possible that: | 322 // the referenced memory is assessible or useful. It's possible that: |
321 // - the memory was free'd and reallocated for a different purpose | 323 // - the memory was free'd and reallocated for a different purpose |
322 // - the memory has been released back to the OS | 324 // - the memory has been released back to the OS |
323 // - the memory belongs to a different process's address space | 325 // - the memory belongs to a different process's address space |
324 // Dereferencing the returned StringPiece when the memory is not accessible | 326 // Dereferencing the returned StringPiece when the memory is not accessible |
325 // will cause the program to SEGV! | 327 // will cause the program to SEGV! |
326 StringPiece GetReference() const; | 328 StringPiece GetReference() const; |
327 StringPiece GetStringReference() const; | 329 StringPiece GetStringReference() const; |
328 | 330 |
329 private: | 331 private: |
330 friend class ActivityUserData; | 332 friend class ActivityUserData; |
331 | 333 |
332 ValueType type; | 334 ValueType type_; |
bcwhite
2017/01/10 18:00:38
Thanks. I think I started this as a struct is why
manzagop (departed)
2017/01/10 18:55:48
Acknowledged.
| |
333 uint64_t short_value; // Used to hold copy of numbers, etc. | 335 uint64_t short_value_; // Used to hold copy of numbers, etc. |
334 std::string long_value; // Used to hold copy of raw/string data. | 336 std::string long_value_; // Used to hold copy of raw/string data. |
335 StringPiece ref_value; // Used to hold reference to external data. | 337 StringPiece ref_value_; // Used to hold reference to external data. |
336 }; | 338 }; |
337 | 339 |
338 using Snapshot = std::map<std::string, TypedValue>; | 340 using Snapshot = std::map<std::string, TypedValue>; |
339 | 341 |
340 ActivityUserData(void* memory, size_t size); | 342 ActivityUserData(void* memory, size_t size); |
341 ~ActivityUserData(); | 343 ~ActivityUserData(); |
342 | 344 |
343 // Gets the unique ID number for this user data. If this changes then the | 345 // Gets the unique ID number for this user data. If this changes then the |
344 // contents have been overwritten by another thread. The return value is | 346 // contents have been overwritten by another thread. The return value is |
345 // always non-zero unless it's actually just a data "sink". | 347 // always non-zero unless it's actually just a data "sink". |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 void ChangeTypeAndData(Activity::Type type, const ActivityData& data); | 532 void ChangeTypeAndData(Activity::Type type, const ActivityData& data); |
531 | 533 |
532 protected: | 534 protected: |
533 // The thread tracker to which this object reports. It can be null if | 535 // The thread tracker to which this object reports. It can be null if |
534 // activity tracking is not (yet) enabled. | 536 // activity tracking is not (yet) enabled. |
535 ThreadActivityTracker* const tracker_; | 537 ThreadActivityTracker* const tracker_; |
536 | 538 |
537 // An identifier that indicates a specific activity on the stack. | 539 // An identifier that indicates a specific activity on the stack. |
538 ActivityId activity_id_; | 540 ActivityId activity_id_; |
539 | 541 |
542 private: | |
540 DISALLOW_COPY_AND_ASSIGN(ScopedActivity); | 543 DISALLOW_COPY_AND_ASSIGN(ScopedActivity); |
541 }; | 544 }; |
542 | 545 |
543 // A ThreadActivityTracker runs on top of memory that is managed externally. | 546 // A ThreadActivityTracker runs on top of memory that is managed externally. |
544 // It must be large enough for the internal header and a few Activity | 547 // It must be large enough for the internal header and a few Activity |
545 // blocks. See SizeForStackDepth(). | 548 // blocks. See SizeForStackDepth(). |
546 ThreadActivityTracker(void* base, size_t size); | 549 ThreadActivityTracker(void* base, size_t size); |
547 virtual ~ThreadActivityTracker(); | 550 virtual ~ThreadActivityTracker(); |
548 | 551 |
549 // Indicates that an activity has started from a given |origin| address in | 552 // Indicates that an activity has started from a given |origin| address in |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 ScopedProcessWaitActivity(const void* program_counter, | 955 ScopedProcessWaitActivity(const void* program_counter, |
953 const base::Process* process); | 956 const base::Process* process); |
954 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); | 957 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); |
955 }; | 958 }; |
956 #endif | 959 #endif |
957 | 960 |
958 } // namespace debug | 961 } // namespace debug |
959 } // namespace base | 962 } // namespace base |
960 | 963 |
961 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ | 964 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ |
OLD | NEW |