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 <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "include/v8-platform.h" |
| 13 |
12 namespace v8 { | 14 namespace v8 { |
13 namespace platform { | 15 namespace platform { |
14 namespace tracing { | 16 namespace tracing { |
15 | 17 |
16 const int kTraceMaxNumArgs = 2; | 18 const int kTraceMaxNumArgs = 2; |
17 | 19 |
18 class TraceObject { | 20 class TraceObject { |
19 public: | 21 public: |
20 union ArgValue { | 22 union ArgValue { |
21 bool as_bool; | 23 bool as_bool; |
22 uint64_t as_uint; | 24 uint64_t as_uint; |
23 int64_t as_int; | 25 int64_t as_int; |
24 double as_double; | 26 double as_double; |
25 const void* as_pointer; | 27 const void* as_pointer; |
26 const char* as_string; | 28 const char* as_string; |
27 }; | 29 }; |
28 | 30 |
29 TraceObject() {} | 31 TraceObject() {} |
30 ~TraceObject(); | 32 ~TraceObject(); |
31 void Initialize(char phase, const uint8_t* category_enabled_flag, | 33 void Initialize( |
32 const char* name, const char* scope, uint64_t id, | 34 char phase, const uint8_t* category_enabled_flag, const char* name, |
33 uint64_t bind_id, int num_args, const char** arg_names, | 35 const char* scope, uint64_t id, uint64_t bind_id, int num_args, |
34 const uint8_t* arg_types, const uint64_t* arg_values, | 36 const char** arg_names, const uint8_t* arg_types, |
35 unsigned int flags); | 37 const uint64_t* arg_values, |
| 38 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, |
| 39 unsigned int flags); |
36 void UpdateDuration(); | 40 void UpdateDuration(); |
37 void InitializeForTesting(char phase, const uint8_t* category_enabled_flag, | 41 void InitializeForTesting( |
38 const char* name, const char* scope, uint64_t id, | 42 char phase, const uint8_t* category_enabled_flag, const char* name, |
39 uint64_t bind_id, int num_args, | 43 const char* scope, uint64_t id, uint64_t bind_id, int num_args, |
40 const char** arg_names, const uint8_t* arg_types, | 44 const char** arg_names, const uint8_t* arg_types, |
41 const uint64_t* arg_values, unsigned int flags, | 45 const uint64_t* arg_values, |
42 int pid, int tid, int64_t ts, int64_t tts, | 46 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, |
43 uint64_t duration, uint64_t cpu_duration); | 47 unsigned int flags, int pid, int tid, int64_t ts, int64_t tts, |
| 48 uint64_t duration, uint64_t cpu_duration); |
44 | 49 |
45 int pid() const { return pid_; } | 50 int pid() const { return pid_; } |
46 int tid() const { return tid_; } | 51 int tid() const { return tid_; } |
47 char phase() const { return phase_; } | 52 char phase() const { return phase_; } |
48 const uint8_t* category_enabled_flag() const { | 53 const uint8_t* category_enabled_flag() const { |
49 return category_enabled_flag_; | 54 return category_enabled_flag_; |
50 } | 55 } |
51 const char* name() const { return name_; } | 56 const char* name() const { return name_; } |
52 const char* scope() const { return scope_; } | 57 const char* scope() const { return scope_; } |
53 uint64_t id() const { return id_; } | 58 uint64_t id() const { return id_; } |
54 uint64_t bind_id() const { return bind_id_; } | 59 uint64_t bind_id() const { return bind_id_; } |
55 int num_args() const { return num_args_; } | 60 int num_args() const { return num_args_; } |
56 const char** arg_names() { return arg_names_; } | 61 const char** arg_names() { return arg_names_; } |
57 uint8_t* arg_types() { return arg_types_; } | 62 uint8_t* arg_types() { return arg_types_; } |
58 ArgValue* arg_values() { return arg_values_; } | 63 ArgValue* arg_values() { return arg_values_; } |
| 64 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables() { |
| 65 return arg_convertables_; |
| 66 } |
59 unsigned int flags() const { return flags_; } | 67 unsigned int flags() const { return flags_; } |
60 int64_t ts() { return ts_; } | 68 int64_t ts() { return ts_; } |
61 int64_t tts() { return tts_; } | 69 int64_t tts() { return tts_; } |
62 uint64_t duration() { return duration_; } | 70 uint64_t duration() { return duration_; } |
63 uint64_t cpu_duration() { return cpu_duration_; } | 71 uint64_t cpu_duration() { return cpu_duration_; } |
64 | 72 |
65 private: | 73 private: |
66 int pid_; | 74 int pid_; |
67 int tid_; | 75 int tid_; |
68 char phase_; | 76 char phase_; |
69 const char* name_; | 77 const char* name_; |
70 const char* scope_; | 78 const char* scope_; |
71 const uint8_t* category_enabled_flag_; | 79 const uint8_t* category_enabled_flag_; |
72 uint64_t id_; | 80 uint64_t id_; |
73 uint64_t bind_id_; | 81 uint64_t bind_id_; |
74 int num_args_; | 82 int num_args_ = 0; |
75 const char* arg_names_[kTraceMaxNumArgs]; | 83 const char* arg_names_[kTraceMaxNumArgs]; |
76 uint8_t arg_types_[kTraceMaxNumArgs]; | 84 uint8_t arg_types_[kTraceMaxNumArgs]; |
77 ArgValue arg_values_[kTraceMaxNumArgs]; | 85 ArgValue arg_values_[kTraceMaxNumArgs]; |
| 86 std::unique_ptr<v8::ConvertableToTraceFormat> |
| 87 arg_convertables_[kTraceMaxNumArgs]; |
78 char* parameter_copy_storage_ = nullptr; | 88 char* parameter_copy_storage_ = nullptr; |
79 unsigned int flags_; | 89 unsigned int flags_; |
80 int64_t ts_; | 90 int64_t ts_; |
81 int64_t tts_; | 91 int64_t tts_; |
82 uint64_t duration_; | 92 uint64_t duration_; |
83 uint64_t cpu_duration_; | 93 uint64_t cpu_duration_; |
84 | 94 |
85 // Disallow copy and assign | 95 // Disallow copy and assign |
86 TraceObject(const TraceObject&) = delete; | 96 TraceObject(const TraceObject&) = delete; |
87 void operator=(const TraceObject&) = delete; | 97 void operator=(const TraceObject&) = delete; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // Category group enabled by SetEventCallbackEnabled(). | 224 // Category group enabled by SetEventCallbackEnabled(). |
215 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, | 225 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, |
216 // Category group enabled to export events to ETW. | 226 // Category group enabled to export events to ETW. |
217 ENABLED_FOR_ETW_EXPORT = 1 << 3 | 227 ENABLED_FOR_ETW_EXPORT = 1 << 3 |
218 }; | 228 }; |
219 | 229 |
220 TracingController() {} | 230 TracingController() {} |
221 void Initialize(TraceBuffer* trace_buffer); | 231 void Initialize(TraceBuffer* trace_buffer); |
222 const uint8_t* GetCategoryGroupEnabled(const char* category_group); | 232 const uint8_t* GetCategoryGroupEnabled(const char* category_group); |
223 static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); | 233 static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); |
224 uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag, | 234 uint64_t AddTraceEvent( |
225 const char* name, const char* scope, uint64_t id, | 235 char phase, const uint8_t* category_enabled_flag, const char* name, |
226 uint64_t bind_id, int32_t num_args, | 236 const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, |
227 const char** arg_names, const uint8_t* arg_types, | 237 const char** arg_names, const uint8_t* arg_types, |
228 const uint64_t* arg_values, unsigned int flags); | 238 const uint64_t* arg_values, |
| 239 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, |
| 240 unsigned int flags); |
229 void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, | 241 void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, |
230 const char* name, uint64_t handle); | 242 const char* name, uint64_t handle); |
231 | 243 |
232 void StartTracing(TraceConfig* trace_config); | 244 void StartTracing(TraceConfig* trace_config); |
233 void StopTracing(); | 245 void StopTracing(); |
234 | 246 |
235 private: | 247 private: |
236 const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group); | 248 const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group); |
237 void UpdateCategoryGroupEnabledFlag(size_t category_index); | 249 void UpdateCategoryGroupEnabledFlag(size_t category_index); |
238 void UpdateCategoryGroupEnabledFlags(); | 250 void UpdateCategoryGroupEnabledFlags(); |
239 | 251 |
240 std::unique_ptr<TraceBuffer> trace_buffer_; | 252 std::unique_ptr<TraceBuffer> trace_buffer_; |
241 std::unique_ptr<TraceConfig> trace_config_; | 253 std::unique_ptr<TraceConfig> trace_config_; |
242 Mode mode_ = DISABLED; | 254 Mode mode_ = DISABLED; |
243 | 255 |
244 // Disallow copy and assign | 256 // Disallow copy and assign |
245 TracingController(const TracingController&) = delete; | 257 TracingController(const TracingController&) = delete; |
246 void operator=(const TracingController&) = delete; | 258 void operator=(const TracingController&) = delete; |
247 }; | 259 }; |
248 | 260 |
249 } // namespace tracing | 261 } // namespace tracing |
250 } // namespace platform | 262 } // namespace platform |
251 } // namespace v8 | 263 } // namespace v8 |
252 | 264 |
253 #endif // V8_LIBPLATFORM_V8_TRACING_H_ | 265 #endif // V8_LIBPLATFORM_V8_TRACING_H_ |
OLD | NEW |