Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: include/libplatform/v8-tracing.h

Issue 2137013006: [Tracing] V8 Tracing Controller (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef V8_LIBPLATFORM_TRACING_CONTROLLER_H_
6 #define V8_LIBPLATFORM_TRACING_CONTROLLER_H_
7
8 #include <fstream>
9 #include <memory>
10
11 #include "include/v8.h"
12
13 namespace v8 {
14 namespace platform {
15 namespace tracing {
16
17 class TraceObject {
18 public:
19 void Initialize(char phase, std::string name, std::string category_group,
20 uint64_t id, uint64_t bind_id, int num_args, int flags);
21 void UpdateDuration();
22 void InitializeForTesting(char phase, std::string name,
23 std::string category_group, uint64_t id,
24 uint64_t bind_id, int num_args, int flags, int pid,
25 int tid, int64_t ts, int64_t tts, uint64_t duration,
26 uint64_t cpu_duration);
27
28 int pid() const { return pid_; }
29 int tid() const { return tid_; }
30 char phase() const { return phase_; }
31 std::string name() const { return name_; }
32 std::string category_group() const { return category_group_; }
33 int64_t ts() { return ts_; }
34 int64_t tts() { return tts_; }
35 uint64_t duration() { return duration_; }
36 uint64_t cpu_duration() { return cpu_duration_; }
37
38 private:
39 int pid_;
40 int tid_;
41 char phase_;
42 std::string name_;
43 std::string category_group_;
44 uint64_t id_;
45 uint64_t bind_id_;
46 int num_args_;
47 unsigned int flags_;
48 int64_t ts_;
49 int64_t tts_;
50 uint64_t duration_;
51 uint64_t cpu_duration_;
52 // TODO(fmeawad): Add args support.
53 };
54
55 class TraceWriter {
56 public:
57 virtual ~TraceWriter() {}
58 virtual void AppendTraceEvent(TraceObject* trace_event) = 0;
59 virtual void Flush() = 0;
60
61 static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
62 };
63
64 class TraceBuffer {
65 public:
66 virtual ~TraceBuffer() {}
67
68 virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0;
69 virtual TraceObject* GetEventByHandle(uint64_t handle) = 0;
70 virtual bool Flush() = 0;
71
72 static const size_t kRingBufferChunks = 1024;
73
74 static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks,
75 TraceWriter* trace_writer);
76 };
77
78 // Options determines how the trace buffer stores data.
79 enum TraceRecordMode {
80 // Record until the trace buffer is full.
81 RECORD_UNTIL_FULL,
82
83 // Record until the user ends the trace. The trace buffer is a fixed size
84 // and we use it as a ring buffer during recording.
85 RECORD_CONTINUOUSLY,
86
87 // Record until the trace buffer is full, but with a huge buffer size.
88 RECORD_AS_MUCH_AS_POSSIBLE,
89
90 // Echo to console. Events are discarded.
91 ECHO_TO_CONSOLE,
92 };
93
94 class TraceConfig {
95 public:
96 typedef std::vector<std::string> StringList;
97
98 static TraceConfig* CreateDefaultTraceConfig();
99 // Create a trace config object using a given JSON format string.
100 static TraceConfig* CreateTraceConfigFromJSON(v8::Isolate* isolate,
101 const char* json_str);
102
103 TraceRecordMode GetTraceRecordMode() const { return record_mode_; }
104 bool IsSamplingEnabled() const { return enable_sampling_; }
105 bool IsSystraceEnabled() const { return enable_systrace_; }
106 bool IsArgumentFilterEnabled() const { return enable_argument_filter_; }
107
108 void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; }
109 void EnableSampling() { enable_sampling_ = true; }
110 void EnableSystrace() { enable_systrace_ = true; }
111 void EnableArgumentFilter() { enable_argument_filter_ = true; }
112
113 bool IsCategoryGroupEnabled(const char* category_group) const;
114
115 private:
116 friend class TraceConfigParser;
117
118 TraceConfig()
119 : enable_sampling_(false),
120 enable_systrace_(false),
121 enable_argument_filter_(false) {}
122
123 TraceRecordMode record_mode_;
124 bool enable_sampling_ : 1;
125 bool enable_systrace_ : 1;
126 bool enable_argument_filter_ : 1;
127 StringList included_categories_;
128 StringList excluded_categories_;
129 };
130
131 class TracingController {
132 public:
133 enum Mode { DISABLED = 0, RECORDING_MODE };
134
135 // The pointer returned from GetCategoryGroupEnabledInternal() points to a
136 // value with zero or more of the following bits. Used in this class only.
137 // The TRACE_EVENT macros should only use the value as a bool.
138 // These values must be in sync with macro values in TraceEvent.h in Blink.
139 enum CategoryGroupEnabledFlags {
140 // Category group enabled for the recording mode.
141 ENABLED_FOR_RECORDING = 1 << 0,
142 // Category group enabled by SetEventCallbackEnabled().
143 ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
144 // Category group enabled to export events to ETW.
145 ENABLED_FOR_ETW_EXPORT = 1 << 3
146 };
147
148 void Initialize(TraceBuffer* trace_buffer, TraceConfig* trace_config);
149 const uint8_t* GetCategoryGroupEnabled(const char* category_group);
150 const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
151 uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
152 const char* name, const char* scope, uint64_t id,
153 uint64_t bind_id, int32_t num_args,
154 const char** arg_names, const uint8_t* arg_types,
155 const uint64_t* arg_values, unsigned int flags);
156 void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
157 const char* name, uint64_t handle);
158
159 void Start();
160 void Stop();
161
162 private:
163 const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group);
164 void UpdateCategoryGroupEnabledFlag(size_t category_index);
165 void UpdateCategoryGroupEnabledFlags();
166
167 std::unique_ptr<TraceBuffer> trace_buffer_;
168 std::unique_ptr<TraceConfig> trace_config_;
169 bool is_recording = true;
170 Mode mode_ = RECORDING_MODE;
171 };
172
173 } // namespace tracing
174 } // namespace platform
175 } // namespace v8
176
177 #endif // V8_LIBPLATFORM_TRACING_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698