ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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

 initSettings ()
 
 retrieveSetting (string $keyword)
 
 retrieveDB ()
 
 isDBavailable ()
 
 retrieveUser ()
 
 isUserAvailable ()
 
 microtimeDiff (string $t1, string $t2)
 

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

47 {
48 global $DIC;
49 $this->dic = $DIC instanceof Container ? $DIC : null;
50 $this->initSettings();
51 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
global $DIC
Definition: shib_login.php:26

References $DIC, and initSettings().

+ Here is the call graph for this function:

Member Function Documentation

◆ clearData()

ilBenchmark::clearData ( )

delete all measurement data

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

115 : void
116 {
117 if ($this->isDBavailable()) {
118 $db = $this->retrieveDB();
119 if ($db !== null) {
120 $db->manipulate("DELETE FROM benchmark");
121 }
122 }
123 }
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 203 of file class.ilBenchmark.php.

203 : void
204 {
205 $this->db_bechmark_enabled = false;
206 $this->settings->set(self::ENABLE_DB_BENCH, '0');
207 $this->db_bechmark_user_id = null;
208 $this->settings->set(self::DB_BENCH_USER, '0');
209 }

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

187 : void
188 {
189 if ($a_user === null) {
190 $this->disableDbBenchmark();
191 return;
192 }
193 $this->initSettings();
194 $this->db_bechmark_enabled = true;
195 $this->settings->set(self::ENABLE_DB_BENCH, '1');
196
198
199 $this->db_bechmark_user_id = $user_id;
200 $this->settings->set(self::DB_BENCH_USER, (string) $user_id);
201 }
static _lookupId(string|array $a_user_str)

References $user_id, ilObjUser\_lookupId(), disableDbBenchmark(), initSettings(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ getDbBenchRecords()

ilBenchmark::getDbBenchRecords ( )

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

244 : array
245 {
246 if ($this->isDBavailable()) {
247 $db = $this->retrieveDB();
248 if ($db !== null) {
249 $set = $db->query("SELECT * FROM benchmark");
250 $b = [];
251 while ($rec = $db->fetchAssoc($set)) {
252 $b[] = [
253 "sql" => $rec["sql_stmt"],
254 "time" => $rec["duration"]
255 ];
256 }
257 return $b;
258 }
259 }
260 return [];
261 }
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)

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

+ Here is the call graph for this function:

◆ initSettings()

ilBenchmark::initSettings ( )
private

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

53 : void
54 {
55 if ($this->dic === null) {
56 return;
57 }
58
59 if (!$this->settings instanceof ilSetting) {
60 $global_settings_available = $this->dic->isDependencyAvailable('settings');
61 if ($global_settings_available) {
62 $this->settings = $this->dic->settings();
63
64 $this->db_bechmark_enabled = (bool) ($this->retrieveSetting(self::ENABLE_DB_BENCH) ?? false);
65 $user_id = $this->retrieveSetting(self::DB_BENCH_USER);
66 $this->db_bechmark_user_id = $user_id !== null ? (int) $user_id : null;
67 }
68 }
69 }
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 86 of file class.ilBenchmark.php.

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

References retrieveDB().

Referenced by clearData(), 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 182 of file class.ilBenchmark.php.

182 : bool
183 {
184 return $this->db_bechmark_enabled === true && $this->isDBavailable();
185 }

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

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

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

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

Referenced by save().

+ Here is the caller graph for this function:

◆ retrieveDB()

ilBenchmark::retrieveDB ( )
private

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

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

References $db.

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

+ Here is the caller graph for this function:

◆ retrieveSetting()

ilBenchmark::retrieveSetting ( string  $keyword)
private

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

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

References ILIAS\Repository\settings().

Referenced by initSettings().

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

◆ retrieveUser()

ilBenchmark::retrieveUser ( )
private

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

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

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

130 : void
131 {
132 }

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

214 : void
215 {
216 $this->initSettings();
217 if (
218 !$this->stop_db_recording
219 && $this->isDbBenchEnabled()
220 && $this->isUserAvailable()
221 && $this->db_bechmark_user_id === $this->user->getId()
222 ) {
223 $this->start = microtime();
224 $this->temporary_sql_storage = $a_sql;
225 }
226 }
start(string $a_module, string $a_bench)
start measurement

References initSettings(), 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 139 of file class.ilBenchmark.php.

139 : void
140 {
141 }

◆ stopDbBench()

ilBenchmark::stopDbBench ( )

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

228 : bool
229 {
230 if (
231 !$this->stop_db_recording
232 && $this->isDbBenchEnabled()
233 && $this->isUserAvailable()
234 && $this->db_bechmark_user_id === $this->user->getId()
235 ) {
236 $this->collected_db_benchmarks[] = ["start" => $this->start, "stop" => microtime(), "sql" => $this->temporary_sql_storage];
237
238 return true;
239 }
240
241 return false;
242 }
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

◆ $collected_db_benchmarks

array ilBenchmark::$collected_db_benchmarks = []
private

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

◆ $db

ilDBInterface ilBenchmark::$db = null
private

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

Referenced by clearData(), getDbBenchRecords(), retrieveDB(), and save().

◆ $db_bechmark_enabled

bool ilBenchmark::$db_bechmark_enabled = null
private

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

◆ $db_bechmark_user_id

int ilBenchmark::$db_bechmark_user_id = null
private

Definition at line 41 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"

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

Referenced by ilObjBenchmarkGUI\settings(), and ilObjBenchmarkGUI\update().

◆ ENABLE_DB_BENCH

const ilBenchmark::ENABLE_DB_BENCH = "enable_db_bench"

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

Referenced by ilObjBenchmarkGUI\settings(), and ilObjBenchmarkGUI\update().


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