benchmark_runner_periodic_suite_common.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import logging
  7. import os
  8. import subprocess
  9. import psutil
  10. import ly_test_tools.environment.process_utils as process_utils
  11. import ly_test_tools.environment.file_system as file_system
  12. import ly_test_tools.launchers.platforms.base
  13. from ly_test_tools.benchmark.data_aggregator import BenchmarkDataAggregator
  14. logger = logging.getLogger(__name__)
  15. def filebeat_service_running():
  16. """
  17. Checks if the filebeat service is currently running on the OS.
  18. :return: True if filebeat service detected and running, False otherwise.
  19. """
  20. result = False
  21. try:
  22. filebeat_service = psutil.win_service_get('filebeat')
  23. filebeat_service_info = filebeat_service.as_dict()
  24. if filebeat_service_info['status'] == 'running':
  25. result = True
  26. except psutil.NoSuchProcess:
  27. return result
  28. return result
  29. class LoftSampleException(Exception):
  30. """Custom Exception class for LoftSample tests."""
  31. pass
  32. def LoftSampleFrameTimingTest_GatherBenchmarkMetrics_Common(
  33. self, request, workspace, rhi, loftsample_gamelauncher_log_monitor):
  34. benchmark_name = f'LoftSample_{rhi}'
  35. cmd = os.path.join(workspace.paths.build_directory(),
  36. 'LoftSample.GameLauncher.exe '
  37. f'--project-path={workspace.paths.project()} '
  38. f'--rhi {rhi} '
  39. '--regset="/O3DE/Performance/FrameTimeRecording/Activate=true" '
  40. '--regset="/O3DE/Performance/FrameTimeRecording/QuitOnComplete=false" '
  41. f'--regset="/O3DE/Performance/FrameTimeRecording/ProfileName={benchmark_name}" '
  42. '+loadlevel levels/archvis/loft/interior_03.spawnable')
  43. def teardown():
  44. process_utils.kill_processes_named(['AssetProcessor', 'LoftSample.GameLauncher'], ignore_extensions=True)
  45. request.addfinalizer(teardown)
  46. # delete any pre-existing data
  47. benchmark_data_folder = [os.path.join(
  48. workspace.paths.project(), "user", "Scripts", "PerformanceBenchmarks", benchmark_name)]
  49. file_system.delete(benchmark_data_folder, True, True)
  50. # Execute test.
  51. launcherPid = subprocess.Popen(cmd, stderr=subprocess.STDOUT, encoding='UTF-8', shell=True).pid
  52. try:
  53. expected_lines = ["(Script) - OutputProfileData complete"]
  54. loftsample_gamelauncher_log_monitor.monitor_log_for_lines(expected_lines, timeout=180)
  55. except ly_test_tools.log.log_monitor.LogMonitorException as e:
  56. raise LoftSampleException(f'Data capturing did not complete in time for RHI {rhi}, got error: {e}')
  57. def LoftSampleFrameTimingTest_SendBenchmarkMetrics_Common(
  58. workspace, launcher_platform, rhi):
  59. """
  60. Gathers the benchmark metrics and uses filebeat to send the metrics data.
  61. """
  62. aggregator = BenchmarkDataAggregator(workspace, logger, 'periodic')
  63. aggregator.upload_metrics(f'{launcher_platform}_{rhi}')