ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBenchmarkTableGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
27 
31  public function __construct(
32  ?object $a_parent_obj,
33  string $a_parent_cmd,
34  array $a_records,
35  protected string $mode = "chronological"
36  ) {
37  global $DIC;
38 
39  $this->ctrl = $DIC->ctrl();
40  $this->lng = $DIC->language();
41  $this->access = $DIC->access();
42  $ilCtrl = $DIC->ctrl();
43  $lng = $DIC->language();
44  $ilAccess = $DIC->access();
45  $lng = $DIC->language();
46 
47  parent::__construct($a_parent_obj, $a_parent_cmd);
48  $this->setLimit(9999);
49 
50  switch ($this->mode) {
51  case "slowest_first":
52  $this->setData(ilArrayUtil::sortArray($a_records, "time", "desc", true));
53  $this->setTitle($lng->txt("adm_db_bench_slowest_first"));
54  $this->addColumn($this->lng->txt("adm_time"));
55  $this->addColumn($this->lng->txt("adm_sql"));
56  break;
57 
58  case "sorted_by_sql":
59  $this->setData(ilArrayUtil::sortArray($a_records, "sql", "asc"));
60  $this->setTitle($lng->txt("adm_db_bench_sorted_by_sql"));
61  $this->addColumn($this->lng->txt("adm_time"));
62  $this->addColumn($this->lng->txt("adm_sql"));
63  break;
64 
65  case "by_first_table":
66  $this->setData($this->getDataByFirstTable($a_records));
67  $this->setTitle($lng->txt("adm_db_bench_by_first_table"));
68  $this->addColumn($this->lng->txt("adm_time"));
69  $this->addColumn($this->lng->txt("adm_nr_statements"));
70  $this->addColumn($this->lng->txt("adm_table"));
71  break;
72 
73  default:
74  $this->setData($a_records);
75  $this->setTitle($lng->txt("adm_db_bench_chronological"));
76  $this->addColumn($this->lng->txt("adm_time"));
77  $this->addColumn($this->lng->txt("adm_sql"));
78  break;
79  }
80 
81  $this->setEnableHeader(true);
82  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
83  $this->setRowTemplate("tpl.db_bench.html", "Modules/SystemFolder");
84  $this->disable("footer");
85  $this->setEnableTitle(true);
86  }
87 
91  public function getFirst(string $a_str, array $a_needles): int
92  {
93  $pos = 0;
94  foreach ($a_needles as $needle) {
95  $pos2 = strpos($a_str, (string) $needle);
96 
97  if ($pos2 > 0 && ($pos2 < $pos || $pos === 0)) {
98  $pos = $pos2;
99  }
100  }
101 
102  return $pos;
103  }
104 
108  public function extractFirstTableFromSQL(string $a_sql): string
109  {
110  $pos1 = $this->getFirst(strtolower($a_sql), ["from ", "from\n", "from\t", "from\r"]);
111 
112  $table = "";
113  if ($pos1 > 0) {
114  $tablef = substr(strtolower($a_sql), $pos1 + 5);
115  $pos2 = $this->getFirst($tablef, [" ", "\n", "\t", "\r"]);
116  $table = $pos2 > 0 ? substr($tablef, 0, $pos2) : $tablef;
117  }
118  if (trim($table) !== "") {
119  return $table;
120  }
121 
122  return "";
123  }
124 
128  public function getDataByFirstTable(array $a_records): array
129  {
130  $data = [];
131  foreach ($a_records as $r) {
132  $table = $this->extractFirstTableFromSQL($r["sql"]);
133  if (trim($table) === '') {
134  continue;
135  }
136  $data[$table]["table"] = $table;
137  if (!isset($data[$table]["cnt"])) {
138  $data[$table]["cnt"] = 1;
139  } else {
140  $data[$table]["cnt"]++;
141  }
142  if (!isset($data[$table]["time"])) {
143  $data[$table]["time"] = $r["time"];
144  } else {
145  $data[$table]["time"] += $r["time"];
146  }
147  }
148  if ($data !== []) {
149  return ilArrayUtil::sortArray($data, "time", "desc", true);
150  }
151 
152  return $data;
153  }
154 
158  protected function fillRow(array $a_set): void
159  {
160  $lng = $this->lng;
161 
162  switch ($this->mode) {
163  case "by_first_table":
164  $this->tpl->setCurrentBlock("td");
165  $this->tpl->setVariable("VAL", $a_set["table"]);
166  $this->tpl->parseCurrentBlock();
167  $this->tpl->setVariable("VAL1", $a_set["time"]);
168  $this->tpl->setVariable("VAL2", $a_set["cnt"]);
169  break;
170 
171  case "slowest_first":
172  case "sorted_by_sql":
173  default:
174  $this->tpl->setVariable("VAL1", $a_set["time"]);
175  $this->tpl->setVariable("VAL2", $a_set["sql"]);
176  break;
177  }
178  }
179 }
extractFirstTableFromSQL(string $a_sql)
Extract first table from sql.
setData(array $a_data)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
fillRow(array $a_set)
Fill table row.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLanguage $lng
getDataByFirstTable(array $a_records)
Get data by first table.
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(?object $a_parent_obj, string $a_parent_cmd, array $a_records, protected string $mode="chronological")
Constructor.
setLimit(int $a_limit=0, int $a_default_limit=0)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
disable(string $a_module_name)
getFirst(string $a_str, array $a_needles)
Get first occurence of string.
setEnableHeader(bool $a_enableheader)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
$r