Profiler.php 2.2 KB

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