| 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  | 
|    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 <map> | 
|    20 #include <memory> |    20 #include <memory> | 
|    21 #include <string> |    21 #include <string> | 
|    22 #include <vector> |    22 #include <vector> | 
|    23  |    23  | 
 |    24 #include "base/atomicops.h" | 
|    24 #include "base/base_export.h" |    25 #include "base/base_export.h" | 
|    25 #include "base/compiler_specific.h" |    26 #include "base/compiler_specific.h" | 
|    26 #include "base/gtest_prod_util.h" |    27 #include "base/gtest_prod_util.h" | 
|    27 #include "base/location.h" |    28 #include "base/location.h" | 
|    28 #include "base/metrics/persistent_memory_allocator.h" |    29 #include "base/metrics/persistent_memory_allocator.h" | 
|    29 #include "base/strings/utf_string_conversions.h" |    30 #include "base/strings/utf_string_conversions.h" | 
|    30 #include "base/threading/platform_thread.h" |    31 #include "base/threading/platform_thread.h" | 
|    31 #include "base/threading/thread_checker.h" |    32 #include "base/threading/thread_checker.h" | 
|    32 #include "base/threading/thread_local_storage.h" |    33 #include "base/threading/thread_local_storage.h" | 
|    33  |    34  | 
|    34 namespace base { |    35 namespace base { | 
|    35  |    36  | 
|    36 struct PendingTask; |    37 struct PendingTask; | 
|    37  |    38  | 
|    38 class FilePath; |    39 class FilePath; | 
|    39 class Lock; |    40 class Lock; | 
|    40 class PlatformThreadHandle; |    41 class PlatformThreadHandle; | 
|    41 class Process; |    42 class Process; | 
 |    43 class StaticAtomicSequenceNumber; | 
|    42 class WaitableEvent; |    44 class WaitableEvent; | 
|    43  |    45  | 
|    44 namespace debug { |    46 namespace debug { | 
|    45  |    47  | 
|    46 class ThreadActivityTracker; |    48 class ThreadActivityTracker; | 
|    47  |    49  | 
|    48  |    50  | 
|    49 enum : int { |    51 enum : int { | 
|    50   // The maximum number of call-stack addresses stored per activity. This |    52   // The maximum number of call-stack addresses stored per activity. This | 
|    51   // cannot be changed without also changing the version number of the |    53   // cannot be changed without also changing the version number of the | 
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   456   mutable char* memory_; |   458   mutable char* memory_; | 
|   457   mutable size_t available_; |   459   mutable size_t available_; | 
|   458  |   460  | 
|   459   // A pointer to the unique ID for this instance. |   461   // A pointer to the unique ID for this instance. | 
|   460   std::atomic<uint32_t>* const id_; |   462   std::atomic<uint32_t>* const id_; | 
|   461  |   463  | 
|   462   base::ThreadChecker thread_checker_; |   464   base::ThreadChecker thread_checker_; | 
|   463  |   465  | 
|   464   // This ID is used to create unique indentifiers for user data so that it's |   466   // This ID is used to create unique indentifiers for user data so that it's | 
|   465   // possible to tell if the information has been overwritten. |   467   // possible to tell if the information has been overwritten. | 
|   466   static std::atomic<uint32_t> next_id_; |   468   static StaticAtomicSequenceNumber next_id_; | 
|   467  |   469  | 
|   468   DISALLOW_COPY_AND_ASSIGN(ActivityUserData); |   470   DISALLOW_COPY_AND_ASSIGN(ActivityUserData); | 
|   469 }; |   471 }; | 
|   470  |   472  | 
|   471 // This class manages tracking a stack of activities for a single thread in |   473 // This class manages tracking a stack of activities for a single thread in | 
|   472 // a persistent manner, implementing a bounded-size stack in a fixed-size |   474 // a persistent manner, implementing a bounded-size stack in a fixed-size | 
|   473 // memory allocation. In order to support an operational mode where another |   475 // memory allocation. In order to support an operational mode where another | 
|   474 // thread is analyzing this data in real-time, atomic operations are used |   476 // thread is analyzing this data in real-time, atomic operations are used | 
|   475 // where necessary to guarantee a consistent view from the outside. |   477 // where necessary to guarantee a consistent view from the outside. | 
|   476 // |   478 // | 
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   733 #endif  // !defined(OS_NACL) |   735 #endif  // !defined(OS_NACL) | 
|   734  |   736  | 
|   735   // Like above but internally creates an allocator using local heap memory of |   737   // Like above but internally creates an allocator using local heap memory of | 
|   736   // the specified size. This is used primarily for unit tests. |   738   // the specified size. This is used primarily for unit tests. | 
|   737   static void CreateWithLocalMemory(size_t size, |   739   static void CreateWithLocalMemory(size_t size, | 
|   738                                     uint64_t id, |   740                                     uint64_t id, | 
|   739                                     StringPiece name, |   741                                     StringPiece name, | 
|   740                                     int stack_depth); |   742                                     int stack_depth); | 
|   741  |   743  | 
|   742   // Gets the global activity-tracker or null if none exists. |   744   // Gets the global activity-tracker or null if none exists. | 
|   743   static GlobalActivityTracker* Get() { return g_tracker_; } |   745   static GlobalActivityTracker* Get() { | 
 |   746     return reinterpret_cast<GlobalActivityTracker*>( | 
 |   747         subtle::NoBarrier_Load(&g_tracker_)); | 
 |   748   } | 
|   744  |   749  | 
|   745   // Gets the persistent-memory-allocator in which data is stored. Callers |   750   // Gets the persistent-memory-allocator in which data is stored. Callers | 
|   746   // can store additional records here to pass more information to the |   751   // can store additional records here to pass more information to the | 
|   747   // analysis process. |   752   // analysis process. | 
|   748   PersistentMemoryAllocator* allocator() { return allocator_.get(); } |   753   PersistentMemoryAllocator* allocator() { return allocator_.get(); } | 
|   749  |   754  | 
|   750   // Gets the thread's activity-tracker if it exists. This is inline for |   755   // Gets the thread's activity-tracker if it exists. This is inline for | 
|   751   // performance reasons and it uses thread-local-storage (TLS) so that there |   756   // performance reasons and it uses thread-local-storage (TLS) so that there | 
|   752   // is no significant lookup time required to find the one for the calling |   757   // is no significant lookup time required to find the one for the calling | 
|   753   // thread. Ownership remains with the global tracker. |   758   // thread. Ownership remains with the global tracker. | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   899  |   904  | 
|   900   // An object for holding global arbitrary key value pairs. Values must always |   905   // An object for holding global arbitrary key value pairs. Values must always | 
|   901   // be written from the main UI thread. |   906   // be written from the main UI thread. | 
|   902   ActivityUserData user_data_; |   907   ActivityUserData user_data_; | 
|   903  |   908  | 
|   904   // A map of global module information, keyed by module path. |   909   // A map of global module information, keyed by module path. | 
|   905   std::map<const std::string, ModuleInfoRecord*> modules_; |   910   std::map<const std::string, ModuleInfoRecord*> modules_; | 
|   906   base::Lock modules_lock_; |   911   base::Lock modules_lock_; | 
|   907  |   912  | 
|   908   // The active global activity tracker. |   913   // The active global activity tracker. | 
|   909   static GlobalActivityTracker* g_tracker_; |   914   static subtle::AtomicWord g_tracker_; | 
|   910  |   915  | 
|   911   DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker); |   916   DISALLOW_COPY_AND_ASSIGN(GlobalActivityTracker); | 
|   912 }; |   917 }; | 
|   913  |   918  | 
|   914  |   919  | 
|   915 // Record entry in to and out of an arbitrary block of code. |   920 // Record entry in to and out of an arbitrary block of code. | 
|   916 class BASE_EXPORT ScopedActivity |   921 class BASE_EXPORT ScopedActivity | 
|   917     : public GlobalActivityTracker::ScopedThreadActivity { |   922     : public GlobalActivityTracker::ScopedThreadActivity { | 
|   918  public: |   923  public: | 
|   919   // Track activity at the specified FROM_HERE location for an arbitrary |   924   // Track activity at the specified FROM_HERE location for an arbitrary | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1035   ScopedProcessWaitActivity(const void* program_counter, |  1040   ScopedProcessWaitActivity(const void* program_counter, | 
|  1036                             const base::Process* process); |  1041                             const base::Process* process); | 
|  1037   DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); |  1042   DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); | 
|  1038 }; |  1043 }; | 
|  1039 #endif |  1044 #endif | 
|  1040  |  1045  | 
|  1041 }  // namespace debug |  1046 }  // namespace debug | 
|  1042 }  // namespace base |  1047 }  // namespace base | 
|  1043  |  1048  | 
|  1044 #endif  // BASE_DEBUG_ACTIVITY_TRACKER_H_ |  1049 #endif  // BASE_DEBUG_ACTIVITY_TRACKER_H_ | 
| OLD | NEW |