frametime.sa.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. -- optional settings
  12. local AssetLoadFrameIdleCountRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/AssetFrameIdleCount"
  13. local FrameIdleCountRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/IdleCount"
  14. local FrameCaptureCountRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/CaptureCount"
  15. local ViewportWidthRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/ViewportWidth"
  16. local ViewportHeightRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/ViewportHeight"
  17. -- required settings
  18. local ProfileNameRegistryKey <const> = "/O3DE/ScriptAutomation/FrameTime/ProfileName"
  19. -- default values
  20. DEFAULT_ASSET_LOAD_FRAME_WAIT_COUNT = 100
  21. DEFAULT_IDLE_COUNT = 100
  22. DEFAULT_FRAME_COUNT = 100
  23. DEFAULT_VIEWPORT_WIDTH = 800
  24. DEFAULT_VIEWPORT_HEIGHT = 600
  25. -- check for SettingsRegistry values that must exist
  26. profileNameSR = g_SettingsRegistry:GetString(ProfileNameRegistryKey)
  27. if (not profileNameSR:has_value()) then
  28. Print('FrameTime script missing profileName settings registry entry, aborting')
  29. return;
  30. end
  31. profileName = profileNameSR:value()
  32. -- get the output folder path
  33. g_profileOutputFolder = GetProfilingOutputPath(true) .. "/" .. tostring(profileName)
  34. Print('Saving screenshots to ' .. NormalizePath(g_profileOutputFolder))
  35. -- read optional SettingsRegistry values
  36. local assetLoadIdleFrameCount = g_SettingsRegistry:GetUInt(AssetLoadFrameIdleCountRegistryKey):value_or(DEFAULT_ASSET_LOAD_FRAME_WAIT_COUNT)
  37. local frameIdleCount = g_SettingsRegistry:GetUInt(FrameIdleCountRegistryKey):value_or(DEFAULT_IDLE_COUNT)
  38. local frameCaptureCount = g_SettingsRegistry:GetUInt(FrameCaptureCountRegistryKey):value_or(DEFAULT_FRAME_COUNT)
  39. local viewportWidth = g_SettingsRegistry:GetUInt(ViewportWidthRegistryKey):value_or(DEFAULT_VIEWPORT_WIDTH)
  40. local viewportHeight = g_SettingsRegistry:GetUInt(ViewportHeightRegistryKey):value_or(DEFAULT_VIEWPORT_HEIGHT)
  41. -- Begin script execution
  42. ResizeViewport(viewportWidth, viewportHeight)
  43. ExecuteConsoleCommand("r_displayInfo=0")
  44. IdleFrames(assetLoadIdleFrameCount) -- wait for assets to load into the level
  45. CaptureBenchmarkMetadata(tostring(profileName), g_profileOutputFolder .. '/benchmark_metadata.json')
  46. Print('Idling for ' .. tostring(frameIdleCount) .. ' frames..')
  47. IdleFrames(frameIdleCount)
  48. Print('Capturing timestamps for ' .. tostring(frameCaptureCount) .. ' frames...')
  49. for i = 1,frameCaptureCount do
  50. cpu_timings = g_profileOutputFolder .. '/cpu_frame' .. tostring(i) .. '_time.json'
  51. CaptureCpuFrameTime(cpu_timings)
  52. end
  53. Print('Capturing complete.')