ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBenchmark.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
14 
18  function ilBenchmark()
19  {
20  }
21 
22 
26  function microtimeDiff($t1, $t2)
27  {
28  $t1 = explode(" ",$t1);
29  $t2 = explode(" ",$t2);
30  $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
31 
32  return $diff;
33  }
34 
35 
36 
40  function clearData()
41  {
42  global $ilDB;
43 
44  $q = "DELETE FROM benchmark";
45  $ilDB->manipulate($q);
46  }
47 
48 
56  function start($a_module, $a_bench)
57  {
58 return;
59  if ($this->isEnabled())
60  {
61  $this->bench[$a_module.":".$a_bench][] = microtime();
62  }
63  }
64 
65 
71  function stop($a_module, $a_bench)
72  {
73 return;
74  if ($this->isEnabled())
75  {
76  $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1]
77  = $this->microtimeDiff($this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1], microtime());
78  }
79  }
80 
81 
85  function save()
86  {
87  global $ilDB;
88 return;
89  if ($this->isEnabled() &&
90  ($this->getMaximumRecords() > $this->getCurrentRecordNumber()))
91  {
92  foreach($this->bench as $key => $bench)
93  {
94  $bench_arr = explode(":", $key);
95  $bench_module = $bench_arr[0];
96  $benchmark = $bench_arr[1];
97  foreach($bench as $time)
98  {
99  $q = "INSERT INTO benchmark (cdate, duration, module, benchmark) VALUES ".
100  "(".
101  $ilDB->now().", ".
102  $ilDB->quote($time, "float").", ".
103  $ilDB->quote($bench_module, "text").", ".
104  $ilDB->quote($benchmark, "text").")";
105  $ilDB->manipulate($q);
106  }
107  }
108  $this->bench = array();
109  }
110  }
111 
112 
113  /*
114  SELECT module, benchmark, COUNT(*) AS cnt, AVG(duration) AS avg_dur FROM benchmark
115  GROUP BY module, benchmark ORDER BY module, benchmark
116  */
117 
121  function getEvaluation($a_module)
122  {
123  global $ilDB;
124 
125  $q = "SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark,".
126  " MIN(duration) AS min_dur, MAX(duration) AS max_dur".
127  " FROM benchmark".
128  " WHERE module = ".$ilDB->quote($a_module, "text")." ".
129  " GROUP BY benchmark".
130  " ORDER BY benchmark";
131  $bench_set = $ilDB->query($q);
132  $eva = array();
133  while($bench_rec = $ilDB->fetchAssoc($bench_set))
134  {
135  $eva[] = array("benchmark" => $bench_rec["benchmark"],
136  "cnt" => $bench_rec["cnt"], "duration" => $bench_rec["avg_dur"],
137  "min" => $bench_rec["min_dur"], "max" => $bench_rec["max_dur"]);
138  }
139  return $eva;
140  }
141 
142 
147  {
148  global $ilDB;
149 
150  $q = "SELECT COUNT(*) AS cnt FROM benchmark";
151  $cnt_set = $ilDB->query($q);
152  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
153 
154  return $cnt_rec["cnt"];
155  }
156 
157 
161  function getMaximumRecords()
162  {
163  global $ilias;
164 
165  return $ilias->getSetting("bench_max_records");
166  }
167 
168 
172  function setMaximumRecords($a_max)
173  {
174  global $ilias;
175 
176  $ilias->setSetting("bench_max_records", (int) $a_max);
177  }
178 
179 
183  function isEnabled()
184  {
185  global $ilSetting;
186 
187  if (!is_object($ilSetting))
188  {
189  return true;
190  }
191 
192  return (boolean) $ilSetting->get("enable_bench");
193  }
194 
195 
199  function enable($a_enable)
200  {
201  global $ilias;
202 
203  if ($a_enable)
204  {
205  $ilias->setSetting("enable_bench", 1);
206  }
207  else
208  {
209  $ilias->setSetting("enable_bench", 0);
210  }
211  }
212 
213 
218  {
219  global $ilDB;
220 
221  $q = "SELECT DISTINCT module FROM benchmark";
222  $mod_set = $ilDB->query($q);
223 
224  $modules = array();
225  while ($mod_rec = $ilDB->fetchAssoc($mod_set))
226  {
227  $modules[$mod_rec["module"]] = $mod_rec["module"];
228  }
229 
230  return $modules;
231  }
232 
233  // BEGIN WebDAV: Get measured time.
239  function getMeasuredTime($a_module, $a_bench)
240  {
241  return $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1];
242  }
243  // END WebDAV: Get measured time.
244 
245 }
246 
247 ?>