ILIAS  Release_5_0_x_branch Revision 61816
 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 33484 2012-03-02 17:23:45Z 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 222 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 306 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 169 of file class.ilBenchmark.php.

References $ilDB.

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

Get db benchmark records.

Parameters
@return

Definition at line 374 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 144 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 184 of file class.ilBenchmark.php.

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

get all current measured modules

Definition at line 240 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 262 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 281 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 206 of file class.ilBenchmark.php.

References $ilSetting.

Referenced by 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 $_GET, $_POST, $GLOBALS, $ilDB, $ilIliasIniFile, $ilUser, enableDbBench(), isDbBenchEnabled(), microtimeDiff(), ilUtil\shortenText(), and ilLog\write().

{
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);
}
// log slow requests
//define("LOG_SLOW_REQUESTS", (float) "0.1");
if (defined("SLOW_REQUEST_TIME") && SLOW_REQUEST_TIME > 0)
{
$t1 = explode(" ", $GLOBALS['ilGlobalStartTime']);
$t2 = explode(" ", microtime());
$diff = $t2[0] - $t1[0] + $t2[1] - $t1[1];
if ($diff > SLOW_REQUEST_TIME)
{
$diff = round($diff, 4);
include_once("./Services/Logging/classes/class.ilLog.php");
$slow_request_log = new ilLog(
$ilIliasIniFile->readVariable("log","slow_request_log_path"),
$ilIliasIniFile->readVariable("log","slow_request_log_file"),
CLIENT_ID);
$slow_request_log->write("SLOW REQUEST (".$diff."), Client:".CLIENT_ID.", GET: ".
str_replace("\n", " ", print_r($_GET, true)).", POST: ".
ilUtil::shortenText(str_replace("\n", " ", print_r($_POST, true)), 800, true));
}
}
}

+ Here is the call graph for this function:

ilBenchmark::setMaximumRecords (   $a_max)

set maximum number of benchmark records

Definition at line 195 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 335 of file class.ilBenchmark.php.

References $ilUser, 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 354 of file class.ilBenchmark.php.

References $ilUser, 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.


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