StopwatchPeriod.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Stopwatch;
  11. /**
  12. * Represents an Period for an Event.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class StopwatchPeriod
  17. {
  18. private $start;
  19. private $end;
  20. private $memory;
  21. /**
  22. * @param int $start The relative time of the start of the period (in milliseconds)
  23. * @param int $end The relative time of the end of the period (in milliseconds)
  24. */
  25. public function __construct($start, $end)
  26. {
  27. $this->start = (int) $start;
  28. $this->end = (int) $end;
  29. $this->memory = memory_get_usage(true);
  30. }
  31. /**
  32. * Gets the relative time of the start of the period.
  33. *
  34. * @return int The time (in milliseconds)
  35. */
  36. public function getStartTime()
  37. {
  38. return $this->start;
  39. }
  40. /**
  41. * Gets the relative time of the end of the period.
  42. *
  43. * @return int The time (in milliseconds)
  44. */
  45. public function getEndTime()
  46. {
  47. return $this->end;
  48. }
  49. /**
  50. * Gets the time spent in this period.
  51. *
  52. * @return int The period duration (in milliseconds)
  53. */
  54. public function getDuration()
  55. {
  56. return $this->end - $this->start;
  57. }
  58. /**
  59. * Gets the memory usage.
  60. *
  61. * @return int The memory usage (in bytes)
  62. */
  63. public function getMemory()
  64. {
  65. return $this->memory;
  66. }
  67. }