| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 #ifndef V8_LIBPLATFORM_V8_TRACING_H_ | 5 #ifndef V8_LIBPLATFORM_V8_TRACING_H_ |
| 6 #define V8_LIBPLATFORM_V8_TRACING_H_ | 6 #define V8_LIBPLATFORM_V8_TRACING_H_ |
| 7 | 7 |
| 8 #include <fstream> | 8 #include <fstream> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "libplatform/libplatform-export.h" |
| 13 #include "v8-platform.h" // NOLINT(build/include) | 14 #include "v8-platform.h" // NOLINT(build/include) |
| 14 | 15 |
| 15 namespace v8 { | 16 namespace v8 { |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class Mutex; | 19 class Mutex; |
| 19 } // namespace base | 20 } // namespace base |
| 20 | 21 |
| 21 namespace platform { | 22 namespace platform { |
| 22 namespace tracing { | 23 namespace tracing { |
| 23 | 24 |
| 24 const int kTraceMaxNumArgs = 2; | 25 const int kTraceMaxNumArgs = 2; |
| 25 | 26 |
| 26 class TraceObject { | 27 class V8_PLATFORM_EXPORT TraceObject { |
| 27 public: | 28 public: |
| 28 union ArgValue { | 29 union ArgValue { |
| 29 bool as_bool; | 30 bool as_bool; |
| 30 uint64_t as_uint; | 31 uint64_t as_uint; |
| 31 int64_t as_int; | 32 int64_t as_int; |
| 32 double as_double; | 33 double as_double; |
| 33 const void* as_pointer; | 34 const void* as_pointer; |
| 34 const char* as_string; | 35 const char* as_string; |
| 35 }; | 36 }; |
| 36 | 37 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 int64_t ts_; | 97 int64_t ts_; |
| 97 int64_t tts_; | 98 int64_t tts_; |
| 98 uint64_t duration_; | 99 uint64_t duration_; |
| 99 uint64_t cpu_duration_; | 100 uint64_t cpu_duration_; |
| 100 | 101 |
| 101 // Disallow copy and assign | 102 // Disallow copy and assign |
| 102 TraceObject(const TraceObject&) = delete; | 103 TraceObject(const TraceObject&) = delete; |
| 103 void operator=(const TraceObject&) = delete; | 104 void operator=(const TraceObject&) = delete; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 class TraceWriter { | 107 class V8_PLATFORM_EXPORT TraceWriter { |
| 107 public: | 108 public: |
| 108 TraceWriter() {} | 109 TraceWriter() {} |
| 109 virtual ~TraceWriter() {} | 110 virtual ~TraceWriter() {} |
| 110 virtual void AppendTraceEvent(TraceObject* trace_event) = 0; | 111 virtual void AppendTraceEvent(TraceObject* trace_event) = 0; |
| 111 virtual void Flush() = 0; | 112 virtual void Flush() = 0; |
| 112 | 113 |
| 113 static TraceWriter* CreateJSONTraceWriter(std::ostream& stream); | 114 static TraceWriter* CreateJSONTraceWriter(std::ostream& stream); |
| 114 | 115 |
| 115 private: | 116 private: |
| 116 // Disallow copy and assign | 117 // Disallow copy and assign |
| 117 TraceWriter(const TraceWriter&) = delete; | 118 TraceWriter(const TraceWriter&) = delete; |
| 118 void operator=(const TraceWriter&) = delete; | 119 void operator=(const TraceWriter&) = delete; |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 class TraceBufferChunk { | 122 class V8_PLATFORM_EXPORT TraceBufferChunk { |
| 122 public: | 123 public: |
| 123 explicit TraceBufferChunk(uint32_t seq); | 124 explicit TraceBufferChunk(uint32_t seq); |
| 124 | 125 |
| 125 void Reset(uint32_t new_seq); | 126 void Reset(uint32_t new_seq); |
| 126 bool IsFull() const { return next_free_ == kChunkSize; } | 127 bool IsFull() const { return next_free_ == kChunkSize; } |
| 127 TraceObject* AddTraceEvent(size_t* event_index); | 128 TraceObject* AddTraceEvent(size_t* event_index); |
| 128 TraceObject* GetEventAt(size_t index) { return &chunk_[index]; } | 129 TraceObject* GetEventAt(size_t index) { return &chunk_[index]; } |
| 129 | 130 |
| 130 uint32_t seq() const { return seq_; } | 131 uint32_t seq() const { return seq_; } |
| 131 size_t size() const { return next_free_; } | 132 size_t size() const { return next_free_; } |
| 132 | 133 |
| 133 static const size_t kChunkSize = 64; | 134 static const size_t kChunkSize = 64; |
| 134 | 135 |
| 135 private: | 136 private: |
| 136 size_t next_free_ = 0; | 137 size_t next_free_ = 0; |
| 137 TraceObject chunk_[kChunkSize]; | 138 TraceObject chunk_[kChunkSize]; |
| 138 uint32_t seq_; | 139 uint32_t seq_; |
| 139 | 140 |
| 140 // Disallow copy and assign | 141 // Disallow copy and assign |
| 141 TraceBufferChunk(const TraceBufferChunk&) = delete; | 142 TraceBufferChunk(const TraceBufferChunk&) = delete; |
| 142 void operator=(const TraceBufferChunk&) = delete; | 143 void operator=(const TraceBufferChunk&) = delete; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 class TraceBuffer { | 146 class V8_PLATFORM_EXPORT TraceBuffer { |
| 146 public: | 147 public: |
| 147 TraceBuffer() {} | 148 TraceBuffer() {} |
| 148 virtual ~TraceBuffer() {} | 149 virtual ~TraceBuffer() {} |
| 149 | 150 |
| 150 virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0; | 151 virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0; |
| 151 virtual TraceObject* GetEventByHandle(uint64_t handle) = 0; | 152 virtual TraceObject* GetEventByHandle(uint64_t handle) = 0; |
| 152 virtual bool Flush() = 0; | 153 virtual bool Flush() = 0; |
| 153 | 154 |
| 154 static const size_t kRingBufferChunks = 1024; | 155 static const size_t kRingBufferChunks = 1024; |
| 155 | 156 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 171 // and we use it as a ring buffer during recording. | 172 // and we use it as a ring buffer during recording. |
| 172 RECORD_CONTINUOUSLY, | 173 RECORD_CONTINUOUSLY, |
| 173 | 174 |
| 174 // Record until the trace buffer is full, but with a huge buffer size. | 175 // Record until the trace buffer is full, but with a huge buffer size. |
| 175 RECORD_AS_MUCH_AS_POSSIBLE, | 176 RECORD_AS_MUCH_AS_POSSIBLE, |
| 176 | 177 |
| 177 // Echo to console. Events are discarded. | 178 // Echo to console. Events are discarded. |
| 178 ECHO_TO_CONSOLE, | 179 ECHO_TO_CONSOLE, |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 class TraceConfig { | 182 class V8_PLATFORM_EXPORT TraceConfig { |
| 182 public: | 183 public: |
| 183 typedef std::vector<std::string> StringList; | 184 typedef std::vector<std::string> StringList; |
| 184 | 185 |
| 185 static TraceConfig* CreateDefaultTraceConfig(); | 186 static TraceConfig* CreateDefaultTraceConfig(); |
| 186 | 187 |
| 187 TraceConfig() | 188 TraceConfig() |
| 188 : enable_sampling_(false), | 189 : enable_sampling_(false), |
| 189 enable_systrace_(false), | 190 enable_systrace_(false), |
| 190 enable_argument_filter_(false) {} | 191 enable_argument_filter_(false) {} |
| 191 TraceRecordMode GetTraceRecordMode() const { return record_mode_; } | 192 TraceRecordMode GetTraceRecordMode() const { return record_mode_; } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 209 bool enable_systrace_ : 1; | 210 bool enable_systrace_ : 1; |
| 210 bool enable_argument_filter_ : 1; | 211 bool enable_argument_filter_ : 1; |
| 211 StringList included_categories_; | 212 StringList included_categories_; |
| 212 StringList excluded_categories_; | 213 StringList excluded_categories_; |
| 213 | 214 |
| 214 // Disallow copy and assign | 215 // Disallow copy and assign |
| 215 TraceConfig(const TraceConfig&) = delete; | 216 TraceConfig(const TraceConfig&) = delete; |
| 216 void operator=(const TraceConfig&) = delete; | 217 void operator=(const TraceConfig&) = delete; |
| 217 }; | 218 }; |
| 218 | 219 |
| 219 class TracingController { | 220 class V8_PLATFORM_EXPORT TracingController { |
| 220 public: | 221 public: |
| 221 enum Mode { DISABLED = 0, RECORDING_MODE }; | 222 enum Mode { DISABLED = 0, RECORDING_MODE }; |
| 222 | 223 |
| 223 // The pointer returned from GetCategoryGroupEnabledInternal() points to a | 224 // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
| 224 // value with zero or more of the following bits. Used in this class only. | 225 // value with zero or more of the following bits. Used in this class only. |
| 225 // The TRACE_EVENT macros should only use the value as a bool. | 226 // The TRACE_EVENT macros should only use the value as a bool. |
| 226 // These values must be in sync with macro values in TraceEvent.h in Blink. | 227 // These values must be in sync with macro values in TraceEvent.h in Blink. |
| 227 enum CategoryGroupEnabledFlags { | 228 enum CategoryGroupEnabledFlags { |
| 228 // Category group enabled for the recording mode. | 229 // Category group enabled for the recording mode. |
| 229 ENABLED_FOR_RECORDING = 1 << 0, | 230 ENABLED_FOR_RECORDING = 1 << 0, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // Disallow copy and assign | 269 // Disallow copy and assign |
| 269 TracingController(const TracingController&) = delete; | 270 TracingController(const TracingController&) = delete; |
| 270 void operator=(const TracingController&) = delete; | 271 void operator=(const TracingController&) = delete; |
| 271 }; | 272 }; |
| 272 | 273 |
| 273 } // namespace tracing | 274 } // namespace tracing |
| 274 } // namespace platform | 275 } // namespace platform |
| 275 } // namespace v8 | 276 } // namespace v8 |
| 276 | 277 |
| 277 #endif // V8_LIBPLATFORM_V8_TRACING_H_ | 278 #endif // V8_LIBPLATFORM_V8_TRACING_H_ |
| OLD | NEW |