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 Memory 030{ 031 // ******************************************************************************************** 032 // ******************************************************************************************** 033 // Class Header Stuff 034 // ******************************************************************************************** 035 // ******************************************************************************************** 036 037 038 // No Pubic Constructors 039 private Memory () { } 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 : Memory.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("getDOMCounters", EMPTY_VEC_STR); 078 079 parameterNames.put("prepareForLeakDetection", EMPTY_VEC_STR); 080 081 parameterNames.put("forciblyPurgeJavaScriptMemory", EMPTY_VEC_STR); 082 083 v = new Vector<String>(1); 084 parameterNames.put("setPressureNotificationsSuppressed", v); 085 Collections.addAll(v, new String[] 086 { "suppressed", }); 087 088 v = new Vector<String>(1); 089 parameterNames.put("simulatePressureNotification", v); 090 Collections.addAll(v, new String[] 091 { "level", }); 092 093 v = new Vector<String>(2); 094 parameterNames.put("startSampling", v); 095 Collections.addAll(v, new String[] 096 { "samplingInterval", "suppressRandomness", }); 097 098 parameterNames.put("stopSampling", EMPTY_VEC_STR); 099 100 parameterNames.put("getAllTimeSamplingProfile", EMPTY_VEC_STR); 101 102 parameterNames.put("getBrowserSamplingProfile", EMPTY_VEC_STR); 103 104 parameterNames.put("getSamplingProfile", EMPTY_VEC_STR); 105 } 106 107 108 // ******************************************************************************************** 109 // ******************************************************************************************** 110 // Types - Static Inner Classes 111 // ******************************************************************************************** 112 // ******************************************************************************************** 113 114 /** Memory pressure level. */ 115 public static final String[] PressureLevel = 116 { "moderate", "critical", }; 117 118 /** Heap profile sample. */ 119 public static class SamplingProfileNode 120 extends BaseType 121 implements java.io.Serializable 122 { 123 /** For Object Serialization. java.io.Serializable */ 124 protected static final long serialVersionUID = 1; 125 126 public boolean[] optionals() 127 { return new boolean[] { false, false, false, }; } 128 129 /** Size of the sampled allocation. */ 130 public final Number size; 131 132 /** Total bytes attributed to this sample. */ 133 public final Number total; 134 135 /** Execution stack at the point of allocation. */ 136 public final String[] stack; 137 138 /** 139 * Constructor 140 * 141 * @param size Size of the sampled allocation. 142 * 143 * @param total Total bytes attributed to this sample. 144 * 145 * @param stack Execution stack at the point of allocation. 146 */ 147 public SamplingProfileNode(Number size, Number total, String[] stack) 148 { 149 // Exception-Check(s) to ensure that if any parameters which are not declared as 150 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 151 152 if (size == null) BRDPC.throwNPE("size"); 153 if (total == null) BRDPC.throwNPE("total"); 154 if (stack == null) BRDPC.throwNPE("stack"); 155 156 this.size = size; 157 this.total = total; 158 this.stack = stack; 159 } 160 161 /** 162 * JSON Object Constructor 163 * @param jo A Json-Object having data about an instance of {@code 'SamplingProfileNode'}. 164 */ 165 public SamplingProfileNode (JsonObject jo) 166 { 167 this.size = ReadNumberJSON.get(jo, "size", false, true); 168 this.total = ReadNumberJSON.get(jo, "total", false, true); 169 this.stack = (jo.getJsonArray("stack") == null) 170 ? null 171 : ReadArrJSON.DimN.strArr(jo.getJsonArray("stack"), null, 0, String[].class); 172 173 } 174 175 176 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 177 public boolean equals(Object other) 178 { 179 if (other == null) return false; 180 if (other.getClass() != this.getClass()) return false; 181 182 SamplingProfileNode o = (SamplingProfileNode) other; 183 184 return 185 Objects.equals(this.size, o.size) 186 && Objects.equals(this.total, o.total) 187 && Arrays.deepEquals(this.stack, o.stack); 188 } 189 190 /** Generates a Hash-Code for {@code 'this'} instance */ 191 public int hashCode() 192 { 193 return 194 Objects.hashCode(this.size) 195 + Objects.hashCode(this.total) 196 + Arrays.deepHashCode(this.stack); 197 } 198 } 199 200 /** Array of heap profile samples. */ 201 public static class SamplingProfile 202 extends BaseType 203 implements java.io.Serializable 204 { 205 /** For Object Serialization. java.io.Serializable */ 206 protected static final long serialVersionUID = 1; 207 208 public boolean[] optionals() 209 { return new boolean[] { false, false, }; } 210 211 /** <CODE>[No Description Provided by Google]</CODE> */ 212 public final Memory.SamplingProfileNode[] samples; 213 214 /** <CODE>[No Description Provided by Google]</CODE> */ 215 public final Memory.Module[] modules; 216 217 /** 218 * Constructor 219 * 220 * @param samples - 221 * 222 * @param modules - 223 */ 224 public SamplingProfile(Memory.SamplingProfileNode[] samples, Memory.Module[] modules) 225 { 226 // Exception-Check(s) to ensure that if any parameters which are not declared as 227 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 228 229 if (samples == null) BRDPC.throwNPE("samples"); 230 if (modules == null) BRDPC.throwNPE("modules"); 231 232 this.samples = samples; 233 this.modules = modules; 234 } 235 236 /** 237 * JSON Object Constructor 238 * @param jo A Json-Object having data about an instance of {@code 'SamplingProfile'}. 239 */ 240 public SamplingProfile (JsonObject jo) 241 { 242 this.samples = (jo.getJsonArray("samples") == null) 243 ? null 244 : ReadArrJSON.DimN.objArr(jo.getJsonArray("samples"), null, 0, Memory.SamplingProfileNode[].class); 245 246 this.modules = (jo.getJsonArray("modules") == null) 247 ? null 248 : ReadArrJSON.DimN.objArr(jo.getJsonArray("modules"), null, 0, Memory.Module[].class); 249 250 } 251 252 253 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 254 public boolean equals(Object other) 255 { 256 if (other == null) return false; 257 if (other.getClass() != this.getClass()) return false; 258 259 SamplingProfile o = (SamplingProfile) other; 260 261 return 262 Arrays.deepEquals(this.samples, o.samples) 263 && Arrays.deepEquals(this.modules, o.modules); 264 } 265 266 /** Generates a Hash-Code for {@code 'this'} instance */ 267 public int hashCode() 268 { 269 return 270 Arrays.deepHashCode(this.samples) 271 + Arrays.deepHashCode(this.modules); 272 } 273 } 274 275 /** Executable module information */ 276 public static class Module 277 extends BaseType 278 implements java.io.Serializable 279 { 280 /** For Object Serialization. java.io.Serializable */ 281 protected static final long serialVersionUID = 1; 282 283 public boolean[] optionals() 284 { return new boolean[] { false, false, false, false, }; } 285 286 /** Name of the module. */ 287 public final String name; 288 289 /** UUID of the module. */ 290 public final String uuid; 291 292 /** 293 * Base address where the module is loaded into memory. Encoded as a decimal 294 * or hexadecimal (0x prefixed) string. 295 */ 296 public final String baseAddress; 297 298 /** Size of the module in bytes. */ 299 public final Number size; 300 301 /** 302 * Constructor 303 * 304 * @param name Name of the module. 305 * 306 * @param uuid UUID of the module. 307 * 308 * @param baseAddress 309 * Base address where the module is loaded into memory. Encoded as a decimal 310 * or hexadecimal (0x prefixed) string. 311 * 312 * @param size Size of the module in bytes. 313 */ 314 public Module(String name, String uuid, String baseAddress, Number size) 315 { 316 // Exception-Check(s) to ensure that if any parameters which are not declared as 317 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 318 319 if (name == null) BRDPC.throwNPE("name"); 320 if (uuid == null) BRDPC.throwNPE("uuid"); 321 if (baseAddress == null) BRDPC.throwNPE("baseAddress"); 322 if (size == null) BRDPC.throwNPE("size"); 323 324 this.name = name; 325 this.uuid = uuid; 326 this.baseAddress = baseAddress; 327 this.size = size; 328 } 329 330 /** 331 * JSON Object Constructor 332 * @param jo A Json-Object having data about an instance of {@code 'Module'}. 333 */ 334 public Module (JsonObject jo) 335 { 336 this.name = ReadJSON.getString(jo, "name", false, true); 337 this.uuid = ReadJSON.getString(jo, "uuid", false, true); 338 this.baseAddress = ReadJSON.getString(jo, "baseAddress", false, true); 339 this.size = ReadNumberJSON.get(jo, "size", false, true); 340 } 341 342 343 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 344 public boolean equals(Object other) 345 { 346 if (other == null) return false; 347 if (other.getClass() != this.getClass()) return false; 348 349 Module o = (Module) other; 350 351 return 352 Objects.equals(this.name, o.name) 353 && Objects.equals(this.uuid, o.uuid) 354 && Objects.equals(this.baseAddress, o.baseAddress) 355 && Objects.equals(this.size, o.size); 356 } 357 358 /** Generates a Hash-Code for {@code 'this'} instance */ 359 public int hashCode() 360 { 361 return 362 Objects.hashCode(this.name) 363 + Objects.hashCode(this.uuid) 364 + Objects.hashCode(this.baseAddress) 365 + Objects.hashCode(this.size); 366 } 367 } 368 369 370 // Counter for keeping the WebSocket Request ID's distinct. 371 private static int counter = 1; 372 373 /** 374 * <CODE>[No Description Provided by Google]</CODE> 375 * 376 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 377 * {@link Ret3}></CODE> 378 * 379 * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 380 * {@link Script#exec()}), and a {@link Promise} returned. 381 * 382 * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B> 383 * (using {@link Promise#await()}), the {@code Ret3} will subsequently 384 * be returned from that call. 385 * 386 * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated 387 * in an instance of <B>{@link Ret3}</B> 388 * 389 * <BR /><BR /><UL CLASS=JDUL> 390 * <LI><CODE><B>Ret3.a:</B> Integer (<B>documents</B>)</CODE> 391 * <BR />- 392 * <BR /><BR /></LI> 393 * <LI><CODE><B>Ret3.b:</B> Integer (<B>nodes</B>)</CODE> 394 * <BR />- 395 * <BR /><BR /></LI> 396 * <LI><CODE><B>Ret3.c:</B> Integer (<B>jsEventListeners</B>)</CODE> 397 * <BR />- 398 * </LI> 399 * </UL> 400 */ 401 public static Script<String, JsonObject, Ret3<Integer, Integer, Integer>> getDOMCounters() 402 { 403 final int webSocketID = 29000000 + counter++; 404 final boolean[] optionals = new boolean[0]; 405 406 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 407 String requestJSON = WriteJSON.get( 408 parameterTypes.get("getDOMCounters"), 409 parameterNames.get("getDOMCounters"), 410 optionals, webSocketID, 411 "Memory.getDOMCounters" 412 ); 413 414 // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret3' 415 Function<JsonObject, Ret3<Integer, Integer, Integer>> 416 responseProcessor = (JsonObject jo) -> new Ret3<>( 417 ReadBoxedJSON.getInteger(jo, "documents", true), 418 ReadBoxedJSON.getInteger(jo, "nodes", true), 419 ReadBoxedJSON.getInteger(jo, "jsEventListeners", true) 420 ); 421 422 // Pass the 'defaultSender' to Script-Constructor 423 // The sender that is used can be changed before executing script. 424 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 425 } 426 427 /** 428 * <CODE>[No Description Provided by Google]</CODE> 429 * 430 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 431 * {@link Ret0}></CODE> 432 * 433 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 434 * browser receives the invocation-request. 435 * 436 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 437 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 438 * {@code >} to ensure the Browser Function has run to completion. 439 */ 440 public static Script<String, JsonObject, Ret0> prepareForLeakDetection() 441 { 442 final int webSocketID = 29001000 + counter++; 443 final boolean[] optionals = new boolean[0]; 444 445 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 446 String requestJSON = WriteJSON.get( 447 parameterTypes.get("prepareForLeakDetection"), 448 parameterNames.get("prepareForLeakDetection"), 449 optionals, webSocketID, 450 "Memory.prepareForLeakDetection" 451 ); 452 453 // This Remote Command does not have a Return-Value. 454 return new Script<> 455 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 456 } 457 458 /** 459 * Simulate OomIntervention by purging V8 memory. 460 * 461 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 462 * {@link Ret0}></CODE> 463 * 464 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 465 * browser receives the invocation-request. 466 * 467 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 468 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 469 * {@code >} to ensure the Browser Function has run to completion. 470 */ 471 public static Script<String, JsonObject, Ret0> forciblyPurgeJavaScriptMemory() 472 { 473 final int webSocketID = 29002000 + counter++; 474 final boolean[] optionals = new boolean[0]; 475 476 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 477 String requestJSON = WriteJSON.get( 478 parameterTypes.get("forciblyPurgeJavaScriptMemory"), 479 parameterNames.get("forciblyPurgeJavaScriptMemory"), 480 optionals, webSocketID, 481 "Memory.forciblyPurgeJavaScriptMemory" 482 ); 483 484 // This Remote Command does not have a Return-Value. 485 return new Script<> 486 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 487 } 488 489 /** 490 * Enable/disable suppressing memory pressure notifications in all processes. 491 * 492 * @param suppressed If true, memory pressure notifications will be suppressed. 493 * 494 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 495 * {@link Ret0}></CODE> 496 * 497 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 498 * browser receives the invocation-request. 499 * 500 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 501 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 502 * {@code >} to ensure the Browser Function has run to completion. 503 */ 504 public static Script<String, JsonObject, Ret0> setPressureNotificationsSuppressed 505 (boolean suppressed) 506 { 507 final int webSocketID = 29003000 + counter++; 508 final boolean[] optionals = { false, }; 509 510 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 511 String requestJSON = WriteJSON.get( 512 parameterTypes.get("setPressureNotificationsSuppressed"), 513 parameterNames.get("setPressureNotificationsSuppressed"), 514 optionals, webSocketID, 515 "Memory.setPressureNotificationsSuppressed", 516 suppressed 517 ); 518 519 // This Remote Command does not have a Return-Value. 520 return new Script<> 521 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 522 } 523 524 /** 525 * Simulate a memory pressure notification in all processes. 526 * 527 * @param level Memory pressure level of the notification. 528 * 529 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 530 * {@link Ret0}></CODE> 531 * 532 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 533 * browser receives the invocation-request. 534 * 535 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 536 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 537 * {@code >} to ensure the Browser Function has run to completion. 538 */ 539 public static Script<String, JsonObject, Ret0> simulatePressureNotification(String level) 540 { 541 // Exception-Check(s) to ensure that if any parameters which are not declared as 542 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 543 544 if (level == null) BRDPC.throwNPE("level"); 545 546 // Exception-Check(s) to ensure that if any parameters which must adhere to a 547 // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw. 548 549 BRDPC.checkIAE("level", level, "Memory.PressureLevel", Memory.PressureLevel); 550 551 final int webSocketID = 29004000 + counter++; 552 final boolean[] optionals = { false, }; 553 554 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 555 String requestJSON = WriteJSON.get( 556 parameterTypes.get("simulatePressureNotification"), 557 parameterNames.get("simulatePressureNotification"), 558 optionals, webSocketID, 559 "Memory.simulatePressureNotification", 560 level 561 ); 562 563 // This Remote Command does not have a Return-Value. 564 return new Script<> 565 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 566 } 567 568 /** 569 * Start collecting native memory profile. 570 * 571 * @param samplingInterval Average number of bytes between samples. 572 * <BR /><B>OPTIONAL</B> 573 * 574 * @param suppressRandomness Do not randomize intervals between samples. 575 * <BR /><B>OPTIONAL</B> 576 * 577 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 578 * {@link Ret0}></CODE> 579 * 580 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 581 * browser receives the invocation-request. 582 * 583 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 584 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 585 * {@code >} to ensure the Browser Function has run to completion. 586 */ 587 public static Script<String, JsonObject, Ret0> startSampling 588 (Integer samplingInterval, Boolean suppressRandomness) 589 { 590 final int webSocketID = 29005000 + counter++; 591 final boolean[] optionals = { true, true, }; 592 593 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 594 String requestJSON = WriteJSON.get( 595 parameterTypes.get("startSampling"), 596 parameterNames.get("startSampling"), 597 optionals, webSocketID, 598 "Memory.startSampling", 599 samplingInterval, suppressRandomness 600 ); 601 602 // This Remote Command does not have a Return-Value. 603 return new Script<> 604 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 605 } 606 607 /** 608 * Stop collecting native memory profile. 609 * 610 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 611 * {@link Ret0}></CODE> 612 * 613 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 614 * browser receives the invocation-request. 615 * 616 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 617 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 618 * {@code >} to ensure the Browser Function has run to completion. 619 */ 620 public static Script<String, JsonObject, Ret0> stopSampling() 621 { 622 final int webSocketID = 29006000 + counter++; 623 final boolean[] optionals = new boolean[0]; 624 625 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 626 String requestJSON = WriteJSON.get( 627 parameterTypes.get("stopSampling"), 628 parameterNames.get("stopSampling"), 629 optionals, webSocketID, 630 "Memory.stopSampling" 631 ); 632 633 // This Remote Command does not have a Return-Value. 634 return new Script<> 635 (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues); 636 } 637 638 /** 639 * Retrieve native memory allocations profile 640 * collected since renderer process startup. 641 * 642 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 643 * {@link Memory.SamplingProfile}></CODE> 644 * 645 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 646 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 647 * {@link Memory.SamplingProfile}></CODE> will be returned. 648 * 649 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 650 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 651 * may be retrieved.</I> 652 * 653 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 654 * <BR /><BR /><UL CLASS=JDUL> 655 * <LI><CODE>{@link Memory.SamplingProfile} (<B>profile</B></CODE>) 656 * <BR />- 657 * </LI> 658 * </UL> */ 659 public static Script<String, JsonObject, Memory.SamplingProfile> getAllTimeSamplingProfile() 660 { 661 final int webSocketID = 29007000 + counter++; 662 final boolean[] optionals = new boolean[0]; 663 664 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 665 String requestJSON = WriteJSON.get( 666 parameterTypes.get("getAllTimeSamplingProfile"), 667 parameterNames.get("getAllTimeSamplingProfile"), 668 optionals, webSocketID, 669 "Memory.getAllTimeSamplingProfile" 670 ); 671 672 // 'JSON Binding' ... Converts Browser Response-JSON to 'Memory.SamplingProfile' 673 Function<JsonObject, Memory.SamplingProfile> responseProcessor = (JsonObject jo) -> 674 ReadJSON.getObject(jo, "profile", Memory.SamplingProfile.class, false, true); 675 676 // Pass the 'defaultSender' to Script-Constructor 677 // The sender that is used can be changed before executing script. 678 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 679 } 680 681 /** 682 * Retrieve native memory allocations profile 683 * collected since browser process startup. 684 * 685 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 686 * {@link Memory.SamplingProfile}></CODE> 687 * 688 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 689 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 690 * {@link Memory.SamplingProfile}></CODE> will be returned. 691 * 692 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 693 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 694 * may be retrieved.</I> 695 * 696 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 697 * <BR /><BR /><UL CLASS=JDUL> 698 * <LI><CODE>{@link Memory.SamplingProfile} (<B>profile</B></CODE>) 699 * <BR />- 700 * </LI> 701 * </UL> */ 702 public static Script<String, JsonObject, Memory.SamplingProfile> getBrowserSamplingProfile() 703 { 704 final int webSocketID = 29008000 + counter++; 705 final boolean[] optionals = new boolean[0]; 706 707 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 708 String requestJSON = WriteJSON.get( 709 parameterTypes.get("getBrowserSamplingProfile"), 710 parameterNames.get("getBrowserSamplingProfile"), 711 optionals, webSocketID, 712 "Memory.getBrowserSamplingProfile" 713 ); 714 715 // 'JSON Binding' ... Converts Browser Response-JSON to 'Memory.SamplingProfile' 716 Function<JsonObject, Memory.SamplingProfile> responseProcessor = (JsonObject jo) -> 717 ReadJSON.getObject(jo, "profile", Memory.SamplingProfile.class, false, true); 718 719 // Pass the 'defaultSender' to Script-Constructor 720 // The sender that is used can be changed before executing script. 721 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 722 } 723 724 /** 725 * Retrieve native memory allocations profile collected since last 726 * <CODE>startSampling</CODE> call. 727 * 728 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 729 * {@link Memory.SamplingProfile}></CODE> 730 * 731 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 732 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 733 * {@link Memory.SamplingProfile}></CODE> will be returned. 734 * 735 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 736 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 737 * may be retrieved.</I> 738 * 739 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 740 * <BR /><BR /><UL CLASS=JDUL> 741 * <LI><CODE>{@link Memory.SamplingProfile} (<B>profile</B></CODE>) 742 * <BR />- 743 * </LI> 744 * </UL> */ 745 public static Script<String, JsonObject, Memory.SamplingProfile> getSamplingProfile() 746 { 747 final int webSocketID = 29009000 + counter++; 748 final boolean[] optionals = new boolean[0]; 749 750 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 751 String requestJSON = WriteJSON.get( 752 parameterTypes.get("getSamplingProfile"), 753 parameterNames.get("getSamplingProfile"), 754 optionals, webSocketID, 755 "Memory.getSamplingProfile" 756 ); 757 758 // 'JSON Binding' ... Converts Browser Response-JSON to 'Memory.SamplingProfile' 759 Function<JsonObject, Memory.SamplingProfile> responseProcessor = (JsonObject jo) -> 760 ReadJSON.getObject(jo, "profile", Memory.SamplingProfile.class, false, true); 761 762 // Pass the 'defaultSender' to Script-Constructor 763 // The sender that is used can be changed before executing script. 764 return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor); 765 } 766 767}