Skip to content

memory

DOMCounter dataclass

DOM object counter data.

Source code in zendriver/cdp/memory.py
@dataclass
class DOMCounter:
    """
    DOM object counter data.
    """

    #: Object name. Note: object names should be presumed volatile and clients should not expect
    #: the returned names to be consistent across runs.
    name: str

    #: Object count.
    count: int

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["name"] = self.name
        json["count"] = self.count
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> DOMCounter:
        return cls(
            name=str(json["name"]),
            count=int(json["count"]),
        )

count: int instance-attribute

name: str instance-attribute

__init__(name, count)

from_json(json) classmethod

Source code in zendriver/cdp/memory.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DOMCounter:
    return cls(
        name=str(json["name"]),
        count=int(json["count"]),
    )

to_json()

Source code in zendriver/cdp/memory.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["name"] = self.name
    json["count"] = self.count
    return json

Module dataclass

Executable module information

Source code in zendriver/cdp/memory.py
@dataclass
class Module:
    """
    Executable module information
    """

    #: Name of the module.
    name: str

    #: UUID of the module.
    uuid: str

    #: Base address where the module is loaded into memory. Encoded as a decimal
    #: or hexadecimal (0x prefixed) string.
    base_address: str

    #: Size of the module in bytes.
    size: float

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["name"] = self.name
        json["uuid"] = self.uuid
        json["baseAddress"] = self.base_address
        json["size"] = self.size
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> Module:
        return cls(
            name=str(json["name"]),
            uuid=str(json["uuid"]),
            base_address=str(json["baseAddress"]),
            size=float(json["size"]),
        )

base_address: str instance-attribute

name: str instance-attribute

size: float instance-attribute

uuid: str instance-attribute

__init__(name, uuid, base_address, size)

from_json(json) classmethod

Source code in zendriver/cdp/memory.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Module:
    return cls(
        name=str(json["name"]),
        uuid=str(json["uuid"]),
        base_address=str(json["baseAddress"]),
        size=float(json["size"]),
    )

to_json()

Source code in zendriver/cdp/memory.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["name"] = self.name
    json["uuid"] = self.uuid
    json["baseAddress"] = self.base_address
    json["size"] = self.size
    return json

PressureLevel

Bases: Enum

Memory pressure level.

Source code in zendriver/cdp/memory.py
class PressureLevel(enum.Enum):
    """
    Memory pressure level.
    """

    MODERATE = "moderate"
    CRITICAL = "critical"

    def to_json(self) -> str:
        return self.value

    @classmethod
    def from_json(cls, json: str) -> PressureLevel:
        return cls(json)

CRITICAL = 'critical' class-attribute instance-attribute

MODERATE = 'moderate' class-attribute instance-attribute

from_json(json) classmethod

Source code in zendriver/cdp/memory.py
@classmethod
def from_json(cls, json: str) -> PressureLevel:
    return cls(json)

to_json()

Source code in zendriver/cdp/memory.py
def to_json(self) -> str:
    return self.value

SamplingProfile dataclass

Array of heap profile samples.

Source code in zendriver/cdp/memory.py
@dataclass
class SamplingProfile:
    """
    Array of heap profile samples.
    """

    samples: typing.List[SamplingProfileNode]

    modules: typing.List[Module]

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["samples"] = [i.to_json() for i in self.samples]
        json["modules"] = [i.to_json() for i in self.modules]
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> SamplingProfile:
        return cls(
            samples=[SamplingProfileNode.from_json(i) for i in json["samples"]],
            modules=[Module.from_json(i) for i in json["modules"]],
        )

modules: typing.List[Module] instance-attribute

samples: typing.List[SamplingProfileNode] instance-attribute

__init__(samples, modules)

from_json(json) classmethod

Source code in zendriver/cdp/memory.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SamplingProfile:
    return cls(
        samples=[SamplingProfileNode.from_json(i) for i in json["samples"]],
        modules=[Module.from_json(i) for i in json["modules"]],
    )

to_json()

Source code in zendriver/cdp/memory.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["samples"] = [i.to_json() for i in self.samples]
    json["modules"] = [i.to_json() for i in self.modules]
    return json

SamplingProfileNode dataclass

Heap profile sample.

Source code in zendriver/cdp/memory.py
@dataclass
class SamplingProfileNode:
    """
    Heap profile sample.
    """

    #: Size of the sampled allocation.
    size: float

    #: Total bytes attributed to this sample.
    total: float

    #: Execution stack at the point of allocation.
    stack: typing.List[str]

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["size"] = self.size
        json["total"] = self.total
        json["stack"] = [i for i in self.stack]
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> SamplingProfileNode:
        return cls(
            size=float(json["size"]),
            total=float(json["total"]),
            stack=[str(i) for i in json["stack"]],
        )

size: float instance-attribute

stack: typing.List[str] instance-attribute

total: float instance-attribute

__init__(size, total, stack)

from_json(json) classmethod

Source code in zendriver/cdp/memory.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SamplingProfileNode:
    return cls(
        size=float(json["size"]),
        total=float(json["total"]),
        stack=[str(i) for i in json["stack"]],
    )

to_json()

Source code in zendriver/cdp/memory.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["size"] = self.size
    json["total"] = self.total
    json["stack"] = [i for i in self.stack]
    return json

forcibly_purge_java_script_memory()

Simulate OomIntervention by purging V8 memory.

Source code in zendriver/cdp/memory.py
def forcibly_purge_java_script_memory() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, None]
):
    """
    Simulate OomIntervention by purging V8 memory.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.forciblyPurgeJavaScriptMemory",
    }
    json = yield cmd_dict

get_all_time_sampling_profile()

Retrieve native memory allocations profile collected since renderer process startup.

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, SamplingProfile]
Source code in zendriver/cdp/memory.py
def get_all_time_sampling_profile() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, SamplingProfile]
):
    """
    Retrieve native memory allocations profile
    collected since renderer process startup.

    :returns:
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.getAllTimeSamplingProfile",
    }
    json = yield cmd_dict
    return SamplingProfile.from_json(json["profile"])

get_browser_sampling_profile()

Retrieve native memory allocations profile collected since browser process startup.

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, SamplingProfile]
Source code in zendriver/cdp/memory.py
def get_browser_sampling_profile() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, SamplingProfile]
):
    """
    Retrieve native memory allocations profile
    collected since browser process startup.

    :returns:
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.getBrowserSamplingProfile",
    }
    json = yield cmd_dict
    return SamplingProfile.from_json(json["profile"])

get_dom_counters()

Retruns current DOM object counters.

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, Tuple[int, int, int]]

A tuple with the following items: 0. documents - 1. nodes - 2. jsEventListeners -

Source code in zendriver/cdp/memory.py
def get_dom_counters() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.Tuple[int, int, int]]
):
    """
    Retruns current DOM object counters.

    :returns: A tuple with the following items:

        0. **documents** -
        1. **nodes** -
        2. **jsEventListeners** -
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.getDOMCounters",
    }
    json = yield cmd_dict
    return (int(json["documents"]), int(json["nodes"]), int(json["jsEventListeners"]))

get_dom_counters_for_leak_detection()

Retruns DOM object counters after preparing renderer for leak detection.

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, List[DOMCounter]]

DOM object counters.

Source code in zendriver/cdp/memory.py
def get_dom_counters_for_leak_detection() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[DOMCounter]]
):
    """
    Retruns DOM object counters after preparing renderer for leak detection.

    :returns: DOM object counters.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.getDOMCountersForLeakDetection",
    }
    json = yield cmd_dict
    return [DOMCounter.from_json(i) for i in json["counters"]]

get_sampling_profile()

Retrieve native memory allocations profile collected since last startSampling call.

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, SamplingProfile]
Source code in zendriver/cdp/memory.py
def get_sampling_profile() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, SamplingProfile]
):
    """
    Retrieve native memory allocations profile collected since last
    ``startSampling`` call.

    :returns:
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.getSamplingProfile",
    }
    json = yield cmd_dict
    return SamplingProfile.from_json(json["profile"])

prepare_for_leak_detection()

Prepares for leak detection by terminating workers, stopping spellcheckers, dropping non-essential internal caches, running garbage collections, etc.

Source code in zendriver/cdp/memory.py
def prepare_for_leak_detection() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Prepares for leak detection by terminating workers, stopping spellcheckers,
    dropping non-essential internal caches, running garbage collections, etc.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.prepareForLeakDetection",
    }
    json = yield cmd_dict

set_pressure_notifications_suppressed(suppressed)

Enable/disable suppressing memory pressure notifications in all processes.

Parameters:

Name Type Description Default
suppressed bool

If true, memory pressure notifications will be suppressed.

required
Source code in zendriver/cdp/memory.py
def set_pressure_notifications_suppressed(
    suppressed: bool,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Enable/disable suppressing memory pressure notifications in all processes.

    :param suppressed: If true, memory pressure notifications will be suppressed.
    """
    params: T_JSON_DICT = dict()
    params["suppressed"] = suppressed
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.setPressureNotificationsSuppressed",
        "params": params,
    }
    json = yield cmd_dict

simulate_pressure_notification(level)

Simulate a memory pressure notification in all processes.

Parameters:

Name Type Description Default
level PressureLevel

Memory pressure level of the notification.

required
Source code in zendriver/cdp/memory.py
def simulate_pressure_notification(
    level: PressureLevel,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Simulate a memory pressure notification in all processes.

    :param level: Memory pressure level of the notification.
    """
    params: T_JSON_DICT = dict()
    params["level"] = level.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.simulatePressureNotification",
        "params": params,
    }
    json = yield cmd_dict

start_sampling(sampling_interval=None, suppress_randomness=None)

Start collecting native memory profile.

Parameters:

Name Type Description Default
sampling_interval Optional[int]

(Optional) Average number of bytes between samples.

None
suppress_randomness Optional[bool]

(Optional) Do not randomize intervals between samples.

None
Source code in zendriver/cdp/memory.py
def start_sampling(
    sampling_interval: typing.Optional[int] = None,
    suppress_randomness: typing.Optional[bool] = None,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Start collecting native memory profile.

    :param sampling_interval: *(Optional)* Average number of bytes between samples.
    :param suppress_randomness: *(Optional)* Do not randomize intervals between samples.
    """
    params: T_JSON_DICT = dict()
    if sampling_interval is not None:
        params["samplingInterval"] = sampling_interval
    if suppress_randomness is not None:
        params["suppressRandomness"] = suppress_randomness
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.startSampling",
        "params": params,
    }
    json = yield cmd_dict

stop_sampling()

Stop collecting native memory profile.

Source code in zendriver/cdp/memory.py
def stop_sampling() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Stop collecting native memory profile.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Memory.stopSampling",
    }
    json = yield cmd_dict