Line data Source code
1 : // This file is generated
2 :
3 : // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #ifndef v8_inspector_protocol_Profiler_h
8 : #define v8_inspector_protocol_Profiler_h
9 :
10 : #include "src/inspector/protocol/Protocol.h"
11 : // For each imported domain we generate a ValueConversions struct instead of a full domain definition
12 : // and include Domain::API version from there.
13 : #include "src/inspector/protocol/Runtime.h"
14 : #include "src/inspector/protocol/Debugger.h"
15 :
16 : namespace v8_inspector {
17 : namespace protocol {
18 : namespace Profiler {
19 :
20 : // ------------- Forward and enum declarations.
21 : // Profile node. Holds callsite information, execution statistics and child nodes.
22 : class ProfileNode;
23 : // Profile.
24 : class Profile;
25 : // Specifies a number of samples attributed to a certain source position.
26 : class PositionTickInfo;
27 : // Coverage data for a source range.
28 : class CoverageRange;
29 : // Coverage data for a JavaScript function.
30 : class FunctionCoverage;
31 : // Coverage data for a JavaScript script.
32 : class ScriptCoverage;
33 : // Describes a type collected during runtime.
34 : class TypeObject;
35 : // Source offset and types for a parameter or return value.
36 : class TypeProfileEntry;
37 : // Type profile data collected during runtime for a JavaScript script.
38 : class ScriptTypeProfile;
39 : // Wrapper for notification params
40 : class ConsoleProfileStartedNotification;
41 : // Wrapper for notification params
42 : class ConsoleProfileFinishedNotification;
43 :
44 : // ------------- Type and builder declarations.
45 :
46 : // Profile node. Holds callsite information, execution statistics and child nodes.
47 : class ProfileNode : public Serializable{
48 : PROTOCOL_DISALLOW_COPY(ProfileNode);
49 : public:
50 : static std::unique_ptr<ProfileNode> fromValue(protocol::Value* value, ErrorSupport* errors);
51 :
52 279 : ~ProfileNode() override { }
53 :
54 : int getId() { return m_id; }
55 93 : void setId(int value) { m_id = value; }
56 :
57 : protocol::Runtime::CallFrame* getCallFrame() { return m_callFrame.get(); }
58 : void setCallFrame(std::unique_ptr<protocol::Runtime::CallFrame> value) { m_callFrame = std::move(value); }
59 :
60 : bool hasHitCount() { return m_hitCount.isJust(); }
61 : int getHitCount(int defaultValue) { return m_hitCount.isJust() ? m_hitCount.fromJust() : defaultValue; }
62 : void setHitCount(int value) { m_hitCount = value; }
63 :
64 : bool hasChildren() { return m_children.isJust(); }
65 : protocol::Array<int>* getChildren(protocol::Array<int>* defaultValue) { return m_children.isJust() ? m_children.fromJust() : defaultValue; }
66 : void setChildren(std::unique_ptr<protocol::Array<int>> value) { m_children = std::move(value); }
67 :
68 : bool hasDeoptReason() { return m_deoptReason.isJust(); }
69 : String getDeoptReason(const String& defaultValue) { return m_deoptReason.isJust() ? m_deoptReason.fromJust() : defaultValue; }
70 0 : void setDeoptReason(const String& value) { m_deoptReason = value; }
71 :
72 : bool hasPositionTicks() { return m_positionTicks.isJust(); }
73 : protocol::Array<protocol::Profiler::PositionTickInfo>* getPositionTicks(protocol::Array<protocol::Profiler::PositionTickInfo>* defaultValue) { return m_positionTicks.isJust() ? m_positionTicks.fromJust() : defaultValue; }
74 : void setPositionTicks(std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> value) { m_positionTicks = std::move(value); }
75 :
76 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
77 0 : String serialize() override { return toValue()->serialize(); }
78 : std::unique_ptr<ProfileNode> clone() const;
79 :
80 : template<int STATE>
81 : class ProfileNodeBuilder {
82 : public:
83 : enum {
84 : NoFieldsSet = 0,
85 : IdSet = 1 << 1,
86 : CallFrameSet = 1 << 2,
87 : AllFieldsSet = (IdSet | CallFrameSet | 0)};
88 :
89 :
90 : ProfileNodeBuilder<STATE | IdSet>& setId(int value)
91 : {
92 : static_assert(!(STATE & IdSet), "property id should not be set yet");
93 : m_result->setId(value);
94 : return castState<IdSet>();
95 : }
96 :
97 : ProfileNodeBuilder<STATE | CallFrameSet>& setCallFrame(std::unique_ptr<protocol::Runtime::CallFrame> value)
98 : {
99 : static_assert(!(STATE & CallFrameSet), "property callFrame should not be set yet");
100 : m_result->setCallFrame(std::move(value));
101 : return castState<CallFrameSet>();
102 : }
103 :
104 : ProfileNodeBuilder<STATE>& setHitCount(int value)
105 : {
106 : m_result->setHitCount(value);
107 : return *this;
108 : }
109 :
110 : ProfileNodeBuilder<STATE>& setChildren(std::unique_ptr<protocol::Array<int>> value)
111 : {
112 : m_result->setChildren(std::move(value));
113 : return *this;
114 : }
115 :
116 : ProfileNodeBuilder<STATE>& setDeoptReason(const String& value)
117 : {
118 : m_result->setDeoptReason(value);
119 : return *this;
120 : }
121 :
122 : ProfileNodeBuilder<STATE>& setPositionTicks(std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> value)
123 : {
124 : m_result->setPositionTicks(std::move(value));
125 : return *this;
126 : }
127 :
128 : std::unique_ptr<ProfileNode> build()
129 : {
130 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
131 : return std::move(m_result);
132 : }
133 :
134 : private:
135 : friend class ProfileNode;
136 186 : ProfileNodeBuilder() : m_result(new ProfileNode()) { }
137 :
138 : template<int STEP> ProfileNodeBuilder<STATE | STEP>& castState()
139 : {
140 : return *reinterpret_cast<ProfileNodeBuilder<STATE | STEP>*>(this);
141 : }
142 :
143 : std::unique_ptr<protocol::Profiler::ProfileNode> m_result;
144 : };
145 :
146 : static ProfileNodeBuilder<0> create()
147 : {
148 93 : return ProfileNodeBuilder<0>();
149 : }
150 :
151 : private:
152 : ProfileNode()
153 93 : {
154 93 : m_id = 0;
155 : }
156 :
157 : int m_id;
158 : std::unique_ptr<protocol::Runtime::CallFrame> m_callFrame;
159 : Maybe<int> m_hitCount;
160 : Maybe<protocol::Array<int>> m_children;
161 : Maybe<String> m_deoptReason;
162 : Maybe<protocol::Array<protocol::Profiler::PositionTickInfo>> m_positionTicks;
163 : };
164 :
165 :
166 : // Profile.
167 : class Profile : public Serializable{
168 : PROTOCOL_DISALLOW_COPY(Profile);
169 : public:
170 : static std::unique_ptr<Profile> fromValue(protocol::Value* value, ErrorSupport* errors);
171 :
172 87 : ~Profile() override { }
173 :
174 : protocol::Array<protocol::Profiler::ProfileNode>* getNodes() { return m_nodes.get(); }
175 : void setNodes(std::unique_ptr<protocol::Array<protocol::Profiler::ProfileNode>> value) { m_nodes = std::move(value); }
176 :
177 : double getStartTime() { return m_startTime; }
178 29 : void setStartTime(double value) { m_startTime = value; }
179 :
180 : double getEndTime() { return m_endTime; }
181 29 : void setEndTime(double value) { m_endTime = value; }
182 :
183 : bool hasSamples() { return m_samples.isJust(); }
184 : protocol::Array<int>* getSamples(protocol::Array<int>* defaultValue) { return m_samples.isJust() ? m_samples.fromJust() : defaultValue; }
185 : void setSamples(std::unique_ptr<protocol::Array<int>> value) { m_samples = std::move(value); }
186 :
187 : bool hasTimeDeltas() { return m_timeDeltas.isJust(); }
188 : protocol::Array<int>* getTimeDeltas(protocol::Array<int>* defaultValue) { return m_timeDeltas.isJust() ? m_timeDeltas.fromJust() : defaultValue; }
189 : void setTimeDeltas(std::unique_ptr<protocol::Array<int>> value) { m_timeDeltas = std::move(value); }
190 :
191 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
192 0 : String serialize() override { return toValue()->serialize(); }
193 : std::unique_ptr<Profile> clone() const;
194 :
195 : template<int STATE>
196 : class ProfileBuilder {
197 : public:
198 : enum {
199 : NoFieldsSet = 0,
200 : NodesSet = 1 << 1,
201 : StartTimeSet = 1 << 2,
202 : EndTimeSet = 1 << 3,
203 : AllFieldsSet = (NodesSet | StartTimeSet | EndTimeSet | 0)};
204 :
205 :
206 : ProfileBuilder<STATE | NodesSet>& setNodes(std::unique_ptr<protocol::Array<protocol::Profiler::ProfileNode>> value)
207 : {
208 : static_assert(!(STATE & NodesSet), "property nodes should not be set yet");
209 : m_result->setNodes(std::move(value));
210 : return castState<NodesSet>();
211 : }
212 :
213 : ProfileBuilder<STATE | StartTimeSet>& setStartTime(double value)
214 : {
215 : static_assert(!(STATE & StartTimeSet), "property startTime should not be set yet");
216 : m_result->setStartTime(value);
217 : return castState<StartTimeSet>();
218 : }
219 :
220 : ProfileBuilder<STATE | EndTimeSet>& setEndTime(double value)
221 : {
222 : static_assert(!(STATE & EndTimeSet), "property endTime should not be set yet");
223 : m_result->setEndTime(value);
224 : return castState<EndTimeSet>();
225 : }
226 :
227 : ProfileBuilder<STATE>& setSamples(std::unique_ptr<protocol::Array<int>> value)
228 : {
229 : m_result->setSamples(std::move(value));
230 : return *this;
231 : }
232 :
233 : ProfileBuilder<STATE>& setTimeDeltas(std::unique_ptr<protocol::Array<int>> value)
234 : {
235 : m_result->setTimeDeltas(std::move(value));
236 : return *this;
237 : }
238 :
239 : std::unique_ptr<Profile> build()
240 : {
241 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
242 : return std::move(m_result);
243 : }
244 :
245 : private:
246 : friend class Profile;
247 58 : ProfileBuilder() : m_result(new Profile()) { }
248 :
249 : template<int STEP> ProfileBuilder<STATE | STEP>& castState()
250 : {
251 : return *reinterpret_cast<ProfileBuilder<STATE | STEP>*>(this);
252 : }
253 :
254 : std::unique_ptr<protocol::Profiler::Profile> m_result;
255 : };
256 :
257 : static ProfileBuilder<0> create()
258 : {
259 29 : return ProfileBuilder<0>();
260 : }
261 :
262 : private:
263 : Profile()
264 29 : {
265 29 : m_startTime = 0;
266 29 : m_endTime = 0;
267 : }
268 :
269 : std::unique_ptr<protocol::Array<protocol::Profiler::ProfileNode>> m_nodes;
270 : double m_startTime;
271 : double m_endTime;
272 : Maybe<protocol::Array<int>> m_samples;
273 : Maybe<protocol::Array<int>> m_timeDeltas;
274 : };
275 :
276 :
277 : // Specifies a number of samples attributed to a certain source position.
278 : class PositionTickInfo : public Serializable{
279 : PROTOCOL_DISALLOW_COPY(PositionTickInfo);
280 : public:
281 : static std::unique_ptr<PositionTickInfo> fromValue(protocol::Value* value, ErrorSupport* errors);
282 :
283 38 : ~PositionTickInfo() override { }
284 :
285 : int getLine() { return m_line; }
286 19 : void setLine(int value) { m_line = value; }
287 :
288 : int getTicks() { return m_ticks; }
289 19 : void setTicks(int value) { m_ticks = value; }
290 :
291 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
292 0 : String serialize() override { return toValue()->serialize(); }
293 : std::unique_ptr<PositionTickInfo> clone() const;
294 :
295 : template<int STATE>
296 : class PositionTickInfoBuilder {
297 : public:
298 : enum {
299 : NoFieldsSet = 0,
300 : LineSet = 1 << 1,
301 : TicksSet = 1 << 2,
302 : AllFieldsSet = (LineSet | TicksSet | 0)};
303 :
304 :
305 : PositionTickInfoBuilder<STATE | LineSet>& setLine(int value)
306 : {
307 : static_assert(!(STATE & LineSet), "property line should not be set yet");
308 : m_result->setLine(value);
309 : return castState<LineSet>();
310 : }
311 :
312 : PositionTickInfoBuilder<STATE | TicksSet>& setTicks(int value)
313 : {
314 : static_assert(!(STATE & TicksSet), "property ticks should not be set yet");
315 : m_result->setTicks(value);
316 : return castState<TicksSet>();
317 : }
318 :
319 : std::unique_ptr<PositionTickInfo> build()
320 : {
321 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
322 : return std::move(m_result);
323 : }
324 :
325 : private:
326 : friend class PositionTickInfo;
327 38 : PositionTickInfoBuilder() : m_result(new PositionTickInfo()) { }
328 :
329 : template<int STEP> PositionTickInfoBuilder<STATE | STEP>& castState()
330 : {
331 : return *reinterpret_cast<PositionTickInfoBuilder<STATE | STEP>*>(this);
332 : }
333 :
334 : std::unique_ptr<protocol::Profiler::PositionTickInfo> m_result;
335 : };
336 :
337 : static PositionTickInfoBuilder<0> create()
338 : {
339 19 : return PositionTickInfoBuilder<0>();
340 : }
341 :
342 : private:
343 : PositionTickInfo()
344 19 : {
345 19 : m_line = 0;
346 19 : m_ticks = 0;
347 : }
348 :
349 : int m_line;
350 : int m_ticks;
351 : };
352 :
353 :
354 : // Coverage data for a source range.
355 : class CoverageRange : public Serializable{
356 : PROTOCOL_DISALLOW_COPY(CoverageRange);
357 : public:
358 : static std::unique_ptr<CoverageRange> fromValue(protocol::Value* value, ErrorSupport* errors);
359 :
360 1170 : ~CoverageRange() override { }
361 :
362 : int getStartOffset() { return m_startOffset; }
363 585 : void setStartOffset(int value) { m_startOffset = value; }
364 :
365 : int getEndOffset() { return m_endOffset; }
366 585 : void setEndOffset(int value) { m_endOffset = value; }
367 :
368 : int getCount() { return m_count; }
369 585 : void setCount(int value) { m_count = value; }
370 :
371 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
372 0 : String serialize() override { return toValue()->serialize(); }
373 : std::unique_ptr<CoverageRange> clone() const;
374 :
375 : template<int STATE>
376 : class CoverageRangeBuilder {
377 : public:
378 : enum {
379 : NoFieldsSet = 0,
380 : StartOffsetSet = 1 << 1,
381 : EndOffsetSet = 1 << 2,
382 : CountSet = 1 << 3,
383 : AllFieldsSet = (StartOffsetSet | EndOffsetSet | CountSet | 0)};
384 :
385 :
386 : CoverageRangeBuilder<STATE | StartOffsetSet>& setStartOffset(int value)
387 : {
388 : static_assert(!(STATE & StartOffsetSet), "property startOffset should not be set yet");
389 : m_result->setStartOffset(value);
390 : return castState<StartOffsetSet>();
391 : }
392 :
393 : CoverageRangeBuilder<STATE | EndOffsetSet>& setEndOffset(int value)
394 : {
395 : static_assert(!(STATE & EndOffsetSet), "property endOffset should not be set yet");
396 : m_result->setEndOffset(value);
397 : return castState<EndOffsetSet>();
398 : }
399 :
400 : CoverageRangeBuilder<STATE | CountSet>& setCount(int value)
401 : {
402 : static_assert(!(STATE & CountSet), "property count should not be set yet");
403 : m_result->setCount(value);
404 : return castState<CountSet>();
405 : }
406 :
407 : std::unique_ptr<CoverageRange> build()
408 : {
409 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
410 : return std::move(m_result);
411 : }
412 :
413 : private:
414 : friend class CoverageRange;
415 1170 : CoverageRangeBuilder() : m_result(new CoverageRange()) { }
416 :
417 : template<int STEP> CoverageRangeBuilder<STATE | STEP>& castState()
418 : {
419 : return *reinterpret_cast<CoverageRangeBuilder<STATE | STEP>*>(this);
420 : }
421 :
422 : std::unique_ptr<protocol::Profiler::CoverageRange> m_result;
423 : };
424 :
425 : static CoverageRangeBuilder<0> create()
426 : {
427 585 : return CoverageRangeBuilder<0>();
428 : }
429 :
430 : private:
431 : CoverageRange()
432 585 : {
433 585 : m_startOffset = 0;
434 585 : m_endOffset = 0;
435 585 : m_count = 0;
436 : }
437 :
438 : int m_startOffset;
439 : int m_endOffset;
440 : int m_count;
441 : };
442 :
443 :
444 : // Coverage data for a JavaScript function.
445 : class FunctionCoverage : public Serializable{
446 : PROTOCOL_DISALLOW_COPY(FunctionCoverage);
447 : public:
448 : static std::unique_ptr<FunctionCoverage> fromValue(protocol::Value* value, ErrorSupport* errors);
449 :
450 1425 : ~FunctionCoverage() override { }
451 :
452 : String getFunctionName() { return m_functionName; }
453 475 : void setFunctionName(const String& value) { m_functionName = value; }
454 :
455 : protocol::Array<protocol::Profiler::CoverageRange>* getRanges() { return m_ranges.get(); }
456 : void setRanges(std::unique_ptr<protocol::Array<protocol::Profiler::CoverageRange>> value) { m_ranges = std::move(value); }
457 :
458 : bool getIsBlockCoverage() { return m_isBlockCoverage; }
459 475 : void setIsBlockCoverage(bool value) { m_isBlockCoverage = value; }
460 :
461 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
462 0 : String serialize() override { return toValue()->serialize(); }
463 : std::unique_ptr<FunctionCoverage> clone() const;
464 :
465 : template<int STATE>
466 : class FunctionCoverageBuilder {
467 : public:
468 : enum {
469 : NoFieldsSet = 0,
470 : FunctionNameSet = 1 << 1,
471 : RangesSet = 1 << 2,
472 : IsBlockCoverageSet = 1 << 3,
473 : AllFieldsSet = (FunctionNameSet | RangesSet | IsBlockCoverageSet | 0)};
474 :
475 :
476 : FunctionCoverageBuilder<STATE | FunctionNameSet>& setFunctionName(const String& value)
477 : {
478 : static_assert(!(STATE & FunctionNameSet), "property functionName should not be set yet");
479 : m_result->setFunctionName(value);
480 : return castState<FunctionNameSet>();
481 : }
482 :
483 : FunctionCoverageBuilder<STATE | RangesSet>& setRanges(std::unique_ptr<protocol::Array<protocol::Profiler::CoverageRange>> value)
484 : {
485 : static_assert(!(STATE & RangesSet), "property ranges should not be set yet");
486 : m_result->setRanges(std::move(value));
487 : return castState<RangesSet>();
488 : }
489 :
490 : FunctionCoverageBuilder<STATE | IsBlockCoverageSet>& setIsBlockCoverage(bool value)
491 : {
492 : static_assert(!(STATE & IsBlockCoverageSet), "property isBlockCoverage should not be set yet");
493 : m_result->setIsBlockCoverage(value);
494 : return castState<IsBlockCoverageSet>();
495 : }
496 :
497 : std::unique_ptr<FunctionCoverage> build()
498 : {
499 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
500 : return std::move(m_result);
501 : }
502 :
503 : private:
504 : friend class FunctionCoverage;
505 950 : FunctionCoverageBuilder() : m_result(new FunctionCoverage()) { }
506 :
507 : template<int STEP> FunctionCoverageBuilder<STATE | STEP>& castState()
508 : {
509 : return *reinterpret_cast<FunctionCoverageBuilder<STATE | STEP>*>(this);
510 : }
511 :
512 : std::unique_ptr<protocol::Profiler::FunctionCoverage> m_result;
513 : };
514 :
515 : static FunctionCoverageBuilder<0> create()
516 : {
517 475 : return FunctionCoverageBuilder<0>();
518 : }
519 :
520 : private:
521 : FunctionCoverage()
522 475 : {
523 475 : m_isBlockCoverage = false;
524 : }
525 :
526 : String m_functionName;
527 : std::unique_ptr<protocol::Array<protocol::Profiler::CoverageRange>> m_ranges;
528 : bool m_isBlockCoverage;
529 : };
530 :
531 :
532 : // Coverage data for a JavaScript script.
533 : class ScriptCoverage : public Serializable{
534 : PROTOCOL_DISALLOW_COPY(ScriptCoverage);
535 : public:
536 : static std::unique_ptr<ScriptCoverage> fromValue(protocol::Value* value, ErrorSupport* errors);
537 :
538 600 : ~ScriptCoverage() override { }
539 :
540 : String getScriptId() { return m_scriptId; }
541 200 : void setScriptId(const String& value) { m_scriptId = value; }
542 :
543 : String getUrl() { return m_url; }
544 200 : void setUrl(const String& value) { m_url = value; }
545 :
546 : protocol::Array<protocol::Profiler::FunctionCoverage>* getFunctions() { return m_functions.get(); }
547 : void setFunctions(std::unique_ptr<protocol::Array<protocol::Profiler::FunctionCoverage>> value) { m_functions = std::move(value); }
548 :
549 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
550 0 : String serialize() override { return toValue()->serialize(); }
551 : std::unique_ptr<ScriptCoverage> clone() const;
552 :
553 : template<int STATE>
554 : class ScriptCoverageBuilder {
555 : public:
556 : enum {
557 : NoFieldsSet = 0,
558 : ScriptIdSet = 1 << 1,
559 : UrlSet = 1 << 2,
560 : FunctionsSet = 1 << 3,
561 : AllFieldsSet = (ScriptIdSet | UrlSet | FunctionsSet | 0)};
562 :
563 :
564 : ScriptCoverageBuilder<STATE | ScriptIdSet>& setScriptId(const String& value)
565 : {
566 : static_assert(!(STATE & ScriptIdSet), "property scriptId should not be set yet");
567 : m_result->setScriptId(value);
568 : return castState<ScriptIdSet>();
569 : }
570 :
571 : ScriptCoverageBuilder<STATE | UrlSet>& setUrl(const String& value)
572 : {
573 : static_assert(!(STATE & UrlSet), "property url should not be set yet");
574 : m_result->setUrl(value);
575 : return castState<UrlSet>();
576 : }
577 :
578 : ScriptCoverageBuilder<STATE | FunctionsSet>& setFunctions(std::unique_ptr<protocol::Array<protocol::Profiler::FunctionCoverage>> value)
579 : {
580 : static_assert(!(STATE & FunctionsSet), "property functions should not be set yet");
581 : m_result->setFunctions(std::move(value));
582 : return castState<FunctionsSet>();
583 : }
584 :
585 : std::unique_ptr<ScriptCoverage> build()
586 : {
587 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
588 : return std::move(m_result);
589 : }
590 :
591 : private:
592 : friend class ScriptCoverage;
593 400 : ScriptCoverageBuilder() : m_result(new ScriptCoverage()) { }
594 :
595 : template<int STEP> ScriptCoverageBuilder<STATE | STEP>& castState()
596 : {
597 : return *reinterpret_cast<ScriptCoverageBuilder<STATE | STEP>*>(this);
598 : }
599 :
600 : std::unique_ptr<protocol::Profiler::ScriptCoverage> m_result;
601 : };
602 :
603 : static ScriptCoverageBuilder<0> create()
604 : {
605 200 : return ScriptCoverageBuilder<0>();
606 : }
607 :
608 : private:
609 200 : ScriptCoverage()
610 200 : {
611 200 : }
612 :
613 : String m_scriptId;
614 : String m_url;
615 : std::unique_ptr<protocol::Array<protocol::Profiler::FunctionCoverage>> m_functions;
616 : };
617 :
618 :
619 : // Describes a type collected during runtime.
620 : class TypeObject : public Serializable{
621 : PROTOCOL_DISALLOW_COPY(TypeObject);
622 : public:
623 : static std::unique_ptr<TypeObject> fromValue(protocol::Value* value, ErrorSupport* errors);
624 :
625 490 : ~TypeObject() override { }
626 :
627 : String getName() { return m_name; }
628 245 : void setName(const String& value) { m_name = value; }
629 :
630 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
631 0 : String serialize() override { return toValue()->serialize(); }
632 : std::unique_ptr<TypeObject> clone() const;
633 :
634 : template<int STATE>
635 : class TypeObjectBuilder {
636 : public:
637 : enum {
638 : NoFieldsSet = 0,
639 : NameSet = 1 << 1,
640 : AllFieldsSet = (NameSet | 0)};
641 :
642 :
643 : TypeObjectBuilder<STATE | NameSet>& setName(const String& value)
644 : {
645 : static_assert(!(STATE & NameSet), "property name should not be set yet");
646 : m_result->setName(value);
647 : return castState<NameSet>();
648 : }
649 :
650 : std::unique_ptr<TypeObject> build()
651 : {
652 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
653 : return std::move(m_result);
654 : }
655 :
656 : private:
657 : friend class TypeObject;
658 490 : TypeObjectBuilder() : m_result(new TypeObject()) { }
659 :
660 : template<int STEP> TypeObjectBuilder<STATE | STEP>& castState()
661 : {
662 : return *reinterpret_cast<TypeObjectBuilder<STATE | STEP>*>(this);
663 : }
664 :
665 : std::unique_ptr<protocol::Profiler::TypeObject> m_result;
666 : };
667 :
668 : static TypeObjectBuilder<0> create()
669 : {
670 245 : return TypeObjectBuilder<0>();
671 : }
672 :
673 : private:
674 : TypeObject()
675 245 : {
676 : }
677 :
678 : String m_name;
679 : };
680 :
681 :
682 : // Source offset and types for a parameter or return value.
683 : class TypeProfileEntry : public Serializable{
684 : PROTOCOL_DISALLOW_COPY(TypeProfileEntry);
685 : public:
686 : static std::unique_ptr<TypeProfileEntry> fromValue(protocol::Value* value, ErrorSupport* errors);
687 :
688 370 : ~TypeProfileEntry() override { }
689 :
690 : int getOffset() { return m_offset; }
691 185 : void setOffset(int value) { m_offset = value; }
692 :
693 : protocol::Array<protocol::Profiler::TypeObject>* getTypes() { return m_types.get(); }
694 : void setTypes(std::unique_ptr<protocol::Array<protocol::Profiler::TypeObject>> value) { m_types = std::move(value); }
695 :
696 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
697 0 : String serialize() override { return toValue()->serialize(); }
698 : std::unique_ptr<TypeProfileEntry> clone() const;
699 :
700 : template<int STATE>
701 : class TypeProfileEntryBuilder {
702 : public:
703 : enum {
704 : NoFieldsSet = 0,
705 : OffsetSet = 1 << 1,
706 : TypesSet = 1 << 2,
707 : AllFieldsSet = (OffsetSet | TypesSet | 0)};
708 :
709 :
710 : TypeProfileEntryBuilder<STATE | OffsetSet>& setOffset(int value)
711 : {
712 : static_assert(!(STATE & OffsetSet), "property offset should not be set yet");
713 : m_result->setOffset(value);
714 : return castState<OffsetSet>();
715 : }
716 :
717 : TypeProfileEntryBuilder<STATE | TypesSet>& setTypes(std::unique_ptr<protocol::Array<protocol::Profiler::TypeObject>> value)
718 : {
719 : static_assert(!(STATE & TypesSet), "property types should not be set yet");
720 : m_result->setTypes(std::move(value));
721 : return castState<TypesSet>();
722 : }
723 :
724 : std::unique_ptr<TypeProfileEntry> build()
725 : {
726 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
727 : return std::move(m_result);
728 : }
729 :
730 : private:
731 : friend class TypeProfileEntry;
732 370 : TypeProfileEntryBuilder() : m_result(new TypeProfileEntry()) { }
733 :
734 : template<int STEP> TypeProfileEntryBuilder<STATE | STEP>& castState()
735 : {
736 : return *reinterpret_cast<TypeProfileEntryBuilder<STATE | STEP>*>(this);
737 : }
738 :
739 : std::unique_ptr<protocol::Profiler::TypeProfileEntry> m_result;
740 : };
741 :
742 : static TypeProfileEntryBuilder<0> create()
743 : {
744 185 : return TypeProfileEntryBuilder<0>();
745 : }
746 :
747 : private:
748 : TypeProfileEntry()
749 185 : {
750 185 : m_offset = 0;
751 : }
752 :
753 : int m_offset;
754 : std::unique_ptr<protocol::Array<protocol::Profiler::TypeObject>> m_types;
755 : };
756 :
757 :
758 : // Type profile data collected during runtime for a JavaScript script.
759 : class ScriptTypeProfile : public Serializable{
760 : PROTOCOL_DISALLOW_COPY(ScriptTypeProfile);
761 : public:
762 : static std::unique_ptr<ScriptTypeProfile> fromValue(protocol::Value* value, ErrorSupport* errors);
763 :
764 120 : ~ScriptTypeProfile() override { }
765 :
766 : String getScriptId() { return m_scriptId; }
767 40 : void setScriptId(const String& value) { m_scriptId = value; }
768 :
769 : String getUrl() { return m_url; }
770 40 : void setUrl(const String& value) { m_url = value; }
771 :
772 : protocol::Array<protocol::Profiler::TypeProfileEntry>* getEntries() { return m_entries.get(); }
773 : void setEntries(std::unique_ptr<protocol::Array<protocol::Profiler::TypeProfileEntry>> value) { m_entries = std::move(value); }
774 :
775 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
776 0 : String serialize() override { return toValue()->serialize(); }
777 : std::unique_ptr<ScriptTypeProfile> clone() const;
778 :
779 : template<int STATE>
780 : class ScriptTypeProfileBuilder {
781 : public:
782 : enum {
783 : NoFieldsSet = 0,
784 : ScriptIdSet = 1 << 1,
785 : UrlSet = 1 << 2,
786 : EntriesSet = 1 << 3,
787 : AllFieldsSet = (ScriptIdSet | UrlSet | EntriesSet | 0)};
788 :
789 :
790 : ScriptTypeProfileBuilder<STATE | ScriptIdSet>& setScriptId(const String& value)
791 : {
792 : static_assert(!(STATE & ScriptIdSet), "property scriptId should not be set yet");
793 : m_result->setScriptId(value);
794 : return castState<ScriptIdSet>();
795 : }
796 :
797 : ScriptTypeProfileBuilder<STATE | UrlSet>& setUrl(const String& value)
798 : {
799 : static_assert(!(STATE & UrlSet), "property url should not be set yet");
800 : m_result->setUrl(value);
801 : return castState<UrlSet>();
802 : }
803 :
804 : ScriptTypeProfileBuilder<STATE | EntriesSet>& setEntries(std::unique_ptr<protocol::Array<protocol::Profiler::TypeProfileEntry>> value)
805 : {
806 : static_assert(!(STATE & EntriesSet), "property entries should not be set yet");
807 : m_result->setEntries(std::move(value));
808 : return castState<EntriesSet>();
809 : }
810 :
811 : std::unique_ptr<ScriptTypeProfile> build()
812 : {
813 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
814 : return std::move(m_result);
815 : }
816 :
817 : private:
818 : friend class ScriptTypeProfile;
819 80 : ScriptTypeProfileBuilder() : m_result(new ScriptTypeProfile()) { }
820 :
821 : template<int STEP> ScriptTypeProfileBuilder<STATE | STEP>& castState()
822 : {
823 : return *reinterpret_cast<ScriptTypeProfileBuilder<STATE | STEP>*>(this);
824 : }
825 :
826 : std::unique_ptr<protocol::Profiler::ScriptTypeProfile> m_result;
827 : };
828 :
829 : static ScriptTypeProfileBuilder<0> create()
830 : {
831 40 : return ScriptTypeProfileBuilder<0>();
832 : }
833 :
834 : private:
835 40 : ScriptTypeProfile()
836 40 : {
837 40 : }
838 :
839 : String m_scriptId;
840 : String m_url;
841 : std::unique_ptr<protocol::Array<protocol::Profiler::TypeProfileEntry>> m_entries;
842 : };
843 :
844 :
845 : // Wrapper for notification params
846 : class ConsoleProfileStartedNotification : public Serializable{
847 : PROTOCOL_DISALLOW_COPY(ConsoleProfileStartedNotification);
848 : public:
849 : static std::unique_ptr<ConsoleProfileStartedNotification> fromValue(protocol::Value* value, ErrorSupport* errors);
850 :
851 72 : ~ConsoleProfileStartedNotification() override { }
852 :
853 : String getId() { return m_id; }
854 24 : void setId(const String& value) { m_id = value; }
855 :
856 : protocol::Debugger::Location* getLocation() { return m_location.get(); }
857 : void setLocation(std::unique_ptr<protocol::Debugger::Location> value) { m_location = std::move(value); }
858 :
859 : bool hasTitle() { return m_title.isJust(); }
860 : String getTitle(const String& defaultValue) { return m_title.isJust() ? m_title.fromJust() : defaultValue; }
861 48 : void setTitle(const String& value) { m_title = value; }
862 :
863 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
864 72 : String serialize() override { return toValue()->serialize(); }
865 : std::unique_ptr<ConsoleProfileStartedNotification> clone() const;
866 :
867 : template<int STATE>
868 : class ConsoleProfileStartedNotificationBuilder {
869 : public:
870 : enum {
871 : NoFieldsSet = 0,
872 : IdSet = 1 << 1,
873 : LocationSet = 1 << 2,
874 : AllFieldsSet = (IdSet | LocationSet | 0)};
875 :
876 :
877 : ConsoleProfileStartedNotificationBuilder<STATE | IdSet>& setId(const String& value)
878 : {
879 : static_assert(!(STATE & IdSet), "property id should not be set yet");
880 : m_result->setId(value);
881 : return castState<IdSet>();
882 : }
883 :
884 : ConsoleProfileStartedNotificationBuilder<STATE | LocationSet>& setLocation(std::unique_ptr<protocol::Debugger::Location> value)
885 : {
886 : static_assert(!(STATE & LocationSet), "property location should not be set yet");
887 : m_result->setLocation(std::move(value));
888 : return castState<LocationSet>();
889 : }
890 :
891 : ConsoleProfileStartedNotificationBuilder<STATE>& setTitle(const String& value)
892 : {
893 : m_result->setTitle(value);
894 : return *this;
895 : }
896 :
897 : std::unique_ptr<ConsoleProfileStartedNotification> build()
898 : {
899 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
900 : return std::move(m_result);
901 : }
902 :
903 : private:
904 : friend class ConsoleProfileStartedNotification;
905 48 : ConsoleProfileStartedNotificationBuilder() : m_result(new ConsoleProfileStartedNotification()) { }
906 :
907 : template<int STEP> ConsoleProfileStartedNotificationBuilder<STATE | STEP>& castState()
908 : {
909 : return *reinterpret_cast<ConsoleProfileStartedNotificationBuilder<STATE | STEP>*>(this);
910 : }
911 :
912 : std::unique_ptr<protocol::Profiler::ConsoleProfileStartedNotification> m_result;
913 : };
914 :
915 : static ConsoleProfileStartedNotificationBuilder<0> create()
916 : {
917 24 : return ConsoleProfileStartedNotificationBuilder<0>();
918 : }
919 :
920 : private:
921 24 : ConsoleProfileStartedNotification()
922 24 : {
923 24 : }
924 :
925 : String m_id;
926 : std::unique_ptr<protocol::Debugger::Location> m_location;
927 : Maybe<String> m_title;
928 : };
929 :
930 :
931 : // Wrapper for notification params
932 : class ConsoleProfileFinishedNotification : public Serializable{
933 : PROTOCOL_DISALLOW_COPY(ConsoleProfileFinishedNotification);
934 : public:
935 : static std::unique_ptr<ConsoleProfileFinishedNotification> fromValue(protocol::Value* value, ErrorSupport* errors);
936 :
937 57 : ~ConsoleProfileFinishedNotification() override { }
938 :
939 : String getId() { return m_id; }
940 19 : void setId(const String& value) { m_id = value; }
941 :
942 : protocol::Debugger::Location* getLocation() { return m_location.get(); }
943 : void setLocation(std::unique_ptr<protocol::Debugger::Location> value) { m_location = std::move(value); }
944 :
945 : protocol::Profiler::Profile* getProfile() { return m_profile.get(); }
946 : void setProfile(std::unique_ptr<protocol::Profiler::Profile> value) { m_profile = std::move(value); }
947 :
948 : bool hasTitle() { return m_title.isJust(); }
949 : String getTitle(const String& defaultValue) { return m_title.isJust() ? m_title.fromJust() : defaultValue; }
950 38 : void setTitle(const String& value) { m_title = value; }
951 :
952 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
953 57 : String serialize() override { return toValue()->serialize(); }
954 : std::unique_ptr<ConsoleProfileFinishedNotification> clone() const;
955 :
956 : template<int STATE>
957 : class ConsoleProfileFinishedNotificationBuilder {
958 : public:
959 : enum {
960 : NoFieldsSet = 0,
961 : IdSet = 1 << 1,
962 : LocationSet = 1 << 2,
963 : ProfileSet = 1 << 3,
964 : AllFieldsSet = (IdSet | LocationSet | ProfileSet | 0)};
965 :
966 :
967 : ConsoleProfileFinishedNotificationBuilder<STATE | IdSet>& setId(const String& value)
968 : {
969 : static_assert(!(STATE & IdSet), "property id should not be set yet");
970 : m_result->setId(value);
971 : return castState<IdSet>();
972 : }
973 :
974 : ConsoleProfileFinishedNotificationBuilder<STATE | LocationSet>& setLocation(std::unique_ptr<protocol::Debugger::Location> value)
975 : {
976 : static_assert(!(STATE & LocationSet), "property location should not be set yet");
977 : m_result->setLocation(std::move(value));
978 : return castState<LocationSet>();
979 : }
980 :
981 : ConsoleProfileFinishedNotificationBuilder<STATE | ProfileSet>& setProfile(std::unique_ptr<protocol::Profiler::Profile> value)
982 : {
983 : static_assert(!(STATE & ProfileSet), "property profile should not be set yet");
984 : m_result->setProfile(std::move(value));
985 : return castState<ProfileSet>();
986 : }
987 :
988 : ConsoleProfileFinishedNotificationBuilder<STATE>& setTitle(const String& value)
989 : {
990 : m_result->setTitle(value);
991 : return *this;
992 : }
993 :
994 : std::unique_ptr<ConsoleProfileFinishedNotification> build()
995 : {
996 : static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
997 : return std::move(m_result);
998 : }
999 :
1000 : private:
1001 : friend class ConsoleProfileFinishedNotification;
1002 38 : ConsoleProfileFinishedNotificationBuilder() : m_result(new ConsoleProfileFinishedNotification()) { }
1003 :
1004 : template<int STEP> ConsoleProfileFinishedNotificationBuilder<STATE | STEP>& castState()
1005 : {
1006 : return *reinterpret_cast<ConsoleProfileFinishedNotificationBuilder<STATE | STEP>*>(this);
1007 : }
1008 :
1009 : std::unique_ptr<protocol::Profiler::ConsoleProfileFinishedNotification> m_result;
1010 : };
1011 :
1012 : static ConsoleProfileFinishedNotificationBuilder<0> create()
1013 : {
1014 19 : return ConsoleProfileFinishedNotificationBuilder<0>();
1015 : }
1016 :
1017 : private:
1018 19 : ConsoleProfileFinishedNotification()
1019 19 : {
1020 19 : }
1021 :
1022 : String m_id;
1023 : std::unique_ptr<protocol::Debugger::Location> m_location;
1024 : std::unique_ptr<protocol::Profiler::Profile> m_profile;
1025 : Maybe<String> m_title;
1026 : };
1027 :
1028 :
1029 : // ------------- Backend interface.
1030 :
1031 3406 : class Backend {
1032 : public:
1033 3406 : virtual ~Backend() { }
1034 :
1035 : virtual DispatchResponse enable() = 0;
1036 : virtual DispatchResponse disable() = 0;
1037 : virtual DispatchResponse setSamplingInterval(int in_interval) = 0;
1038 : virtual DispatchResponse start() = 0;
1039 : virtual DispatchResponse stop(std::unique_ptr<protocol::Profiler::Profile>* out_profile) = 0;
1040 : virtual DispatchResponse startPreciseCoverage(Maybe<bool> in_callCount, Maybe<bool> in_detailed) = 0;
1041 : virtual DispatchResponse stopPreciseCoverage() = 0;
1042 : virtual DispatchResponse takePreciseCoverage(std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>* out_result) = 0;
1043 : virtual DispatchResponse getBestEffortCoverage(std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>* out_result) = 0;
1044 : virtual DispatchResponse startTypeProfile() = 0;
1045 : virtual DispatchResponse stopTypeProfile() = 0;
1046 : virtual DispatchResponse takeTypeProfile(std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>* out_result) = 0;
1047 :
1048 : };
1049 :
1050 : // ------------- Frontend interface.
1051 :
1052 : class Frontend {
1053 : public:
1054 3406 : explicit Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { }
1055 : void consoleProfileStarted(const String& id, std::unique_ptr<protocol::Debugger::Location> location, Maybe<String> title = Maybe<String>());
1056 : void consoleProfileFinished(const String& id, std::unique_ptr<protocol::Debugger::Location> location, std::unique_ptr<protocol::Profiler::Profile> profile, Maybe<String> title = Maybe<String>());
1057 :
1058 : void flush();
1059 : void sendRawNotification(const String&);
1060 : private:
1061 : FrontendChannel* m_frontendChannel;
1062 : };
1063 :
1064 : // ------------- Dispatcher.
1065 :
1066 : class Dispatcher {
1067 : public:
1068 : static void wire(UberDispatcher*, Backend*);
1069 :
1070 : private:
1071 : Dispatcher() { }
1072 : };
1073 :
1074 : // ------------- Metainfo.
1075 :
1076 : class Metainfo {
1077 : public:
1078 : using BackendClass = Backend;
1079 : using FrontendClass = Frontend;
1080 : using DispatcherClass = Dispatcher;
1081 : static const char domainName[];
1082 : static const char commandPrefix[];
1083 : static const char version[];
1084 : };
1085 :
1086 : } // namespace Profiler
1087 : } // namespace v8_inspector
1088 : } // namespace protocol
1089 :
1090 : #endif // !defined(v8_inspector_protocol_Profiler_h)
|