Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build troubleshooting for long builds #2447

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions content/docs/user-guide/build/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,89 @@ Call Stack (most recent call first):

* Change the value to remove the trailing `\`.
* Change the format of your `LY_3RDPARTY_PATH` to use the platform-agnostic `/` path separator.

## Long build times

**Issue:** Building takes longer than expected.

**Remedy:** There are several steps to troubleshooting builds that are taking a long time.
1. Use a build command that measures the amount of time taken so you can compare build times when troubleshooting. On Windows you can use the PowerShell `measure-command` to measure build times, and on linux `time`.
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved
{{< tabs name="CMake build timing example" >}}
{{% tab name="Windows" %}}

```cmd
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved
measure-command { cmake --build build/windows --target Editor AutomatedTesting.GameLauncher --config profile | Out-Default}
```

{{% /tab %}}
{{% tab name="Linux" %}}

```shell
time cmake --build build/linux --target Editor AutomatedTesting.GameLauncher --config profile
```

{{% /tab %}}
{{< /tabs >}}
1. Make sure you are only building the targets you are using. For example, select an appropriate target like the `Editor` for building and not the `ALL_BUILD` target which will build everything and take longer.
Keep in mind that your first build will take the longest because all the code for the selected target and dependencies must be compiled, but subsequent builds should be much faster (minutes or seconds) especially when writing game code.
1. Use the `profile` build configuration when developing when you don't need all the un-optimized debugging information of a `debug` build configuration.
1. Make sure you're using unity builds (on by default) by configuring with the option `-DLY_UNITY_BUILD=ON`.
1. Don't build unit tests if you aren't making engine changes by configuring with the option `-DLY_DISABLE_TEST_MODULES=ON`.
1. Deactivate Gems your project is not using using the [o3de CLI or Project Manager](/docs/user-guide/project-config/add-remove-gems/).
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved
1. See the [troubleshooting step for configuring compiler-specific settings](#building-causes-computer-to-freeze-or-lock-up) below which may be necessary on hardware with high CPU core counts.
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved

## Building causes computer to freeze, lock up or reboot

**Issue:** On some computers, especially those with CPUs that have high core counts, the way compilation is spread across cores can lead to resource starvation and even freezing. It's also possible that a build could run out of memory and cause issues including resource starvation and reboot.
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved

**Remedy:** Adjust the build settings to spread out the maximum number of parallel processes used and the maximum CL processor counts allowed per project if possible.
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved

{{< tabs name="Platform Specific Settings" >}}
{{% tab name="Windows" %}}

For Visual Studio on Windows, the command might look like this to set the maximum cpu count to 16 and limit to 32 CL processor counts per project.
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved
```cmd
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved
cmake --build build/windows --target Editor --config profile -- /m:16 /p:CL_MPCount=32
```
If building or debugging in the Visual Studio IDE set the maximum number of parallel project builds in the Tools -> Options -> Projects and Solutions -> Build And Run option page:

![Visual Studio Maximum Number of Parallel Build Options](/images/user-guide/build/visual-studio-options-build-and-run.jpg)

Set the Maximum Concurrent C++ Compilations in the Tools -> Options -> Projects and Solutions -> VC++ Project Settings option page:

![Visual Studio Maximum Concurrent C++ Compilations](/images/user-guide/build/visual-studio-options-vc++-project-settings.jpg)

Experiment with different values to find the best settings for your hardware.
On Windows you can measure your compile times in a PowerShell terminal with different settings with a command like this:

```cmd
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved
measure-command { cmake --build build/windows --target Editor --config profile -- /m:8 /p:CL_MPCount=8 | Out-Default}
```
Example output:
```cmd
Days : 0
Hours : 0
Minutes : 15
Seconds : 56
Milliseconds : 701
Ticks : 9567014354
TotalDays : 0.0110729332800926
TotalHours : 0.265750398722222
TotalMinutes : 15.9450239233333
TotalSeconds : 956.7014354
TotalMilliseconds : 956701.4354
```

{{% /tab %}}
{{% tab name="Linux" %}}

Use the [`-j/--parallel` cmake option](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-build-j) to reduce the number of parallel jobs used when building.
AMZN-alexpete marked this conversation as resolved.
Show resolved Hide resolved

For example, on a 12-core 32-GiB machine, you may want to reduce the number of parallel build jobs to 6 if compile processes are being killed.

```bash
cmake --build <build-dir> -j 6 --config profile --target MyProject.GameLauncher -- <generator specific options>
```

{{% /tab %}}
{{< /tabs >}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.