ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilBenchmark Class Reference

performance measurement class More...

+ Collaboration diagram for ilBenchmark:

Public Member Functions

 __construct ()
 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 ()
 
 getDbBenchRecords ()
 Get db benchmark records. More...
 

Data Fields

 $bench = array()
 

Protected Attributes

 $db_bench
 
 $start
 
 $sql
 
 $db_bench_stop_rec
 
 $db_enabled_user
 

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.

Constructor & Destructor Documentation

◆ __construct()

ilBenchmark::__construct ( )

Constructor.

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

41  {
42  }

Member Function Documentation

◆ clearData()

ilBenchmark::clearData ( )

delete all measurement data

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

References $DIC, and $ilDB.

64  {
65  global $DIC;
66  $ilDB = $DIC->database();
67 
68  $q = "DELETE FROM benchmark";
69  $ilDB->manipulate($q);
70  }
global $DIC
Definition: saml.php:7
global $ilDB

◆ enable()

ilBenchmark::enable (   $a_enable)

enable benchmarking

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

References $DIC, and $ilSetting.

238  {
239  global $DIC;
240  $ilSetting = $DIC->settings();
241 
242 
243  if ($a_enable) {
244  $ilSetting->get("enable_bench", 1);
245  } else {
246  $ilSetting->get("enable_bench", 0);
247  }
248  }
global $DIC
Definition: saml.php:7
global $ilSetting
Definition: privfeed.php:17

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

References $DIC, and $ilSetting.

Referenced by save().

321  {
322  global $DIC;
323  $ilSetting = $DIC->settings();
324 
325 
326  if ($a_enable) {
327  $ilSetting->set("enable_db_bench", 1);
328  if ($a_user !== 0) {
329  $ilSetting->set("db_bench_user", $a_user);
330  }
331  } else {
332  $ilSetting->set("enable_db_bench", 0);
333  if ($a_user !== 0) {
334  $ilSetting->set("db_bench_user", $a_user);
335  }
336  }
337  }
global $DIC
Definition: saml.php:7
global $ilSetting
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ getCurrentRecordNumber()

ilBenchmark::getCurrentRecordNumber ( )

get current number of benchmark records

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

References $DIC, and $ilDB.

181  {
182  global $DIC;
183  $ilDB = $DIC->database();
184 
185  $q = "SELECT COUNT(*) AS cnt FROM benchmark";
186  $cnt_set = $ilDB->query($q);
187  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
188 
189  return $cnt_rec["cnt"];
190  }
global $DIC
Definition: saml.php:7
global $ilDB

◆ getDbBenchRecords()

ilBenchmark::getDbBenchRecords ( )

Get db benchmark records.

Parameters

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

References $DIC, $ilDB, and array.

401  {
402  global $DIC;
403  $ilDB = $DIC->database();
404 
405  $set = $ilDB->query("SELECT * FROM benchmark");
406  $b = array();
407  while ($rec = $ilDB->fetchAssoc($set)) {
408  $b[] = array("sql" => $rec["sql_stmt"],
409  "time" => $rec["duration"]);
410  }
411  return $b;
412  }
global $DIC
Definition: saml.php:7
Create styles array
The data for the language used.
global $ilDB

◆ getEvaluation()

ilBenchmark::getEvaluation (   $a_module)

get performance evaluation data

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

References $ilDB, and array.

157  {
158  $ilDB = $this->db;
159 
160  $q = "SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark," .
161  " MIN(duration) AS min_dur, MAX(duration) AS max_dur" .
162  " FROM benchmark" .
163  " WHERE module = " . $ilDB->quote($a_module, "text") . " " .
164  " GROUP BY benchmark" .
165  " ORDER BY benchmark";
166  $bench_set = $ilDB->query($q);
167  $eva = array();
168  while ($bench_rec = $ilDB->fetchAssoc($bench_set)) {
169  $eva[] = array("benchmark" => $bench_rec["benchmark"],
170  "cnt" => $bench_rec["cnt"], "duration" => $bench_rec["avg_dur"],
171  "min" => $bench_rec["min_dur"], "max" => $bench_rec["max_dur"]);
172  }
173  return $eva;
174  }
Create styles array
The data for the language used.
global $ilDB

◆ getMaximumRecords()

ilBenchmark::getMaximumRecords ( )

get maximum number of benchmark records

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

References $DIC, and $ilSetting.

197  {
198  global $DIC;
199  $ilSetting = $DIC->settings();
200 
201  return $ilSetting->get("bench_max_records");
202  }
global $DIC
Definition: saml.php:7
global $ilSetting
Definition: privfeed.php:17

◆ getMeasuredModules()

ilBenchmark::getMeasuredModules ( )

get all current measured modules

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

References $DIC, $ilDB, and array.

255  {
256  global $DIC;
257  $ilDB = $DIC->database();
258 
259 
260  $q = "SELECT DISTINCT module FROM benchmark";
261  $mod_set = $ilDB->query($q);
262 
263  $modules = array();
264  while ($mod_rec = $ilDB->fetchAssoc($mod_set)) {
265  $modules[$mod_rec["module"]] = $mod_rec["module"];
266  }
267 
268  return $modules;
269  }
global $DIC
Definition: saml.php:7
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 277 of file class.ilBenchmark.php.

278  {
279  if (isset($this->bench[$a_module . ":" . $a_bench])) {
280  return $this->bench[$a_module . ":" . $a_bench][count($this->bench[$a_module . ":" . $a_bench]) - 1];
281  }
282  return false;
283  }

◆ isDbBenchEnabled()

ilBenchmark::isDbBenchEnabled ( )

Check wether benchmarking is enabled or not.

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

References $DIC, and $ilSetting.

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

296  {
297  global $DIC;
298  $ilSetting = $DIC->settings();
299 
300 
301  if (isset($this->db_enabled)) {
302  return $this->db_enabled;
303  }
304 
305  if (!is_object($ilSetting)) {
306  return false;
307  }
308 
309  $this->db_enabled = $ilSetting->get("enable_db_bench");
310  $this->db_enabled_user = $ilSetting->get("db_bench_user");
311  return $this->db_enabled;
312  }
global $DIC
Definition: saml.php:7
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 220 of file class.ilBenchmark.php.

References $DIC, and $ilSetting.

221  {
222  global $DIC;
223  $ilSetting = $DIC->settings();
224 
225 
226  if (!is_object($ilSetting)) {
227  return true;
228  }
229 
230  return (boolean) $ilSetting->get("enable_bench");
231  }
global $DIC
Definition: saml.php:7
global $ilSetting
Definition: privfeed.php:17

◆ microtimeDiff()

ilBenchmark::microtimeDiff (   $t1,
  $t2 
)

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

Referenced by save().

50  {
51  $t1 = explode(" ", $t1);
52  $t2 = explode(" ", $t2);
53  $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
54 
55  return $diff;
56  }
+ Here is the caller graph for this function:

◆ save()

ilBenchmark::save ( )

save all measurements

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

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

101  {
102  global $DIC;
103  $ilDB = $DIC->database();
104  $ilUser = $DIC->user();
105  if ($this->isDbBenchEnabled() && is_object($ilUser) &&
106  $this->db_enabled_user == $ilUser->getLogin()) {
107  if (is_array($this->db_bench) && is_object($ilDB)) {
108  $this->db_bench_stop_rec = true;
109 
110  $ilDB->manipulate("DELETE FROM benchmark");
111  foreach ($this->db_bench as $b) {
112  $id = $ilDB->nextId('benchmark');
113  $ilDB->insert("benchmark", array(
114  "id" => array("integer", $id),
115  "duration" => array("float", $this->microtimeDiff($b["start"], $b["stop"])),
116  "sql_stmt" => array("clob", $b["sql"])
117  ));
118  }
119  }
120  $this->enableDbBench(false);
121  }
122 
123  // log slow requests
124  //define("LOG_SLOW_REQUESTS", (float) "0.1");
125  if (defined("SLOW_REQUEST_TIME") && SLOW_REQUEST_TIME > 0) {
126  $t1 = explode(" ", $GLOBALS['ilGlobalStartTime']);
127  $t2 = explode(" ", microtime());
128  $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
129  if ($diff > SLOW_REQUEST_TIME) {
130  $ilIliasIniFile = $DIC["ilIliasIniFile"];
131 
132  $diff = round($diff, 4);
133 
134  include_once("./Services/Logging/classes/class.ilLog.php");
135  $slow_request_log = new ilLog(
136  $ilIliasIniFile->readVariable("log", "slow_request_log_path"),
137  $ilIliasIniFile->readVariable("log", "slow_request_log_file"),
138  CLIENT_ID
139  );
140  $slow_request_log->write("SLOW REQUEST (" . $diff . "), Client:" . CLIENT_ID . ", GET: " .
141  str_replace("\n", " ", print_r($_GET, true)) . ", POST: " .
142  ilUtil::shortenText(str_replace("\n", " ", print_r($_POST, true)), 800, true));
143  }
144  }
145  }
microtimeDiff($t1, $t2)
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if(!array_key_exists('StateId', $_REQUEST)) $id
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 208 of file class.ilBenchmark.php.

References $DIC, and $ilSetting.

209  {
210  global $DIC;
211  $ilSetting = $DIC->settings();
212 
213  return $ilSetting->get("bench_max_records", (int) $a_max);
214  }
global $DIC
Definition: saml.php:7
global $ilSetting
Definition: privfeed.php:17

◆ start()

ilBenchmark::start (   $a_module,
  $a_bench 
)

start measurement

Parameters
string$typemeasurement type
Returns
int measurement id
Deprecated:

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

Referenced by startDbBench(), and stopDbBench().

82  {
83  }
+ Here is the caller graph for this function:

◆ startDbBench()

ilBenchmark::startDbBench (   $a_sql)

start measurement

Parameters
string$a_sql
Returns
bool|int

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

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

348  {
349  global $DIC;
350 
351  try {
352  $ilUser = $DIC->user();
353  } catch (InvalidArgumentException $e) {
354  return false;
355  }
356 
357  if ($this->isDbBenchEnabled() && is_object($ilUser)
358  && $this->db_enabled_user == $ilUser->getLogin()
360  $this->start = microtime();
361  $this->sql = $a_sql;
362  }
363  }
global $DIC
Definition: saml.php:7
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
Deprecated:

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

93  {
94  }

◆ stopDbBench()

ilBenchmark::stopDbBench ( )
Returns
bool

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

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

370  {
371  global $DIC;
372 
373  try {
374  $ilUser = $DIC->user();
375  } catch (InvalidArgumentException $e) {
376  return false;
377  }
378 
379  if ($this->isDbBenchEnabled() && is_object($ilUser)
380  && $this->db_enabled_user == $ilUser->getLogin()
382  $this->db_bench[] = array(
383  "start" => $this->start,
384  "stop" => microtime(),
385  "sql" => $this->sql,
386  );
387 
388  return true;
389  }
390 
391  return false;
392  }
global $DIC
Definition: saml.php:7
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 44 of file class.ilBenchmark.php.

◆ $db_bench

ilBenchmark::$db_bench
protected

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

◆ $db_bench_stop_rec

ilBenchmark::$db_bench_stop_rec
protected

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

Referenced by startDbBench(), and stopDbBench().

◆ $db_enabled_user

ilBenchmark::$db_enabled_user
protected

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

◆ $sql

ilBenchmark::$sql
protected

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

◆ $start

ilBenchmark::$start
protected

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


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