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 `Profiler` domain.
//!
//! Types, command parameters and event payloads for the `Profiler`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].

use serde::{Deserialize, Serialize};

/// Profile node. Holds callsite information, execution statistics and child
/// nodes.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ProfileNode {
    /// Unique id of the node.
    pub id: i64,
    /// Function location.
    #[serde(rename = "callFrame")]
    pub call_frame: crate::protocol::runtime::CallFrame,
    /// Number of samples where this node was on top of the call stack.
    #[serde(rename = "hitCount", default, skip_serializing_if = "Option::is_none")]
    pub hit_count: Option<i64>,
    /// Child node ids.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub children: Option<Vec<i64>>,
    /// The reason of being not optimized. The function may be deoptimized or
    /// marked as don't optimize.
    #[serde(
        rename = "deoptReason",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub deopt_reason: Option<String>,
    /// An array of source position ticks.
    #[serde(
        rename = "positionTicks",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub position_ticks: Option<Vec<PositionTickInfo>>,
}

/// Profile.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Profile {
    /// The list of profile nodes. First item is the root node.
    pub nodes: Vec<ProfileNode>,
    /// Profiling start timestamp in microseconds.
    #[serde(rename = "startTime")]
    pub start_time: f64,
    /// Profiling end timestamp in microseconds.
    #[serde(rename = "endTime")]
    pub end_time: f64,
    /// Ids of samples top nodes.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub samples: Option<Vec<i64>>,
    /// Time intervals between adjacent samples in microseconds. The first delta
    /// is relative to the profile startTime.
    #[serde(
        rename = "timeDeltas",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub time_deltas: Option<Vec<i64>>,
}

/// Specifies a number of samples attributed to a certain source position.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PositionTickInfo {
    /// Source line number (1-based).
    pub line: i64,
    /// Number of samples attributed to the source line.
    pub ticks: i64,
}

/// Coverage data for a source range.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CoverageRange {
    /// JavaScript script source offset for the range start.
    #[serde(rename = "startOffset")]
    pub start_offset: i64,
    /// JavaScript script source offset for the range end.
    #[serde(rename = "endOffset")]
    pub end_offset: i64,
    /// Collected execution count of the source range.
    pub count: i64,
}

/// Coverage data for a JavaScript function.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct FunctionCoverage {
    /// JavaScript function name.
    #[serde(rename = "functionName")]
    pub function_name: String,
    /// Source ranges inside the function with coverage data.
    pub ranges: Vec<CoverageRange>,
    /// Whether coverage data for this function has block granularity.
    #[serde(rename = "isBlockCoverage")]
    pub is_block_coverage: bool,
}

/// Coverage data for a JavaScript script.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ScriptCoverage {
    /// JavaScript script id.
    #[serde(rename = "scriptId")]
    pub script_id: crate::protocol::runtime::ScriptId,
    /// JavaScript script name or url.
    pub url: String,
    /// Functions contained in the script that has coverage data.
    pub functions: Vec<FunctionCoverage>,
}

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

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

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

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

/// Collect coverage data for the current isolate. The coverage data may be
/// incomplete due to garbage collection.
///
/// Parameters of `Profiler.getBestEffortCoverage`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetBestEffortCoverageParams {}

/// What `Profiler.getBestEffortCoverage` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetBestEffortCoverageReturns {
    /// Coverage data for the current isolate.
    pub result: Vec<ScriptCoverage>,
}

impl crate::typed::Command for GetBestEffortCoverageParams {
    const METHOD: &'static str = "Profiler.getBestEffortCoverage";
    type Returns = GetBestEffortCoverageReturns;
}

/// Changes CPU profiler sampling interval. Must be called before CPU profiles
/// recording started.
///
/// Parameters of `Profiler.setSamplingInterval`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetSamplingIntervalParams {
    /// New sampling interval in microseconds.
    pub interval: i64,
}

impl crate::typed::Command for SetSamplingIntervalParams {
    const METHOD: &'static str = "Profiler.setSamplingInterval";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `Profiler.start`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartParams {}

impl crate::typed::Command for StartParams {
    const METHOD: &'static str = "Profiler.start";
    type Returns = crate::typed::NoReturns;
}

/// Enable precise code coverage. Coverage data for JavaScript executed before
/// enabling precise code coverage may be incomplete. Enabling prevents
/// running optimized code and resets execution counters.
///
/// Parameters of `Profiler.startPreciseCoverage`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartPreciseCoverageParams {
    /// Collect accurate call counts beyond simple 'covered' or 'not covered'.
    #[serde(rename = "callCount", default, skip_serializing_if = "Option::is_none")]
    pub call_count: Option<bool>,
    /// Collect block-based coverage.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub detailed: Option<bool>,
    /// Allow the backend to send updates on its own initiative
    #[serde(
        rename = "allowTriggeredUpdates",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub allow_triggered_updates: Option<bool>,
}

/// What `Profiler.startPreciseCoverage` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartPreciseCoverageReturns {
    /// Monotonically increasing time (in seconds) when the coverage update was
    /// taken in the backend.
    pub timestamp: f64,
}

impl crate::typed::Command for StartPreciseCoverageParams {
    const METHOD: &'static str = "Profiler.startPreciseCoverage";
    type Returns = StartPreciseCoverageReturns;
}

/// Parameters of `Profiler.stop`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopParams {}

/// What `Profiler.stop` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopReturns {
    /// Recorded profile.
    pub profile: Profile,
}

impl crate::typed::Command for StopParams {
    const METHOD: &'static str = "Profiler.stop";
    type Returns = StopReturns;
}

/// Disable precise code coverage. Disabling releases unnecessary execution
/// count records and allows executing optimized code.
///
/// Parameters of `Profiler.stopPreciseCoverage`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopPreciseCoverageParams {}

impl crate::typed::Command for StopPreciseCoverageParams {
    const METHOD: &'static str = "Profiler.stopPreciseCoverage";
    type Returns = crate::typed::NoReturns;
}

/// Collect coverage data for the current isolate, and resets execution
/// counters. Precise code coverage needs to have started.
///
/// Parameters of `Profiler.takePreciseCoverage`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TakePreciseCoverageParams {}

/// What `Profiler.takePreciseCoverage` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TakePreciseCoverageReturns {
    /// Coverage data for the current isolate.
    pub result: Vec<ScriptCoverage>,
    /// Monotonically increasing time (in seconds) when the coverage update was
    /// taken in the backend.
    pub timestamp: f64,
}

impl crate::typed::Command for TakePreciseCoverageParams {
    const METHOD: &'static str = "Profiler.takePreciseCoverage";
    type Returns = TakePreciseCoverageReturns;
}

/// Payload of the `Profiler.consoleProfileFinished` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ConsoleProfileFinishedEvent {
    pub id: String,
    /// Location of console.profileEnd().
    pub location: crate::protocol::debugger::Location,
    pub profile: Profile,
    /// Profile title passed as an argument to console.profile().
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
}

impl crate::typed::Event for ConsoleProfileFinishedEvent {
    const METHOD: &'static str = "Profiler.consoleProfileFinished";
}

/// Sent when new profile recording is started using console.profile() call.
///
/// Payload of the `Profiler.consoleProfileStarted` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ConsoleProfileStartedEvent {
    pub id: String,
    /// Location of console.profile().
    pub location: crate::protocol::debugger::Location,
    /// Profile title passed as an argument to console.profile().
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
}

impl crate::typed::Event for ConsoleProfileStartedEvent {
    const METHOD: &'static str = "Profiler.consoleProfileStarted";
}

/// Reports coverage delta since the last poll (either from an event like
/// this, or from `takePreciseCoverage` for the current isolate. May only be
/// sent if precise code coverage has been started. This event can be trigged
/// by the embedder to, for example, trigger collection of coverage data
/// immediately at a certain point in time.
///
/// Experimental: may change without notice.
///
/// Payload of the `Profiler.preciseCoverageDeltaUpdate` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PreciseCoverageDeltaUpdateEvent {
    /// Monotonically increasing time (in seconds) when the coverage update was
    /// taken in the backend.
    pub timestamp: f64,
    /// Identifier for distinguishing coverage events.
    pub occasion: String,
    /// Coverage data for the current isolate.
    pub result: Vec<ScriptCoverage>,
}

impl crate::typed::Event for PreciseCoverageDeltaUpdateEvent {
    const METHOD: &'static str = "Profiler.preciseCoverageDeltaUpdate";
}