frametime.sa.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ----------------------------------------------------------------------------------------------------
  2. --
  3. -- Copyright (c) Contributors to the Open 3D Engine Project.
  4. -- For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. --
  6. -- SPDX-License-Identifier: Apache-2.0 OR MIT
  7. --
  8. --
  9. --
  10. ----------------------------------------------------------------------------------------------------
  11. -- values provided by the runtime
  12. local ProjectUserPath <const> = "/O3DE/Runtime/FilePaths/SourceProjectUserPath"
  13. -- optional settings
  14. local AssetLoadFrameIdleCountRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/AssetFrameIdleCount"
  15. local FrameIdleCountRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/IdleCount"
  16. local FrameCaptureCountRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/CaptureCount"
  17. local ViewportWidthRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/ViewportWidth"
  18. local ViewportHeightRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/ViewportHeight"
  19. local ProfileOutputPathKey <const> = "/O3DE/ScriptAutomation/FrameTime/OutputPath"
  20. -- required settings
  21. local ProfileNameRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/ProfileName"
  22. IdleFrames(100) -- wait for assets to load into the level
  23. function GetRequiredStringValue(valueKey, prettyName)
  24. value = g_SettingsRegistry:GetString(valueKey)
  25. if (not value:has_value()) then
  26. Print('FrameTime script missing ' .. tostring(prettyName) .. ' settings registry entry, ending script early')
  27. return false, nil
  28. end
  29. return true, value:value()
  30. end
  31. function GetOptionalUIntValue(valueKey, defaultValue)
  32. return g_SettingsRegistry:GetUInt(valueKey):value_or(defaultValue)
  33. end
  34. function GetOptionalStringValue(valueKey, defaultValue)
  35. return g_SettingsRegistry:GetString(valueKey):value_or(defaultValue)
  36. end
  37. -- default values
  38. DEFAULT_ASSET_LOAD_FRAME_WAIT_COUNT = 100
  39. DEFAULT_IDLE_COUNT = 100
  40. DEFAULT_FRAME_COUNT = 100
  41. DEFAULT_VIEWPORT_WIDTH = 800
  42. DEFAULT_VIEWPORT_HEIGHT = 600
  43. DEFAULT_OUTPUT_PATH = "ScriptAutomation/Profiling"
  44. -- check for SettingsRegistry values that must exist
  45. succeeded, userFolderPath = GetRequiredStringValue(ProjectUserPath, "Project User Path")
  46. if (not succeeded) then return end
  47. succeeded, profileName = GetRequiredStringValue(ProfileNameRegistryKey, "Profile Name")
  48. if (not succeeded) then return end
  49. -- read optional SettingsRegistry values
  50. local assetLoadIdleFrameCount = GetOptionalUIntValue(AssetLoadFrameIdleCountRegistryKey, DEFAULT_ASSET_LOAD_FRAME_WAIT_COUNT)
  51. local frameIdleCount = GetOptionalUIntValue(FrameIdleCountRegistryKey, DEFAULT_IDLE_COUNT)
  52. local frameCaptureCount = GetOptionalUIntValue(FrameCaptureCountRegistryKey, DEFAULT_FRAME_COUNT)
  53. local viewportWidth = GetOptionalUIntValue(ViewportWidthRegistryKey, DEFAULT_VIEWPORT_WIDTH)
  54. local viewportHeight = GetOptionalUIntValue(ViewportHeightRegistryKey, DEFAULT_VIEWPORT_HEIGHT)
  55. local outputPath = GetOptionalStringValue(ProfileOutputPathKey, DEFAULT_OUTPUT_PATH)
  56. -- get the output folder path
  57. g_profileOutputFolder = userFolderPath .. "/" .. tostring(outputPath) .. "/" .. tostring(profileName)
  58. Print('Saving profile data to ' .. NormalizePath(g_profileOutputFolder))
  59. -- Begin script execution
  60. ResizeViewport(viewportWidth, viewportHeight)
  61. ExecuteConsoleCommand("r_displayInfo=0")
  62. CaptureBenchmarkMetadata(tostring(profileName), g_profileOutputFolder .. '/benchmark_metadata.json')
  63. Print('Idling for ' .. tostring(frameIdleCount) .. ' frames..')
  64. IdleFrames(frameIdleCount)
  65. Print('Capturing timestamps for ' .. tostring(frameCaptureCount) .. ' frames...')
  66. for i = 1,frameCaptureCount do
  67. cpu_timings = g_profileOutputFolder .. '/cpu_frame' .. tostring(i) .. '_time.json'
  68. CaptureCpuFrameTime(cpu_timings)
  69. end
  70. Print('Capturing complete.')