Profiler.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package TeamSpeak3
  20. * @author Sven 'ScP' Paulsen
  21. * @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
  22. */
  23. /**
  24. * @class TeamSpeak3_Helper_Profiler
  25. * @brief Helper class for profiler handling.
  26. */
  27. class TeamSpeak3_Helper_Profiler
  28. {
  29. /**
  30. * Stores various timers for code profiling.
  31. *
  32. * @var array
  33. */
  34. protected static $timers = array();
  35. /**
  36. * Inits a timer.
  37. *
  38. * @param string $name
  39. * @return void
  40. */
  41. public static function init($name = "default")
  42. {
  43. self::$timers[$name] = new TeamSpeak3_Helper_Profiler_Timer($name);
  44. }
  45. /**
  46. * Starts a timer.
  47. *
  48. * @param string $name
  49. * @return void
  50. */
  51. public static function start($name = "default")
  52. {
  53. if(array_key_exists($name, self::$timers))
  54. {
  55. self::$timers[$name]->start();
  56. }
  57. else
  58. {
  59. self::$timers[$name] = new TeamSpeak3_Helper_Profiler_Timer($name);
  60. }
  61. }
  62. /**
  63. * Stops a timer.
  64. *
  65. * @param string $name
  66. * @return void
  67. */
  68. public static function stop($name = "default")
  69. {
  70. if(!array_key_exists($name, self::$timers))
  71. {
  72. self::init($name);
  73. }
  74. self::$timers[$name]->stop();
  75. }
  76. /**
  77. * Returns a timer.
  78. *
  79. * @param string $name
  80. * @return TeamSpeak3_Helper_Profiler_Timer
  81. */
  82. public static function get($name = "default")
  83. {
  84. if(!array_key_exists($name, self::$timers))
  85. {
  86. self::init($name);
  87. }
  88. return self::$timers[$name];
  89. }
  90. }