ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBenchmarkTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16 
20  function __construct($a_parent_obj, $a_parent_cmd, $a_records, $a_mode = "chronological")
21  {
22  global $ilCtrl, $lng, $ilAccess, $lng;
23 
24  parent::__construct($a_parent_obj, $a_parent_cmd);
25  $this->setLimit(9999);
26  $this->mode = $a_mode;
27 
28  switch ($this->mode)
29  {
30  case "slowest_first":
31  $this->setData(ilUtil::sortArray($a_records, "time", "desc", true));
32  $this->setTitle($lng->txt("adm_db_bench_slowest_first"));
33  $this->addColumn($this->lng->txt("adm_time"));
34  $this->addColumn($this->lng->txt("adm_sql"));
35  break;
36 
37  case "sorted_by_sql":
38  $this->setData(ilUtil::sortArray($a_records, "sql", "asc"));
39  $this->setTitle($lng->txt("adm_db_bench_sorted_by_sql"));
40  $this->addColumn($this->lng->txt("adm_time"));
41  $this->addColumn($this->lng->txt("adm_sql"));
42  break;
43 
44  case "by_first_table":
45  $this->setData($this->getDataByFirstTable($a_records));
46  $this->setTitle($lng->txt("adm_db_bench_by_first_table"));
47  $this->addColumn($this->lng->txt("adm_time"));
48  $this->addColumn($this->lng->txt("adm_nr_statements"));
49  $this->addColumn($this->lng->txt("adm_table"));
50  break;
51 
52  default:
53  $this->setData($a_records);
54  $this->setTitle($lng->txt("adm_db_bench_chronological"));
55  $this->addColumn($this->lng->txt("adm_time"));
56  $this->addColumn($this->lng->txt("adm_sql"));
57  break;
58 
59  }
60 
61  $this->setEnableHeader(true);
62  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
63  $this->setRowTemplate("tpl.db_bench.html", "Modules/SystemFolder");
64  $this->disable("footer");
65  $this->setEnableTitle(true);
66 
67 // $this->addMultiCommand("", $lng->txt(""));
68 // $this->addCommandButton("", $lng->txt(""));
69  }
70 
77  function getFirst($a_str, $a_needles)
78  {
79  $pos = 0;
80  foreach ($a_needles as $needle)
81  {
82  $pos2 = strpos($a_str, $needle);
83 
84  if ($pos2 > 0 && ($pos2 < $pos || $pos == 0))
85  {
86  $pos = $pos2;
87  }
88  }
89 
90  return $pos;
91  }
92 
99  function extractFirstTableFromSQL($a_sql)
100  {
101  $pos1 = $this->getFirst(strtolower($a_sql), array("from ", "from\n", "from\t", "from\r"));
102 
103  $table = "";
104  if ($pos1 > 0)
105  {
106  $tablef = substr(strtolower($a_sql), $pos1+5);
107  $pos2 = $this->getFirst($tablef, array(" ", "\n", "\t", "\r"));
108  if ($pos2 > 0)
109  {
110  $table =substr($tablef, 0, $pos2);
111  }
112  else
113  {
114  $table = $tablef;
115  }
116  }
117  if (trim($table) != "")
118  {
119  return $table;
120  }
121 
122  return "";
123  }
124 
125 
132  function getDataByFirstTable($a_records)
133  {
134  $data = array();
135  foreach ($a_records as $r)
136  {
137  $table = $this->extractFirstTableFromSQL($r["sql"]);
138  $data[$table]["table"] = $table;
139  $data[$table]["cnt"]++;
140  $data[$table]["time"] += $r["time"];
141  }
142  if (count($data) > 0)
143  {
144  $data = ilUtil::sortArray($data, "time", "desc", true);
145  }
146 
147  return $data;
148  }
149 
153  protected function fillRow($a_set)
154  {
155  global $lng;
156 
157  switch ($this->mode)
158  {
159  case "by_first_table":
160  $this->tpl->setCurrentBlock("td");
161  $this->tpl->setVariable("VAL", $a_set["table"]);
162  $this->tpl->parseCurrentBlock();
163  $this->tpl->setVariable("VAL1", $a_set["time"]);
164  $this->tpl->setVariable("VAL2", $a_set["cnt"]);
165  break;
166 
167  case "slowest_first":
168  case "sorted_by_sql":
169  default:
170  $this->tpl->setVariable("VAL1", $a_set["time"]);
171  $this->tpl->setVariable("VAL2", $a_set["sql"]);
172  break;
173  }
174  }
175 
176 }
177 ?>