ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 = 2000
 
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();//(int) ($this->retrieveSetting("bench_max_records") ?? 0);
53 }
global $DIC
Definition: shib_login.php:26

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 113 of file class.ilBenchmark.php.

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

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

Referenced by ilObjSystemFolderGUI\clearBenchObject().

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

◆ disableDbBenchmark()

ilBenchmark::disableDbBenchmark ( )

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

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

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 201 of file class.ilBenchmark.php.

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

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

174 : int
175 {
176 if ($this->isDBavailable()) {
177 $db = $this->retrieveDB();
178 if ($db !== null) {
179 $cnt_set = $db->query("SELECT COUNT(*) AS cnt FROM benchmark");
180 $cnt_rec = $db->fetchAssoc($cnt_set);
181 return (int) $cnt_rec["cnt"];
182 }
183 }
184 return 0;
185 }
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 258 of file class.ilBenchmark.php.

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

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

Referenced by ilObjSystemFolderGUI\benchmarkSubTabs(), and ilObjSystemFolderGUI\showDbBenchResults().

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

◆ initSettins()

ilBenchmark::initSettins ( )
private

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

55 : void
56 {
57 if (!$this->settings instanceof ilSetting) {
58 $global_settings_available = $this->dic->isDependencyAvailable('settings');
59 if ($global_settings_available) {
60 $this->settings = $this->dic->settings();
61
62 $this->db_bechmark_enabled = (bool) ($this->retrieveSetting(self::ENABLE_DB_BENCH) ?? false);
63 $user_id = $this->retrieveSetting(self::DB_BENCH_USER);
64 $this->db_bechmark_user_id = $user_id !== null ? (int) $user_id : null;
65 }
66 }
67 }
retrieveSetting(string $keyword)
ILIAS Setting Class.

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

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

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 196 of file class.ilBenchmark.php.

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

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 97 of file class.ilBenchmark.php.

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

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 102 of file class.ilBenchmark.php.

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

Referenced by save().

+ Here is the caller graph for this function:

◆ retrieveDB()

ilBenchmark::retrieveDB ( )
private

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

77 {
78 if (!$this->db instanceof ilDBInterface && $this->dic->isDependencyAvailable('database')) {
79 $this->db = $this->dic->database();
80 }
81 return $this->db;
82 }
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 69 of file class.ilBenchmark.php.

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

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 89 of file class.ilBenchmark.php.

89 : ?ilObjUser
90 {
91 if (!$this->user instanceof ilObjUser && $this->dic->isDependencyAvailable('user')) {
92 $this->user = $this->dic->user();
93 }
94 return $this->user;
95 }
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 144 of file class.ilBenchmark.php.

144 : void
145 {
146 if (!$this->isDBavailable() || !$this->isUserAvailable()) {
147 return;
148 }
149 if ($this->isDbBenchEnabled()
150 && $this->db_bechmark_user_id === $this->user->getId()) {
151 if (is_array($this->collected_db_benchmarks)) {
152 $this->stop_db_recording = true;
153
154 $db = $this->retrieveDB();
155 if ($db !== null) {
156 $db->manipulate("DELETE FROM benchmark");
157 foreach ($this->collected_db_benchmarks as $b) {
158 $id = $db->nextId('benchmark');
159 $db->insert("benchmark", [
160 "id" => ["integer", $id],
161 "duration" => ["float", $this->microtimeDiff($b["start"], $b["stop"])],
162 "sql_stmt" => ["clob", $b["sql"]]
163 ]);
164 }
165 }
166 }
167 $this->disableDbBenchmark();
168 }
169 }
$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 128 of file class.ilBenchmark.php.

128 : void
129 {
130 }

Referenced by ilObjQuestionPool\exportXMLPageObjects(), and startDbBench().

+ Here is the caller graph for this function:

◆ startDbBench()

ilBenchmark::startDbBench ( string  $a_sql)

start measurement

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

228 : void
229 {
230 $this->initSettins();
231 if (
232 !$this->stop_db_recording
233 && $this->isDbBenchEnabled()
234 && $this->isUserAvailable()
235 && $this->db_bechmark_user_id === $this->user->getId()
236 ) {
237 $this->start = (string) microtime();
238 $this->temporary_sql_storage = $a_sql;
239 }
240 }
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 137 of file class.ilBenchmark.php.

137 : void
138 {
139 }

◆ stopDbBench()

ilBenchmark::stopDbBench ( )

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

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