Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00033 class ilBenchmark
00034 {
00035
00039 function ilBenchmark()
00040 {
00041 }
00042
00043
00047 function microtimeDiff($t1, $t2)
00048 {
00049 $t1 = explode(" ",$t1);
00050 $t2 = explode(" ",$t2);
00051 $diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
00052
00053 return $diff;
00054 }
00055
00056
00057
00061 function clearData()
00062 {
00063 global $ilDB;
00064
00065 $q = "DELETE FROM benchmark";
00066 $ilDB->query($q);
00067 }
00068
00069
00077 function start($a_module, $a_bench)
00078 {
00079 $this->bench[$a_module.":".$a_bench][] = microtime();
00080 }
00081
00082
00088 function stop($a_module, $a_bench)
00089 {
00090 $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1]
00091 = $this->microtimeDiff($this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1], microtime());
00092 }
00093
00094
00098 function save()
00099 {
00100 global $ilDB;
00101
00102 if ($this->isEnabled() &&
00103 ($this->getMaximumRecords() > $this->getCurrentRecordNumber()))
00104 {
00105 foreach($this->bench as $key => $bench)
00106 {
00107 $bench_arr = explode(":", $key);
00108 $bench_module = $bench_arr[0];
00109 $benchmark = $bench_arr[1];
00110 foreach($bench as $time)
00111 {
00112 $q = "INSERT INTO benchmark (cdate, duration, module, benchmark) VALUES ".
00113 "(now(), ".$ilDB->quote($time).", ".$ilDB->quote($bench_module).", ".$ilDB->quote($benchmark).")";
00114 $ilDB->query($q);
00115 }
00116 }
00117 $this->bench = array();
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126
00130 function getEvaluation($a_module)
00131 {
00132 global $ilDB;
00133
00134 $q = "SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark,".
00135 " MIN(duration) AS min_dur, MAX(duration) AS max_dur".
00136 " FROM benchmark".
00137 " WHERE module = ".$ilDB->quote($a_module)." ".
00138 " GROUP BY benchmark".
00139 " ORDER BY benchmark";
00140 $bench_set = $ilDB->query($q);
00141 $eva = array();
00142 while($bench_rec = $bench_set->fetchRow(DB_FETCHMODE_ASSOC))
00143 {
00144 $eva[] = array("benchmark" => $bench_rec["benchmark"],
00145 "cnt" => $bench_rec["cnt"], "duration" => $bench_rec["avg_dur"],
00146 "min" => $bench_rec["min_dur"], "max" => $bench_rec["max_dur"]);
00147 }
00148 return $eva;
00149 }
00150
00151
00155 function getCurrentRecordNumber()
00156 {
00157 global $ilDB;
00158
00159 $q = "SELECT COUNT(*) AS cnt FROM benchmark";
00160 $cnt_set = $ilDB->query($q);
00161 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00162
00163 return $cnt_rec["cnt"];
00164 }
00165
00166
00170 function getMaximumRecords()
00171 {
00172 global $ilias;
00173
00174 return $ilias->getSetting("bench_max_records");
00175 }
00176
00177
00181 function setMaximumRecords($a_max)
00182 {
00183 global $ilias;
00184
00185 $ilias->setSetting("bench_max_records", (int) $a_max);
00186 }
00187
00188
00192 function isEnabled()
00193 {
00194 global $ilias;
00195
00196 return (boolean) $ilias->getSetting("enable_bench");
00197 }
00198
00199
00203 function enable($a_enable)
00204 {
00205 global $ilias;
00206
00207 if ($a_enable)
00208 {
00209 $ilias->setSetting("enable_bench", 1);
00210 }
00211 else
00212 {
00213 $ilias->setSetting("enable_bench", 0);
00214 }
00215 }
00216
00217
00221 function getMeasuredModules()
00222 {
00223 global $ilDB;
00224
00225 $q = "SELECT DISTINCT module FROM benchmark";
00226 $mod_set = $ilDB->query($q);
00227
00228 $modules = array();
00229 while ($mod_rec = $mod_set->fetchRow(DB_FETCHMODE_ASSOC))
00230 {
00231 $modules[$mod_rec["module"]] = $mod_rec["module"];
00232 }
00233
00234 return $modules;
00235 }
00236
00237 }
00238
00239 ?>