| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Tool to log the execution of the process (Chrome). Writes logs containing | 5 // Tool to log the execution of the process (Chrome). Writes logs containing |
| 6 // time and address of the callback being called for the first time. | 6 // time and address of the callback being called for the first time. |
| 7 // | 7 // |
| 8 // For performance reasons logs are buffered. Every thread has its own buffer | 8 // For performance reasons logs are buffered. Every thread has its own buffer |
| 9 // and log file so the contention between threads is minimal. As a side-effect, | 9 // and log file so the contention between threads is minimal. As a side-effect, |
| 10 // functions called might be mentioned in many thread logs. | 10 // functions called might be mentioned in many thread logs. |
| 11 // | 11 // |
| 12 // A special thread is created in the process to periodically flush logs for all | 12 // A special thread is created in the process to periodically flush logs for all |
| 13 // threads in case the thread had stopped before flushing its logs. | 13 // threads in case the thread had stopped before flushing its logs. |
| 14 // | 14 // |
| 15 // Also note that the instrumentation code is self-activated. It begins to | 15 // Also note that the instrumentation code is self-activated. It begins to |
| 16 // record the log data when it is called first, including the run-time startup. | 16 // record the log data when it is called first, including the run-time startup. |
| 17 // Have it in mind when modifying it, in particular do not use global objects | 17 // Have it in mind when modifying it, in particular do not use global objects |
| 18 // with constructors as they are called during startup (too late for us). | 18 // with constructors as they are called during startup (too late for us). |
| 19 | 19 |
| 20 #ifndef TOOLS_CYGPROFILE_CYGPROFILE_H_ | 20 #ifndef TOOLS_CYGPROFILE_CYGPROFILE_H_ |
| 21 #define TOOLS_CYGPROFILE_CYGPROFILE_H_ | 21 #define TOOLS_CYGPROFILE_CYGPROFILE_H_ |
| 22 | 22 |
| 23 #include <vector> | |
| 24 | |
| 25 #include <sys/time.h> | 23 #include <sys/time.h> |
| 26 #include <sys/types.h> | 24 #include <sys/types.h> |
| 27 | 25 |
| 26 #include <memory> |
| 27 #include <vector> |
| 28 |
| 28 #include "base/callback.h" | 29 #include "base/callback.h" |
| 29 #include "base/containers/hash_tables.h" | 30 #include "base/containers/hash_tables.h" |
| 30 #include "base/macros.h" | 31 #include "base/macros.h" |
| 31 #include "base/memory/scoped_ptr.h" | |
| 32 #include "base/synchronization/lock.h" | 32 #include "base/synchronization/lock.h" |
| 33 #include "build/build_config.h" | 33 #include "build/build_config.h" |
| 34 | 34 |
| 35 #if !defined(OS_ANDROID) | 35 #if !defined(OS_ANDROID) |
| 36 // This is only supported on Android thanks to the fact that on Android | 36 // This is only supported on Android thanks to the fact that on Android |
| 37 // processes (other than the system's zygote) don't fork. | 37 // processes (other than the system's zygote) don't fork. |
| 38 // | 38 // |
| 39 // To make cygprofile truly work (i.e. without any deadlock) on Chrome | 39 // To make cygprofile truly work (i.e. without any deadlock) on Chrome |
| 40 // platforms that use fork(), cygprofile.cc should be written in a way that | 40 // platforms that use fork(), cygprofile.cc should be written in a way that |
| 41 // guarantees that: | 41 // guarantees that: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 // Used for testing. The provided callbacks are used for testing to | 133 // Used for testing. The provided callbacks are used for testing to |
| 134 // synchronize the internal thread with the unit test running on the main | 134 // synchronize the internal thread with the unit test running on the main |
| 135 // thread. | 135 // thread. |
| 136 ThreadLogsManager(const base::Closure& wait_callback, | 136 ThreadLogsManager(const base::Closure& wait_callback, |
| 137 const base::Closure& notify_callback); | 137 const base::Closure& notify_callback); |
| 138 | 138 |
| 139 ~ThreadLogsManager(); | 139 ~ThreadLogsManager(); |
| 140 | 140 |
| 141 // Can be called from any thread. | 141 // Can be called from any thread. |
| 142 void AddLog(scoped_ptr<ThreadLog> new_log); | 142 void AddLog(std::unique_ptr<ThreadLog> new_log); |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 void StartInternalFlushThread_Locked(); | 145 void StartInternalFlushThread_Locked(); |
| 146 | 146 |
| 147 // Flush thread's entry point. | 147 // Flush thread's entry point. |
| 148 void FlushAllLogsOnFlushThread(); | 148 void FlushAllLogsOnFlushThread(); |
| 149 | 149 |
| 150 // Used to make the internal thread sleep before each flush iteration. | 150 // Used to make the internal thread sleep before each flush iteration. |
| 151 const base::Closure wait_callback_; | 151 const base::Closure wait_callback_; |
| 152 // Used to trigger a notification when a flush happened on the internal | 152 // Used to trigger a notification when a flush happened on the internal |
| 153 // thread. | 153 // thread. |
| 154 const base::Closure notify_callback_; | 154 const base::Closure notify_callback_; |
| 155 | 155 |
| 156 // Protects the state below. | 156 // Protects the state below. |
| 157 base::Lock lock_; | 157 base::Lock lock_; |
| 158 scoped_ptr<Thread> flush_thread_; | 158 std::unique_ptr<Thread> flush_thread_; |
| 159 std::vector<ThreadLog*> logs_; | 159 std::vector<ThreadLog*> logs_; |
| 160 | 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(ThreadLogsManager); | 161 DISALLOW_COPY_AND_ASSIGN(ThreadLogsManager); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 } // namespace cygprofile | 164 } // namespace cygprofile |
| 165 | 165 |
| 166 #endif // TOOLS_CYGPROFILE_CYGPROFILE_H_ | 166 #endif // TOOLS_CYGPROFILE_CYGPROFILE_H_ |
| OLD | NEW |