Использование профилировщиков C++

Чтобы оптимизировать производительность Godot, нужно знать, что именно оптимизировать в первую очередь. Для этого полезны профилировщики.

Примечание

There is a built-in GDScript profiler in the editor, but using a C++ profiler may be useful in cases where the GDScript profiler is not accurate enough or is missing information due to bugs in the profiler.

There are two main types of profilers: sampling profilers and tracing profilers.

Sampling profilers periodically interrupt the running program and take a "sample", which records which functions are running. Using this information, the profiler estimates which functions the program spent the most time in.

Tracing profilers work by recording application-specific events (such as the start and end of a single frame), producing a log called a "trace". The profiler can use the trace to produce a graph showing an accurate high-level timeline of what happened. However, any code that is not explicitly instrumented will not appear in a tracing profiler's timeline!

Godot supports both sampling profilers and tracing profilers, and already includes the logging code for common Godot events for use with a tracing profiler!

Different problems may be easier to debug with one kind of profiler over the other, but it's difficult to provide a set of rules for which to use. Give both a try, and see what you can learn from them!

Sampling profilers

We recommend the following sampling profilers:

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

Настройка Godot

Для получения полезной информации о профилировании абсолютно необходимо использовать сборку Godot, включающую отладочные символы. Официальные исполняемые файлы не содержат отладочных символов, поскольку они значительно увеличат размер загружаемого файла.

Чтобы получить данные профилирования, которые наилучшим образом соответствуют производственной среде (но с отладочными символами), следует скомпилировать двоичные файлы с параметрами production=yes debug_symbols=yes SCons.

Можно запустить профилировщик на менее оптимизированных сборках (например, target=template_debug без LTO), но результаты, естественно, будут менее репрезентативны для реальных условий.

Предупреждение

Не удаляйте отладочную символику из двоичных файлов с помощью команды strip после их компиляции. В противном случае вы больше не получите полезной информации о профилировании при запуске профилировщика.

Сравнительный анализ времени запуска/выключения

If you're looking into optimizing Godot's startup/shutdown performance, you can tell the profiler to use the --quit command line option on the Godot binary. This will exit Godot just after it's done starting. The --quit option works with --editor, --project-manager, and --path <path to project directory> (which runs a project directly).

См. также

Дополнительные аргументы командной строки, поддерживаемые Godot, см. в Руководство по командной строке.

Tracing profilers

Godot currently supports three tracing profilers:

In order to use either of them, you'll need to build the engine from source. If you've never done this before, please read these docs for the platform you want to profile on. You'll need to perform the same steps here, but with some additional arguments for scons.