29 $t1 = explode(
" ",$t1);
30 $t2 = explode(
" ",$t2);
31 $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
45 $q =
"DELETE FROM benchmark";
46 $ilDB->manipulate($q);
57 function start($a_module, $a_bench)
62 $this->bench[$a_module.
":".$a_bench][] = microtime();
72 function stop($a_module, $a_bench)
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());
91 $this->db_enabled_user ==
$ilUser->getLogin())
93 if (is_array($this->db_bench) && is_object(
$ilDB))
95 $this->db_bench_stop_rec =
true;
97 $ilDB->manipulate(
"DELETE FROM benchmark");
98 foreach ($this->db_bench as $b)
100 $ilDB->insert(
"benchmark", array(
101 "duration" => array(
"float", $this->
microtimeDiff($b[
"start"], $b[
"stop"])),
102 "sql_stmt" => array(
"clob", $b[
"sql"])
111 if (defined(
"SLOW_REQUEST_TIME") && SLOW_REQUEST_TIME > 0)
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)
120 $diff = round($diff, 4);
122 include_once(
"./Services/Logging/classes/class.ilLog.php");
123 $slow_request_log =
new ilLog(
127 $slow_request_log->write(
"SLOW REQUEST (".$diff.
"), Client:".CLIENT_ID.
", GET: ".
128 str_replace(
"\n",
" ", print_r(
$_GET,
true)).
", POST: ".
148 $q =
"SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark,".
149 " MIN(duration) AS min_dur, MAX(duration) AS max_dur".
151 " WHERE module = ".$ilDB->quote($a_module,
"text").
" ".
152 " GROUP BY benchmark".
153 " ORDER BY benchmark";
154 $bench_set =
$ilDB->query($q);
156 while($bench_rec =
$ilDB->fetchAssoc($bench_set))
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"]);
173 $q =
"SELECT COUNT(*) AS cnt FROM benchmark";
174 $cnt_set =
$ilDB->query($q);
175 $cnt_rec =
$ilDB->fetchAssoc($cnt_set);
177 return $cnt_rec[
"cnt"];
188 return $ilias->getSetting(
"bench_max_records");
199 $ilias->setSetting(
"bench_max_records", (
int) $a_max);
215 return (
boolean)
$ilSetting->get(
"enable_bench");
228 $ilias->setSetting(
"enable_bench", 1);
232 $ilias->setSetting(
"enable_bench", 0);
244 $q =
"SELECT DISTINCT module FROM benchmark";
245 $mod_set =
$ilDB->query($q);
248 while ($mod_rec =
$ilDB->fetchAssoc($mod_set))
250 $modules[$mod_rec[
"module"]] = $mod_rec[
"module"];
264 if (isset($this->bench[$a_module.
":".$a_bench]))
266 return $this->bench[$a_module.
":".$a_bench][count($this->bench[$a_module.
":".$a_bench]) - 1];
285 if (isset($this->db_enabled))
287 return $this->db_enabled;
295 $this->db_enabled =
$ilSetting->get(
"enable_db_bench");
296 $this->db_enabled_user =
$ilSetting->get(
"db_bench_user");
297 return $this->db_enabled;
312 $ilias->setSetting(
"enable_db_bench", 1);
315 $ilias->setSetting(
"db_bench_user", $a_user);
320 $ilias->setSetting(
"enable_db_bench", 0);
323 $ilias->setSetting(
"db_bench_user", $a_user);
340 $this->db_enabled_user ==
$ilUser->getLogin() &&
341 !$this->db_bench_stop_rec)
343 $this->
start = microtime();
359 $this->db_enabled_user ==
$ilUser->getLogin() &&
360 !$this->db_bench_stop_rec)
363 array(
"start" => $this->
start,
"stop" => microtime(),
364 "sql" => $this->sql);
378 $set =
$ilDB->query(
"SELECT * FROM benchmark");
380 while ($rec =
$ilDB->fetchAssoc($set))
382 $b[] = array(
"sql" => $rec[
"sql_stmt"],
383 "time" => $rec[
"duration"]);
performance measurement class
start($a_module, $a_bench)
start measurement
getMeasuredTime($a_module, $a_bench)
Get measurement.
getMeasuredModules()
get all current measured modules
enableDbBench($a_enable, $a_user=0)
Enable DB benchmarking.
setMaximumRecords($a_max)
set maximum number of benchmark records
stop($a_module, $a_bench)
stop measurement
getMaximumRecords()
get maximum number of benchmark records
getCurrentRecordNumber()
get current number of benchmark records
getDbBenchRecords()
Get db benchmark records.
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
stopDbBench()
stop measurement
enable($a_enable)
enable benchmarking
getEvaluation($a_module)
get performance evaluation data
startDbBench($a_sql)
start measurement
save()
save all measurements
isEnabled()
check wether benchmarking is enabled or not
clearData()
delete all measurement data
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.