ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBenchmark Class Reference

performance measurement class More...

+ Collaboration diagram for ilBenchmark:

Public Member Functions

 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 33 of file class.ilBenchmark.php.

References $ilDB.

34  {
35  global $ilDB;
36 
37  $q = "DELETE FROM benchmark";
38  $ilDB->manipulate($q);
39  }
global $ilDB

◆ enable()

ilBenchmark::enable (   $a_enable)

enable benchmarking

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

217  {
218  global $ilias;
219 
220  if ($a_enable)
221  {
222  $ilias->setSetting("enable_bench", 1);
223  }
224  else
225  {
226  $ilias->setSetting("enable_bench", 0);
227  }
228  }

◆ 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 300 of file class.ilBenchmark.php.

Referenced by save().

301  {
302  global $ilias;
303 
304  if ($a_enable)
305  {
306  $ilias->setSetting("enable_db_bench", 1);
307  if ($a_user !== 0)
308  {
309  $ilias->setSetting("db_bench_user", $a_user);
310  }
311  }
312  else
313  {
314  $ilias->setSetting("enable_db_bench", 0);
315  if ($a_user !== 0)
316  {
317  $ilias->setSetting("db_bench_user", $a_user);
318  }
319  }
320  }
+ Here is the caller graph for this function:

◆ getCurrentRecordNumber()

ilBenchmark::getCurrentRecordNumber ( )

get current number of benchmark records

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

References $ilDB.

164  {
165  global $ilDB;
166 
167  $q = "SELECT COUNT(*) AS cnt FROM benchmark";
168  $cnt_set = $ilDB->query($q);
169  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
170 
171  return $cnt_rec["cnt"];
172  }
global $ilDB

◆ getDbBenchRecords()

ilBenchmark::getDbBenchRecords ( )

Get db benchmark records.

Parameters

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

References $ilDB, and array.

369  {
370  global $ilDB;
371 
372  $set = $ilDB->query("SELECT * FROM benchmark");
373  $b = array();
374  while ($rec = $ilDB->fetchAssoc($set))
375  {
376  $b[] = array("sql" => $rec["sql_stmt"],
377  "time" => $rec["duration"]);
378  }
379  return $b;
380  }
Create styles array
The data for the language used.
global $ilDB

◆ getEvaluation()

ilBenchmark::getEvaluation (   $a_module)

get performance evaluation data

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

References $ilDB, and array.

139  {
140  global $ilDB;
141 
142  $q = "SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark,".
143  " MIN(duration) AS min_dur, MAX(duration) AS max_dur".
144  " FROM benchmark".
145  " WHERE module = ".$ilDB->quote($a_module, "text")." ".
146  " GROUP BY benchmark".
147  " ORDER BY benchmark";
148  $bench_set = $ilDB->query($q);
149  $eva = array();
150  while($bench_rec = $ilDB->fetchAssoc($bench_set))
151  {
152  $eva[] = array("benchmark" => $bench_rec["benchmark"],
153  "cnt" => $bench_rec["cnt"], "duration" => $bench_rec["avg_dur"],
154  "min" => $bench_rec["min_dur"], "max" => $bench_rec["max_dur"]);
155  }
156  return $eva;
157  }
Create styles array
The data for the language used.
global $ilDB

◆ getMaximumRecords()

ilBenchmark::getMaximumRecords ( )

get maximum number of benchmark records

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

179  {
180  global $ilias;
181 
182  return $ilias->getSetting("bench_max_records");
183  }

◆ getMeasuredModules()

ilBenchmark::getMeasuredModules ( )

get all current measured modules

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

References $ilDB, and array.

235  {
236  global $ilDB;
237 
238  $q = "SELECT DISTINCT module FROM benchmark";
239  $mod_set = $ilDB->query($q);
240 
241  $modules = array();
242  while ($mod_rec = $ilDB->fetchAssoc($mod_set))
243  {
244  $modules[$mod_rec["module"]] = $mod_rec["module"];
245  }
246 
247  return $modules;
248  }
Create styles array
The data for the language used.
global $ilDB

◆ getMeasuredTime()

ilBenchmark::getMeasuredTime (   $a_module,
  $a_bench 
)

Get measurement.

Returns
Measurement in milliseconds.

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

257  {
258  if (isset($this->bench[$a_module.":".$a_bench]))
259  {
260  return $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1];
261  }
262  return false;
263  }

◆ isDbBenchEnabled()

ilBenchmark::isDbBenchEnabled ( )

Check wether benchmarking is enabled or not.

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

References $ilSetting.

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

276  {
277  global $ilSetting;
278 
279  if (isset($this->db_enabled))
280  {
281  return $this->db_enabled;
282  }
283 
284  if (!is_object($ilSetting))
285  {
286  return false;
287  }
288 
289  $this->db_enabled = $ilSetting->get("enable_db_bench");
290  $this->db_enabled_user = $ilSetting->get("db_bench_user");
291  return $this->db_enabled;
292  }
global $ilSetting
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ isEnabled()

ilBenchmark::isEnabled ( )

check wether benchmarking is enabled or not

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

References $ilSetting.

Referenced by start(), and stop().

201  {
202  global $ilSetting;
203 
204  if (!is_object($ilSetting))
205  {
206  return true;
207  }
208 
209  return (boolean) $ilSetting->get("enable_bench");
210  }
global $ilSetting
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ microtimeDiff()

ilBenchmark::microtimeDiff (   $t1,
  $t2 
)

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

Referenced by save(), and stop().

20  {
21  $t1 = explode(" ",$t1);
22  $t2 = explode(" ",$t2);
23  $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
24 
25  return $diff;
26  }
+ Here is the caller graph for this function:

◆ save()

ilBenchmark::save ( )

save all measurements

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

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

79  {
80  global $ilDB, $ilUser;
81 
82  if ($this->isDbBenchEnabled() && is_object($ilUser) &&
83  $this->db_enabled_user == $ilUser->getLogin())
84  {
85  if (is_array($this->db_bench) && is_object($ilDB))
86  {
87  $this->db_bench_stop_rec = true;
88 
89  $ilDB->manipulate("DELETE FROM benchmark");
90  foreach ($this->db_bench as $b)
91  {
92  $id = $ilDB->nextId('benchmark');
93  $ilDB->insert("benchmark", array(
94  "id" => array("integer", $id),
95  "duration" => array("float", $this->microtimeDiff($b["start"], $b["stop"])),
96  "sql_stmt" => array("clob", $b["sql"])
97  ));
98  }
99  }
100  $this->enableDbBench(false);
101  }
102 
103  // log slow requests
104  //define("LOG_SLOW_REQUESTS", (float) "0.1");
105  if (defined("SLOW_REQUEST_TIME") && SLOW_REQUEST_TIME > 0)
106  {
107  $t1 = explode(" ", $GLOBALS['ilGlobalStartTime']);
108  $t2 = explode(" ", microtime());
109  $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
110  if ($diff > SLOW_REQUEST_TIME)
111  {
112  global $ilIliasIniFile;
113 
114  $diff = round($diff, 4);
115 
116  include_once("./Services/Logging/classes/class.ilLog.php");
117  $slow_request_log = new ilLog(
118  $ilIliasIniFile->readVariable("log","slow_request_log_path"),
119  $ilIliasIniFile->readVariable("log","slow_request_log_file"),
120  CLIENT_ID);
121  $slow_request_log->write("SLOW REQUEST (".$diff."), Client:".CLIENT_ID.", GET: ".
122  str_replace("\n", " ", print_r($_GET, true)).", POST: ".
123  ilUtil::shortenText(str_replace("\n", " ", print_r($_POST, true)), 800, true));
124  }
125  }
126 
127  }
microtimeDiff($t1, $t2)
$_GET["client_id"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
logging
Definition: class.ilLog.php:18
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
write($a_msg, $a_log_level=NULL)
logging
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $ilDB
$ilIliasIniFile
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$_POST["username"]
enableDbBench($a_enable, $a_user=0)
Enable DB benchmarking.
+ Here is the call graph for this function:

◆ setMaximumRecords()

ilBenchmark::setMaximumRecords (   $a_max)

set maximum number of benchmark records

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

190  {
191  global $ilias;
192 
193  $ilias->setSetting("bench_max_records", (int) $a_max);
194  }

◆ start()

ilBenchmark::start (   $a_module,
  $a_bench 
)

start measurement

Parameters
string$typemeasurement type
Returns
int measurement id

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

References isEnabled().

Referenced by startDbBench(), and stopDbBench().

50  {
51 return;
52  if ($this->isEnabled())
53  {
54  $this->bench[$a_module.":".$a_bench][] = microtime();
55  }
56  }
isEnabled()
check wether benchmarking is enabled or not
+ 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 329 of file class.ilBenchmark.php.

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

330  {
331  global $ilUser;
332 
333  if ($this->isDbBenchEnabled() && is_object($ilUser) &&
334  $this->db_enabled_user == $ilUser->getLogin() &&
335  !$this->db_bench_stop_rec)
336  {
337  $this->start = microtime();
338  $this->sql = $a_sql;
339  }
340  }
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
$ilUser
Definition: imgupload.php:18
start($a_module, $a_bench)
start measurement
+ Here is the call graph for this function:

◆ stop()

ilBenchmark::stop (   $a_module,
  $a_bench 
)

stop measurement

Parameters
int$midmeasurement id

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

References isEnabled(), and microtimeDiff().

65  {
66 return;
67  if ($this->isEnabled())
68  {
69  $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1]
70  = $this->microtimeDiff($this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1], microtime());
71  }
72  }
microtimeDiff($t1, $t2)
isEnabled()
check wether benchmarking is enabled or not
+ Here is the call graph for this function:

◆ stopDbBench()

ilBenchmark::stopDbBench ( )

stop measurement

Parameters
int$midmeasurement id

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

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

349  {
350  global $ilUser;
351 
352  if ($this->isDbBenchEnabled() && is_object($ilUser) &&
353  $this->db_enabled_user == $ilUser->getLogin() &&
354  !$this->db_bench_stop_rec)
355  {
356  $this->db_bench[] =
357  array("start" => $this->start, "stop" => microtime(),
358  "sql" => $this->sql);
359  }
360  }
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
start($a_module, $a_bench)
start measurement
+ 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: