index 9d6517c3d3cf4d882bfc58987afd4303c96af44e..c9b7dd80f08fa379c1cbe4ec947a1665e7d65d6e 100644 (file)
static protected $lastHandle = NULL;
static protected $statsEnabled = FALSE;
+
+ static function prepareFloatForWriting($float){
+ return(floor($float * 1000));
+ }
+
+ static function prepareFloatForReading($int){
+ return($int / 1000);
+ }
+
static function getDatabaseHandle()
{
// Try to return last valid handle.
$TABLE_NAME = stats::$tableName;
$query = "DROP TABLE '{$TABLE_NAME}'";
$ret = sqlite_query($query, $handle);
+ stats::$lastHandle = NULL;
+ stats::getDatabaseHandle();
}
// Get database handle, if it is invalid (NULL) return without creating stats
$res = stats::getDatabaseHandle();
+# stats::dropTable($res);
if(!$res) return;
// Ensure that 'clicks' and 'overallRenderTimer' are present and set correctly,
// -- 'clicks' is a counter wich is set in main.php -> Number of page reloads
// -- 'overallRenderTimer' is set in main.php -> timestamp of rendering start.
if(!isset($clicks) || empty($clicks)) $clicks = 0;
- if(!isset($overallRenderTimer) || empty($overallRenderTimer)){
+ if(!isset($overallRenderTimer)){
$renderTime = 0;
}else{
$renderTime = microtime(TRUE) - $overallRenderTimer;
$overallRenderTimer = microtime(TRUE);
}
+ $duration = stats::prepareFloatForWriting($duration);
+ $renderTime = stats::prepareFloatForWriting($renderTime);
+
// Prepare values to be useable within a database
$uuid = $config->getGOsaUUID();
$type = sqlite_escape_string($type);
$info = sqlite_escape_string($info);
$clicks = sqlite_escape_string($clicks);
$memory_usage = sqlite_escape_string(stats::get_memory_usage());
- $cpu_load = sqlite_escape_string(stats::get_cpu_load());
+ $cpu_load = sqlite_escape_string(sprintf("%0.6f",stats::get_cpu_load()));
// Clean up category, which usally comes from acl_category and may still contain
// some special chars like /
'{$memory_usage}','{$cpu_load}','{$info}')";
sqlite_query($query, $res);
}
-
+
+
+ /*! \brief |
+ * @param |
+ * @return |
+ */
+ static function dumpTables($from = NULL, $to = NULL)
+ {
+ // Get database connection
+ $TABLE_NAME = stats::$tableName;
+ $handle = stats::getDatabaseHandle();
+ if(!$handle) return;
+
+ // Build up filter to limit dumped entries to the given range.
+ $tim = "";
+ if($from != NULL){
+ $from = sqlite_escape_string($from);
+ $tim.= "AND TIMESTAMP >= '{$from}' ";
+ }
+ if($to != NULL){
+ $to = sqlite_escape_string($to);
+ $tim.= "AND TIMESTAMP <= '{$to}' ";
+ }
+ $tim = preg_replace("/^AND /"," WHERE ",$tim);
+
+ // Create Filter and start query
+ $filter = "SELECT * FROM {$TABLE_NAME}{$tim}";
+ $ret = sqlite_array_query($filter, $handle, SQLITE_ASSOC);
+ return($ret);
+ }
+
/*! \brief |
* @param |
*/
static function show()
{
+
+ stats::dumpTables();
+
+ return;
+
$res = stats::getDatabaseHandle();
+# stats::dropTable($res);
if(!$res) return;
$TABLE_NAME = stats::$tableName;
}
echo sqlite_error_string($ret);
+
+ echo "\n------ \n";
+ echo "Rendertime per plugin\n";
+ echo "------ \n";
+
+ $query = "
+ SELECT PLUGIN, RENDER_TIME AS RM
+ FROM {$TABLE_NAME}
+ GROUP BY PLUGIN
+ ORDER BY RM DESC
+ LIMIT 10
+ ";
+ $ret = sqlite_query($query, $res);
+
+ $colSize = 16;
+ $title = FALSE;
+ foreach(sqlite_fetch_all($ret) as $entry){
+ foreach($entry as $key => $str){
+ if(is_numeric($key)) continue;
+ echo str_pad($str,$colSize,' ')."|";
+ }
+ echo "\n";
+ }
+ echo sqlite_error_string($ret);
+
echo "</pre>";
}
}