public function after() { $firebugEnabled = ProfilerToolbar::cfg('firebug.enabled'); $firebugShowEverywhere = ProfilerToolbar::cfg('firebug.showEverywhere'); if ($this->request->is_initial() && $firebugEnabled && $firebugShowEverywhere) { ProfilerToolbar::firebug(); } }
echo View::factory('PTB/items/sql')->render(); } ?> <?php if (ProfilerToolbar::cfg('html.showCache')) { echo View::factory('PTB/items/cache')->render(); } ?> <?php if (ProfilerToolbar::cfg('html.showVars')) { echo View::factory('PTB/items/vars')->render(); } ?> <?php if (ProfilerToolbar::cfg('html.showRoutes')) { echo View::factory('PTB/items/route')->render(); } ?> <?php if (ProfilerToolbar::cfg('html.showIncFiles')) { echo View::factory('PTB/items/files')->render(); } ?> <?php if (ProfilerToolbar::cfg('html.showCustom')) { echo View::factory('PTB/items/custom')->render(); } ?> </div> </div> <!-- ============================= /PROFILER TOOLBAR ============================= -->
/** * Set a value to cache with id and lifetime * * $data = 'bar'; * * // Set 'bar' to 'foo' in default group, using default expiry * Cache::instance()->set('foo', $data); * * // Set 'bar' to 'foo' in default group for 30 seconds * Cache::instance()->set('foo', $data, 30); * * // Set 'bar' to 'foo' in memcache group for 10 minutes * if (Cache::instance('memcache')->set('foo', $data, 600)) * { * // Cache was set successfully * return * } * * @param string id of cache entry * @param string data to set to cache * @param integer lifetime in seconds * @return boolean */ public function set($id, $data, $lifetime = 3600) { // for ProfilerToolbar ProfilerToolbar::cacheLog('set', array_search($this, Cache::$instances), $id, $lifetime); // /for ProfilerToolbar return $this->memcached_instance->set($id, $data, $lifetime); }
?> </head> <body> <div class="wrapper"> <div class="header"><?php echo $header; ?> </div> <div class="middle"> <div class="container"> <div class="content"><?php echo $content; ?> </div> </div> <div class="right-sidebar"><?php echo $sidebar; ?> </div> </div> </div> <div class="footer"><?php echo $footer; ?> </div> <?php ProfilerToolbar::render(true); ?> </body> </html>
/** * Delete a cache entry based on id * * @param string id * @param integer timeout [Optional] * @return boolean * @throws Cache_Exception */ public function delete($id) { // for ProfilerToolbar ProfilerToolbar::cacheLog('del', array_search($this, Cache::$instances), $id); // /for ProfilerToolbar // Prepare statement $statement = $this->_db->prepare('DELETE FROM caches WHERE id = :id'); // Remove the entry try { $statement->execute(array(':id' => $this->_sanitize_id($id))); } catch (PDOException $e) { throw new Cache_Exception('There was a problem querying the local SQLite3 cache. :error', array(':error' => $e->getMessage())); } return (bool) $statement->rowCount(); }
/** * */ private static function appendIncFiles() { self::$_fb->group('Files (' . self::$DATA_INC_FILES['total']['count'] . ')', ['Collapsed' => true]); $tbl = [0 => ['№', 'file', 'size', 'lines', 'last modified']]; $num = 0; foreach (self::$DATA_INC_FILES['data'] as $file) { $tbl[] = [++$num, $file['name'], ProfilerToolbar::formatMemory($file['size']), number_format($file['lines']), date("Y.m.d H:i:s", $file['lastModified'])]; } self::$_fb->table('Files', $tbl); self::$_fb->groupEnd(); }
</td> </tr> <?php } ?> <tr class="total"> <td></td> <td>total <?php echo $group['total']['count']; ?> queries</td> <td></td> <td class="tRight"><?php echo ProfilerToolbar::formatTime($group['total']['time']); ?> </td> <td class="tRight"><?php echo ProfilerToolbar::formatMemory($group['total']['memory']); ?> </td> </tr> </tbody> </table> </div> <?php } ?> <?php } ?> </div>
public function query($type, $sql, $as_object = FALSE, array $params = NULL) { // Make sure the database is connected $this->_connection or $this->connect(); if (Kohana::$profiling && stripos($sql, 'explain') !== 0) { // Benchmark this query for the current instance $benchmark = Profiler::start("Database ({$this->_instance})", $sql); } if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== Database_MySQL::$_current_databases[$this->_connection_id]) { // Select database on persistent connections $this->_select_db($this->_config['connection']['database']); } // Execute the query if (($result = mysql_query($sql, $this->_connection)) === FALSE) { if (isset($benchmark)) { // This benchmark is worthless Profiler::delete($benchmark); } throw new Database_Exception(':error [ :query ]', array(':error' => mysql_error($this->_connection), ':query' => $sql), mysql_errno($this->_connection)); } if (isset($benchmark)) { Profiler::stop($benchmark); } // Set the last query $this->last_query = $sql; if ($type === Database::SELECT) { // Return an iterator of results $res = new Database_MySQL_Result($result, $sql, $as_object, $params); if (stripos($sql, 'explain') !== 0) { ProfilerToolbar::setSqlData($this->_instance, $sql, $res->count()); } return $res; } elseif ($type === Database::INSERT) { // Return a list of insert id and rows created $res = array(mysql_insert_id($this->_connection), mysql_affected_rows($this->_connection)); ProfilerToolbar::setSqlData($this->_instance, $sql, $res[1]); return $res; } else { // Return the number of rows affected $res = mysql_affected_rows($this->_connection); ProfilerToolbar::setSqlData($this->_instance, $sql, $res); return $res; } }
public function after() { if ($this->request->is_initial() && ProfilerToolbar::cfg('firebug.enabled') && ProfilerToolbar::cfg('firebug.showEverywhere')) { ProfilerToolbar::firebug(); } }
<th>№</th> <th style="width: 1px;">key</th> <th>value</th> </tr> </thead> <tbody> <?php $i = 0; foreach (ProfilerToolbar::$DATA_SERVER as $k => $v) { ?> <tr> <td class="num"><?php echo ++$i; ?> </td> <td><?php echo $k; ?> </td> <td><?php echo ProfilerToolbar::varDump($v); ?> </td> </tr> <?php } ?> </tbody> </table> </div> </div>
public function query($type, $sql, $as_object = FALSE, array $params = NULL) { // Make sure the database is connected $this->_connection or $this->connect(); if (Kohana::$profiling) { // Benchmark this query for the current instance $benchmark = Profiler::start("Database ({$this->_instance})", $sql); } try { $result = $this->_connection->query($sql); // add query to PTB ProfilerToolbar::setSqlData($this->_instance, $sql, $result->rowCount()); } catch (Exception $e) { if (isset($benchmark)) { // This benchmark is worthless Profiler::delete($benchmark); } // Convert the exception in a database exception throw new Database_Exception(':error [ :query ]', array(':error' => $e->getMessage(), ':query' => $sql), $e->getCode()); } if (isset($benchmark)) { Profiler::stop($benchmark); } // Set the last query $this->last_query = $sql; if ($type === Database::SELECT) { // Convert the result into an array, as PDOStatement::rowCount is not reliable if ($as_object === FALSE) { $result->setFetchMode(PDO::FETCH_ASSOC); } elseif (is_string($as_object)) { $result->setFetchMode(PDO::FETCH_CLASS, $as_object, $params); } else { $result->setFetchMode(PDO::FETCH_CLASS, 'stdClass'); } $result = $result->fetchAll(); // Return an iterator of results return new Database_Result_Cached($result, $sql, $as_object, $params); } elseif ($type === Database::INSERT) { // Return a list of insert id and rows created return array($this->_connection->lastInsertId(), $result->rowCount()); } else { // Return the number of rows affected return $result->rowCount(); } }
function var_echo($var, $tab = 'default') { ProfilerToolbar::addData($var, $tab); }
<?php echo date("Y.m.d", $file['lastModified']); ?> <?php echo date("H:i:s", $file['lastModified']); ?> </td> </tr> <?php } ?> <tr class="total"> <th></th> <th>total <?php echo ProfilerToolbar::$DATA_INC_FILES['total']['count']; ?> files</th> <th class="tRight"><?php echo ProfilerToolbar::formatMemory(ProfilerToolbar::$DATA_INC_FILES['total']['size']); ?> </th> <th class="tRight"><?php echo number_format(ProfilerToolbar::$DATA_INC_FILES['total']['lines']); ?> </th> <th></th> </tr> </tbody> </table> </div> </div>
/** * @param string $method method of PDOStatement to be called * @param mixed $mode parameters to be passed to the method * @param array $params input parameters (name=>value) for the SQL execution. This is an alternative * to {@link bindParam} and {@link bindValue}. If you have multiple input parameters, passing * them in this way can improve the performance. Note that if you pass parameters in this way, * you cannot bind parameters or values using {@link bindParam} or {@link bindValue}, and vice versa. * Please also note that all values are treated as strings in this case, if you need them to be handled as * their real data types, you have to use {@link bindParam} or {@link bindValue} instead. * @throws Exception if CDbCommand failed to execute the SQL statement * @return mixed the method execution result */ private function queryInternal($method, $mode, $params = []) { $params = array_merge($this->params, $params); if ($this->_connection->enableParamLogging && ($pars = array_merge($this->_paramLog, $params)) !== []) { $p = []; foreach ($pars as $name => $value) { $p[$name] = $name . '=' . var_export($value, true); } $par = '. Bound with ' . implode(', ', $p); } else { $par = ''; } //var_echo('Querying SQL: ' . $this->getText() . $par, 'system.db.CDbCommand'); if ($this->_connection->queryCachingCount > 0 && $method !== '' && $this->_connection->queryCachingDuration > 0 && $this->_connection->queryCacheID !== false) { #TODO Сделать систему кеширования Sql запросов /*$this->_connection->queryCachingCount--; $cacheKey='yii:dbquery'.$this->_connection->connectionString.':'.$this->_connection->username; $cacheKey.=':'.$this->getText().':'.serialize(array_merge($this->_paramLog,$params)); if(($result=$cache->get($cacheKey))!==false) { var_echo('Query result found in cache','system.db.CDbCommand'); return $result[0]; }*/ } try { if (\Kohana::$profiling and $this->_connection->enableProfiling) { // Benchmark this query for the current instance //var_dump($this->getText()); foreach ($params as $item) { //var_echo($item); } //str_replace('') $benchmark = \Profiler::start("Database ('default')", $this->Debug($this->getText(), $this->_paramLog) . $par); } $this->prepare(); if ($params === []) { $this->_statement->execute(); } else { $this->_statement->execute($params); } if ($method === '') { $result = new DataReader($this); } else { $mode = (array) $mode; call_user_func_array([$this->_statement, 'setFetchMode'], $mode); $result = $this->_statement->{$method}(); $this->_statement->closeCursor(); } if (\Kohana::$profiling and $this->_connection->enableProfiling) { //var_dump($this->getText()); \ProfilerToolbar::setSqlData('default', $this->Debug($this->getText(), $this->_paramLog), sizeof($result)); } if (isset($cache, $cacheKey)) { \Cache::instance('database')->set($this->getText(), $result, $this->_connection->caching); } return $result; } catch (Exception $e) { if (isset($benchmark)) { // This benchmark is worthless \Profiler::delete($benchmark); } $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $message = $e->getMessage(); \Kohana::$log->add(\Log::EMERGENCY, '\\Database\\Command::' . $method . ' failed ' . $message . '. The SQL statement executed was: ' . $this->getText() . $par); if (\Kohana::DEVELOPMENT) { $message .= '. The SQL statement executed was: ' . $this->getText() . $par; } throw new Exception('\\Database\\Command failed to execute the SQL statement: ' . $message, (int) $e->getCode(), $errorInfo); } }
/** * Delete a cache entry based on id * // Delete the 'foo' cache entry immediately * Cache::instance('memcache')->delete('foo'); * // Delete the 'bar' cache entry after 30 seconds * Cache::instance('memcache')->delete('bar', 30); * @param string $id id of entry to delete * @param integer $timeout timeout of entry, if zero item is deleted immediately, otherwise the item will delete after the specified value in seconds * @return boolean */ public function delete($id, $timeout = 0) { // for ProfilerToolbar ProfilerToolbar::cacheLog('del', array_search($this, Cache::$instances), $id); // /for ProfilerToolbar // Delete the id return $this->_memcache->delete($this->_sanitize_id($id), $timeout); }
<?php defined('SYSPATH') or die('No direct script access.'); // include vendor FireBug if (ProfilerToolbar::cfg('firebug.enabled') && !class_exists('FirePHP')) { require_once Kohana::find_file('vendor/FirePHPCore', 'FirePHP.class', 'php'); } // include vendor GeShi for code highlight if (!class_exists('GeSHi') && (ProfilerToolbar::cfg('html.highlightSQL') || ProfilerToolbar::cfg('errorPage.highlightSQL') || ProfilerToolbar::cfg('errorPage.highlightPHP'))) { require_once Kohana::find_file('vendor/geshi', 'geshi', 'php'); }
/** * Delete a cache entry based on id * // Delete 'foo' entry from the apc group * Cache::instance('apc')->delete('foo'); * @param string $id id to remove from cache * @return boolean */ public function delete($id) { // for ProfilerToolbar ProfilerToolbar::cacheLog('del', array_search($this, Cache::$instances), $id); // /for ProfilerToolbar return apc_delete($this->_sanitize_id($id)); }
/** * Delete a cache entry based on id * * // Delete 'foo' entry from the file group * Cache::instance('file')->delete('foo'); * * @param string id to remove from cache * @return boolean */ public function delete($id) { // for ProfilerToolbar ProfilerToolbar::cacheLog('del', array_search($this, Cache::$instances), $id); // /for ProfilerToolbar $filename = Cache_File::filename($this->_sanitize_id($id)); $directory = $this->_resolve_directory($filename); return $this->_delete_file(new SplFileInfo($directory . $filename), NULL, TRUE); }
<tr> <th>№</th> <th>var</th> </tr> </thead> <?php $i = 0; foreach ($v as $item) { ?> <tr> <td class="num"><?php echo ++$i; ?> </td> <td><?php echo ProfilerToolbar::varDump($item); ?> </td> </tr> <?php } ?> </table> </div> <?php } ?> <?php }
?> " class="collapsed"> <table cellspacing="0"> <?php foreach ($GLOBALS[$var] as $key => $value) { ?> <tr> <td><code><?php echo htmlspecialchars((string) $key, ENT_QUOTES, Kohana::$charset, TRUE); ?> </code></td> <td><pre><?php echo Debug::dump($value); ?> </pre></td> </tr> <?php } ?> </table> </div> <?php } ?> </div> </div> <?php if (Kohana::$profiling and Kohana::$environment == Kohana::DEVELOPMENT or true) { echo ProfilerToolbar::render(); }