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(
124 $ilIliasIniFile->readVariable(
"log",
"slow_request_log_path"),
125 $ilIliasIniFile->readVariable(
"log",
"slow_request_log_file"),
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);
210 if (!is_object($ilSetting))
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;
290 if (!is_object($ilSetting))
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"]);