# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.profiler
from cdp.profiler import (
    ConsoleProfileFinished,
    ConsoleProfileStarted,
    CoverageRange,
    FunctionCoverage,
    PositionTickInfo,
    Profile,
    ProfileNode,
    ScriptCoverage,
    ScriptTypeProfile,
    TypeObject,
    TypeProfileEntry
)


async def disable() -> None:
    session = get_session_context('profiler.disable')
    return await session.execute(cdp.profiler.disable())


async def enable() -> None:
    session = get_session_context('profiler.enable')
    return await session.execute(cdp.profiler.enable())


async def get_best_effort_coverage() -> typing.List[ScriptCoverage]:
    '''
    Collect coverage data for the current isolate. The coverage data may be incomplete due to
    garbage collection.

    :returns: Coverage data for the current isolate.
    '''
    session = get_session_context('profiler.get_best_effort_coverage')
    return await session.execute(cdp.profiler.get_best_effort_coverage())


async def set_sampling_interval(
        interval: int
    ) -> None:
    '''
    Changes CPU profiler sampling interval. Must be called before CPU profiles recording started.

    :param interval: New sampling interval in microseconds.
    '''
    session = get_session_context('profiler.set_sampling_interval')
    return await session.execute(cdp.profiler.set_sampling_interval(interval))


async def start() -> None:
    session = get_session_context('profiler.start')
    return await session.execute(cdp.profiler.start())


async def start_precise_coverage(
        call_count: typing.Optional[bool] = None,
        detailed: typing.Optional[bool] = None
    ) -> None:
    '''
    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.

    :param call_count: *(Optional)* Collect accurate call counts beyond simple 'covered' or 'not covered'.
    :param detailed: *(Optional)* Collect block-based coverage.
    '''
    session = get_session_context('profiler.start_precise_coverage')
    return await session.execute(cdp.profiler.start_precise_coverage(call_count, detailed))


async def start_type_profile() -> None:
    '''
    Enable type profile.

    **EXPERIMENTAL**
    '''
    session = get_session_context('profiler.start_type_profile')
    return await session.execute(cdp.profiler.start_type_profile())


async def stop() -> Profile:
    '''


    :returns: Recorded profile.
    '''
    session = get_session_context('profiler.stop')
    return await session.execute(cdp.profiler.stop())


async def stop_precise_coverage() -> None:
    '''
    Disable precise code coverage. Disabling releases unnecessary execution count records and allows
    executing optimized code.
    '''
    session = get_session_context('profiler.stop_precise_coverage')
    return await session.execute(cdp.profiler.stop_precise_coverage())


async def stop_type_profile() -> None:
    '''
    Disable type profile. Disabling releases type profile data collected so far.

    **EXPERIMENTAL**
    '''
    session = get_session_context('profiler.stop_type_profile')
    return await session.execute(cdp.profiler.stop_type_profile())


async def take_precise_coverage() -> typing.List[ScriptCoverage]:
    '''
    Collect coverage data for the current isolate, and resets execution counters. Precise code
    coverage needs to have started.

    :returns: Coverage data for the current isolate.
    '''
    session = get_session_context('profiler.take_precise_coverage')
    return await session.execute(cdp.profiler.take_precise_coverage())


async def take_type_profile() -> typing.List[ScriptTypeProfile]:
    '''
    Collect type profile.

    **EXPERIMENTAL**

    :returns: Type profile for all scripts since startTypeProfile() was turned on.
    '''
    session = get_session_context('profiler.take_type_profile')
    return await session.execute(cdp.profiler.take_type_profile())
