ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilBenchmark Class Reference

performance measurement class More...

+ Collaboration diagram for ilBenchmark:

Public Member Functions

 ilBenchmark ()
 constructor More...
 
 microtimeDiff ($t1, $t2)
 
 clearData ()
 delete all measurement data More...
 
 start ($a_module, $a_bench)
 start measurement More...
 
 stop ($a_module, $a_bench)
 stop measurement More...
 
 save ()
 save all measurements More...
 
 getEvaluation ($a_module)
 get performance evaluation data More...
 
 getCurrentRecordNumber ()
 get current number of benchmark records More...
 
 getMaximumRecords ()
 get maximum number of benchmark records More...
 
 setMaximumRecords ($a_max)
 set maximum number of benchmark records More...
 
 isEnabled ()
 check wether benchmarking is enabled or not More...
 
 enable ($a_enable)
 enable benchmarking More...
 
 getMeasuredModules ()
 get all current measured modules More...
 
 getMeasuredTime ($a_module, $a_bench)
 Get measurement. More...
 
 isDbBenchEnabled ()
 Check wether benchmarking is enabled or not. More...
 
 enableDbBench ($a_enable, $a_user=0)
 Enable DB benchmarking. More...
 
 startDbBench ($a_sql)
 start measurement More...
 
 stopDbBench ()
 stop measurement More...
 
 getDbBenchRecords ()
 Get db benchmark records. More...
 

Data Fields

 $bench = array()
 

Detailed Description

performance measurement class

Author: Alex Killing Alex..nosp@m.Kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e

Version
$Id$

Definition at line 12 of file class.ilBenchmark.php.

Member Function Documentation

◆ clearData()

ilBenchmark::clearData ( )

delete all measurement data

Definition at line 41 of file class.ilBenchmark.php.

42 {
43 global $ilDB;
44
45 $q = "DELETE FROM benchmark";
46 $ilDB->manipulate($q);
47 }
global $ilDB

References $ilDB.

◆ enable()

ilBenchmark::enable (   $a_enable)

enable benchmarking

Definition at line 222 of file class.ilBenchmark.php.

223 {
224 global $ilias;
225
226 if ($a_enable)
227 {
228 $ilias->setSetting("enable_bench", 1);
229 }
230 else
231 {
232 $ilias->setSetting("enable_bench", 0);
233 }
234 }

◆ enableDbBench()

ilBenchmark::enableDbBench (   $a_enable,
  $a_user = 0 
)

Enable DB benchmarking.

Parameters
booleanenable db benchmarking
stringuser account name that should be benchmarked

Definition at line 306 of file class.ilBenchmark.php.

307 {
308 global $ilias;
309
310 if ($a_enable)
311 {
312 $ilias->setSetting("enable_db_bench", 1);
313 if ($a_user !== 0)
314 {
315 $ilias->setSetting("db_bench_user", $a_user);
316 }
317 }
318 else
319 {
320 $ilias->setSetting("enable_db_bench", 0);
321 if ($a_user !== 0)
322 {
323 $ilias->setSetting("db_bench_user", $a_user);
324 }
325 }
326 }

Referenced by save().

+ Here is the caller graph for this function:

◆ getCurrentRecordNumber()

ilBenchmark::getCurrentRecordNumber ( )

get current number of benchmark records

Definition at line 169 of file class.ilBenchmark.php.

170 {
171 global $ilDB;
172
173 $q = "SELECT COUNT(*) AS cnt FROM benchmark";
174 $cnt_set = $ilDB->query($q);
175 $cnt_rec = $ilDB->fetchAssoc($cnt_set);
176
177 return $cnt_rec["cnt"];
178 }

References $ilDB.

◆ getDbBenchRecords()

ilBenchmark::getDbBenchRecords ( )

Get db benchmark records.

Parameters

return

Definition at line 374 of file class.ilBenchmark.php.

375 {
376 global $ilDB;
377
378 $set = $ilDB->query("SELECT * FROM benchmark");
379 $b = array();
380 while ($rec = $ilDB->fetchAssoc($set))
381 {
382 $b[] = array("sql" => $rec["sql_stmt"],
383 "time" => $rec["duration"]);
384 }
385 return $b;
386 }

References $ilDB.

◆ getEvaluation()

ilBenchmark::getEvaluation (   $a_module)

get performance evaluation data

Definition at line 144 of file class.ilBenchmark.php.

145 {
146 global $ilDB;
147
148 $q = "SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark,".
149 " MIN(duration) AS min_dur, MAX(duration) AS max_dur".
150 " FROM benchmark".
151 " WHERE module = ".$ilDB->quote($a_module, "text")." ".
152 " GROUP BY benchmark".
153 " ORDER BY benchmark";
154 $bench_set = $ilDB->query($q);
155 $eva = array();
156 while($bench_rec = $ilDB->fetchAssoc($bench_set))
157 {
158 $eva[] = array("benchmark" => $bench_rec["benchmark"],
159 "cnt" => $bench_rec["cnt"], "duration" => $bench_rec["avg_dur"],
160 "min" => $bench_rec["min_dur"], "max" => $bench_rec["max_dur"]);
161 }
162 return $eva;
163 }

References $ilDB.

◆ getMaximumRecords()

ilBenchmark::getMaximumRecords ( )

get maximum number of benchmark records

Definition at line 184 of file class.ilBenchmark.php.

185 {
186 global $ilias;
187
188 return $ilias->getSetting("bench_max_records");
189 }

◆ getMeasuredModules()

ilBenchmark::getMeasuredModules ( )

get all current measured modules

Definition at line 240 of file class.ilBenchmark.php.

241 {
242 global $ilDB;
243
244 $q = "SELECT DISTINCT module FROM benchmark";
245 $mod_set = $ilDB->query($q);
246
247 $modules = array();
248 while ($mod_rec = $ilDB->fetchAssoc($mod_set))
249 {
250 $modules[$mod_rec["module"]] = $mod_rec["module"];
251 }
252
253 return $modules;
254 }

References $ilDB.

◆ getMeasuredTime()

ilBenchmark::getMeasuredTime (   $a_module,
  $a_bench 
)

Get measurement.

Returns
Measurement in milliseconds.

Definition at line 262 of file class.ilBenchmark.php.

263 {
264 if (isset($this->bench[$a_module.":".$a_bench]))
265 {
266 return $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1];
267 }
268 return false;
269 }

◆ ilBenchmark()

ilBenchmark::ilBenchmark ( )

constructor

Definition at line 19 of file class.ilBenchmark.php.

20 {
21 }

◆ isDbBenchEnabled()

ilBenchmark::isDbBenchEnabled ( )

Check wether benchmarking is enabled or not.

Definition at line 281 of file class.ilBenchmark.php.

282 {
283 global $ilSetting;
284
285 if (isset($this->db_enabled))
286 {
287 return $this->db_enabled;
288 }
289
290 if (!is_object($ilSetting))
291 {
292 return false;
293 }
294
295 $this->db_enabled = $ilSetting->get("enable_db_bench");
296 $this->db_enabled_user = $ilSetting->get("db_bench_user");
297 return $this->db_enabled;
298 }
global $ilSetting
Definition: privfeed.php:40

References $ilSetting.

Referenced by save(), startDbBench(), and stopDbBench().

+ Here is the caller graph for this function:

◆ isEnabled()

ilBenchmark::isEnabled ( )

check wether benchmarking is enabled or not

Definition at line 206 of file class.ilBenchmark.php.

207 {
208 global $ilSetting;
209
210 if (!is_object($ilSetting))
211 {
212 return true;
213 }
214
215 return (boolean) $ilSetting->get("enable_bench");
216 }

References $ilSetting.

Referenced by start(), and stop().

+ Here is the caller graph for this function:

◆ microtimeDiff()

ilBenchmark::microtimeDiff (   $t1,
  $t2 
)

Definition at line 27 of file class.ilBenchmark.php.

28 {
29 $t1 = explode(" ",$t1);
30 $t2 = explode(" ",$t2);
31 $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
32
33 return $diff;
34 }

Referenced by save(), and stop().

+ Here is the caller graph for this function:

◆ save()

ilBenchmark::save ( )

save all measurements

Definition at line 86 of file class.ilBenchmark.php.

87 {
88 global $ilDB, $ilUser;
89
90 if ($this->isDbBenchEnabled() && is_object($ilUser) &&
91 $this->db_enabled_user == $ilUser->getLogin())
92 {
93 if (is_array($this->db_bench) && is_object($ilDB))
94 {
95 $this->db_bench_stop_rec = true;
96
97 $ilDB->manipulate("DELETE FROM benchmark");
98 foreach ($this->db_bench as $b)
99 {
100 $ilDB->insert("benchmark", array(
101 "duration" => array("float", $this->microtimeDiff($b["start"], $b["stop"])),
102 "sql_stmt" => array("clob", $b["sql"])
103 ));
104 }
105 }
106 $this->enableDbBench(false);
107 }
108
109 // log slow requests
110 //define("LOG_SLOW_REQUESTS", (float) "0.1");
111 if (defined("SLOW_REQUEST_TIME") && SLOW_REQUEST_TIME > 0)
112 {
113 $t1 = explode(" ", $GLOBALS['ilGlobalStartTime']);
114 $t2 = explode(" ", microtime());
115 $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
116 if ($diff > SLOW_REQUEST_TIME)
117 {
118 global $ilIliasIniFile;
119
120 $diff = round($diff, 4);
121
122 include_once("./Services/Logging/classes/class.ilLog.php");
123 $slow_request_log = new ilLog(
124 $ilIliasIniFile->readVariable("log","slow_request_log_path"),
125 $ilIliasIniFile->readVariable("log","slow_request_log_file"),
126 CLIENT_ID);
127 $slow_request_log->write("SLOW REQUEST (".$diff."), Client:".CLIENT_ID.", GET: ".
128 str_replace("\n", " ", print_r($_GET, true)).", POST: ".
129 ilUtil::shortenText(str_replace("\n", " ", print_r($_POST, true)), 800, true));
130 }
131 }
132
133 }
$_GET["client_id"]
enableDbBench($a_enable, $a_user=0)
Enable DB benchmarking.
microtimeDiff($t1, $t2)
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
logging
Definition: class.ilLog.php:19
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
$_POST['username']
Definition: cron.php:12
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilIliasIniFile
global $ilUser
Definition: imgupload.php:15

References $_GET, $_POST, $GLOBALS, $ilDB, $ilIliasIniFile, $ilUser, enableDbBench(), isDbBenchEnabled(), microtimeDiff(), and ilUtil\shortenText().

+ Here is the call graph for this function:

◆ setMaximumRecords()

ilBenchmark::setMaximumRecords (   $a_max)

set maximum number of benchmark records

Definition at line 195 of file class.ilBenchmark.php.

196 {
197 global $ilias;
198
199 $ilias->setSetting("bench_max_records", (int) $a_max);
200 }

◆ start()

ilBenchmark::start (   $a_module,
  $a_bench 
)

start measurement

Parameters
string$typemeasurement type
Returns
int measurement id

Definition at line 57 of file class.ilBenchmark.php.

58 {
59return;
60 if ($this->isEnabled())
61 {
62 $this->bench[$a_module.":".$a_bench][] = microtime();
63 }
64 }
isEnabled()
check wether benchmarking is enabled or not

References isEnabled().

Referenced by startDbBench(), and stopDbBench().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startDbBench()

ilBenchmark::startDbBench (   $a_sql)

start measurement

Parameters
string$typemeasurement type
Returns
int measurement id

Definition at line 335 of file class.ilBenchmark.php.

336 {
337 global $ilUser;
338
339 if ($this->isDbBenchEnabled() && is_object($ilUser) &&
340 $this->db_enabled_user == $ilUser->getLogin() &&
341 !$this->db_bench_stop_rec)
342 {
343 $this->start = microtime();
344 $this->sql = $a_sql;
345 }
346 }
start($a_module, $a_bench)
start measurement

References $ilUser, isDbBenchEnabled(), and start().

+ Here is the call graph for this function:

◆ stop()

ilBenchmark::stop (   $a_module,
  $a_bench 
)

stop measurement

Parameters
int$midmeasurement id

Definition at line 72 of file class.ilBenchmark.php.

73 {
74return;
75 if ($this->isEnabled())
76 {
77 $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1]
78 = $this->microtimeDiff($this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1], microtime());
79 }
80 }

References isEnabled(), and microtimeDiff().

+ Here is the call graph for this function:

◆ stopDbBench()

ilBenchmark::stopDbBench ( )

stop measurement

Parameters
int$midmeasurement id

Definition at line 354 of file class.ilBenchmark.php.

355 {
356 global $ilUser;
357
358 if ($this->isDbBenchEnabled() && is_object($ilUser) &&
359 $this->db_enabled_user == $ilUser->getLogin() &&
360 !$this->db_bench_stop_rec)
361 {
362 $this->db_bench[] =
363 array("start" => $this->start, "stop" => microtime(),
364 "sql" => $this->sql);
365 }
366 }

References $ilUser, isDbBenchEnabled(), and start().

+ Here is the call graph for this function:

Field Documentation

◆ $bench

ilBenchmark::$bench = array()

Definition at line 14 of file class.ilBenchmark.php.


The documentation for this class was generated from the following file: