cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `HeapProfiler` domain.
//!
//! Types, command parameters and event payloads for the `HeapProfiler`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Heap snapshot object id.
pub type HeapSnapshotObjectId = String;

/// Sampling Heap Profile node. Holds callsite information, allocation
/// statistics and child nodes.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SamplingHeapProfileNode {
    /// Function location.
    #[serde(rename = "callFrame")]
    pub call_frame: crate::protocol::runtime::CallFrame,
    /// Allocations size in bytes for the node excluding children.
    #[serde(rename = "selfSize")]
    pub self_size: f64,
    /// Node id. Ids are unique across all profiles collected between
    /// startSampling and stopSampling.
    pub id: i64,
    /// Child nodes.
    pub children: Vec<SamplingHeapProfileNode>,
}

/// A single sample from a sampling profile.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SamplingHeapProfileSample {
    /// Allocation size in bytes attributed to the sample.
    pub size: f64,
    /// Id of the corresponding profile tree node.
    #[serde(rename = "nodeId")]
    pub node_id: i64,
    /// Time-ordered sample ordinal number. It is unique across all profiles
    /// retrieved between startSampling and stopSampling.
    pub ordinal: f64,
}

/// Sampling profile.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SamplingHeapProfile {
    pub head: SamplingHeapProfileNode,
    pub samples: Vec<SamplingHeapProfileSample>,
}

/// Enables console to refer to the node with given id via $x (see Command
/// Line API for more details $x functions).
///
/// Parameters of `HeapProfiler.addInspectedHeapObject`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddInspectedHeapObjectParams {
    /// Heap snapshot object id to be accessible by means of $x command line API.
    #[serde(rename = "heapObjectId")]
    pub heap_object_id: HeapSnapshotObjectId,
}

impl crate::typed::Command for AddInspectedHeapObjectParams {
    const METHOD: &'static str = "HeapProfiler.addInspectedHeapObject";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.collectGarbage`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CollectGarbageParams {}

impl crate::typed::Command for CollectGarbageParams {
    const METHOD: &'static str = "HeapProfiler.collectGarbage";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "HeapProfiler.disable";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "HeapProfiler.enable";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.getHeapObjectId`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetHeapObjectIdParams {
    /// Identifier of the object to get heap object id for.
    #[serde(rename = "objectId")]
    pub object_id: crate::protocol::runtime::RemoteObjectId,
}

/// What `HeapProfiler.getHeapObjectId` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetHeapObjectIdReturns {
    /// Id of the heap snapshot object corresponding to the passed remote object
    /// id.
    #[serde(rename = "heapSnapshotObjectId")]
    pub heap_snapshot_object_id: HeapSnapshotObjectId,
}

impl crate::typed::Command for GetHeapObjectIdParams {
    const METHOD: &'static str = "HeapProfiler.getHeapObjectId";
    type Returns = GetHeapObjectIdReturns;
}

/// Parameters of `HeapProfiler.getObjectByHeapObjectId`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetObjectByHeapObjectIdParams {
    #[serde(rename = "objectId")]
    pub object_id: HeapSnapshotObjectId,
    /// Symbolic group name that can be used to release multiple objects.
    #[serde(
        rename = "objectGroup",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub object_group: Option<String>,
}

/// What `HeapProfiler.getObjectByHeapObjectId` answers with.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GetObjectByHeapObjectIdReturns {
    /// Evaluation result.
    pub result: crate::protocol::runtime::RemoteObject,
}

impl crate::typed::Command for GetObjectByHeapObjectIdParams {
    const METHOD: &'static str = "HeapProfiler.getObjectByHeapObjectId";
    type Returns = GetObjectByHeapObjectIdReturns;
}

/// Parameters of `HeapProfiler.getSamplingProfile`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetSamplingProfileParams {}

/// What `HeapProfiler.getSamplingProfile` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetSamplingProfileReturns {
    /// Return the sampling profile being collected.
    pub profile: SamplingHeapProfile,
}

impl crate::typed::Command for GetSamplingProfileParams {
    const METHOD: &'static str = "HeapProfiler.getSamplingProfile";
    type Returns = GetSamplingProfileReturns;
}

/// Parameters of `HeapProfiler.startSampling`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartSamplingParams {
    /// Average sample interval in bytes. Poisson distribution is used for the
    /// intervals. The default value is 32768 bytes.
    #[serde(
        rename = "samplingInterval",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub sampling_interval: Option<f64>,
    /// Maximum stack depth. The default value is 128.
    #[serde(
        rename = "stackDepth",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub stack_depth: Option<f64>,
    /// By default, the sampling heap profiler reports only objects which are
    /// still alive when the profile is returned via getSamplingProfile or
    /// stopSampling, which is useful for determining what functions contribute
    /// the most to steady-state memory usage. This flag instructs the sampling
    /// heap profiler to also include information about objects discarded by major
    /// GC, which will show which functions cause large temporary memory usage or
    /// long GC pauses.
    #[serde(
        rename = "includeObjectsCollectedByMajorGC",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub include_objects_collected_by_major_gc: Option<bool>,
    /// By default, the sampling heap profiler reports only objects which are
    /// still alive when the profile is returned via getSamplingProfile or
    /// stopSampling, which is useful for determining what functions contribute
    /// the most to steady-state memory usage. This flag instructs the sampling
    /// heap profiler to also include information about objects discarded by minor
    /// GC, which is useful when tuning a latency-sensitive application for
    /// minimal GC activity.
    #[serde(
        rename = "includeObjectsCollectedByMinorGC",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub include_objects_collected_by_minor_gc: Option<bool>,
}

impl crate::typed::Command for StartSamplingParams {
    const METHOD: &'static str = "HeapProfiler.startSampling";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.startTrackingHeapObjects`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartTrackingHeapObjectsParams {
    #[serde(
        rename = "trackAllocations",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub track_allocations: Option<bool>,
}

impl crate::typed::Command for StartTrackingHeapObjectsParams {
    const METHOD: &'static str = "HeapProfiler.startTrackingHeapObjects";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.stopSampling`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopSamplingParams {}

/// What `HeapProfiler.stopSampling` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopSamplingReturns {
    /// Recorded sampling heap profile.
    pub profile: SamplingHeapProfile,
}

impl crate::typed::Command for StopSamplingParams {
    const METHOD: &'static str = "HeapProfiler.stopSampling";
    type Returns = StopSamplingReturns;
}

/// Parameters of `HeapProfiler.stopTrackingHeapObjects`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopTrackingHeapObjectsParams {
    /// If true 'reportHeapSnapshotProgress' events will be generated while
    /// snapshot is being taken when the tracking is stopped.
    #[serde(
        rename = "reportProgress",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub report_progress: Option<bool>,
    /// Deprecated in favor of `exposeInternals`.
    ///
    /// Deprecated in the protocol.
    #[serde(
        rename = "treatGlobalObjectsAsRoots",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub treat_global_objects_as_roots: Option<bool>,
    /// If true, numerical values are included in the snapshot
    #[serde(
        rename = "captureNumericValue",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub capture_numeric_value: Option<bool>,
    /// If true, exposes internals of the snapshot.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "exposeInternals",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub expose_internals: Option<bool>,
}

impl crate::typed::Command for StopTrackingHeapObjectsParams {
    const METHOD: &'static str = "HeapProfiler.stopTrackingHeapObjects";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `HeapProfiler.takeHeapSnapshot`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TakeHeapSnapshotParams {
    /// If true 'reportHeapSnapshotProgress' events will be generated while
    /// snapshot is being taken.
    #[serde(
        rename = "reportProgress",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub report_progress: Option<bool>,
    /// If true, a raw snapshot without artificial roots will be generated.
    /// Deprecated in favor of `exposeInternals`.
    ///
    /// Deprecated in the protocol.
    #[serde(
        rename = "treatGlobalObjectsAsRoots",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub treat_global_objects_as_roots: Option<bool>,
    /// If true, numerical values are included in the snapshot
    #[serde(
        rename = "captureNumericValue",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub capture_numeric_value: Option<bool>,
    /// If true, exposes internals of the snapshot.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "exposeInternals",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub expose_internals: Option<bool>,
}

impl crate::typed::Command for TakeHeapSnapshotParams {
    const METHOD: &'static str = "HeapProfiler.takeHeapSnapshot";
    type Returns = crate::typed::NoReturns;
}

/// Payload of the `HeapProfiler.addHeapSnapshotChunk` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddHeapSnapshotChunkEvent {
    pub chunk: String,
}

impl crate::typed::Event for AddHeapSnapshotChunkEvent {
    const METHOD: &'static str = "HeapProfiler.addHeapSnapshotChunk";
}

/// If heap objects tracking has been started then backend may send update for
/// one or more fragments
///
/// Payload of the `HeapProfiler.heapStatsUpdate` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct HeapStatsUpdateEvent {
    /// An array of triplets. Each triplet describes a fragment. The first integer
    /// is the fragment index, the second integer is a total count of objects for
    /// the fragment, the third integer is a total size of the objects for the
    /// fragment.
    #[serde(rename = "statsUpdate")]
    pub stats_update: Vec<i64>,
}

impl crate::typed::Event for HeapStatsUpdateEvent {
    const METHOD: &'static str = "HeapProfiler.heapStatsUpdate";
}

/// If heap objects tracking has been started then backend regularly sends a
/// current value for last seen object id and corresponding timestamp. If the
/// were changes in the heap since last event then one or more heapStatsUpdate
/// events will be sent before a new lastSeenObjectId event.
///
/// Payload of the `HeapProfiler.lastSeenObjectId` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LastSeenObjectIdEvent {
    #[serde(rename = "lastSeenObjectId")]
    pub last_seen_object_id: i64,
    pub timestamp: f64,
}

impl crate::typed::Event for LastSeenObjectIdEvent {
    const METHOD: &'static str = "HeapProfiler.lastSeenObjectId";
}

/// Payload of the `HeapProfiler.reportHeapSnapshotProgress` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ReportHeapSnapshotProgressEvent {
    pub done: i64,
    pub total: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub finished: Option<bool>,
}

impl crate::typed::Event for ReportHeapSnapshotProgressEvent {
    const METHOD: &'static str = "HeapProfiler.reportHeapSnapshotProgress";
}

/// Payload of the `HeapProfiler.resetProfiles` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResetProfilesEvent {}

impl crate::typed::Event for ResetProfilesEvent {
    const METHOD: &'static str = "HeapProfiler.resetProfiles";
}