• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilBenchmark.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004     +-----------------------------------------------------------------------------+
00005     | ILIAS open source                                                           |
00006     +-----------------------------------------------------------------------------+
00007     | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00008     |                                                                             |
00009     | This program is free software; you can redistribute it and/or               |
00010     | modify it under the terms of the GNU General Public License                 |
00011     | as published by the Free Software Foundation; either version 2              |
00012     | of the License, or (at your option) any later version.                      |
00013     |                                                                             |
00014     | This program is distributed in the hope that it will be useful,             |
00015     | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016     | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017     | GNU General Public License for more details.                                |
00018     |                                                                             |
00019     | You should have received a copy of the GNU General Public License           |
00020     | along with this program; if not, write to the Free Software                 |
00021     | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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         SELECT module, benchmark, COUNT(*) AS cnt, AVG(duration) AS avg_dur FROM benchmark
00124         GROUP BY module, benchmark ORDER BY module, benchmark
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 ?>

Generated on Fri Dec 13 2013 09:06:33 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1