5 #ifndef V8_LIBPLATFORM_V8_TRACING_H_ 6 #define V8_LIBPLATFORM_V8_TRACING_H_ 10 #include <unordered_set> 13 #include "libplatform/libplatform-export.h" 14 #include "v8-platform.h" 25 const int kTraceMaxNumArgs = 2;
34 const void* as_pointer;
35 const char* as_string;
41 char phase,
const uint8_t* category_enabled_flag,
const char* name,
42 const char* scope, uint64_t
id, uint64_t bind_id,
int num_args,
43 const char** arg_names,
const uint8_t* arg_types,
44 const uint64_t* arg_values,
45 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
48 void InitializeForTesting(
49 char phase,
const uint8_t* category_enabled_flag,
const char* name,
50 const char* scope, uint64_t
id, uint64_t bind_id,
int num_args,
51 const char** arg_names,
const uint8_t* arg_types,
52 const uint64_t* arg_values,
53 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
55 uint64_t duration, uint64_t cpu_duration);
57 int pid()
const {
return pid_; }
58 int tid()
const {
return tid_; }
59 char phase()
const {
return phase_; }
60 const uint8_t* category_enabled_flag()
const {
61 return category_enabled_flag_;
63 const char* name()
const {
return name_; }
64 const char* scope()
const {
return scope_; }
65 uint64_t id()
const {
return id_; }
66 uint64_t bind_id()
const {
return bind_id_; }
67 int num_args()
const {
return num_args_; }
68 const char** arg_names() {
return arg_names_; }
69 uint8_t* arg_types() {
return arg_types_; }
70 ArgValue* arg_values() {
return arg_values_; }
71 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables() {
72 return arg_convertables_;
74 unsigned int flags()
const {
return flags_; }
77 uint64_t duration() {
return duration_; }
78 uint64_t cpu_duration() {
return cpu_duration_; }
86 const uint8_t* category_enabled_flag_;
90 const char* arg_names_[kTraceMaxNumArgs];
91 uint8_t arg_types_[kTraceMaxNumArgs];
92 ArgValue arg_values_[kTraceMaxNumArgs];
93 std::unique_ptr<v8::ConvertableToTraceFormat>
94 arg_convertables_[kTraceMaxNumArgs];
95 char* parameter_copy_storage_ =
nullptr;
100 uint64_t cpu_duration_;
103 TraceObject(
const TraceObject&) =
delete;
104 void operator=(
const TraceObject&) =
delete;
111 virtual void AppendTraceEvent(
TraceObject* trace_event) = 0;
112 virtual void Flush() = 0;
114 static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
115 static TraceWriter* CreateJSONTraceWriter(std::ostream& stream,
116 const std::string& tag);
129 bool IsFull()
const {
return next_free_ == kChunkSize; }
131 TraceObject* GetEventAt(
size_t index) {
return &chunk_[index]; }
133 uint32_t seq()
const {
return seq_; }
134 size_t size()
const {
return next_free_; }
136 static const size_t kChunkSize = 64;
139 size_t next_free_ = 0;
153 virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0;
154 virtual TraceObject* GetEventByHandle(uint64_t handle) = 0;
155 virtual bool Flush() = 0;
157 static const size_t kRingBufferChunks = 1024;
159 static TraceBuffer* CreateTraceBufferRingBuffer(
size_t max_chunks,
169 enum TraceRecordMode {
178 RECORD_AS_MUCH_AS_POSSIBLE,
186 typedef std::vector<std::string> StringList;
190 TraceConfig() : enable_systrace_(
false), enable_argument_filter_(
false) {}
191 TraceRecordMode GetTraceRecordMode()
const {
return record_mode_; }
192 bool IsSystraceEnabled()
const {
return enable_systrace_; }
193 bool IsArgumentFilterEnabled()
const {
return enable_argument_filter_; }
195 void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; }
196 void EnableSystrace() { enable_systrace_ =
true; }
197 void EnableArgumentFilter() { enable_argument_filter_ =
true; }
199 void AddIncludedCategory(
const char* included_category);
201 bool IsCategoryGroupEnabled(
const char* category_group)
const;
204 TraceRecordMode record_mode_;
205 bool enable_systrace_ : 1;
206 bool enable_argument_filter_ : 1;
207 StringList included_categories_;
214 #if defined(_MSC_VER) 215 #define V8_PLATFORM_NON_EXPORTED_BASE(code) \ 216 __pragma(warning(suppress : 4275)) code 218 #define V8_PLATFORM_NON_EXPORTED_BASE(code) code 219 #endif // defined(_MSC_VER) 222 :
public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
224 enum Mode { DISABLED = 0, RECORDING_MODE };
230 enum CategoryGroupEnabledFlags {
232 ENABLED_FOR_RECORDING = 1 << 0,
234 ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
236 ENABLED_FOR_ETW_EXPORT = 1 << 3
244 const uint8_t* GetCategoryGroupEnabled(
const char* category_group)
override;
245 uint64_t AddTraceEvent(
246 char phase,
const uint8_t* category_enabled_flag,
const char* name,
247 const char* scope, uint64_t
id, uint64_t bind_id, int32_t num_args,
248 const char** arg_names,
const uint8_t* arg_types,
249 const uint64_t* arg_values,
250 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
251 unsigned int flags)
override;
252 uint64_t AddTraceEventWithTimestamp(
253 char phase,
const uint8_t* category_enabled_flag,
const char* name,
254 const char* scope, uint64_t
id, uint64_t bind_id, int32_t num_args,
255 const char** arg_names,
const uint8_t* arg_types,
256 const uint64_t* arg_values,
257 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
258 unsigned int flags,
int64_t timestamp)
override;
259 void UpdateTraceEventDuration(
const uint8_t* category_enabled_flag,
260 const char* name, uint64_t handle)
override;
261 void AddTraceStateObserver(
263 void RemoveTraceStateObserver(
269 static const char* GetCategoryGroupName(
const uint8_t* category_enabled_flag);
272 virtual int64_t CurrentTimestampMicroseconds();
273 virtual int64_t CurrentCpuTimestampMicroseconds();
276 const uint8_t* GetCategoryGroupEnabledInternal(
const char* category_group);
277 void UpdateCategoryGroupEnabledFlag(
size_t category_index);
278 void UpdateCategoryGroupEnabledFlags();
280 std::unique_ptr<TraceBuffer> trace_buffer_;
281 std::unique_ptr<TraceConfig> trace_config_;
282 std::unique_ptr<base::Mutex> mutex_;
283 std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
284 Mode mode_ = DISABLED;
291 #undef V8_PLATFORM_NON_EXPORTED_BASE 297 #endif // V8_LIBPLATFORM_V8_TRACING_H_