ILIAS  release_8 Revision v8.24
ilBenchmark Class Reference

Class ilBenchmark. More...

+ Collaboration diagram for ilBenchmark:

Public Member Functions

 __construct ()
 Constructor. More...
 
 clearData ()
 delete all measurement data More...
 
 start (string $a_module, string $a_bench)
 start measurement More...
 
 stop (string $a_module, string $a_bench)
 stop measurement More...
 
 save ()
 save all measurements More...
 
 isDbBenchEnabled ()
 Check wether benchmarking is enabled or not. More...
 
 enableDbBenchmarkForUserName (?string $a_user)
 
 disableDbBenchmark ()
 
 startDbBench (string $a_sql)
 start measurement More...
 
 stopDbBench ()
 
 getDbBenchRecords ()
 

Data Fields

const DB_BENCH_USER = "db_bench_user"
 
const ENABLE_DB_BENCH = "enable_db_bench"
 

Private Member Functions

 initSettins ()
 
 retrieveSetting (string $keyword)
 
 retrieveDB ()
 
 isDBavailable ()
 
 retrieveUser ()
 
 isUserAvailable ()
 
 microtimeDiff (string $t1, string $t2)
 
 getCurrentRecordNumber ()
 get current number of benchmark records More...
 

Private Attributes

ilDBInterface $db = null
 
ilSetting $settings = null
 
ilObjUser $user = null
 
Container $dic
 
string $start = ''
 
string $temporary_sql_storage = ''
 
array $collected_db_benchmarks = []
 
bool $stop_db_recording = false
 
int $bench_max_records
 
bool $db_bechmark_enabled = null
 
int $db_bechmark_user_id = null
 

Detailed Description

Class ilBenchmark.

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

Constructor & Destructor Documentation

◆ __construct()

ilBenchmark::__construct ( )

Constructor.

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

49 {
50 global $DIC;
51 $this->dic = $DIC;
52 $this->initSettins();
53 $this->bench_max_records = 2000;//(int) ($this->retrieveSetting("bench_max_records") ?? 0);
54 }
global $DIC
Definition: feed.php:28

References $DIC, and initSettins().

+ Here is the call graph for this function:

Member Function Documentation

◆ clearData()

ilBenchmark::clearData ( )

delete all measurement data

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

114 : void
115 {
116 if ($this->isDBavailable()) {
117 $db = $this->retrieveDB();
118 if ($db !== null) {
119 $db->manipulate("DELETE FROM benchmark");
120 }
121 }
122 }
ilDBInterface $db
manipulate(string $query)
Run a (write) Query on the database.

References $db, isDBavailable(), ilDBInterface\manipulate(), and retrieveDB().

+ Here is the call graph for this function:

◆ disableDbBenchmark()

ilBenchmark::disableDbBenchmark ( )

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

218 : void
219 {
220 $this->db_bechmark_enabled = false;
221 $this->settings->set(self::ENABLE_DB_BENCH, '0');
222 $this->db_bechmark_user_id = null;
223 $this->settings->set(self::DB_BENCH_USER, '0');
224 }

References ILIAS\Repository\settings().

Referenced by enableDbBenchmarkForUserName(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enableDbBenchmarkForUserName()

ilBenchmark::enableDbBenchmarkForUserName ( ?string  $a_user)

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

202 : void
203 {
204 if ($a_user === null) {
205 $this->disableDbBenchmark();
206 return;
207 }
208 $this->initSettins();
209 $this->db_bechmark_enabled = true;
210 $this->settings->set(self::ENABLE_DB_BENCH, '1');
211
212 $user_id = ilObjUser::_lookupId($a_user);
213
214 $this->db_bechmark_user_id = $user_id;
215 $this->settings->set(self::DB_BENCH_USER, (string) $user_id);
216 }
static _lookupId($a_user_str)

References ilObjUser\_lookupId(), disableDbBenchmark(), initSettins(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ getCurrentRecordNumber()

ilBenchmark::getCurrentRecordNumber ( )
private

get current number of benchmark records

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

175 : int
176 {
177 if ($this->isDBavailable()) {
178 $db = $this->retrieveDB();
179 if ($db !== null) {
180 $cnt_set = $db->query("SELECT COUNT(*) AS cnt FROM benchmark");
181 $cnt_rec = $db->fetchAssoc($cnt_set);
182 return (int) $cnt_rec["cnt"];
183 }
184 }
185 return 0;
186 }
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)

References $db, ilDBInterface\fetchAssoc(), isDBavailable(), ilDBInterface\query(), and retrieveDB().

+ Here is the call graph for this function:

◆ getDbBenchRecords()

ilBenchmark::getDbBenchRecords ( )

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

259 : array
260 {
261 if ($this->isDBavailable()) {
262 $db = $this->retrieveDB();
263 if ($db !== null) {
264 $set = $db->query("SELECT * FROM benchmark");
265 $b = [];
266 while ($rec = $db->fetchAssoc($set)) {
267 $b[] = [
268 "sql" => $rec["sql_stmt"],
269 "time" => $rec["duration"]
270 ];
271 }
272 return $b;
273 }
274 }
275 return [];
276 }

References Vendor\Package\$b, $db, ilDBInterface\fetchAssoc(), isDBavailable(), ilDBInterface\query(), and retrieveDB().

+ Here is the call graph for this function:

◆ initSettins()

ilBenchmark::initSettins ( )
private

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

56 : void
57 {
58 if (!$this->settings instanceof ilSetting) {
59 $global_settings_available = $this->dic->isDependencyAvailable('settings');
60 if ($global_settings_available) {
61 $this->settings = $this->dic->settings();
62
63 $this->db_bechmark_enabled = (bool) ($this->retrieveSetting(self::ENABLE_DB_BENCH) ?? false);
64 $user_id = $this->retrieveSetting(self::DB_BENCH_USER);
65 $this->db_bechmark_user_id = $user_id !== null ? (int) $user_id : null;
66 }
67 }
68 }
retrieveSetting(string $keyword)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ILIAS\Repository\int(), retrieveSetting(), and ILIAS\Repository\settings().

Referenced by __construct(), enableDbBenchmarkForUserName(), and startDbBench().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDBavailable()

ilBenchmark::isDBavailable ( )
private

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

85 : bool
86 {
87 return !is_null($this->retrieveDB());
88 }

References retrieveDB().

Referenced by clearData(), getCurrentRecordNumber(), getDbBenchRecords(), isDbBenchEnabled(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDbBenchEnabled()

ilBenchmark::isDbBenchEnabled ( )

Check wether benchmarking is enabled or not.

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

197 : bool
198 {
199 return $this->db_bechmark_enabled === true && $this->isDBavailable();
200 }

References isDBavailable().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isUserAvailable()

ilBenchmark::isUserAvailable ( )
private

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

98 : bool
99 {
100 return !is_null($this->retrieveUser());
101 }

References retrieveUser().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ microtimeDiff()

ilBenchmark::microtimeDiff ( string  $t1,
string  $t2 
)
private

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

103 : string
104 {
105 $partials1 = explode(" ", $t1);
106 $partials2 = explode(" ", $t2);
107
108 return (string) ((float) $partials2[0] - (float) $partials1[0] + (float) $partials2[1] - (float) $partials1[1]);
109 }

Referenced by save().

+ Here is the caller graph for this function:

◆ retrieveDB()

ilBenchmark::retrieveDB ( )
private

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

78 {
79 if (!$this->db instanceof ilDBInterface && $this->dic->isDependencyAvailable('database')) {
80 $this->db = $this->dic->database();
81 }
82 return $this->db;
83 }
Interface ilDBInterface.

References $db.

Referenced by clearData(), getCurrentRecordNumber(), getDbBenchRecords(), isDBavailable(), and save().

+ Here is the caller graph for this function:

◆ retrieveSetting()

ilBenchmark::retrieveSetting ( string  $keyword)
private

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

70 : ?string
71 {
72 return $this->settings !== null
73 ? $this->settings->get($keyword)
74 : null;
75 }

References ILIAS\Repository\settings().

Referenced by initSettins().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveUser()

ilBenchmark::retrieveUser ( )
private

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

90 : ?ilObjUser
91 {
92 if (!$this->user instanceof ilObjUser && $this->dic->isDependencyAvailable('user')) {
93 $this->user = $this->dic->user();
94 }
95 return $this->user;
96 }
User class.

References $user, and ILIAS\Repository\user().

Referenced by isUserAvailable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBenchmark::save ( )

save all measurements

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

145 : void
146 {
147 if (!$this->isDBavailable() || !$this->isUserAvailable()) {
148 return;
149 }
150 if ($this->isDbBenchEnabled()
151 && $this->db_bechmark_user_id === $this->user->getId()) {
152 if (is_array($this->collected_db_benchmarks)) {
153 $this->stop_db_recording = true;
154
155 $db = $this->retrieveDB();
156 if ($db !== null) {
157 $db->manipulate("DELETE FROM benchmark");
158 foreach ($this->collected_db_benchmarks as $b) {
159 $id = $db->nextId('benchmark');
160 $db->insert("benchmark", [
161 "id" => ["integer", $id],
162 "duration" => ["float", $this->microtimeDiff($b["start"], $b["stop"])],
163 "sql_stmt" => ["clob", $b["sql"]]
164 ]);
165 }
166 }
167 }
168 $this->disableDbBenchmark();
169 }
170 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
microtimeDiff(string $t1, string $t2)
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
insert(string $table_name, array $values)
nextId(string $table_name)

References Vendor\Package\$b, $db, $id, disableDbBenchmark(), ilDBInterface\insert(), isDBavailable(), isDbBenchEnabled(), isUserAvailable(), ilDBInterface\manipulate(), microtimeDiff(), ilDBInterface\nextId(), retrieveDB(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ start()

ilBenchmark::start ( string  $a_module,
string  $a_bench 
)

start measurement

Deprecated:

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

129 : void
130 {
131 }

Referenced by startDbBench().

+ Here is the caller graph for this function:

◆ startDbBench()

ilBenchmark::startDbBench ( string  $a_sql)

start measurement

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

229 : void
230 {
231 $this->initSettins();
232 if (
233 !$this->stop_db_recording
234 && $this->isDbBenchEnabled()
235 && $this->isUserAvailable()
236 && $this->db_bechmark_user_id === $this->user->getId()
237 ) {
238 $this->start = (string) microtime();
239 $this->temporary_sql_storage = $a_sql;
240 }
241 }
start(string $a_module, string $a_bench)
start measurement

References initSettins(), isDbBenchEnabled(), isUserAvailable(), start(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ stop()

ilBenchmark::stop ( string  $a_module,
string  $a_bench 
)

stop measurement

Deprecated:

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

138 : void
139 {
140 }

◆ stopDbBench()

ilBenchmark::stopDbBench ( )

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

243 : bool
244 {
245 if (
246 !$this->stop_db_recording
247 && $this->isDbBenchEnabled()
248 && $this->isUserAvailable()
249 && $this->db_bechmark_user_id === $this->user->getId()
250 ) {
251 $this->collected_db_benchmarks[] = ["start" => $this->start, "stop" => (string) microtime(), "sql" => $this->temporary_sql_storage];
252
253 return true;
254 }
255
256 return false;
257 }
string $temporary_sql_storage

References $start, $temporary_sql_storage, isDbBenchEnabled(), isUserAvailable(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Field Documentation

◆ $bench_max_records

int ilBenchmark::$bench_max_records
private

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

◆ $collected_db_benchmarks

array ilBenchmark::$collected_db_benchmarks = []
private

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

◆ $db

ilDBInterface ilBenchmark::$db = null
private

◆ $db_bechmark_enabled

bool ilBenchmark::$db_bechmark_enabled = null
private

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

◆ $db_bechmark_user_id

int ilBenchmark::$db_bechmark_user_id = null
private

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

◆ $dic

Container ilBenchmark::$dic
private

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

◆ $settings

ilSetting ilBenchmark::$settings = null
private

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

◆ $start

string ilBenchmark::$start = ''
private

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

Referenced by stopDbBench().

◆ $stop_db_recording

bool ilBenchmark::$stop_db_recording = false
private

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

◆ $temporary_sql_storage

string ilBenchmark::$temporary_sql_storage = ''
private

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

Referenced by stopDbBench().

◆ $user

ilObjUser ilBenchmark::$user = null
private

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

Referenced by retrieveUser().

◆ DB_BENCH_USER

const ilBenchmark::DB_BENCH_USER = "db_bench_user"

◆ ENABLE_DB_BENCH

const ilBenchmark::ENABLE_DB_BENCH = "enable_db_bench"

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