Profiler.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Bootstrap of the application profiler
  8. */
  9. namespace Magento\TestFramework\Bootstrap;
  10. class Profiler
  11. {
  12. /**
  13. * Profiler driver instance
  14. *
  15. * @var \Magento\Framework\Profiler\Driver\Standard
  16. */
  17. protected $_driver;
  18. /**
  19. * Whether a profiler driver has been already registered or not
  20. *
  21. * @var bool
  22. */
  23. protected $_isDriverRegistered = false;
  24. /**
  25. * Constructor
  26. *
  27. * @param \Magento\Framework\Profiler\Driver\Standard $driver
  28. */
  29. public function __construct(\Magento\Framework\Profiler\Driver\Standard $driver)
  30. {
  31. $this->_driver = $driver;
  32. }
  33. /**
  34. * Register profiler driver to involve it into the results processing
  35. */
  36. protected function _registerDriver()
  37. {
  38. if (!$this->_isDriverRegistered) {
  39. $this->_isDriverRegistered = true;
  40. \Magento\Framework\Profiler::add($this->_driver);
  41. }
  42. }
  43. /**
  44. * Register file-based profiling
  45. *
  46. * @param string $profilerOutputFile
  47. */
  48. public function registerFileProfiler($profilerOutputFile)
  49. {
  50. $this->_registerDriver();
  51. $this->_driver->registerOutput(
  52. new \Magento\Framework\Profiler\Driver\Standard\Output\Csvfile(['filePath' => $profilerOutputFile])
  53. );
  54. }
  55. /**
  56. * Register profiler with Bamboo-friendly output format
  57. *
  58. * @param string $profilerOutputFile
  59. * @param string $profilerMetricsFile
  60. */
  61. public function registerBambooProfiler($profilerOutputFile, $profilerMetricsFile)
  62. {
  63. $this->_registerDriver();
  64. $this->_driver->registerOutput(
  65. new \Magento\TestFramework\Profiler\OutputBamboo(
  66. ['filePath' => $profilerOutputFile, 'metrics' => require $profilerMetricsFile]
  67. )
  68. );
  69. }
  70. }