Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: base/debug/activity_tracker.h

Issue 2422213002: Added support for storing arbitrary user data. (Closed)
Patch Set: addressed comments by PA Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #ifndef BASE_DEBUG_ACTIVITY_TRACKER_H_ 11 #ifndef BASE_DEBUG_ACTIVITY_TRACKER_H_
12 #define BASE_DEBUG_ACTIVITY_TRACKER_H_ 12 #define BASE_DEBUG_ACTIVITY_TRACKER_H_
13 13
14 // std::atomic is undesired due to performance issues when used as global 14 // std::atomic is undesired due to performance issues when used as global
15 // variables. There are no such instances here. This module uses the 15 // variables. There are no such instances here. This module uses the
16 // PersistentMemoryAllocator which also uses std::atomic and is written 16 // PersistentMemoryAllocator which also uses std::atomic and is written
17 // by the same author. 17 // by the same author.
18 #include <atomic> 18 #include <atomic>
19 #include <map>
19 #include <memory> 20 #include <memory>
20 #include <string> 21 #include <string>
21 #include <vector> 22 #include <vector>
22 23
23 #include "base/base_export.h" 24 #include "base/base_export.h"
25 #include "base/gtest_prod_util.h"
24 #include "base/location.h" 26 #include "base/location.h"
25 #include "base/metrics/persistent_memory_allocator.h" 27 #include "base/metrics/persistent_memory_allocator.h"
26 #include "base/threading/platform_thread.h" 28 #include "base/threading/platform_thread.h"
27 #include "base/threading/thread_checker.h" 29 #include "base/threading/thread_checker.h"
28 #include "base/threading/thread_local_storage.h" 30 #include "base/threading/thread_local_storage.h"
29 31
30 namespace base { 32 namespace base {
31 33
32 struct PendingTask; 34 struct PendingTask;
33 35
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // A helper class that is used for managing memory allocations within a 131 // A helper class that is used for managing memory allocations within a
130 // persistent memory allocator. Instances of this class are NOT thread-safe. 132 // persistent memory allocator. Instances of this class are NOT thread-safe.
131 // Use from a single thread or protect access with a lock. 133 // Use from a single thread or protect access with a lock.
132 class ActivityTrackerMemoryAllocator { 134 class ActivityTrackerMemoryAllocator {
133 public: 135 public:
134 using Reference = PersistentMemoryAllocator::Reference; 136 using Reference = PersistentMemoryAllocator::Reference;
135 137
136 // Creates a instance for allocating objects of a fixed |object_type|, a 138 // Creates a instance for allocating objects of a fixed |object_type|, a
137 // corresponding |object_free| type, and the |object_size|. An internal 139 // corresponding |object_free| type, and the |object_size|. An internal
138 // cache of the last |cache_size| released references will be kept for 140 // cache of the last |cache_size| released references will be kept for
139 // quick future fetches. 141 // quick future fetches. If |make_iterable| then allocated objects will
142 // be marked "iterable" in the allocator.
140 ActivityTrackerMemoryAllocator(PersistentMemoryAllocator* allocator, 143 ActivityTrackerMemoryAllocator(PersistentMemoryAllocator* allocator,
141 uint32_t object_type, 144 uint32_t object_type,
142 uint32_t object_free_type, 145 uint32_t object_free_type,
143 size_t object_size, 146 size_t object_size,
144 size_t cache_size); 147 size_t cache_size,
148 bool make_iterable);
145 ~ActivityTrackerMemoryAllocator(); 149 ~ActivityTrackerMemoryAllocator();
146 150
147 // Gets a reference to an object of the configured type. This can return 151 // Gets a reference to an object of the configured type. This can return
148 // a null reference if it was not possible to allocate the memory. 152 // a null reference if it was not possible to allocate the memory.
149 Reference GetObjectReference(); 153 Reference GetObjectReference();
150 154
151 // Returns an object to the "free" pool. 155 // Returns an object to the "free" pool.
152 void ReleaseObjectReference(Reference ref); 156 void ReleaseObjectReference(Reference ref);
153 157
154 // The current "used size" of the internal cache, visible for testing. 158 // The current "used size" of the internal cache, visible for testing.
155 size_t cache_used() const { return cache_used_; } 159 size_t cache_used() const { return cache_used_; }
156 160
157 private: 161 private:
158 PersistentMemoryAllocator* const allocator_; 162 PersistentMemoryAllocator* const allocator_;
159 const uint32_t object_type_; 163 const uint32_t object_type_;
160 const uint32_t object_free_type_; 164 const uint32_t object_free_type_;
161 const size_t object_size_; 165 const size_t object_size_;
162 const size_t cache_size_; 166 const size_t cache_size_;
167 const bool make_iterable_;
163 168
164 // An iterator for going through persistent memory looking for free'd objects. 169 // An iterator for going through persistent memory looking for free'd objects.
165 PersistentMemoryAllocator::Iterator iterator_; 170 PersistentMemoryAllocator::Iterator iterator_;
166 171
167 // The cache of released object memories. 172 // The cache of released object memories.
168 std::unique_ptr<Reference[]> cache_values_; 173 std::unique_ptr<Reference[]> cache_values_;
169 size_t cache_used_; 174 size_t cache_used_;
170 175
171 DISALLOW_COPY_AND_ASSIGN(ActivityTrackerMemoryAllocator); 176 DISALLOW_COPY_AND_ASSIGN(ActivityTrackerMemoryAllocator);
172 }; 177 };
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // it null. 234 // it null.
230 uint64_t origin_address; 235 uint64_t origin_address;
231 236
232 // Array of program-counters that make up the top of the call stack. 237 // Array of program-counters that make up the top of the call stack.
233 // Despite the fixed size, this list is always null-terminated. Entries 238 // Despite the fixed size, this list is always null-terminated. Entries
234 // after the terminator have no meaning and may or may not also be null. 239 // after the terminator have no meaning and may or may not also be null.
235 // The list will be completely empty if call-stack collection is not 240 // The list will be completely empty if call-stack collection is not
236 // enabled. 241 // enabled.
237 uint64_t call_stack[kActivityCallStackSize]; 242 uint64_t call_stack[kActivityCallStackSize];
238 243
244 // Reference to arbitrary user data within the persistent memory segment.
245 uint32_t user_data;
246
239 // The (enumerated) type of the activity. This defines what fields of the 247 // The (enumerated) type of the activity. This defines what fields of the
240 // |data| record are valid. 248 // |data| record are valid.
241 uint8_t activity_type; 249 uint8_t activity_type;
242 250
243 // Padding to ensure that the next member begins on a 64-bit boundary 251 // Padding to ensure that the next member begins on a 64-bit boundary
244 // even on 32-bit builds which ensures inter-operability between CPU 252 // even on 32-bit builds which ensures inter-operability between CPU
245 // architectures. New fields can be taken from this space. 253 // architectures. New fields can be taken from this space.
246 uint8_t padding[7]; 254 uint8_t padding[3];
247 255
248 // Information specific to the |activity_type|. 256 // Information specific to the |activity_type|.
249 ActivityData data; 257 ActivityData data;
250 258
251 static void FillFrom(Activity* activity, 259 static void FillFrom(Activity* activity,
252 const void* origin, 260 const void* origin,
253 Type type, 261 Type type,
254 const ActivityData& data); 262 const ActivityData& data);
255 }; 263 };
256 264
(...skipping 20 matching lines...) Expand all
277 // The current stack of activities that are underway for this thread. It 285 // The current stack of activities that are underway for this thread. It
278 // is limited in its maximum size with later entries being left off. 286 // is limited in its maximum size with later entries being left off.
279 std::vector<Activity> activity_stack; 287 std::vector<Activity> activity_stack;
280 288
281 // The current total depth of the activity stack, including those later 289 // The current total depth of the activity stack, including those later
282 // entries not recorded in the |activity_stack| vector. 290 // entries not recorded in the |activity_stack| vector.
283 uint32_t activity_stack_depth = 0; 291 uint32_t activity_stack_depth = 0;
284 }; 292 };
285 293
286 294
295 // This class manages arbitrary user data that can be associated with activities
296 // done by a thread by supporting key/value pairs of any type. This can provide
297 // additional information during debugging. It is also used to store arbitrary
298 // global data. All updates must be done from the same thread.
299 class BASE_EXPORT ActivityUserData {
300 // List of known value type. REFERENCE types must immediately follow the non-
301 // external types.
302 enum ValueType : uint8_t {
303 END_OF_VALUES = 0,
304 RAW_VALUE,
305 RAW_VALUE_REFERENCE,
306 STRING_VALUE,
307 STRING_VALUE_REFERENCE,
308 CHAR_VALUE,
309 SIGNED_VALUE,
310 UNSIGNED_VALUE,
311 };
312
313 public:
314 ActivityUserData(void* memory, size_t size);
315 ~ActivityUserData();
316
317 // Writes a |value| (as part of a key/value pair) that will be included with
318 // the activity in any reports. The same |name| can be written multiple times
319 // with each successive call overwriting the previously stored |value|. For
320 // raw and string values, the maximum size of successive writes is limited by
321 // the first call. The length of "name" is limited to 255 characters.
322 //
323 // This information is stored on a "best effort" basis. It may be dropped if
324 // the memory buffer is full or the associated activity is beyond the maximum
325 // recording depth.
326 void Set(StringPiece name, const void* memory, size_t size) {
327 Set(name, RAW_VALUE, memory, size);
328 }
329 void SetString(StringPiece name, StringPiece value) {
330 Set(name, STRING_VALUE, value.data(), value.length());
331 }
332 void SetChar(StringPiece name, char value) {
333 Set(name, CHAR_VALUE, &value, sizeof(value));
334 }
335 void SetInt(StringPiece name, int64_t value) {
336 Set(name, SIGNED_VALUE, &value, sizeof(value));
337 }
338 void SetUint(StringPiece name, uint64_t value) {
339 Set(name, UNSIGNED_VALUE, &value, sizeof(value));
340 }
341
342 // These function as above but don't actually copy the data into the
343 // persistent memory. They store unaltered pointers along with a size. These
344 // can be used in conjuction with a memory dump to find certain large pieces
345 // of information.
346 void SetReference(StringPiece name, const void* memory, size_t size) {
347 SetReference(name, RAW_VALUE_REFERENCE, memory, size);
348 }
349 void SetStringReference(StringPiece name, StringPiece value) {
350 SetReference(name, STRING_VALUE_REFERENCE, value.data(), value.length());
351 }
352
353 private:
354 FRIEND_TEST_ALL_PREFIXES(ActivityTrackerTest, UserDataTest);
355
356 enum : size_t { kMemoryAlignment = sizeof(uint64_t) };
357
358 // A structure used to reference data held outside of persistent memory.
359 struct ReferenceRecord {
360 uint64_t address;
361 uint64_t size;
362 };
363
364 // Header to a key/value record held in persistent memory.
365 struct Header {
366 std::atomic<uint8_t> type; // Encoded ValueType
367 uint8_t name_size; // Length of "name" key.
368 std::atomic<uint16_t> value_size; // Actual size of of the stored value.
369 uint16_t record_size; // Total storage of name, value, header.
370 };
371
372 // This record is used to hold known value is a map so that they can be
373 // found and overwritten later.
374 struct ValueInfo {
375 ValueInfo();
376 ValueInfo(ValueInfo&&);
377 ~ValueInfo();
378
379 StringPiece name; // The "key" of the record.
380 ValueType type; // The type of the value.
381 void* memory; // Where the "value" is held.
382 std::atomic<uint16_t>* size_ptr; // Address of the actual size of value.
383 size_t extent; // The total storage of the value,
384 }; // typically rounded up for alignment.
385
386 void Set(StringPiece name, ValueType type, const void* memory, size_t size);
387 void SetReference(StringPiece name,
388 ValueType type,
389 const void* memory,
390 size_t size);
391
392 // TODO(bcwhite): Add Get() methods for Analyzer to use.
393
394 std::map<StringPiece, ValueInfo> values_;
395
396 char* memory_;
397 size_t available_;
398
399 base::ThreadChecker thread_checker_;
400
401 DISALLOW_COPY_AND_ASSIGN(ActivityUserData);
402 };
403
404
287 // This class manages tracking a stack of activities for a single thread in 405 // This class manages tracking a stack of activities for a single thread in
288 // a persistent manner, implementing a bounded-size stack in a fixed-size 406 // a persistent manner, implementing a bounded-size stack in a fixed-size
289 // memory allocation. In order to support an operational mode where another 407 // memory allocation. In order to support an operational mode where another
290 // thread is analyzing this data in real-time, atomic operations are used 408 // thread is analyzing this data in real-time, atomic operations are used
291 // where necessary to guarantee a consistent view from the outside. 409 // where necessary to guarantee a consistent view from the outside.
292 // 410 //
293 // This class is not generally used directly but instead managed by the 411 // This class is not generally used directly but instead managed by the
294 // GlobalActivityTracker instance and updated using Scoped*Activity local 412 // GlobalActivityTracker instance and updated using Scoped*Activity local
295 // objects. 413 // objects.
296 class BASE_EXPORT ThreadActivityTracker { 414 class BASE_EXPORT ThreadActivityTracker {
297 public: 415 public:
416 using ActivityId = uint32_t;
417
298 // This is the base class for having the compiler manage an activity on the 418 // This is the base class for having the compiler manage an activity on the
299 // tracker's stack. It does nothing but call methods on the passed |tracker| 419 // tracker's stack. It does nothing but call methods on the passed |tracker|
300 // if it is not null, making it safe (and cheap) to create these objects 420 // if it is not null, making it safe (and cheap) to create these objects
301 // even if activity tracking is not enabled. 421 // even if activity tracking is not enabled.
302 class BASE_EXPORT ScopedActivity { 422 class BASE_EXPORT ScopedActivity {
303 public: 423 public:
304 ScopedActivity(ThreadActivityTracker* tracker, 424 ScopedActivity(ThreadActivityTracker* tracker,
305 const void* origin, 425 const void* origin,
306 Activity::Type type, 426 Activity::Type type,
307 const ActivityData& data) 427 const ActivityData& data);
308 : tracker_(tracker) { 428 ~ScopedActivity();
309 if (tracker_)
310 tracker_->PushActivity(origin, type, data);
311 }
312 429
313 ~ScopedActivity() { 430 // Changes some basic metadata about the activity.
314 if (tracker_) 431 void ChangeTypeAndData(Activity::Type type, const ActivityData& data);
315 tracker_->PopActivity();
316 }
317 432
318 void ChangeTypeAndData(Activity::Type type, const ActivityData& data) { 433 // Returns an object for manipulating user data.
319 if (tracker_) 434 ActivityUserData& user_data();
320 tracker_->ChangeActivity(type, data);
321 }
322 435
323 private: 436 private:
324 // The thread tracker to which this object reports. It can be null if 437 // The thread tracker to which this object reports. It can be null if
325 // activity tracking is not (yet) enabled. 438 // activity tracking is not (yet) enabled.
326 ThreadActivityTracker* const tracker_; 439 ThreadActivityTracker* const tracker_;
327 440
441 // An identifier that indicates a specific activity on the stack.
442 ActivityId activity_id_;
443
444 // An object that manages additional user data, created only upon request.
445 std::unique_ptr<ActivityUserData> user_data_;
446
328 DISALLOW_COPY_AND_ASSIGN(ScopedActivity); 447 DISALLOW_COPY_AND_ASSIGN(ScopedActivity);
329 }; 448 };
330 449
331 // A ThreadActivityTracker runs on top of memory that is managed externally. 450 // A ThreadActivityTracker runs on top of memory that is managed externally.
332 // It must be large enough for the internal header and a few Activity 451 // It must be large enough for the internal header and a few Activity
333 // blocks. See SizeForStackDepth(). 452 // blocks. See SizeForStackDepth().
334 ThreadActivityTracker(void* base, size_t size); 453 ThreadActivityTracker(void* base, size_t size);
335 virtual ~ThreadActivityTracker(); 454 virtual ~ThreadActivityTracker();
336 455
337 // Indicates that an activity has started from a given |origin| address in 456 // Indicates that an activity has started from a given |origin| address in
338 // the code, though it can be null if the creator's address is not known. 457 // the code, though it can be null if the creator's address is not known.
339 // The |type| and |data| describe the activity. 458 // The |type| and |data| describe the activity. Returned is an ID that can
340 void PushActivity(const void* origin, 459 // be used to adjust the pushed activity.
341 Activity::Type type, 460 ActivityId PushActivity(const void* origin,
342 const ActivityData& data); 461 Activity::Type type,
462 const ActivityData& data);
343 463
344 // Changes the activity |type| and |data| of the top-most entry on the stack. 464 // Changes the activity |type| and |data| of the top-most entry on the stack.
345 // This is useful if the information has changed and it is desireable to 465 // This is useful if the information has changed and it is desireable to
346 // track that change without creating a new stack entry. If the type is 466 // track that change without creating a new stack entry. If the type is
347 // ACT_NULL or the data is kNullActivityData then that value will remain 467 // ACT_NULL or the data is kNullActivityData then that value will remain
348 // unchanged. The type, if changed, must remain in the same category. 468 // unchanged. The type, if changed, must remain in the same category.
349 // Changing both is not atomic so a snapshot operation could occur between 469 // Changing both is not atomic so a snapshot operation could occur between
350 // the update of |type| and |data| or between update of |data| fields. 470 // the update of |type| and |data| or between update of |data| fields.
351 void ChangeActivity(Activity::Type type, const ActivityData& data); 471 void ChangeActivity(ActivityId id,
472 Activity::Type type,
473 const ActivityData& data);
352 474
353 // Indicates that an activity has completed. 475 // Indicates that an activity has completed.
354 void PopActivity(); 476 void PopActivity(ActivityId id);
477
478 // Returns an object capable of storing arbitrary user data.
479 std::unique_ptr<ActivityUserData> GetUserData(ActivityId id);
355 480
356 // Returns whether the current data is valid or not. It is not valid if 481 // Returns whether the current data is valid or not. It is not valid if
357 // corruption has been detected in the header or other data structures. 482 // corruption has been detected in the header or other data structures.
358 bool IsValid() const; 483 bool IsValid() const;
359 484
360 // Gets a copy of the tracker contents for analysis. Returns false if a 485 // Gets a copy of the tracker contents for analysis. Returns false if a
361 // snapshot was not possible, perhaps because the data is not valid; the 486 // snapshot was not possible, perhaps because the data is not valid; the
362 // contents of |output_snapshot| are undefined in that case. The current 487 // contents of |output_snapshot| are undefined in that case. The current
363 // implementation does not support concurrent snapshot operations. 488 // implementation does not support concurrent snapshot operations.
364 bool Snapshot(ActivitySnapshot* output_snapshot) const; 489 bool Snapshot(ActivitySnapshot* output_snapshot) const;
(...skipping 27 matching lines...) Expand all
392 // for the data to be analyzed by a parallel process or even post-mortem. 517 // for the data to be analyzed by a parallel process or even post-mortem.
393 class BASE_EXPORT GlobalActivityTracker { 518 class BASE_EXPORT GlobalActivityTracker {
394 public: 519 public:
395 // Type identifiers used when storing in persistent memory so they can be 520 // Type identifiers used when storing in persistent memory so they can be
396 // identified during extraction; the first 4 bytes of the SHA1 of the name 521 // identified during extraction; the first 4 bytes of the SHA1 of the name
397 // is used as a unique integer. A "version number" is added to the base 522 // is used as a unique integer. A "version number" is added to the base
398 // so that, if the structure of that object changes, stored older versions 523 // so that, if the structure of that object changes, stored older versions
399 // will be safely ignored. These are public so that an external process 524 // will be safely ignored. These are public so that an external process
400 // can recognize records of this type within an allocator. 525 // can recognize records of this type within an allocator.
401 enum : uint32_t { 526 enum : uint32_t {
402 kTypeIdActivityTracker = 0x5D7381AF + 1, // SHA1(ActivityTracker) v1 527 kTypeIdActivityTracker = 0x5D7381AF + 2, // SHA1(ActivityTracker) v2
528 kTypeIdUserDataRecord = 0x615EDDD7 + 1, // SHA1(UserDataRecord) v1
529 kTypeIdGlobalDataRecord = 0xAFE61ABE + 1, // SHA1(GlobalDataRecord) v1
530
403 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker, 531 kTypeIdActivityTrackerFree = ~kTypeIdActivityTracker,
532 kTypeIdUserDataRecordFree = ~kTypeIdUserDataRecord,
404 }; 533 };
405 534
406 // This is a thin wrapper around the thread-tracker's ScopedActivity that 535 // This is a thin wrapper around the thread-tracker's ScopedActivity that
407 // accesses the global tracker to provide some of the information, notably 536 // accesses the global tracker to provide some of the information, notably
408 // which thread-tracker to use. It is safe to create even if activity 537 // which thread-tracker to use. It is safe to create even if activity
409 // tracking is not enabled. 538 // tracking is not enabled.
410 class BASE_EXPORT ScopedThreadActivity 539 class BASE_EXPORT ScopedThreadActivity
411 : public ThreadActivityTracker::ScopedActivity { 540 : public ThreadActivityTracker::ScopedActivity {
412 public: 541 public:
413 ScopedThreadActivity(const void* origin, 542 ScopedThreadActivity(const void* origin,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return tracker; 621 return tracker;
493 return CreateTrackerForCurrentThread(); 622 return CreateTrackerForCurrentThread();
494 } 623 }
495 624
496 // Creates an activity-tracker for the current thread. 625 // Creates an activity-tracker for the current thread.
497 ThreadActivityTracker* CreateTrackerForCurrentThread(); 626 ThreadActivityTracker* CreateTrackerForCurrentThread();
498 627
499 // Releases the activity-tracker for the current thread (for testing only). 628 // Releases the activity-tracker for the current thread (for testing only).
500 void ReleaseTrackerForCurrentThreadForTesting(); 629 void ReleaseTrackerForCurrentThreadForTesting();
501 630
631 // Gets a reference to memory for holding user-defined activity data. If
632 // the reference is valid, it's memory will be returned. If not, then a
633 // new reference will be created (and stored) and that memory returned.
634 void* GetUserDataMemory(PersistentMemoryAllocator::Reference* reference);
635
636 // Releases memory for user-defined activity data.
637 void ReleaseUserDataMemory(PersistentMemoryAllocator::Reference* reference);
638
639 // Accesses the global data record for storing arbitrary key/value pairs.
640 ActivityUserData& user_data() { return user_data_; }
641
502 private: 642 private:
503 friend class ActivityTrackerTest; 643 friend class ActivityTrackerTest;
504 644
505 enum : int { 645 enum : int {
506 // The maximum number of threads that can be tracked within a process. If 646 // The maximum number of threads that can be tracked within a process. If
507 // more than this number run concurrently, tracking of new ones may cease. 647 // more than this number run concurrently, tracking of new ones may cease.
508 kMaxThreadCount = 100, 648 kMaxThreadCount = 100,
509 kCachedThreadMemories = 10, 649 kCachedThreadMemories = 10,
650 kCachedUserDataMemories = 10,
510 }; 651 };
511 652
512 // A thin wrapper around the main thread-tracker that keeps additional 653 // A thin wrapper around the main thread-tracker that keeps additional
513 // information that the global tracker needs to handle joined threads. 654 // information that the global tracker needs to handle joined threads.
514 class ManagedActivityTracker : public ThreadActivityTracker { 655 class ManagedActivityTracker : public ThreadActivityTracker {
515 public: 656 public:
516 ManagedActivityTracker(PersistentMemoryAllocator::Reference mem_reference, 657 ManagedActivityTracker(PersistentMemoryAllocator::Reference mem_reference,
517 void* base, 658 void* base,
518 size_t size); 659 size_t size);
519 ~ManagedActivityTracker() override; 660 ~ManagedActivityTracker() override;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 // The activity tracker for the currently executing thread. 696 // The activity tracker for the currently executing thread.
556 base::ThreadLocalStorage::Slot this_thread_tracker_; 697 base::ThreadLocalStorage::Slot this_thread_tracker_;
557 698
558 // The number of thread trackers currently active. 699 // The number of thread trackers currently active.
559 std::atomic<int> thread_tracker_count_; 700 std::atomic<int> thread_tracker_count_;
560 701
561 // A caching memory allocator for thread-tracker objects. 702 // A caching memory allocator for thread-tracker objects.
562 ActivityTrackerMemoryAllocator thread_tracker_allocator_; 703 ActivityTrackerMemoryAllocator thread_tracker_allocator_;
563 base::Lock thread_tracker_allocator_lock_; 704 base::Lock thread_tracker_allocator_lock_;
564 705
706 // A caching memory allocator for user data attached to activity data.
707 ActivityTrackerMemoryAllocator user_data_allocator_;
708 base::Lock user_data_allocator_lock_;
709
710 // An object for holding global arbitrary key value pairs. Values must always
711 // be written from the main UI thread.
712 ActivityUserData user_data_;
713
565 // The active global activity tracker. 714 // The active global activity tracker.
566 static GlobalActivityTracker* g_tracker_; 715 static GlobalActivityTracker* g_tracker_;
567 716
568 DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker); 717 DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker);
569 }; 718 };
570 719
571 720
572 // Record entry in to and out of an arbitrary block of code. 721 // Record entry in to and out of an arbitrary block of code.
573 class BASE_EXPORT ScopedActivity 722 class BASE_EXPORT ScopedActivity
574 : public GlobalActivityTracker::ScopedThreadActivity { 723 : public GlobalActivityTracker::ScopedThreadActivity {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 explicit ScopedProcessWaitActivity(const base::Process* process); 806 explicit ScopedProcessWaitActivity(const base::Process* process);
658 private: 807 private:
659 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); 808 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity);
660 }; 809 };
661 #endif 810 #endif
662 811
663 } // namespace debug 812 } // namespace debug
664 } // namespace base 813 } // namespace base
665 814
666 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ 815 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698