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