001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013import Torello.Java.JSON.*;
014
015import static Torello.Java.JSON.JFlag.*;
016
017import Torello.Java.StrCmpr;
018import Torello.JavaDoc.StaticFunctional;
019import Torello.JavaDoc.JDHeaderBackgroundImg;
020import Torello.JavaDoc.Excuse;
021
022/**
023 * <SPAN CLASS=COPIEDJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class Profiler
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private Profiler () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : Profiler.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        parameterNames.put("disable", EMPTY_VEC_STR);
078
079        parameterNames.put("enable", EMPTY_VEC_STR);
080
081        parameterNames.put("getBestEffortCoverage", EMPTY_VEC_STR);
082
083        v = new Vector<String>(1);
084        parameterNames.put("setSamplingInterval", v);
085        Collections.addAll(v, new String[]
086        { "interval", });
087
088        parameterNames.put("start", EMPTY_VEC_STR);
089
090        v = new Vector<String>(3);
091        parameterNames.put("startPreciseCoverage", v);
092        Collections.addAll(v, new String[]
093        { "callCount", "detailed", "allowTriggeredUpdates", });
094
095        parameterNames.put("startTypeProfile", EMPTY_VEC_STR);
096
097        parameterNames.put("stop", EMPTY_VEC_STR);
098
099        parameterNames.put("stopPreciseCoverage", EMPTY_VEC_STR);
100
101        parameterNames.put("stopTypeProfile", EMPTY_VEC_STR);
102
103        parameterNames.put("takePreciseCoverage", EMPTY_VEC_STR);
104
105        parameterNames.put("takeTypeProfile", EMPTY_VEC_STR);
106    }
107
108
109    // ********************************************************************************************
110    // ********************************************************************************************
111    // Types - Static Inner Classes
112    // ********************************************************************************************
113    // ********************************************************************************************
114
115    /** Profile node. Holds callsite information, execution statistics and child nodes. */
116    public static class ProfileNode
117        extends BaseType
118        implements java.io.Serializable
119    {
120        /** For Object Serialization.  java.io.Serializable */
121        protected static final long serialVersionUID = 1;
122        
123        public boolean[] optionals()
124        { return new boolean[] { false, false, true, true, true, true, }; }
125        
126        /** Unique id of the node. */
127        public final int id;
128        
129        /** Function location. */
130        public final RunTime.CallFrame callFrame;
131        
132        /**
133         * Number of samples where this node was on top of the call stack.
134         * <BR />
135         * <BR /><B>OPTIONAL</B>
136         */
137        public final Integer hitCount;
138        
139        /**
140         * Child node ids.
141         * <BR />
142         * <BR /><B>OPTIONAL</B>
143         */
144        public final int[] children;
145        
146        /**
147         * The reason of being not optimized. The function may be deoptimized or marked as don't
148         * optimize.
149         * <BR />
150         * <BR /><B>OPTIONAL</B>
151         */
152        public final String deoptReason;
153        
154        /**
155         * An array of source position ticks.
156         * <BR />
157         * <BR /><B>OPTIONAL</B>
158         */
159        public final Profiler.PositionTickInfo[] positionTicks;
160        
161        /**
162         * Constructor
163         *
164         * @param id Unique id of the node.
165         * 
166         * @param callFrame Function location.
167         * 
168         * @param hitCount Number of samples where this node was on top of the call stack.
169         * <BR /><B>OPTIONAL</B>
170         * 
171         * @param children Child node ids.
172         * <BR /><B>OPTIONAL</B>
173         * 
174         * @param deoptReason 
175         * The reason of being not optimized. The function may be deoptimized or marked as don't
176         * optimize.
177         * <BR /><B>OPTIONAL</B>
178         * 
179         * @param positionTicks An array of source position ticks.
180         * <BR /><B>OPTIONAL</B>
181         */
182        public ProfileNode(
183                int id, RunTime.CallFrame callFrame, Integer hitCount, int[] children, 
184                String deoptReason, Profiler.PositionTickInfo[] positionTicks
185            )
186        {
187            // Exception-Check(s) to ensure that if any parameters which are not declared as
188            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
189            
190            if (callFrame == null) BRDPC.throwNPE("callFrame");
191            
192            this.id             = id;
193            this.callFrame      = callFrame;
194            this.hitCount       = hitCount;
195            this.children       = children;
196            this.deoptReason    = deoptReason;
197            this.positionTicks  = positionTicks;
198        }
199        
200        /**
201         * JSON Object Constructor
202         * @param jo A Json-Object having data about an instance of {@code 'ProfileNode'}.
203         */
204        public ProfileNode (JsonObject jo)
205        {
206            this.id             = ReadPrimJSON.getInt(jo, "id");
207            this.callFrame      = ReadJSON.getObject(jo, "callFrame", RunTime.CallFrame.class, false, true);
208            this.hitCount       = ReadBoxedJSON.getInteger(jo, "hitCount", true);
209            this.children = (jo.getJsonArray("children") == null)
210                ? null
211                : ReadArrJSON.DimN.intArr(jo.getJsonArray("children"), -1, 0, null, int[].class);
212        
213            this.deoptReason    = ReadJSON.getString(jo, "deoptReason", true, false);
214            this.positionTicks = (jo.getJsonArray("positionTicks") == null)
215                ? null
216                : ReadArrJSON.DimN.objArr(jo.getJsonArray("positionTicks"), null, 0, Profiler.PositionTickInfo[].class);
217        
218        }
219        
220        
221        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
222        public boolean equals(Object other)
223        {
224            if (other == null)                       return false;
225            if (other.getClass() != this.getClass()) return false;
226        
227            ProfileNode o = (ProfileNode) other;
228        
229            return
230                    (this.id == o.id)
231                &&  Objects.equals(this.callFrame, o.callFrame)
232                &&  Objects.equals(this.hitCount, o.hitCount)
233                &&  Arrays.equals(this.children, o.children)
234                &&  Objects.equals(this.deoptReason, o.deoptReason)
235                &&  Arrays.deepEquals(this.positionTicks, o.positionTicks);
236        }
237        
238        /** Generates a Hash-Code for {@code 'this'} instance */
239        public int hashCode()
240        {
241            return
242                    this.id
243                +   this.callFrame.hashCode()
244                +   Objects.hashCode(this.hitCount)
245                +   Arrays.hashCode(this.children)
246                +   Objects.hashCode(this.deoptReason)
247                +   Arrays.deepHashCode(this.positionTicks);
248        }
249    }
250    
251    /** Profile. */
252    public static class Profile
253        extends BaseType
254        implements java.io.Serializable
255    {
256        /** For Object Serialization.  java.io.Serializable */
257        protected static final long serialVersionUID = 1;
258        
259        public boolean[] optionals()
260        { return new boolean[] { false, false, false, true, true, }; }
261        
262        /** The list of profile nodes. First item is the root node. */
263        public final Profiler.ProfileNode[] nodes;
264        
265        /** Profiling start timestamp in microseconds. */
266        public final Number startTime;
267        
268        /** Profiling end timestamp in microseconds. */
269        public final Number endTime;
270        
271        /**
272         * Ids of samples top nodes.
273         * <BR />
274         * <BR /><B>OPTIONAL</B>
275         */
276        public final int[] samples;
277        
278        /**
279         * Time intervals between adjacent samples in microseconds. The first delta is relative to the
280         * profile startTime.
281         * <BR />
282         * <BR /><B>OPTIONAL</B>
283         */
284        public final int[] timeDeltas;
285        
286        /**
287         * Constructor
288         *
289         * @param nodes The list of profile nodes. First item is the root node.
290         * 
291         * @param startTime Profiling start timestamp in microseconds.
292         * 
293         * @param endTime Profiling end timestamp in microseconds.
294         * 
295         * @param samples Ids of samples top nodes.
296         * <BR /><B>OPTIONAL</B>
297         * 
298         * @param timeDeltas 
299         * Time intervals between adjacent samples in microseconds. The first delta is relative to the
300         * profile startTime.
301         * <BR /><B>OPTIONAL</B>
302         */
303        public Profile(
304                Profiler.ProfileNode[] nodes, Number startTime, Number endTime, int[] samples, 
305                int[] timeDeltas
306            )
307        {
308            // Exception-Check(s) to ensure that if any parameters which are not declared as
309            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
310            
311            if (nodes == null)     BRDPC.throwNPE("nodes");
312            if (startTime == null) BRDPC.throwNPE("startTime");
313            if (endTime == null)   BRDPC.throwNPE("endTime");
314            
315            this.nodes       = nodes;
316            this.startTime   = startTime;
317            this.endTime     = endTime;
318            this.samples     = samples;
319            this.timeDeltas  = timeDeltas;
320        }
321        
322        /**
323         * JSON Object Constructor
324         * @param jo A Json-Object having data about an instance of {@code 'Profile'}.
325         */
326        public Profile (JsonObject jo)
327        {
328            this.nodes = (jo.getJsonArray("nodes") == null)
329                ? null
330                : ReadArrJSON.DimN.objArr(jo.getJsonArray("nodes"), null, 0, Profiler.ProfileNode[].class);
331        
332            this.startTime   = ReadNumberJSON.get(jo, "startTime", false, true);
333            this.endTime     = ReadNumberJSON.get(jo, "endTime", false, true);
334            this.samples = (jo.getJsonArray("samples") == null)
335                ? null
336                : ReadArrJSON.DimN.intArr(jo.getJsonArray("samples"), -1, 0, null, int[].class);
337        
338            this.timeDeltas = (jo.getJsonArray("timeDeltas") == null)
339                ? null
340                : ReadArrJSON.DimN.intArr(jo.getJsonArray("timeDeltas"), -1, 0, null, int[].class);
341        
342        }
343        
344        
345        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
346        public boolean equals(Object other)
347        {
348            if (other == null)                       return false;
349            if (other.getClass() != this.getClass()) return false;
350        
351            Profile o = (Profile) other;
352        
353            return
354                    Arrays.deepEquals(this.nodes, o.nodes)
355                &&  Objects.equals(this.startTime, o.startTime)
356                &&  Objects.equals(this.endTime, o.endTime)
357                &&  Arrays.equals(this.samples, o.samples)
358                &&  Arrays.equals(this.timeDeltas, o.timeDeltas);
359        }
360        
361        /** Generates a Hash-Code for {@code 'this'} instance */
362        public int hashCode()
363        {
364            return
365                    Arrays.deepHashCode(this.nodes)
366                +   Objects.hashCode(this.startTime)
367                +   Objects.hashCode(this.endTime)
368                +   Arrays.hashCode(this.samples)
369                +   Arrays.hashCode(this.timeDeltas);
370        }
371    }
372    
373    /** Specifies a number of samples attributed to a certain source position. */
374    public static class PositionTickInfo
375        extends BaseType
376        implements java.io.Serializable
377    {
378        /** For Object Serialization.  java.io.Serializable */
379        protected static final long serialVersionUID = 1;
380        
381        public boolean[] optionals()
382        { return new boolean[] { false, false, }; }
383        
384        /** Source line number (1-based). */
385        public final int line;
386        
387        /** Number of samples attributed to the source line. */
388        public final int ticks;
389        
390        /**
391         * Constructor
392         *
393         * @param line Source line number (1-based).
394         * 
395         * @param ticks Number of samples attributed to the source line.
396         */
397        public PositionTickInfo(int line, int ticks)
398        {
399            this.line   = line;
400            this.ticks  = ticks;
401        }
402        
403        /**
404         * JSON Object Constructor
405         * @param jo A Json-Object having data about an instance of {@code 'PositionTickInfo'}.
406         */
407        public PositionTickInfo (JsonObject jo)
408        {
409            this.line   = ReadPrimJSON.getInt(jo, "line");
410            this.ticks  = ReadPrimJSON.getInt(jo, "ticks");
411        }
412        
413        
414        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
415        public boolean equals(Object other)
416        {
417            if (other == null)                       return false;
418            if (other.getClass() != this.getClass()) return false;
419        
420            PositionTickInfo o = (PositionTickInfo) other;
421        
422            return
423                    (this.line == o.line)
424                &&  (this.ticks == o.ticks);
425        }
426        
427        /** Generates a Hash-Code for {@code 'this'} instance */
428        public int hashCode()
429        {
430            return
431                    this.line
432                +   this.ticks;
433        }
434    }
435    
436    /** Coverage data for a source range. */
437    public static class CoverageRange
438        extends BaseType
439        implements java.io.Serializable
440    {
441        /** For Object Serialization.  java.io.Serializable */
442        protected static final long serialVersionUID = 1;
443        
444        public boolean[] optionals()
445        { return new boolean[] { false, false, false, }; }
446        
447        /** JavaScript script source offset for the range start. */
448        public final int startOffset;
449        
450        /** JavaScript script source offset for the range end. */
451        public final int endOffset;
452        
453        /** Collected execution count of the source range. */
454        public final int count;
455        
456        /**
457         * Constructor
458         *
459         * @param startOffset JavaScript script source offset for the range start.
460         * 
461         * @param endOffset JavaScript script source offset for the range end.
462         * 
463         * @param count Collected execution count of the source range.
464         */
465        public CoverageRange(int startOffset, int endOffset, int count)
466        {
467            this.startOffset  = startOffset;
468            this.endOffset    = endOffset;
469            this.count        = count;
470        }
471        
472        /**
473         * JSON Object Constructor
474         * @param jo A Json-Object having data about an instance of {@code 'CoverageRange'}.
475         */
476        public CoverageRange (JsonObject jo)
477        {
478            this.startOffset  = ReadPrimJSON.getInt(jo, "startOffset");
479            this.endOffset    = ReadPrimJSON.getInt(jo, "endOffset");
480            this.count        = ReadPrimJSON.getInt(jo, "count");
481        }
482        
483        
484        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
485        public boolean equals(Object other)
486        {
487            if (other == null)                       return false;
488            if (other.getClass() != this.getClass()) return false;
489        
490            CoverageRange o = (CoverageRange) other;
491        
492            return
493                    (this.startOffset == o.startOffset)
494                &&  (this.endOffset == o.endOffset)
495                &&  (this.count == o.count);
496        }
497        
498        /** Generates a Hash-Code for {@code 'this'} instance */
499        public int hashCode()
500        {
501            return
502                    this.startOffset
503                +   this.endOffset
504                +   this.count;
505        }
506    }
507    
508    /** Coverage data for a JavaScript function. */
509    public static class FunctionCoverage
510        extends BaseType
511        implements java.io.Serializable
512    {
513        /** For Object Serialization.  java.io.Serializable */
514        protected static final long serialVersionUID = 1;
515        
516        public boolean[] optionals()
517        { return new boolean[] { false, false, false, }; }
518        
519        /** JavaScript function name. */
520        public final String functionName;
521        
522        /** Source ranges inside the function with coverage data. */
523        public final Profiler.CoverageRange[] ranges;
524        
525        /** Whether coverage data for this function has block granularity. */
526        public final boolean isBlockCoverage;
527        
528        /**
529         * Constructor
530         *
531         * @param functionName JavaScript function name.
532         * 
533         * @param ranges Source ranges inside the function with coverage data.
534         * 
535         * @param isBlockCoverage Whether coverage data for this function has block granularity.
536         */
537        public FunctionCoverage
538            (String functionName, Profiler.CoverageRange[] ranges, boolean isBlockCoverage)
539        {
540            // Exception-Check(s) to ensure that if any parameters which are not declared as
541            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
542            
543            if (functionName == null) BRDPC.throwNPE("functionName");
544            if (ranges == null)       BRDPC.throwNPE("ranges");
545            
546            this.functionName     = functionName;
547            this.ranges           = ranges;
548            this.isBlockCoverage  = isBlockCoverage;
549        }
550        
551        /**
552         * JSON Object Constructor
553         * @param jo A Json-Object having data about an instance of {@code 'FunctionCoverage'}.
554         */
555        public FunctionCoverage (JsonObject jo)
556        {
557            this.functionName     = ReadJSON.getString(jo, "functionName", false, true);
558            this.ranges = (jo.getJsonArray("ranges") == null)
559                ? null
560                : ReadArrJSON.DimN.objArr(jo.getJsonArray("ranges"), null, 0, Profiler.CoverageRange[].class);
561        
562            this.isBlockCoverage  = ReadPrimJSON.getBoolean(jo, "isBlockCoverage");
563        }
564        
565        
566        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
567        public boolean equals(Object other)
568        {
569            if (other == null)                       return false;
570            if (other.getClass() != this.getClass()) return false;
571        
572            FunctionCoverage o = (FunctionCoverage) other;
573        
574            return
575                    Objects.equals(this.functionName, o.functionName)
576                &&  Arrays.deepEquals(this.ranges, o.ranges)
577                &&  (this.isBlockCoverage == o.isBlockCoverage);
578        }
579        
580        /** Generates a Hash-Code for {@code 'this'} instance */
581        public int hashCode()
582        {
583            return
584                    Objects.hashCode(this.functionName)
585                +   Arrays.deepHashCode(this.ranges)
586                +   (this.isBlockCoverage ? 1 : 0);
587        }
588    }
589    
590    /** Coverage data for a JavaScript script. */
591    public static class ScriptCoverage
592        extends BaseType
593        implements java.io.Serializable
594    {
595        /** For Object Serialization.  java.io.Serializable */
596        protected static final long serialVersionUID = 1;
597        
598        public boolean[] optionals()
599        { return new boolean[] { false, false, false, }; }
600        
601        /** JavaScript script id. */
602        public final String scriptId;
603        
604        /** JavaScript script name or url. */
605        public final String url;
606        
607        /** Functions contained in the script that has coverage data. */
608        public final Profiler.FunctionCoverage[] functions;
609        
610        /**
611         * Constructor
612         *
613         * @param scriptId JavaScript script id.
614         * 
615         * @param url JavaScript script name or url.
616         * 
617         * @param functions Functions contained in the script that has coverage data.
618         */
619        public ScriptCoverage
620            (String scriptId, String url, Profiler.FunctionCoverage[] functions)
621        {
622            // Exception-Check(s) to ensure that if any parameters which are not declared as
623            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
624            
625            if (scriptId == null)  BRDPC.throwNPE("scriptId");
626            if (url == null)       BRDPC.throwNPE("url");
627            if (functions == null) BRDPC.throwNPE("functions");
628            
629            this.scriptId   = scriptId;
630            this.url        = url;
631            this.functions  = functions;
632        }
633        
634        /**
635         * JSON Object Constructor
636         * @param jo A Json-Object having data about an instance of {@code 'ScriptCoverage'}.
637         */
638        public ScriptCoverage (JsonObject jo)
639        {
640            this.scriptId   = ReadJSON.getString(jo, "scriptId", false, true);
641            this.url        = ReadJSON.getString(jo, "url", false, true);
642            this.functions = (jo.getJsonArray("functions") == null)
643                ? null
644                : ReadArrJSON.DimN.objArr(jo.getJsonArray("functions"), null, 0, Profiler.FunctionCoverage[].class);
645        
646        }
647        
648        
649        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
650        public boolean equals(Object other)
651        {
652            if (other == null)                       return false;
653            if (other.getClass() != this.getClass()) return false;
654        
655            ScriptCoverage o = (ScriptCoverage) other;
656        
657            return
658                    Objects.equals(this.scriptId, o.scriptId)
659                &&  Objects.equals(this.url, o.url)
660                &&  Arrays.deepEquals(this.functions, o.functions);
661        }
662        
663        /** Generates a Hash-Code for {@code 'this'} instance */
664        public int hashCode()
665        {
666            return
667                    Objects.hashCode(this.scriptId)
668                +   Objects.hashCode(this.url)
669                +   Arrays.deepHashCode(this.functions);
670        }
671    }
672    
673    /**
674     * Describes a type collected during runtime.
675     * <BR />
676     * <BR /><B>EXPERIMENTAL</B>
677     */
678    public static class TypeObject
679        extends BaseType
680        implements java.io.Serializable
681    {
682        /** For Object Serialization.  java.io.Serializable */
683        protected static final long serialVersionUID = 1;
684        
685        public boolean[] optionals()
686        { return new boolean[] { false, }; }
687        
688        /** Name of a type collected with type profiling. */
689        public final String name;
690        
691        /**
692         * Constructor
693         *
694         * @param name Name of a type collected with type profiling.
695         */
696        public TypeObject(String name)
697        {
698            // Exception-Check(s) to ensure that if any parameters which are not declared as
699            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
700            
701            if (name == null) BRDPC.throwNPE("name");
702            
703            this.name  = name;
704        }
705        
706        /**
707         * JSON Object Constructor
708         * @param jo A Json-Object having data about an instance of {@code 'TypeObject'}.
709         */
710        public TypeObject (JsonObject jo)
711        {
712            this.name  = ReadJSON.getString(jo, "name", false, true);
713        }
714        
715        
716        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
717        public boolean equals(Object other)
718        {
719            if (other == null)                       return false;
720            if (other.getClass() != this.getClass()) return false;
721        
722            TypeObject o = (TypeObject) other;
723        
724            return
725                    Objects.equals(this.name, o.name);
726        }
727        
728        /** Generates a Hash-Code for {@code 'this'} instance */
729        public int hashCode()
730        {
731            return
732                    Objects.hashCode(this.name);
733        }
734    }
735    
736    /**
737     * Source offset and types for a parameter or return value.
738     * <BR />
739     * <BR /><B>EXPERIMENTAL</B>
740     */
741    public static class TypeProfileEntry
742        extends BaseType
743        implements java.io.Serializable
744    {
745        /** For Object Serialization.  java.io.Serializable */
746        protected static final long serialVersionUID = 1;
747        
748        public boolean[] optionals()
749        { return new boolean[] { false, false, }; }
750        
751        /** Source offset of the parameter or end of function for return values. */
752        public final int offset;
753        
754        /** The types for this parameter or return value. */
755        public final Profiler.TypeObject[] types;
756        
757        /**
758         * Constructor
759         *
760         * @param offset Source offset of the parameter or end of function for return values.
761         * 
762         * @param types The types for this parameter or return value.
763         */
764        public TypeProfileEntry(int offset, Profiler.TypeObject[] types)
765        {
766            // Exception-Check(s) to ensure that if any parameters which are not declared as
767            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
768            
769            if (types == null) BRDPC.throwNPE("types");
770            
771            this.offset  = offset;
772            this.types   = types;
773        }
774        
775        /**
776         * JSON Object Constructor
777         * @param jo A Json-Object having data about an instance of {@code 'TypeProfileEntry'}.
778         */
779        public TypeProfileEntry (JsonObject jo)
780        {
781            this.offset  = ReadPrimJSON.getInt(jo, "offset");
782            this.types = (jo.getJsonArray("types") == null)
783                ? null
784                : ReadArrJSON.DimN.objArr(jo.getJsonArray("types"), null, 0, Profiler.TypeObject[].class);
785        
786        }
787        
788        
789        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
790        public boolean equals(Object other)
791        {
792            if (other == null)                       return false;
793            if (other.getClass() != this.getClass()) return false;
794        
795            TypeProfileEntry o = (TypeProfileEntry) other;
796        
797            return
798                    (this.offset == o.offset)
799                &&  Arrays.deepEquals(this.types, o.types);
800        }
801        
802        /** Generates a Hash-Code for {@code 'this'} instance */
803        public int hashCode()
804        {
805            return
806                    this.offset
807                +   Arrays.deepHashCode(this.types);
808        }
809    }
810    
811    /**
812     * Type profile data collected during runtime for a JavaScript script.
813     * <BR />
814     * <BR /><B>EXPERIMENTAL</B>
815     */
816    public static class ScriptTypeProfile
817        extends BaseType
818        implements java.io.Serializable
819    {
820        /** For Object Serialization.  java.io.Serializable */
821        protected static final long serialVersionUID = 1;
822        
823        public boolean[] optionals()
824        { return new boolean[] { false, false, false, }; }
825        
826        /** JavaScript script id. */
827        public final String scriptId;
828        
829        /** JavaScript script name or url. */
830        public final String url;
831        
832        /** Type profile entries for parameters and return values of the functions in the script. */
833        public final Profiler.TypeProfileEntry[] entries;
834        
835        /**
836         * Constructor
837         *
838         * @param scriptId JavaScript script id.
839         * 
840         * @param url JavaScript script name or url.
841         * 
842         * @param entries Type profile entries for parameters and return values of the functions in the script.
843         */
844        public ScriptTypeProfile
845            (String scriptId, String url, Profiler.TypeProfileEntry[] entries)
846        {
847            // Exception-Check(s) to ensure that if any parameters which are not declared as
848            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
849            
850            if (scriptId == null) BRDPC.throwNPE("scriptId");
851            if (url == null)      BRDPC.throwNPE("url");
852            if (entries == null)  BRDPC.throwNPE("entries");
853            
854            this.scriptId  = scriptId;
855            this.url       = url;
856            this.entries   = entries;
857        }
858        
859        /**
860         * JSON Object Constructor
861         * @param jo A Json-Object having data about an instance of {@code 'ScriptTypeProfile'}.
862         */
863        public ScriptTypeProfile (JsonObject jo)
864        {
865            this.scriptId  = ReadJSON.getString(jo, "scriptId", false, true);
866            this.url       = ReadJSON.getString(jo, "url", false, true);
867            this.entries = (jo.getJsonArray("entries") == null)
868                ? null
869                : ReadArrJSON.DimN.objArr(jo.getJsonArray("entries"), null, 0, Profiler.TypeProfileEntry[].class);
870        
871        }
872        
873        
874        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
875        public boolean equals(Object other)
876        {
877            if (other == null)                       return false;
878            if (other.getClass() != this.getClass()) return false;
879        
880            ScriptTypeProfile o = (ScriptTypeProfile) other;
881        
882            return
883                    Objects.equals(this.scriptId, o.scriptId)
884                &&  Objects.equals(this.url, o.url)
885                &&  Arrays.deepEquals(this.entries, o.entries);
886        }
887        
888        /** Generates a Hash-Code for {@code 'this'} instance */
889        public int hashCode()
890        {
891            return
892                    Objects.hashCode(this.scriptId)
893                +   Objects.hashCode(this.url)
894                +   Arrays.deepHashCode(this.entries);
895        }
896    }
897    
898    /** <CODE>[No Description Provided by Google]</CODE> */
899    public static class consoleProfileFinished
900        extends BrowserEvent
901        implements java.io.Serializable
902    {
903        /** For Object Serialization.  java.io.Serializable */
904        protected static final long serialVersionUID = 1;
905        
906        public boolean[] optionals()
907        { return new boolean[] { false, false, false, true, }; }
908        
909        /** <CODE>[No Description Provided by Google]</CODE> */
910        public final String id;
911        
912        /** Location of console.profileEnd(). */
913        public final Debugger.Location location;
914        
915        /** <CODE>[No Description Provided by Google]</CODE> */
916        public final Profiler.Profile profile;
917        
918        /**
919         * Profile title passed as an argument to console.profile().
920         * <BR />
921         * <BR /><B>OPTIONAL</B>
922         */
923        public final String title;
924        
925        /**
926         * Constructor
927         *
928         * @param id -
929         * 
930         * @param location Location of console.profileEnd().
931         * 
932         * @param profile -
933         * 
934         * @param title Profile title passed as an argument to console.profile().
935         * <BR /><B>OPTIONAL</B>
936         */
937        public consoleProfileFinished
938            (String id, Debugger.Location location, Profiler.Profile profile, String title)
939        {
940            super("Profiler", "consoleProfileFinished", 4);
941            
942            // Exception-Check(s) to ensure that if any parameters which are not declared as
943            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
944            
945            if (id == null)       BRDPC.throwNPE("id");
946            if (location == null) BRDPC.throwNPE("location");
947            if (profile == null)  BRDPC.throwNPE("profile");
948            
949            this.id        = id;
950            this.location  = location;
951            this.profile   = profile;
952            this.title     = title;
953        }
954        
955        /**
956         * JSON Object Constructor
957         * @param jo A Json-Object having data about an instance of {@code 'consoleProfileFinished'}.
958         */
959        public consoleProfileFinished (JsonObject jo)
960        {
961            super("Profiler", "consoleProfileFinished", 4);
962        
963            this.id        = ReadJSON.getString(jo, "id", false, true);
964            this.location  = ReadJSON.getObject(jo, "location", Debugger.Location.class, false, true);
965            this.profile   = ReadJSON.getObject(jo, "profile", Profiler.Profile.class, false, true);
966            this.title     = ReadJSON.getString(jo, "title", true, false);
967        }
968        
969        
970        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
971        public boolean equals(Object other)
972        {
973            if (other == null)                       return false;
974            if (other.getClass() != this.getClass()) return false;
975        
976            consoleProfileFinished o = (consoleProfileFinished) other;
977        
978            return
979                    Objects.equals(this.id, o.id)
980                &&  Objects.equals(this.location, o.location)
981                &&  Objects.equals(this.profile, o.profile)
982                &&  Objects.equals(this.title, o.title);
983        }
984        
985        /** Generates a Hash-Code for {@code 'this'} instance */
986        public int hashCode()
987        {
988            return
989                    Objects.hashCode(this.id)
990                +   this.location.hashCode()
991                +   this.profile.hashCode()
992                +   Objects.hashCode(this.title);
993        }
994    }
995    
996    /** Sent when new profile recording is started using console.profile() call. */
997    public static class consoleProfileStarted
998        extends BrowserEvent
999        implements java.io.Serializable
1000    {
1001        /** For Object Serialization.  java.io.Serializable */
1002        protected static final long serialVersionUID = 1;
1003        
1004        public boolean[] optionals()
1005        { return new boolean[] { false, false, true, }; }
1006        
1007        /** <CODE>[No Description Provided by Google]</CODE> */
1008        public final String id;
1009        
1010        /** Location of console.profile(). */
1011        public final Debugger.Location location;
1012        
1013        /**
1014         * Profile title passed as an argument to console.profile().
1015         * <BR />
1016         * <BR /><B>OPTIONAL</B>
1017         */
1018        public final String title;
1019        
1020        /**
1021         * Constructor
1022         *
1023         * @param id -
1024         * 
1025         * @param location Location of console.profile().
1026         * 
1027         * @param title Profile title passed as an argument to console.profile().
1028         * <BR /><B>OPTIONAL</B>
1029         */
1030        public consoleProfileStarted(String id, Debugger.Location location, String title)
1031        {
1032            super("Profiler", "consoleProfileStarted", 3);
1033            
1034            // Exception-Check(s) to ensure that if any parameters which are not declared as
1035            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1036            
1037            if (id == null)       BRDPC.throwNPE("id");
1038            if (location == null) BRDPC.throwNPE("location");
1039            
1040            this.id        = id;
1041            this.location  = location;
1042            this.title     = title;
1043        }
1044        
1045        /**
1046         * JSON Object Constructor
1047         * @param jo A Json-Object having data about an instance of {@code 'consoleProfileStarted'}.
1048         */
1049        public consoleProfileStarted (JsonObject jo)
1050        {
1051            super("Profiler", "consoleProfileStarted", 3);
1052        
1053            this.id        = ReadJSON.getString(jo, "id", false, true);
1054            this.location  = ReadJSON.getObject(jo, "location", Debugger.Location.class, false, true);
1055            this.title     = ReadJSON.getString(jo, "title", true, false);
1056        }
1057        
1058        
1059        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
1060        public boolean equals(Object other)
1061        {
1062            if (other == null)                       return false;
1063            if (other.getClass() != this.getClass()) return false;
1064        
1065            consoleProfileStarted o = (consoleProfileStarted) other;
1066        
1067            return
1068                    Objects.equals(this.id, o.id)
1069                &&  Objects.equals(this.location, o.location)
1070                &&  Objects.equals(this.title, o.title);
1071        }
1072        
1073        /** Generates a Hash-Code for {@code 'this'} instance */
1074        public int hashCode()
1075        {
1076            return
1077                    Objects.hashCode(this.id)
1078                +   this.location.hashCode()
1079                +   Objects.hashCode(this.title);
1080        }
1081    }
1082    
1083    /**
1084     * Reports coverage delta since the last poll (either from an event like this, or from
1085     * <CODE>takePreciseCoverage</CODE> for the current isolate. May only be sent if precise code
1086     * coverage has been started. This event can be trigged by the embedder to, for example,
1087     * trigger collection of coverage data immediately at a certain point in time.
1088     * <BR />
1089     * <BR /><B>EXPERIMENTAL</B>
1090     */
1091    public static class preciseCoverageDeltaUpdate
1092        extends BrowserEvent
1093        implements java.io.Serializable
1094    {
1095        /** For Object Serialization.  java.io.Serializable */
1096        protected static final long serialVersionUID = 1;
1097        
1098        public boolean[] optionals()
1099        { return new boolean[] { false, false, false, }; }
1100        
1101        /** Monotonically increasing time (in seconds) when the coverage update was taken in the backend. */
1102        public final Number timestamp;
1103        
1104        /** Identifier for distinguishing coverage events. */
1105        public final String occasion;
1106        
1107        /** Coverage data for the current isolate. */
1108        public final Profiler.ScriptCoverage[] result;
1109        
1110        /**
1111         * Constructor
1112         *
1113         * @param timestamp Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
1114         * 
1115         * @param occasion Identifier for distinguishing coverage events.
1116         * 
1117         * @param result Coverage data for the current isolate.
1118         */
1119        public preciseCoverageDeltaUpdate
1120            (Number timestamp, String occasion, Profiler.ScriptCoverage[] result)
1121        {
1122            super("Profiler", "preciseCoverageDeltaUpdate", 3);
1123            
1124            // Exception-Check(s) to ensure that if any parameters which are not declared as
1125            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1126            
1127            if (timestamp == null) BRDPC.throwNPE("timestamp");
1128            if (occasion == null)  BRDPC.throwNPE("occasion");
1129            if (result == null)    BRDPC.throwNPE("result");
1130            
1131            this.timestamp  = timestamp;
1132            this.occasion   = occasion;
1133            this.result     = result;
1134        }
1135        
1136        /**
1137         * JSON Object Constructor
1138         * @param jo A Json-Object having data about an instance of {@code 'preciseCoverageDeltaUpdate'}.
1139         */
1140        public preciseCoverageDeltaUpdate (JsonObject jo)
1141        {
1142            super("Profiler", "preciseCoverageDeltaUpdate", 3);
1143        
1144            this.timestamp  = ReadNumberJSON.get(jo, "timestamp", false, true);
1145            this.occasion   = ReadJSON.getString(jo, "occasion", false, true);
1146            this.result = (jo.getJsonArray("result") == null)
1147                ? null
1148                : ReadArrJSON.DimN.objArr(jo.getJsonArray("result"), null, 0, Profiler.ScriptCoverage[].class);
1149        
1150        }
1151        
1152        
1153        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
1154        public boolean equals(Object other)
1155        {
1156            if (other == null)                       return false;
1157            if (other.getClass() != this.getClass()) return false;
1158        
1159            preciseCoverageDeltaUpdate o = (preciseCoverageDeltaUpdate) other;
1160        
1161            return
1162                    Objects.equals(this.timestamp, o.timestamp)
1163                &&  Objects.equals(this.occasion, o.occasion)
1164                &&  Arrays.deepEquals(this.result, o.result);
1165        }
1166        
1167        /** Generates a Hash-Code for {@code 'this'} instance */
1168        public int hashCode()
1169        {
1170            return
1171                    Objects.hashCode(this.timestamp)
1172                +   Objects.hashCode(this.occasion)
1173                +   Arrays.deepHashCode(this.result);
1174        }
1175    }
1176    
1177    
1178    // Counter for keeping the WebSocket Request ID's distinct.
1179    private static int counter = 1;
1180    
1181    /**
1182     * <CODE>[No Description Provided by Google]</CODE>
1183     * 
1184     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1185     * {@link Ret0}&gt;</CODE>
1186     *
1187     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1188     * browser receives the invocation-request.
1189     *
1190     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1191     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1192     * {@code >} to ensure the Browser Function has run to completion.
1193     */
1194    public static Script<String, JsonObject, Ret0> disable()
1195    {
1196        final int          webSocketID = 4000000 + counter++;
1197        final boolean[]    optionals   = new boolean[0];
1198        
1199        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1200        String requestJSON = WriteJSON.get(
1201            parameterTypes.get("disable"),
1202            parameterNames.get("disable"),
1203            optionals, webSocketID,
1204            "Profiler.disable"
1205        );
1206        
1207        // This Remote Command does not have a Return-Value.
1208        return new Script<>
1209            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1210    }
1211    
1212    /**
1213     * <CODE>[No Description Provided by Google]</CODE>
1214     * 
1215     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1216     * {@link Ret0}&gt;</CODE>
1217     *
1218     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1219     * browser receives the invocation-request.
1220     *
1221     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1222     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1223     * {@code >} to ensure the Browser Function has run to completion.
1224     */
1225    public static Script<String, JsonObject, Ret0> enable()
1226    {
1227        final int          webSocketID = 4001000 + counter++;
1228        final boolean[]    optionals   = new boolean[0];
1229        
1230        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1231        String requestJSON = WriteJSON.get(
1232            parameterTypes.get("enable"),
1233            parameterNames.get("enable"),
1234            optionals, webSocketID,
1235            "Profiler.enable"
1236        );
1237        
1238        // This Remote Command does not have a Return-Value.
1239        return new Script<>
1240            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1241    }
1242    
1243    /**
1244     * Collect coverage data for the current isolate. The coverage data may be incomplete due to
1245     * garbage collection.
1246     * 
1247     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1248     * {@link Profiler.ScriptCoverage}[]&gt;</CODE>
1249     * 
1250     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1251     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1252     * {@link Profiler.ScriptCoverage}[]&gt;</CODE> will be returned.
1253     *
1254     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1255     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1256      * may be retrieved.</I>
1257     *
1258     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1259     * <BR /><BR /><UL CLASS=JDUL>
1260     * <LI><CODE>{@link Profiler.ScriptCoverage}[] (<B>result</B></CODE>)
1261     *     <BR />Coverage data for the current isolate.
1262     * </LI>
1263     * </UL> */
1264    public static Script<String, JsonObject, Profiler.ScriptCoverage[]> getBestEffortCoverage()
1265    {
1266        final int          webSocketID = 4002000 + counter++;
1267        final boolean[]    optionals   = new boolean[0];
1268        
1269        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1270        String requestJSON = WriteJSON.get(
1271            parameterTypes.get("getBestEffortCoverage"),
1272            parameterNames.get("getBestEffortCoverage"),
1273            optionals, webSocketID,
1274            "Profiler.getBestEffortCoverage"
1275        );
1276        
1277        // 'JSON Binding' ... Converts Browser Response-JSON to 'Profiler.ScriptCoverage[]'
1278        Function<JsonObject, Profiler.ScriptCoverage[]> responseProcessor = (JsonObject jo) ->
1279            (jo.getJsonArray("result") == null)
1280                ? null
1281                : ReadArrJSON.DimN.objArr(jo.getJsonArray("result"), null, 0, Profiler.ScriptCoverage[].class);
1282        
1283        // Pass the 'defaultSender' to Script-Constructor
1284        // The sender that is used can be changed before executing script.
1285        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1286    }
1287    
1288    /**
1289     * Changes CPU profiler sampling interval. Must be called before CPU profiles recording started.
1290     * 
1291     * @param interval New sampling interval in microseconds.
1292     * 
1293     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1294     * {@link Ret0}&gt;</CODE>
1295     *
1296     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1297     * browser receives the invocation-request.
1298     *
1299     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1300     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1301     * {@code >} to ensure the Browser Function has run to completion.
1302     */
1303    public static Script<String, JsonObject, Ret0> setSamplingInterval(int interval)
1304    {
1305        final int       webSocketID = 4003000 + counter++;
1306        final boolean[] optionals   = { false, };
1307        
1308        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1309        String requestJSON = WriteJSON.get(
1310            parameterTypes.get("setSamplingInterval"),
1311            parameterNames.get("setSamplingInterval"),
1312            optionals, webSocketID,
1313            "Profiler.setSamplingInterval",
1314            interval
1315        );
1316        
1317        // This Remote Command does not have a Return-Value.
1318        return new Script<>
1319            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1320    }
1321    
1322    /**
1323     * <CODE>[No Description Provided by Google]</CODE>
1324     * 
1325     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1326     * {@link Ret0}&gt;</CODE>
1327     *
1328     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1329     * browser receives the invocation-request.
1330     *
1331     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1332     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1333     * {@code >} to ensure the Browser Function has run to completion.
1334     */
1335    public static Script<String, JsonObject, Ret0> start()
1336    {
1337        final int          webSocketID = 4004000 + counter++;
1338        final boolean[]    optionals   = new boolean[0];
1339        
1340        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1341        String requestJSON = WriteJSON.get(
1342            parameterTypes.get("start"),
1343            parameterNames.get("start"),
1344            optionals, webSocketID,
1345            "Profiler.start"
1346        );
1347        
1348        // This Remote Command does not have a Return-Value.
1349        return new Script<>
1350            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1351    }
1352    
1353    /**
1354     * Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code
1355     * coverage may be incomplete. Enabling prevents running optimized code and resets execution
1356     * counters.
1357     * 
1358     * @param callCount Collect accurate call counts beyond simple 'covered' or 'not covered'.
1359     * <BR /><B>OPTIONAL</B>
1360     * 
1361     * @param detailed Collect block-based coverage.
1362     * <BR /><B>OPTIONAL</B>
1363     * 
1364     * @param allowTriggeredUpdates Allow the backend to send updates on its own initiative
1365     * <BR /><B>OPTIONAL</B>
1366     * 
1367     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1368     * Number&gt;</CODE>
1369     * 
1370     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1371     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1372     * Number&gt;</CODE> will be returned.
1373     *
1374     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1375     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1376      * may be retrieved.</I>
1377     *
1378     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1379     * <BR /><BR /><UL CLASS=JDUL>
1380     * <LI><CODE>Number (<B>timestamp</B></CODE>)
1381     *     <BR />Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
1382     * </LI>
1383     * </UL> */
1384    public static Script<String, JsonObject, Number> startPreciseCoverage
1385        (Boolean callCount, Boolean detailed, Boolean allowTriggeredUpdates)
1386    {
1387        final int       webSocketID = 4005000 + counter++;
1388        final boolean[] optionals   = { true, true, true, };
1389        
1390        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1391        String requestJSON = WriteJSON.get(
1392            parameterTypes.get("startPreciseCoverage"),
1393            parameterNames.get("startPreciseCoverage"),
1394            optionals, webSocketID,
1395            "Profiler.startPreciseCoverage",
1396            callCount, detailed, allowTriggeredUpdates
1397        );
1398        
1399        // 'JSON Binding' ... Converts Browser Response-JSON to 'Number'
1400        Function<JsonObject, Number> responseProcessor = (JsonObject jo) ->
1401            ReadNumberJSON.get(jo, "timestamp", false, true);
1402        
1403        // Pass the 'defaultSender' to Script-Constructor
1404        // The sender that is used can be changed before executing script.
1405        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1406    }
1407    
1408    /**
1409     * Enable type profile.
1410     * <BR /><B>EXPERIMENTAL</B>
1411     * 
1412     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1413     * {@link Ret0}&gt;</CODE>
1414     *
1415     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1416     * browser receives the invocation-request.
1417     *
1418     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1419     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1420     * {@code >} to ensure the Browser Function has run to completion.
1421     */
1422    public static Script<String, JsonObject, Ret0> startTypeProfile()
1423    {
1424        final int          webSocketID = 4006000 + counter++;
1425        final boolean[]    optionals   = new boolean[0];
1426        
1427        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1428        String requestJSON = WriteJSON.get(
1429            parameterTypes.get("startTypeProfile"),
1430            parameterNames.get("startTypeProfile"),
1431            optionals, webSocketID,
1432            "Profiler.startTypeProfile"
1433        );
1434        
1435        // This Remote Command does not have a Return-Value.
1436        return new Script<>
1437            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1438    }
1439    
1440    /**
1441     * <CODE>[No Description Provided by Google]</CODE>
1442     * 
1443     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1444     * {@link Profiler.Profile}&gt;</CODE>
1445     * 
1446     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1447     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1448     * {@link Profiler.Profile}&gt;</CODE> will be returned.
1449     *
1450     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1451     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1452      * may be retrieved.</I>
1453     *
1454     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1455     * <BR /><BR /><UL CLASS=JDUL>
1456     * <LI><CODE>{@link Profiler.Profile} (<B>profile</B></CODE>)
1457     *     <BR />Recorded profile.
1458     * </LI>
1459     * </UL> */
1460    public static Script<String, JsonObject, Profiler.Profile> stop()
1461    {
1462        final int          webSocketID = 4007000 + counter++;
1463        final boolean[]    optionals   = new boolean[0];
1464        
1465        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1466        String requestJSON = WriteJSON.get(
1467            parameterTypes.get("stop"),
1468            parameterNames.get("stop"),
1469            optionals, webSocketID,
1470            "Profiler.stop"
1471        );
1472        
1473        // 'JSON Binding' ... Converts Browser Response-JSON to 'Profiler.Profile'
1474        Function<JsonObject, Profiler.Profile> responseProcessor = (JsonObject jo) ->
1475            ReadJSON.getObject(jo, "profile", Profiler.Profile.class, false, true);
1476        
1477        // Pass the 'defaultSender' to Script-Constructor
1478        // The sender that is used can be changed before executing script.
1479        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1480    }
1481    
1482    /**
1483     * Disable precise code coverage. Disabling releases unnecessary execution count records and allows
1484     * executing optimized code.
1485     * 
1486     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1487     * {@link Ret0}&gt;</CODE>
1488     *
1489     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1490     * browser receives the invocation-request.
1491     *
1492     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1493     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1494     * {@code >} to ensure the Browser Function has run to completion.
1495     */
1496    public static Script<String, JsonObject, Ret0> stopPreciseCoverage()
1497    {
1498        final int          webSocketID = 4008000 + counter++;
1499        final boolean[]    optionals   = new boolean[0];
1500        
1501        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1502        String requestJSON = WriteJSON.get(
1503            parameterTypes.get("stopPreciseCoverage"),
1504            parameterNames.get("stopPreciseCoverage"),
1505            optionals, webSocketID,
1506            "Profiler.stopPreciseCoverage"
1507        );
1508        
1509        // This Remote Command does not have a Return-Value.
1510        return new Script<>
1511            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1512    }
1513    
1514    /**
1515     * Disable type profile. Disabling releases type profile data collected so far.
1516     * <BR /><B>EXPERIMENTAL</B>
1517     * 
1518     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1519     * {@link Ret0}&gt;</CODE>
1520     *
1521     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1522     * browser receives the invocation-request.
1523     *
1524     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1525     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1526     * {@code >} to ensure the Browser Function has run to completion.
1527     */
1528    public static Script<String, JsonObject, Ret0> stopTypeProfile()
1529    {
1530        final int          webSocketID = 4009000 + counter++;
1531        final boolean[]    optionals   = new boolean[0];
1532        
1533        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1534        String requestJSON = WriteJSON.get(
1535            parameterTypes.get("stopTypeProfile"),
1536            parameterNames.get("stopTypeProfile"),
1537            optionals, webSocketID,
1538            "Profiler.stopTypeProfile"
1539        );
1540        
1541        // This Remote Command does not have a Return-Value.
1542        return new Script<>
1543            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1544    }
1545    
1546    /**
1547     * Collect coverage data for the current isolate, and resets execution counters. Precise code
1548     * coverage needs to have started.
1549     * 
1550     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1551     * {@link Ret2}&gt;</CODE>
1552     *
1553     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
1554     * {@link Script#exec()}), and a {@link Promise} returned.
1555     *
1556     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
1557     * (using {@link Promise#await()}), the {@code Ret2} will subsequently
1558     * be returned from that call.
1559     * 
1560     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
1561     * in an instance of <B>{@link Ret2}</B>
1562     *
1563     * <BR /><BR /><UL CLASS=JDUL>
1564     * <LI><CODE><B>Ret2.a:</B> {@link Profiler.ScriptCoverage}[] (<B>result</B>)</CODE>
1565     *     <BR />Coverage data for the current isolate.
1566     *     <BR /><BR /></LI>
1567     * <LI><CODE><B>Ret2.b:</B> Number (<B>timestamp</B>)</CODE>
1568     *     <BR />Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
1569     *     </LI>
1570     * </UL>
1571     */
1572    public static Script<String, JsonObject, Ret2<Profiler.ScriptCoverage[], Number>> takePreciseCoverage()
1573    {
1574        final int          webSocketID = 4010000 + counter++;
1575        final boolean[]    optionals   = new boolean[0];
1576        
1577        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1578        String requestJSON = WriteJSON.get(
1579            parameterTypes.get("takePreciseCoverage"),
1580            parameterNames.get("takePreciseCoverage"),
1581            optionals, webSocketID,
1582            "Profiler.takePreciseCoverage"
1583        );
1584        
1585        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret2'
1586        Function<JsonObject, Ret2<Profiler.ScriptCoverage[], Number>> 
1587            responseProcessor = (JsonObject jo) -> new Ret2<>(
1588                (jo.getJsonArray("result") == null)
1589                    ? null
1590                    : ReadArrJSON.DimN.objArr(jo.getJsonArray("result"), null, 0, Profiler.ScriptCoverage[].class),
1591                ReadNumberJSON.get(jo, "timestamp", false, true)
1592            );
1593        
1594        // Pass the 'defaultSender' to Script-Constructor
1595        // The sender that is used can be changed before executing script.
1596        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1597    }
1598    
1599    /**
1600     * Collect type profile.
1601     * <BR /><B>EXPERIMENTAL</B>
1602     * 
1603     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1604     * {@link Profiler.ScriptTypeProfile}[]&gt;</CODE>
1605     * 
1606     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1607     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1608     * {@link Profiler.ScriptTypeProfile}[]&gt;</CODE> will be returned.
1609     *
1610     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1611     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1612      * may be retrieved.</I>
1613     *
1614     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1615     * <BR /><BR /><UL CLASS=JDUL>
1616     * <LI><CODE>{@link Profiler.ScriptTypeProfile}[] (<B>result</B></CODE>)
1617     *     <BR />Type profile for all scripts since startTypeProfile() was turned on.
1618     * </LI>
1619     * </UL> */
1620    public static Script<String, JsonObject, Profiler.ScriptTypeProfile[]> takeTypeProfile()
1621    {
1622        final int          webSocketID = 4011000 + counter++;
1623        final boolean[]    optionals   = new boolean[0];
1624        
1625        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1626        String requestJSON = WriteJSON.get(
1627            parameterTypes.get("takeTypeProfile"),
1628            parameterNames.get("takeTypeProfile"),
1629            optionals, webSocketID,
1630            "Profiler.takeTypeProfile"
1631        );
1632        
1633        // 'JSON Binding' ... Converts Browser Response-JSON to 'Profiler.ScriptTypeProfile[]'
1634        Function<JsonObject, Profiler.ScriptTypeProfile[]> responseProcessor = (JsonObject jo) ->
1635            (jo.getJsonArray("result") == null)
1636                ? null
1637                : ReadArrJSON.DimN.objArr(jo.getJsonArray("result"), null, 0, Profiler.ScriptTypeProfile[].class);
1638        
1639        // Pass the 'defaultSender' to Script-Constructor
1640        // The sender that is used can be changed before executing script.
1641        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1642    }
1643    
1644}