OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_DEBUG_TRACE_EVENT_SYSTEM_H_ |
| 6 #define BASE_DEBUG_TRACE_EVENT_SYSTEM_H_ |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/debug/trace_event_impl.h" |
| 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/process/process_metrics.h" |
| 14 #include "base/timer/timer.h" |
| 15 |
| 16 namespace base { |
| 17 |
| 18 class MessageLoopProxy; |
| 19 |
| 20 namespace debug { |
| 21 |
| 22 // Watches for chrome://tracing to be enabled or disabled. When tracing is |
| 23 // enabled, also enables system events profiling. This class is the preferred |
| 24 // way to turn system tracing on and off. |
| 25 class BASE_EXPORT TraceSystemController |
| 26 : public TraceLog::EnabledStateObserver { |
| 27 public: |
| 28 // |message_loop_proxy| must be a proxy to the primary thread for the client |
| 29 // process, e.g. the UI thread in a browser. |
| 30 explicit TraceSystemController( |
| 31 scoped_refptr<MessageLoopProxy> message_loop_proxy); |
| 32 virtual ~TraceSystemController(); |
| 33 |
| 34 // base::debug::TraceLog::EnabledStateChangedObserver overrides: |
| 35 virtual void OnTraceLogEnabled() OVERRIDE; |
| 36 virtual void OnTraceLogDisabled() OVERRIDE; |
| 37 |
| 38 // Starts system profiling. |
| 39 void StartProfiling(); |
| 40 |
| 41 // Ends system profiling. |
| 42 void StopProfiling(); |
| 43 |
| 44 private: |
| 45 FRIEND_TEST_ALL_PREFIXES(TraceSystemTest, TraceSystemController); |
| 46 |
| 47 bool IsTimerRunningForTest() const; |
| 48 |
| 49 // Ensures the observer starts and stops tracing on the primary thread. |
| 50 scoped_refptr<MessageLoopProxy> message_loop_proxy_; |
| 51 |
| 52 // Timer to schedule system profile dumps. |
| 53 RepeatingTimer<TraceSystemController> dump_timer_; |
| 54 |
| 55 WeakPtrFactory<TraceSystemController> weak_factory_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(TraceSystemController); |
| 58 }; |
| 59 |
| 60 #ifdef OS_LINUX |
| 61 // Converts system memory profiling stats in |input| to |
| 62 // trace event compatible JSON and appends to |output|. Visible for testing. |
| 63 BASE_EXPORT void AppendSystemProfileAsTraceFormat(SystemMemoryInfoKB *meminfo, |
| 64 std::string* output); |
| 65 #endif |
| 66 |
| 67 } // namespace debug |
| 68 } // namespace base |
| 69 |
| 70 #endif // BASE_DEBUG_TRACE_EVENT_SYSTEM_H_ |
OLD | NEW |