| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Trace events to track application performance. Events consist of a name | 5 // Trace events to track application performance. Events consist of a name |
| 6 // a type (BEGIN, END or INSTANT), a tracking id and extra string data. | 6 // a type (BEGIN, END or INSTANT), a tracking id and extra string data. |
| 7 // In addition, the current process id, thread id, a timestamp down to the | 7 // In addition, the current process id, thread id, a timestamp down to the |
| 8 // microsecond and a file and line number of the calling location. | 8 // microsecond and a file and line number of the calling location. |
| 9 // | 9 // |
| 10 // The current implementation logs these events into a log file of the form | 10 // The current implementation logs these events into a log file of the form |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #else // CHROMIUM_ENABLE_TRACE_EVENT | 45 #else // CHROMIUM_ENABLE_TRACE_EVENT |
| 46 // Use the following macros rather than using the TraceLog class directly as the | 46 // Use the following macros rather than using the TraceLog class directly as the |
| 47 // underlying implementation may change in the future. Here's a sample usage: | 47 // underlying implementation may change in the future. Here's a sample usage: |
| 48 // TRACE_EVENT_BEGIN("v8.run", documentId, scriptLocation); | 48 // TRACE_EVENT_BEGIN("v8.run", documentId, scriptLocation); |
| 49 // RunScript(script); | 49 // RunScript(script); |
| 50 // TRACE_EVENT_END("v8.run", documentId, scriptLocation); | 50 // TRACE_EVENT_END("v8.run", documentId, scriptLocation); |
| 51 | 51 |
| 52 // Record that an event (of name, id) has begun. All BEGIN events should have | 52 // Record that an event (of name, id) has begun. All BEGIN events should have |
| 53 // corresponding END events with a matching (name, id). | 53 // corresponding END events with a matching (name, id). |
| 54 #define TRACE_EVENT_BEGIN(name, id, extra) \ | 54 #define TRACE_EVENT_BEGIN(name, id, extra) \ |
| 55 Singleton<base::debug::TraceLog>::get()->Trace( \ | 55 base::debug::TraceLog::GetInstance()->Trace( \ |
| 56 name, \ | 56 name, \ |
| 57 base::debug::TraceLog::EVENT_BEGIN, \ | 57 base::debug::TraceLog::EVENT_BEGIN, \ |
| 58 reinterpret_cast<const void*>(id), \ | 58 reinterpret_cast<const void*>(id), \ |
| 59 extra, \ | 59 extra, \ |
| 60 __FILE__, \ | 60 __FILE__, \ |
| 61 __LINE__) | 61 __LINE__) |
| 62 | 62 |
| 63 // Record that an event (of name, id) has ended. All END events should have | 63 // Record that an event (of name, id) has ended. All END events should have |
| 64 // corresponding BEGIN events with a matching (name, id). | 64 // corresponding BEGIN events with a matching (name, id). |
| 65 #define TRACE_EVENT_END(name, id, extra) \ | 65 #define TRACE_EVENT_END(name, id, extra) \ |
| 66 Singleton<base::debug::TraceLog>::get()->Trace( \ | 66 base::debug::TraceLog::GetInstance()->Trace( \ |
| 67 name, \ | 67 name, \ |
| 68 base::debug::TraceLog::EVENT_END, \ | 68 base::debug::TraceLog::EVENT_END, \ |
| 69 reinterpret_cast<const void*>(id), \ | 69 reinterpret_cast<const void*>(id), \ |
| 70 extra, \ | 70 extra, \ |
| 71 __FILE__, \ | 71 __FILE__, \ |
| 72 __LINE__) | 72 __LINE__) |
| 73 | 73 |
| 74 // Record that an event (of name, id) with no duration has happened. | 74 // Record that an event (of name, id) with no duration has happened. |
| 75 #define TRACE_EVENT_INSTANT(name, id, extra) \ | 75 #define TRACE_EVENT_INSTANT(name, id, extra) \ |
| 76 Singleton<base::debug::TraceLog>::get()->Trace( \ | 76 base::debug::TraceLog::GetInstance()->Trace( \ |
| 77 name, \ | 77 name, \ |
| 78 base::debug::TraceLog::EVENT_INSTANT, \ | 78 base::debug::TraceLog::EVENT_INSTANT, \ |
| 79 reinterpret_cast<const void*>(id), \ | 79 reinterpret_cast<const void*>(id), \ |
| 80 extra, \ | 80 extra, \ |
| 81 __FILE__, \ | 81 __FILE__, \ |
| 82 __LINE__) | 82 __LINE__) |
| 83 #endif // CHROMIUM_ENABLE_TRACE_EVENT | 83 #endif // CHROMIUM_ENABLE_TRACE_EVENT |
| 84 | 84 |
| 85 namespace base { | 85 namespace base { |
| 86 | 86 |
| 87 class ProcessMetrics; | 87 class ProcessMetrics; |
| 88 | 88 |
| 89 namespace debug { | 89 namespace debug { |
| 90 | 90 |
| 91 class TraceLog { | 91 class TraceLog { |
| 92 public: | 92 public: |
| 93 enum EventType { | 93 enum EventType { |
| 94 EVENT_BEGIN, | 94 EVENT_BEGIN, |
| 95 EVENT_END, | 95 EVENT_END, |
| 96 EVENT_INSTANT | 96 EVENT_INSTANT |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 static TraceLog* GetInstance(); |
| 100 |
| 99 // Is tracing currently enabled. | 101 // Is tracing currently enabled. |
| 100 static bool IsTracing(); | 102 static bool IsTracing(); |
| 101 // Start logging trace events. | 103 // Start logging trace events. |
| 102 static bool StartTracing(); | 104 static bool StartTracing(); |
| 103 // Stop logging trace events. | 105 // Stop logging trace events. |
| 104 static void StopTracing(); | 106 static void StopTracing(); |
| 105 | 107 |
| 106 // Log a trace event of (name, type, id) with the optional extra string. | 108 // Log a trace event of (name, type, id) with the optional extra string. |
| 107 void Trace(const std::string& name, | 109 void Trace(const std::string& name, |
| 108 EventType type, | 110 EventType type, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 138 scoped_ptr<base::ProcessMetrics> process_metrics_; | 140 scoped_ptr<base::ProcessMetrics> process_metrics_; |
| 139 RepeatingTimer<TraceLog> timer_; | 141 RepeatingTimer<TraceLog> timer_; |
| 140 }; | 142 }; |
| 141 | 143 |
| 142 } // namespace debug | 144 } // namespace debug |
| 143 } // namespace base | 145 } // namespace base |
| 144 | 146 |
| 145 #endif // defined(OS_WIN) | 147 #endif // defined(OS_WIN) |
| 146 | 148 |
| 147 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 149 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |