ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilBenchmark Class Reference

performance measurement class More...

+ Collaboration diagram for ilBenchmark:

Public Member Functions

 ilBenchmark ()
 constructor
 microtimeDiff ($t1, $t2)
 clearData ()
 delete all measurement data
 start ($a_module, $a_bench)
 start measurement
 stop ($a_module, $a_bench)
 stop measurement
 save ()
 save all measurements
 getEvaluation ($a_module)
 get performance evaluation data
 getCurrentRecordNumber ()
 get current number of benchmark records
 getMaximumRecords ()
 get maximum number of benchmark records
 setMaximumRecords ($a_max)
 set maximum number of benchmark records
 isEnabled ()
 check wether benchmarking is enabled or not
 enable ($a_enable)
 enable benchmarking
 getMeasuredModules ()
 get all current measured modules
 getMeasuredTime ($a_module, $a_bench)
 Get measurement.
 isDbBenchEnabled ()
 Check wether benchmarking is enabled or not.
 enableDbBench ($a_enable, $a_user=0)
 Enable DB benchmarking.
 startDbBench ($a_sql)
 start measurement
 stopDbBench ()
 stop measurement
 getDbBenchRecords ()
 Get db benchmark records.

Data Fields

 $bench = array()

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:
class.ilBenchmark.php 24074 2010-06-04 13:44:01Z akill

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

Member Function Documentation

ilBenchmark::clearData ( )

delete all measurement data

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

References $ilDB.

{
global $ilDB;
$q = "DELETE FROM benchmark";
$ilDB->manipulate($q);
}
ilBenchmark::enable (   $a_enable)

enable benchmarking

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

{
global $ilias;
if ($a_enable)
{
$ilias->setSetting("enable_bench", 1);
}
else
{
$ilias->setSetting("enable_bench", 0);
}
}
ilBenchmark::enableDbBench (   $a_enable,
  $a_user = 0 
)

Enable DB benchmarking.

Parameters
booleanenable db benchmarking
stringuser account name that should be benchmarked

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

Referenced by save().

{
global $ilias;
if ($a_enable)
{
$ilias->setSetting("enable_db_bench", 1);
if ($a_user !== 0)
{
$ilias->setSetting("db_bench_user", $a_user);
}
}
else
{
$ilias->setSetting("enable_db_bench", 0);
if ($a_user !== 0)
{
$ilias->setSetting("db_bench_user", $a_user);
}
}
}

+ Here is the caller graph for this function:

ilBenchmark::getCurrentRecordNumber ( )

get current number of benchmark records

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

References $ilDB.

Referenced by save().

{
global $ilDB;
$q = "SELECT COUNT(*) AS cnt FROM benchmark";
$cnt_set = $ilDB->query($q);
$cnt_rec = $ilDB->fetchAssoc($cnt_set);
return $cnt_rec["cnt"];
}

+ Here is the caller graph for this function:

ilBenchmark::getDbBenchRecords ( )

Get db benchmark records.

Parameters
@return

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

References $ilDB.

{
global $ilDB;
$set = $ilDB->query("SELECT * FROM benchmark");
$b = array();
while ($rec = $ilDB->fetchAssoc($set))
{
$b[] = array("sql" => $rec["sql_stmt"],
"time" => $rec["duration"]);
}
return $b;
}
ilBenchmark::getEvaluation (   $a_module)

get performance evaluation data

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

References $ilDB.

{
global $ilDB;
$q = "SELECT COUNT(*) AS cnt, AVG(duration) AS avg_dur, benchmark,".
" MIN(duration) AS min_dur, MAX(duration) AS max_dur".
" FROM benchmark".
" WHERE module = ".$ilDB->quote($a_module, "text")." ".
" GROUP BY benchmark".
" ORDER BY benchmark";
$bench_set = $ilDB->query($q);
$eva = array();
while($bench_rec = $ilDB->fetchAssoc($bench_set))
{
$eva[] = array("benchmark" => $bench_rec["benchmark"],
"cnt" => $bench_rec["cnt"], "duration" => $bench_rec["avg_dur"],
"min" => $bench_rec["min_dur"], "max" => $bench_rec["max_dur"]);
}
return $eva;
}
ilBenchmark::getMaximumRecords ( )

get maximum number of benchmark records

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

Referenced by save().

{
global $ilias;
return $ilias->getSetting("bench_max_records");
}

+ Here is the caller graph for this function:

ilBenchmark::getMeasuredModules ( )

get all current measured modules

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

References $ilDB.

{
global $ilDB;
$q = "SELECT DISTINCT module FROM benchmark";
$mod_set = $ilDB->query($q);
$modules = array();
while ($mod_rec = $ilDB->fetchAssoc($mod_set))
{
$modules[$mod_rec["module"]] = $mod_rec["module"];
}
return $modules;
}
ilBenchmark::getMeasuredTime (   $a_module,
  $a_bench 
)

Get measurement.

Returns
Measurement in milliseconds.

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

{
if (isset($this->bench[$a_module.":".$a_bench]))
{
return $this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1];
}
return false;
}
ilBenchmark::ilBenchmark ( )

constructor

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

{
}
ilBenchmark::isDbBenchEnabled ( )

Check wether benchmarking is enabled or not.

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

References $ilSetting.

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

{
global $ilSetting;
if (isset($this->db_enabled))
{
return $this->db_enabled;
}
if (!is_object($ilSetting))
{
return false;
}
$this->db_enabled = $ilSetting->get("enable_db_bench");
$this->db_enabled_user = $ilSetting->get("db_bench_user");
return $this->db_enabled;
}

+ Here is the caller graph for this function:

ilBenchmark::isEnabled ( )

check wether benchmarking is enabled or not

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

References $ilSetting.

Referenced by save(), start(), and stop().

{
global $ilSetting;
if (!is_object($ilSetting))
{
return true;
}
return (boolean) $ilSetting->get("enable_bench");
}

+ Here is the caller graph for this function:

ilBenchmark::microtimeDiff (   $t1,
  $t2 
)

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

Referenced by save(), and stop().

{
$t1 = explode(" ",$t1);
$t2 = explode(" ",$t2);
$diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
return $diff;
}

+ Here is the caller graph for this function:

ilBenchmark::save ( )

save all measurements

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

References $bench, $ilDB, enableDbBench(), getCurrentRecordNumber(), getMaximumRecords(), isDbBenchEnabled(), isEnabled(), and microtimeDiff().

{
global $ilDB, $ilUser;
if ($this->isDbBenchEnabled() && is_object($ilUser) &&
$this->db_enabled_user == $ilUser->getLogin())
{
if (is_array($this->db_bench) && is_object($ilDB))
{
$this->db_bench_stop_rec = true;
$ilDB->manipulate("DELETE FROM benchmark");
foreach ($this->db_bench as $b)
{
$ilDB->insert("benchmark", array(
"duration" => array("float", $this->microtimeDiff($b["start"], $b["stop"])),
"sql_stmt" => array("clob", $b["sql"])
));
}
}
$this->enableDbBench(false);
}
return;
if ($this->isEnabled() &&
{
foreach($this->bench as $key => $bench)
{
$bench_arr = explode(":", $key);
$bench_module = $bench_arr[0];
$benchmark = $bench_arr[1];
foreach($bench as $time)
{
$q = "INSERT INTO benchmark (cdate, duration, module, benchmark) VALUES ".
"(".
$ilDB->now().", ".
$ilDB->quote($time, "float").", ".
$ilDB->quote($bench_module, "text").", ".
$ilDB->quote($benchmark, "text").")";
$ilDB->manipulate($q);
}
}
$this->bench = array();
}
}

+ Here is the call graph for this function:

ilBenchmark::setMaximumRecords (   $a_max)

set maximum number of benchmark records

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

{
global $ilias;
$ilias->setSetting("bench_max_records", (int) $a_max);
}
ilBenchmark::start (   $a_module,
  $a_bench 
)

start measurement

Parameters
string$typemeasurement type
Returns
int measurement id

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

References isEnabled().

Referenced by startDbBench(), and stopDbBench().

{
return;
if ($this->isEnabled())
{
$this->bench[$a_module.":".$a_bench][] = microtime();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBenchmark::startDbBench (   $a_sql)

start measurement

Parameters
string$typemeasurement type
Returns
int measurement id

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

References isDbBenchEnabled(), and start().

{
global $ilUser;
if ($this->isDbBenchEnabled() && is_object($ilUser) &&
$this->db_enabled_user == $ilUser->getLogin() &&
!$this->db_bench_stop_rec)
{
$this->start = microtime();
$this->sql = $a_sql;
}
}

+ Here is the call graph for this function:

ilBenchmark::stop (   $a_module,
  $a_bench 
)

stop measurement

Parameters
int$midmeasurement id

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

References isEnabled(), and microtimeDiff().

{
return;
if ($this->isEnabled())
{
$this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1]
= $this->microtimeDiff($this->bench[$a_module.":".$a_bench][count($this->bench[$a_module.":".$a_bench]) - 1], microtime());
}
}

+ Here is the call graph for this function:

ilBenchmark::stopDbBench ( )

stop measurement

Parameters
int$midmeasurement id

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

References isDbBenchEnabled(), and start().

{
global $ilUser;
if ($this->isDbBenchEnabled() && is_object($ilUser) &&
$this->db_enabled_user == $ilUser->getLogin() &&
!$this->db_bench_stop_rec)
{
$this->db_bench[] =
array("start" => $this->start, "stop" => microtime(),
"sql" => $this->sql);
}
}

+ Here is the call graph for this function:

Field Documentation

ilBenchmark::$bench = array()

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

Referenced by save().


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