add($entry, $sizef, $timef, $errorf); } } private function fixCharset($action) { if (!is_string($action)) { return $action; } else { return is_utf8($action) ? $action : utf8_encode($action); } } private function add(array &$entry, $sizef = 'rows', $timef = 'exectime', $errorf = 'error') { $trace = array(); $trace['action'] = $this->fixCharset($entry['action']); unset($entry['action']); $trace['exectime'] = @$entry[$timef]; $this->totaltime += $trace['exectime']; unset($entry[$timef]); $trace['rows'] = @$entry[$sizef]; unset($entry[$sizef]); $trace['error'] = $this->fixCharset(@$entry[$errorf]); unset($entry[$errorf]); if ($trace['error']) { $this->error = true; } $trace['data'] = array($this->fixCharset($entry)); $this->traces[] =& $trace; } public function newEvent($action, $rows = 0, $error = null, array $userdata = array()) { $trace = array('action' => $this->fixCharset($action), 'time' => 0); $this->traces[] =& $trace; $this->update($rows, $error, $userdata); } public function start($action) { $this->traces[] = array('action' => $this->fixCharset($action), 'starttime' => microtime(true));; } public function stop($rows = 0, $error = null, array $userdata = array()) { $time = microtime(true); if (!$this->traces) { return; } $trace =& $this->traces[count($this->traces) - 1]; $trace['exectime'] = $time - $trace['starttime']; unset($trace['starttime']); $this->totaltime += $trace['exectime']; $this->update($rows, $error, $userdata); } public function update($rows = 0, $error = null, array $userdata = array()) { $trace =& $this->traces[count($this->traces) - 1]; $trace['rows'] = $rows; $trace['error'] = $this->fixCharset($error); array_walk_recursive($userdata, array($this, 'fixCharset')); $trace['data'] = $userdata; if ($trace['error']) { $this->error = true; } } public static function clean() { foreach (PlBacktrace::$bt as $name=>&$entry) { if (!$entry->traces) { unset(PlBacktrace::$bt[$name]); } } } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>