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