StopwatchPeriod.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * Constructor.
  23. *
  24. * @param int $start The relative time of the start of the period (in milliseconds)
  25. * @param int $end The relative time of the end of the period (in milliseconds)
  26. */
  27. public function __construct($start, $end)
  28. {
  29. $this->start = (int) $start;
  30. $this->end = (int) $end;
  31. $this->memory = memory_get_usage(true);
  32. }
  33. /**
  34. * Gets the relative time of the start of the period.
  35. *
  36. * @return int The time (in milliseconds)
  37. */
  38. public function getStartTime()
  39. {
  40. return $this->start;
  41. }
  42. /**
  43. * Gets the relative time of the end of the period.
  44. *
  45. * @return int The time (in milliseconds)
  46. */
  47. public function getEndTime()
  48. {
  49. return $this->end;
  50. }
  51. /**
  52. * Gets the time spent in this period.
  53. *
  54. * @return int The period duration (in milliseconds)
  55. */
  56. public function getDuration()
  57. {
  58. return $this->end - $this->start;
  59. }
  60. /**
  61. * Gets the memory usage.
  62. *
  63. * @return int The memory usage (in bytes)
  64. */
  65. public function getMemory()
  66. {
  67. return $this->memory;
  68. }
  69. }