---
title: AdvancedProfiler
description: >-
  This profiler uses Python’s cProfiler to record more detailed information
  about time spent in each function call

  recorded during a given action.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.profilers.AdvancedProfiler
---
# AdvancedProfiler {#advancedprofiler}

### `class lightning.pytorch.profilers.AdvancedProfiler(dirpath=None, filename=None, line_count_restriction=1.0, dump_stats=False)` {#lightning.pytorch.profilers.AdvancedProfiler}

Bases: [`Profiler`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.profilers.Profiler.md#lightning.pytorch.profilers.Profiler "lightning.pytorch.profilers.profiler.Profiler")

This profiler uses Python’s cProfiler to record more detailed information about time spent in each function call recorded during a given action.

The output is quite verbose and you should only use this if you want very detailed reports.

Parameters:

*   **dirpath** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Directory path for the `filename`. If `dirpath` is `None` but `filename` is present, the `trainer.log_dir` (from [`TensorBoardLogger`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.loggers.tensorboard.md#lightning.pytorch.loggers.tensorboard.TensorBoardLogger "lightning.pytorch.loggers.tensorboard.TensorBoardLogger")) will be used.
    
*   **filename** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]) – If present, filename where the profiler results will be saved instead of printing to stdout. The `.txt` extension will be used automatically.
    
*   **line\_count\_restriction** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – this can be used to limit the number of functions reported for each action. either an integer (to select a count of lines), or a decimal fraction between 0.0 and 1.0 inclusive (to select a percentage of lines)
    
*   **dump\_stats** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to save raw profiler results. When `True` then `dirpath` must be provided.
    

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If you attempt to stop recording an action which was never started.

#### `start(action_name)` {#lightning.pytorch.profilers.AdvancedProfiler.start}

Defines how to start recording an action.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `stop(action_name)` {#lightning.pytorch.profilers.AdvancedProfiler.stop}

Defines how to record the duration once an action is complete.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `teardown(stage)` {#lightning.pytorch.profilers.AdvancedProfiler.teardown}

Execute arbitrary post-profiling tear-down steps.

Closes the currently open file and stream.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
