> **Источник:** https://python-all.ru/3.16/library/debug.html
>
> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.

---

# Отладка и профилирование

Эти библиотеки помогают в разработке на Python: отладчик позволяет пошагово выполнять код, анализировать стековые кадры и устанавливать точки останова и т.д., а профилировщики запускают код и предоставляют детальную разбивку времени выполнения, что позволяет выявить узкие места в программах. События аудита обеспечивают прозрачность поведения во время выполнения, которое в противном случае потребовало бы интрузивной отладки или внесения исправлений.

- [Таблица событий аудита](https://python-all.ru/3.16/library/audit_events.html)
- [`bdb` – фреймворк отладчика](https://python-all.ru/3.16/library/bdb.html)
- [`faulthandler` – дамп трассировки Python](https://python-all.ru/3.16/library/faulthandler.html)

  - [Дамп трассировки](https://python-all.ru/3.16/library/faulthandler.html#dumping-the-traceback)
  - [Дамп стека C](https://python-all.ru/3.16/library/faulthandler.html#dumping-the-c-stack)

    - [Совместимость стека C](https://python-all.ru/3.16/library/faulthandler.html#c-stack-compatibility)
  - [Состояние обработчика сбоев](https://python-all.ru/3.16/library/faulthandler.html#fault-handler-state)
  - [Дамп трассировок по тайм-ауту](https://python-all.ru/3.16/library/faulthandler.html#dumping-the-tracebacks-after-a-timeout)
  - [Дамп трассировки по сигналу пользователя](https://python-all.ru/3.16/library/faulthandler.html#dumping-the-traceback-on-a-user-signal)
  - [Проблема с файловыми дескрипторами](https://python-all.ru/3.16/library/faulthandler.html#issue-with-file-descriptors)
  - [Пример](https://python-all.ru/3.16/library/faulthandler.html#example)
- [`pdb` – отладчик Python](https://python-all.ru/3.16/library/pdb.html)

  - [Интерфейс командной строки](https://python-all.ru/3.16/library/pdb.html#command-line-interface)
  - [Команды отладчика](https://python-all.ru/3.16/library/pdb.html#debugger-commands)
- [`profiling` – профилировщики Python](https://python-all.ru/3.16/library/profiling.html)

  - [Введение в профилирование](https://python-all.ru/3.16/library/profiling.html#introduction-to-profiling)
  - [Выбор профилировщика](https://python-all.ru/3.16/library/profiling.html#choosing-a-profiler)

    - [Когда использовать статистическую выборку](https://python-all.ru/3.16/library/profiling.html#when-to-use-statistical-sampling)
    - [Когда использовать детерминированную трассировку](https://python-all.ru/3.16/library/profiling.html#when-to-use-deterministic-tracing)
  - [Быстрый старт](https://python-all.ru/3.16/library/profiling.html#quick-start)

    - [Статистическое профилирование](https://python-all.ru/3.16/library/profiling.html#statistical-profiling)
    - [Детерминированное профилирование](https://python-all.ru/3.16/library/profiling.html#deterministic-profiling)
  - [Понимание вывода профилировщика](https://python-all.ru/3.16/library/profiling.html#understanding-profile-output)
  - [Совместимость с устаревшим кодом](https://python-all.ru/3.16/library/profiling.html#legacy-compatibility)

    - [`profiling.tracing` – детерминированный профилировщик](https://python-all.ru/3.16/library/profiling.tracing.html)

      - [Что такое детерминированное профилирование?](https://python-all.ru/3.16/library/profiling.tracing.html#what-is-deterministic-profiling)
      - [Интерфейс командной строки](https://python-all.ru/3.16/library/profiling.tracing.html#command-line-interface)
      - [Примеры программного использования](https://python-all.ru/3.16/library/profiling.tracing.html#programmatic-usage-examples)

        - [Базовое профилирование](https://python-all.ru/3.16/library/profiling.tracing.html#basic-profiling)
        - [Использование класса `Profile`](https://python-all.ru/3.16/library/profiling.tracing.html#using-the-profile-class)
      - [Справочник модуля](https://python-all.ru/3.16/library/profiling.tracing.html#module-reference)
      - [Использование пользовательского таймера](https://python-all.ru/3.16/library/profiling.tracing.html#using-a-custom-timer)
      - [Ограничения](https://python-all.ru/3.16/library/profiling.tracing.html#limitations)
    - [`profiling.sampling` – Статистический профилировщик](https://python-all.ru/3.16/library/profiling.sampling.html)

      - [Что такое статистическое профилирование?](https://python-all.ru/3.16/library/profiling.sampling.html#what-is-statistical-profiling)

        - [Как оценивается время](https://python-all.ru/3.16/library/profiling.sampling.html#how-time-is-estimated)
        - [Когда использовать другой подход](https://python-all.ru/3.16/library/profiling.sampling.html#when-to-use-a-different-approach)
      - [Краткие примеры](https://python-all.ru/3.16/library/profiling.sampling.html#quick-examples)
      - [Команды](https://python-all.ru/3.16/library/profiling.sampling.html#commands)

        - [Команда `run`](https://python-all.ru/3.16/library/profiling.sampling.html#the-run-command)
        - [Команда `attach`](https://python-all.ru/3.16/library/profiling.sampling.html#the-attach-command)
        - [Команда `dump`](https://python-all.ru/3.16/library/profiling.sampling.html#the-dump-command)
        - [Команда `replay`](https://python-all.ru/3.16/library/profiling.sampling.html#the-replay-command)
        - [Профилирование в продакшене](https://python-all.ru/3.16/library/profiling.sampling.html#profiling-in-production)
        - [Требования к платформе](https://python-all.ru/3.16/library/profiling.sampling.html#platform-requirements)
        - [Совместимость версий](https://python-all.ru/3.16/library/profiling.sampling.html#version-compatibility)
      - [Настройка сэмплирования](https://python-all.ru/3.16/library/profiling.sampling.html#sampling-configuration)

        - [Частота и длительность сэмплирования](https://python-all.ru/3.16/library/profiling.sampling.html#sampling-rate-and-duration)
        - [Выбор потоков](https://python-all.ru/3.16/library/profiling.sampling.html#thread-selection)
        - [Режим блокировки](https://python-all.ru/3.16/library/profiling.sampling.html#blocking-mode)
        - [Специальные кадры](https://python-all.ru/3.16/library/profiling.sampling.html#special-frames)
        - [Профилирование с учётом опкодов](https://python-all.ru/3.16/library/profiling.sampling.html#opcode-aware-profiling)
        - [Статистика в реальном времени](https://python-all.ru/3.16/library/profiling.sampling.html#real-time-statistics)
        - [Профилирование подпроцессов](https://python-all.ru/3.16/library/profiling.sampling.html#subprocess-profiling)
        - [Эффективность сэмплирования](https://python-all.ru/3.16/library/profiling.sampling.html#sampling-efficiency)
      - [Режимы профилирования](https://python-all.ru/3.16/library/profiling.sampling.html#profiling-modes)

        - [Режим реального времени](https://python-all.ru/3.16/library/profiling.sampling.html#wall-clock-mode)
        - [Режим ЦП](https://python-all.ru/3.16/library/profiling.sampling.html#cpu-mode)
        - [Сравнение профилей реального времени и ЦП](https://python-all.ru/3.16/library/profiling.sampling.html#comparing-wall-clock-and-cpu-profiles)
        - [Режим GIL](https://python-all.ru/3.16/library/profiling.sampling.html#gil-mode)
        - [Режим исключений](https://python-all.ru/3.16/library/profiling.sampling.html#exception-mode)
      - [Форматы вывода](https://python-all.ru/3.16/library/profiling.sampling.html#output-formats)

        - [Формат pstats](https://python-all.ru/3.16/library/profiling.sampling.html#pstats-format)
        - [Формат свёрнутых стеков](https://python-all.ru/3.16/library/profiling.sampling.html#collapsed-stacks-format)
        - [Формат флейм-графа](https://python-all.ru/3.16/library/profiling.sampling.html#flame-graph-format)

          - [Дифференциальные флейм-графы](https://python-all.ru/3.16/library/profiling.sampling.html#differential-flame-graphs)
        - [Формат Gecko](https://python-all.ru/3.16/library/profiling.sampling.html#gecko-format)
        - [Формат тепловой карты](https://python-all.ru/3.16/library/profiling.sampling.html#heatmap-format)
        - [Двоичный формат](https://python-all.ru/3.16/library/profiling.sampling.html#binary-format)
      - [Рабочий процесс записи и воспроизведения](https://python-all.ru/3.16/library/profiling.sampling.html#record-and-replay-workflow)
      - [Режим реального времени](https://python-all.ru/3.16/library/profiling.sampling.html#live-mode)

        - [Команды клавиатуры](https://python-all.ru/3.16/library/profiling.sampling.html#keyboard-commands)
      - [Профилирование с учётом асинхронности](https://python-all.ru/3.16/library/profiling.sampling.html#async-aware-profiling)

        - [Асинхронные режимы](https://python-all.ru/3.16/library/profiling.sampling.html#async-modes)
        - [Маркеры задач и восстановление стеков](https://python-all.ru/3.16/library/profiling.sampling.html#task-markers-and-stack-reconstruction)
        - [Ограничения параметров](https://python-all.ru/3.16/library/profiling.sampling.html#option-restrictions)
      - [Интерфейс командной строки](https://python-all.ru/3.16/library/profiling.sampling.html#command-line-interface)

        - [Глобальные параметры](https://python-all.ru/3.16/library/profiling.sampling.html#global-options)
        - [Параметры дампа](https://python-all.ru/3.16/library/profiling.sampling.html#dump-options)
        - [Параметры сэмплирования](https://python-all.ru/3.16/library/profiling.sampling.html#sampling-options)
        - [Параметры режима](https://python-all.ru/3.16/library/profiling.sampling.html#mode-options)
        - [Параметры вывода](https://python-all.ru/3.16/library/profiling.sampling.html#output-options)
        - [Параметры отображения pstats](https://python-all.ru/3.16/library/profiling.sampling.html#pstats-display-options)
        - [Параметры команды запуска](https://python-all.ru/3.16/library/profiling.sampling.html#run-command-options)
- [`pstats` – Статистика для профилировщиков](https://python-all.ru/3.16/library/pstats.html)

  - [Чтение и отображение данных профилирования](https://python-all.ru/3.16/library/pstats.html#reading-and-displaying-profile-data)

    - [Работа со статистикой](https://python-all.ru/3.16/library/pstats.html#working-with-statistics)
    - [Фильтрация вывода](https://python-all.ru/3.16/library/pstats.html#filtering-output)
    - [Анализ взаимосвязей вызовов](https://python-all.ru/3.16/library/pstats.html#analyzing-call-relationships)
    - [Объединение нескольких профилей](https://python-all.ru/3.16/library/pstats.html#combining-multiple-profiles)
  - [Класс `Stats`](https://python-all.ru/3.16/library/pstats.html#the-stats-class)
  - [Интерфейс командной строки](https://python-all.ru/3.16/library/pstats.html#command-line-interface)
- [`timeit` – Измерение времени выполнения небольших фрагментов кода](https://python-all.ru/3.16/library/timeit.html)

  - [Базовые примеры](https://python-all.ru/3.16/library/timeit.html#basic-examples)
  - [Интерфейс Python](https://python-all.ru/3.16/library/timeit.html#python-interface)
  - [Интерфейс командной строки](https://python-all.ru/3.16/library/timeit.html#command-line-interface)
  - [Примеры](https://python-all.ru/3.16/library/timeit.html#examples)
- [`trace` – Трассировка или отслеживание выполнения операторов Python](https://python-all.ru/3.16/library/trace.html)

  - [Использование командной строки](https://python-all.ru/3.16/library/trace.html#command-line-usage)

    - [Основные параметры](https://python-all.ru/3.16/library/trace.html#main-options)
    - [Модификаторы](https://python-all.ru/3.16/library/trace.html#modifiers)
    - [Фильтры](https://python-all.ru/3.16/library/trace.html#filters)
  - [Программный интерфейс](https://python-all.ru/3.16/library/trace.html#programmatic-interface)
- [`tracemalloc` – Трассировка выделений памяти](https://python-all.ru/3.16/library/tracemalloc.html)

  - [Примеры](https://python-all.ru/3.16/library/tracemalloc.html#examples)

    - [Отображение первых 10](https://python-all.ru/3.16/library/tracemalloc.html#display-the-top-10)
    - [Вычисление различий](https://python-all.ru/3.16/library/tracemalloc.html#compute-differences)
    - [Получение трассировки для блока памяти](https://python-all.ru/3.16/library/tracemalloc.html#get-the-traceback-of-a-memory-block)
    - [Удобный вывод топа](https://python-all.ru/3.16/library/tracemalloc.html#pretty-top)

      - [Запись текущего и пикового размера всех отслеживаемых блоков памяти](https://python-all.ru/3.16/library/tracemalloc.html#record-the-current-and-peak-size-of-all-traced-memory-blocks)
  - [API](https://python-all.ru/3.16/library/tracemalloc.html#api)

    - [Функции](https://python-all.ru/3.16/library/tracemalloc.html#functions)
    - [DomainFilter](https://python-all.ru/3.16/library/tracemalloc.html#domainfilter)
    - [Filter](https://python-all.ru/3.16/library/tracemalloc.html#filter)
    - [Frame](https://python-all.ru/3.16/library/tracemalloc.html#frame)
    - [Snapshot](https://python-all.ru/3.16/library/tracemalloc.html#snapshot)
    - [Statistic](https://python-all.ru/3.16/library/tracemalloc.html#statistic)
    - [StatisticDiff](https://python-all.ru/3.16/library/tracemalloc.html#statisticdiff)
    - [Trace](https://python-all.ru/3.16/library/tracemalloc.html#trace)
    - [Traceback](https://python-all.ru/3.16/library/tracemalloc.html#traceback)
