HeapProfiler#

This CDP domain is experimental.

Types#

Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.

class HeapSnapshotObjectId[source]#

Heap snapshot object id.

class SamplingHeapProfileNode(call_frame, self_size, id_, children)[source]#

Sampling Heap Profile node. Holds callsite information, allocation statistics and child nodes.

call_frame: CallFrame#

Function location.

self_size: float#

Allocations size in bytes for the node excluding children.

id_: int#

Node id. Ids are unique across all profiles collected between startSampling and stopSampling.

children: List[SamplingHeapProfileNode]#

Child nodes.

class SamplingHeapProfileSample(size, node_id, ordinal)[source]#

A single sample from a sampling profile.

size: float#

Allocation size in bytes attributed to the sample.

node_id: int#

Id of the corresponding profile tree node.

ordinal: float#

Time-ordered sample ordinal number. It is unique across all profiles retrieved between startSampling and stopSampling.

class SamplingHeapProfile(head, samples)[source]#

Sampling profile.

head: SamplingHeapProfileNode#
samples: List[SamplingHeapProfileSample]#

Commands#

Each command is a generator function. The return type Generator[x, y, z] indicates that the generator yields arguments of type x, it must be resumed with an argument of type y, and it returns type z. In this library, types x and y are the same for all commands, and z is the return type you should pay attention to. For more information, see Getting Started: Commands.

add_inspected_heap_object(heap_object_id)[source]#

Enables console to refer to the node with given id via $x (see Command Line API for more details $x functions).

Parameters:

heap_object_id (HeapSnapshotObjectId) – Heap snapshot object id to be accessible by means of $x command line API.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

collect_garbage()[source]#
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

disable()[source]#
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

enable()[source]#
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

get_heap_object_id(object_id)[source]#
Parameters:

object_id (RemoteObjectId) – Identifier of the object to get heap object id for.

Return type:

Generator[Dict[str, Any], Dict[str, Any], HeapSnapshotObjectId]

Returns:

Id of the heap snapshot object corresponding to the passed remote object id.

get_object_by_heap_object_id(object_id, object_group=None)[source]#
Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], RemoteObject]

Returns:

Evaluation result.

get_sampling_profile()[source]#
Return type:

Generator[Dict[str, Any], Dict[str, Any], SamplingHeapProfile]

Returns:

Return the sampling profile being collected.

start_sampling(sampling_interval=None, include_objects_collected_by_major_gc=None, include_objects_collected_by_minor_gc=None)[source]#
Parameters:
  • sampling_interval (Optional[float]) – (Optional) Average sample interval in bytes. Poisson distribution is used for the intervals. The default value is 32768 bytes.

  • include_objects_collected_by_major_gc (Optional[bool]) – (Optional) 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.

  • include_objects_collected_by_minor_gc (Optional[bool]) – (Optional) 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.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

start_tracking_heap_objects(track_allocations=None)[source]#
Parameters:

track_allocations (Optional[bool]) – (Optional)

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

stop_sampling()[source]#
Return type:

Generator[Dict[str, Any], Dict[str, Any], SamplingHeapProfile]

Returns:

Recorded sampling heap profile.

stop_tracking_heap_objects(report_progress=None, treat_global_objects_as_roots=None, capture_numeric_value=None, expose_internals=None)[source]#
Parameters:
  • report_progress (Optional[bool]) – (Optional) If true ‘reportHeapSnapshotProgress’ events will be generated while snapshot is being taken when the tracking is stopped.

  • treat_global_objects_as_roots (Optional[bool]) – (DEPRECATED) (Optional) Deprecated in favor of `exposeInternals`.

  • capture_numeric_value (Optional[bool]) – (Optional) If true, numerical values are included in the snapshot

  • expose_internals (Optional[bool]) – (EXPERIMENTAL) (Optional) If true, exposes internals of the snapshot.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

take_heap_snapshot(report_progress=None, treat_global_objects_as_roots=None, capture_numeric_value=None, expose_internals=None)[source]#
Parameters:
  • report_progress (Optional[bool]) – (Optional) If true ‘reportHeapSnapshotProgress’ events will be generated while snapshot is being taken.

  • treat_global_objects_as_roots (Optional[bool]) – (DEPRECATED) (Optional) If true, a raw snapshot without artificial roots will be generated. Deprecated in favor of `exposeInternals`.

  • capture_numeric_value (Optional[bool]) – (Optional) If true, numerical values are included in the snapshot

  • expose_internals (Optional[bool]) – (EXPERIMENTAL) (Optional) If true, exposes internals of the snapshot.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

Events#

Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.

class AddHeapSnapshotChunk(chunk)[source]#
chunk: str#
class HeapStatsUpdate(stats_update)[source]#

If heap objects tracking has been started then backend may send update for one or more fragments

stats_update: List[int]#

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.

class LastSeenObjectId(last_seen_object_id, timestamp)[source]#

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.

last_seen_object_id: int#
timestamp: float#
class ReportHeapSnapshotProgress(done, total, finished)[source]#
done: int#
total: int#
finished: Optional[bool]#
class ResetProfiles[source]#