ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

References $DIC, and initSettins().

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
+ 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.

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

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.
+ Here is the call graph for this function:

◆ disableDbBenchmark()

ilBenchmark::disableDbBenchmark ( )

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

References ILIAS\Repository\settings().

Referenced by enableDbBenchmarkForUserName(), and save().

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  }
+ 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.

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

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)
+ 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.

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

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  }
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
ilDBInterface $db
+ Here is the call graph for this function:

◆ getDbBenchRecords()

ilBenchmark::getDbBenchRecords ( )

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

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

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  }
fetchAssoc(ilDBStatement $statement)
query(string $query)
Run a (read-only) Query on the database.
ilDBInterface $db
+ Here is the call graph for this function:

◆ initSettins()

ilBenchmark::initSettins ( )
private

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

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

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

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)
+ 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.

References retrieveDB().

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

85  : bool
86  {
87  return !is_null($this->retrieveDB());
88  }
+ 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.

References isDBavailable().

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

197  : bool
198  {
199  return $this->db_bechmark_enabled === true && $this->isDBavailable();
200  }
+ 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.

References retrieveUser().

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

98  : bool
99  {
100  return !is_null($this->retrieveUser());
101  }
+ 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.

Referenced by save().

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  }
+ Here is the caller graph for this function:

◆ retrieveDB()

ilBenchmark::retrieveDB ( )
private

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

References $db.

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

77  : ?ilDBInterface
78  {
79  if (!$this->db instanceof ilDBInterface && $this->dic->isDependencyAvailable('database')) {
80  $this->db = $this->dic->database();
81  }
82  return $this->db;
83  }
ilDBInterface $db
+ Here is the caller graph for this function:

◆ retrieveSetting()

ilBenchmark::retrieveSetting ( string  $keyword)
private

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

References ILIAS\Repository\settings().

Referenced by initSettins().

70  : ?string
71  {
72  return $this->settings !== null
73  ? $this->settings->get($keyword)
74  : null;
75  }
+ 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.

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

Referenced by isUserAvailable().

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  }
+ 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.

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

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  }
insert(string $table_name, array $values)
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
nextId(string $table_name)
ilDBInterface $db
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
microtimeDiff(string $t1, string $t2)
manipulate(string $query)
Run a (write) Query on the database.
+ 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.

Referenced by startDbBench().

129  : void
130  {
131  }
+ 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.

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

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
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
+ 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.

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

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  }
isDbBenchEnabled()
Check wether benchmarking is enabled or not.
string $temporary_sql_storage
+ 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

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

Referenced by retrieveDB().

◆ $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: