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