All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openqa.selenium.devtools.memory.Memory Maven / Gradle / Ivy

Go to download

Selenium automates browsers. That's it! What you do with that power is entirely up to you.

There is a newer version: 4.0.0-rc-1
Show newest version
package org.openqa.selenium.devtools.memory;

import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.ConverterFunctions;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.json.JsonInput;

@Beta()
public class Memory {

    public static class GetDOMCountersResponse {

        private final java.lang.Integer documents;

        private final java.lang.Integer nodes;

        private final java.lang.Integer jsEventListeners;

        public GetDOMCountersResponse(java.lang.Integer documents, java.lang.Integer nodes, java.lang.Integer jsEventListeners) {
            this.documents = java.util.Objects.requireNonNull(documents, "documents is required");
            this.nodes = java.util.Objects.requireNonNull(nodes, "nodes is required");
            this.jsEventListeners = java.util.Objects.requireNonNull(jsEventListeners, "jsEventListeners is required");
        }

        public java.lang.Integer getDocuments() {
            return documents;
        }

        public java.lang.Integer getNodes() {
            return nodes;
        }

        public java.lang.Integer getJsEventListeners() {
            return jsEventListeners;
        }

        private static GetDOMCountersResponse fromJson(JsonInput input) {
            java.lang.Integer documents = null;
            java.lang.Integer nodes = null;
            java.lang.Integer jsEventListeners = null;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "documents":
                        documents = input.nextNumber().intValue();
                        break;
                    case "nodes":
                        nodes = input.nextNumber().intValue();
                        break;
                    case "jsEventListeners":
                        jsEventListeners = input.nextNumber().intValue();
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new GetDOMCountersResponse(documents, nodes, jsEventListeners);
        }
    }

    public static Command getDOMCounters() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.getDOMCounters", params.build(), input -> input.read(org.openqa.selenium.devtools.memory.Memory.GetDOMCountersResponse.class));
    }

    public static Command prepareForLeakDetection() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.prepareForLeakDetection", params.build());
    }

    /**
     * Simulate OomIntervention by purging V8 memory.
     */
    public static Command forciblyPurgeJavaScriptMemory() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.forciblyPurgeJavaScriptMemory", params.build());
    }

    /**
     * Enable/disable suppressing memory pressure notifications in all processes.
     */
    public static Command setPressureNotificationsSuppressed(java.lang.Boolean suppressed) {
        java.util.Objects.requireNonNull(suppressed, "suppressed is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("suppressed", suppressed);
        return new Command<>("Memory.setPressureNotificationsSuppressed", params.build());
    }

    /**
     * Simulate a memory pressure notification in all processes.
     */
    public static Command simulatePressureNotification(org.openqa.selenium.devtools.memory.model.PressureLevel level) {
        java.util.Objects.requireNonNull(level, "level is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("level", level);
        return new Command<>("Memory.simulatePressureNotification", params.build());
    }

    /**
     * Start collecting native memory profile.
     */
    public static Command startSampling(java.util.Optional samplingInterval, java.util.Optional suppressRandomness) {
        ImmutableMap.Builder params = ImmutableMap.builder();
        samplingInterval.ifPresent(p -> params.put("samplingInterval", p));
        suppressRandomness.ifPresent(p -> params.put("suppressRandomness", p));
        return new Command<>("Memory.startSampling", params.build());
    }

    /**
     * Stop collecting native memory profile.
     */
    public static Command stopSampling() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.stopSampling", params.build());
    }

    /**
     * Retrieve native memory allocations profile
     * collected since renderer process startup.
     */
    public static Command getAllTimeSamplingProfile() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.getAllTimeSamplingProfile", params.build(), ConverterFunctions.map("profile", org.openqa.selenium.devtools.memory.model.SamplingProfile.class));
    }

    /**
     * Retrieve native memory allocations profile
     * collected since browser process startup.
     */
    public static Command getBrowserSamplingProfile() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.getBrowserSamplingProfile", params.build(), ConverterFunctions.map("profile", org.openqa.selenium.devtools.memory.model.SamplingProfile.class));
    }

    /**
     * Retrieve native memory allocations profile collected since last
     * `startSampling` call.
     */
    public static Command getSamplingProfile() {
        ImmutableMap.Builder params = ImmutableMap.builder();
        return new Command<>("Memory.getSamplingProfile", params.build(), ConverterFunctions.map("profile", org.openqa.selenium.devtools.memory.model.SamplingProfile.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy