/** * @param DebugBar $debugBar */ public function __construct(DebugBar $debugBar) { if (!$debugBar->isDataPersisted()) { throw new DebugBarException("DebugBar must have a storage backend to use OpenHandler"); } $this->debugBar = $debugBar; }
/** * @param array $event */ public function _write($event) { $debugbar = DebugBar::getDebugBar(); if (!$debugbar) { return; } /* @var $messagesCollector DebugBar\DataCollector\MessagesCollector */ $messagesCollector = $debugbar['messages']; if (!$messagesCollector) { return; } $level = $event['priorityName']; // Gather info if (isset($event['message']['errstr'])) { $str = $event['message']['errstr']; $file = $event['message']['errfile']; $line = $event['message']['errline']; } else { $str = $event['message']['function']; $file = $event['message']['file']; $line = isset($event['message']['line']) ? $event['message']['line'] : 0; } $relfile = Director::makeRelative($file); // Save message $message = "{$level} - {$str} ({$relfile}:{$line})"; // Escape \ for proper js display $message = str_replace('\\', '\\\\', $message); $messagesCollector->addMessage($message, false); }
public function getUsage() { if (!function_exists('memcache_get_extended_stats')) { return false; } if ($this->usage === null) { $servers = DebugBar::getConfig('memcached'); $server = array_shift($servers); $memcache = memcache_connect($server['host'], $server['port']); if ($memcache === false) { return false; } foreach ($servers as $server) { memcache_add_server($memcache, $server['host'], $server['port']); } $stats = memcache_get_extended_stats($memcache); $memory_used = 0; $memory_total = 0; foreach ($stats as $host => $usage) { $memory_used += $usage['bytes']; $memory_total += $usage['limit_maxbytes']; $this->usage[$host] = array('Version' => $usage['version'], 'Uptime' => $this->formatSeconds($usage['uptime']), 'Total memory' => $this->formatBytes($usage['limit_maxbytes']), 'Used memory' => $this->formatBytes($usage['bytes']), 'Available memory' => $this->formatBytes($usage['limit_maxbytes'] - $usage['bytes']), 'Threads / second' => $this->formatNum($usage['total_connections'] / $usage['uptime']), 'Current threads' => $usage['curr_connections'], 'Queries / second' => $this->formatNum($usage['cmd_get'] / $usage['uptime']), 'Hits' => $usage['get_hits'] . ' (' . $this->formatNum($usage['get_hits'] * 100 / $usage['cmd_get']) . '%)', 'Misses' => $usage['get_misses'] . ' (' . $this->formatNum($usage['get_misses'] * 100 / $usage['cmd_get']) . '%)', 'Inserts' => $usage['cmd_set'], 'Deletes' => $usage['delete_hits'], 'Items' => $usage['curr_items']); } $this->percent_used = $this->formatNum($memory_used * 100 / $memory_total); } return $this->usage; }
/** * Collects data * * @param TimeDataCollector $timeCollector * @return array */ protected function collectData(TimeDataCollector $timeCollector = null) { $stmts = array(); $total_duration = 0; $total_mem = 0; $failed = 0; $i = 0; $queries = $this->db->getQueries(); $limit = DebugBar::config()->query_limit; $showDb = count(array_unique(array_map(function ($stmt) { return $stmt['database']; }, $queries))) > 1; foreach ($queries as $stmt) { $i++; $total_duration += $stmt['duration']; $total_mem += $stmt['memory']; if (!$stmt['success']) { $failed++; } if ($limit && $i > $limit) { $stmts[] = array('sql' => "Only the first {$limit} queries are shown"); break; } $stmts[] = array('sql' => $stmt['short_query'], 'row_count' => $stmt['rows'], 'params' => $stmt['select'] ? $stmt['select'] : null, 'duration' => $stmt['duration'], 'duration_str' => $this->getDataFormatter()->formatDuration($stmt['duration']), 'memory' => $stmt['memory'], 'memory_str' => $this->getDataFormatter()->formatBytes($stmt['memory']), 'is_success' => $stmt['success'], 'database' => $showDb ? $stmt['database'] : null, 'source' => $stmt['source']); if ($timeCollector !== null) { $timeCollector->addMeasure($stmt['short_query'], $stmt['start_time'], $stmt['end_time']); } } return array('nb_statements' => count($queries), 'nb_failed_statements' => $failed, 'statements' => $stmts, 'accumulated_duration' => $total_duration, 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($total_duration), 'memory_usage' => $total_mem, 'memory_usage_str' => $this->getDataFormatter()->formatBytes($total_mem)); }
public function getResources() { if ($this->resources === null) { $this->resources = array('Memory' => memory_get_usage(true) / 1024 . ' KB', 'Time' => $this->formatTime(microtime(true) - DebugBar::getInit()) . ' ms', 'Files' => count(get_included_files())); } return $this->resources; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // $d = ImageDataSet::findOrFail($id); \DebugBar::info($d->categories); //->get()); return view('app.dataset', ['title' => 'Dataset', 'dataset' => $d, 'categories' => $d->categories]); }
/** * @param MySQLDatabase $realConn */ public function __construct($realConn) { $this->realConn = $realConn; $this->connector = $this->connector ?: $realConn->getConnector(); $this->schemaManager = $this->schemaManager ?: $realConn->getSchemaManager(); $this->queryBuilder = $this->queryBuilder ?: $realConn->getQueryBuilder(); $this->queries = []; $this->findSource = DebugBar::config()->find_source; }
public function init() { DebugBar::withDebugBar(function (DebugBar\DebugBar $debugbar) { /* @var $timeData DebugBar\DataCollector\TimeDataCollector */ $timeData = $debugbar['time']; if (!$timeData) { return; } if ($timeData->hasStartedMeasure("cms_accessed")) { $timeData->stopMeasure("cms_accessed"); } $timeData->startMeasure("cms_init", "cms init"); }); }
public function index(SS_HTTPRequest $request) { if (!DebugBar::config()->enable_storage) { return $this->httpError(404, 'Storage not enabled'); } $debugbar = DebugBar::getDebugBar(); if (!$debugbar) { return $this->httpError(404, 'DebugBar not enabled'); } $openHandler = new DebugBar\OpenHandler($debugbar); $openHandler->handle(); exit; // Handle will echo and set headers }
/** * Filter executed AFTER a request * * @param SS_HTTPRequest $request Request container object * @param SS_HTTPResponse $response Response output object * @param DataModel $model Current DataModel * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional) */ public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) { $debugbar = DebugBar::getDebugBar(); if (!$debugbar) { return; } // All queries have been displayed if (DebugBar::getShowQueries()) { exit; } $script = DebugBar::renderDebugBar(); // If the bar is not renderable, return early if (!$script) { return; } // Inject init script into the HTML response $body = $response->getBody(); if (strpos($body, '</body>') !== false) { $body = str_replace('</body>', $script . '</body>', $body); $response->setBody($body); } // Ajax support if (Director::is_ajax() && !headers_sent()) { if (DebugBar::IsAdminUrl() && !DebugBar::config()->enabled_in_admin) { return; } // Skip anything that is not a GET request if (!$request->isGET()) { return; } // Always enable in admin because everything is mostly loaded through ajax if (DebugBar::config()->ajax || DebugBar::IsAdminUrl()) { $headers = $debugbar->getDataAsHeaders(); // Prevent throwing js errors in case header size is too large if (is_array($headers)) { $debugbar->sendDataInHeaders(); } } } }
public function getLogin() { var_dump('getLogin'); \DebugBar::error('Error!'); return view('auth.login')->with('title', 'Login'); }
public function getLogin() { \DebugBar::error('Error!'); return view('user.login'); }
public static function includeRequirements() { $debugbar = self::getDebugBar(); if (!$debugbar) { return; } // Already called if (self::$renderer) { return; } $renderer = $debugbar->getJavascriptRenderer(); // We don't need the true path since we are going to use Requirements API that appends the BASE_PATH $renderer->setBasePath(DEBUGBAR_DIR . '/assets'); $renderer->setBaseUrl(DEBUGBAR_DIR . '/assets'); $renderer->disableVendor('jquery'); $renderer->setEnableJqueryNoConflict(false); if (DebugBar::config()->enable_storage) { $renderer->setOpenHandlerUrl('__debugbar'); } foreach ($renderer->getAssets('css') as $cssFile) { Requirements::css(ltrim($cssFile, '/')); } foreach ($renderer->getAssets('js') as $jsFile) { Requirements::javascript(ltrim($jsFile, '/')); } self::$renderer = $renderer; }
public function setHidden($hidden) { self::$hidden = $hidden; }
| Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { print_r("Hello!"); $debug_var = ["1", "2", ["3"]]; var_dump($debug_var); DebugBar::info($debug_var); DebugBar::error('Error!'); DebugBar::warning('Watch out…'); DebugBar::addMessage('Another message', 'mylabel'); return view('app.index'); }); Route::group(['middleware' => ['auth', 'guest']], function () { Route::get('user/profile', function () { // Uses Auth Middleware }); }); Route::get('/dashboard', function (Request $request) { if (Auth::user()) { return view('app.dashboard')->with('title', 'Dashboard'); } else { $request->session()->flash('message', 'please login first'); return redirect("auth/login"); } });
/** * @param MySQLDatabase $realConn */ public function __construct($realConn) { $this->realConn = $realConn; $this->queries = []; $this->findSource = DebugBar::config()->find_source; }
/** @deprecated */ public static function addPanel(IBarPanel $panel, $id = NULL) { return self::$bar->addPanel($panel, $id); }
public function getNext($id) { // TODO: Delete unused 'count' $userid = $this->auth->user()->id; $batchId = $this->auth->user()->batch_id; $batch = \App\Batch::find($batchId); if ($batch == null) { \DebugBar::warning('$batch==null:'); $batch = $this->newBatch($id, $userid); $this->auth->user()->batch_id = $batch->id; $this->auth->user()->save(); } elseif ($batch->remain_count == 0) { \DebugBar::warning('$batch->remain_count == 0'); $standard = \App\StandardItem::find($batch->standard_item_id); // if user owns no valid batch or he/she has already done a batch $batch = $this->newBatch($id, $userid); if ($batch == null) { return view('tag.no_more', ['user' => $this->auth->user(), 'dataset' => \App\Dataset::find($id)]); } $this->auth->user()->batch_id = $batch->id; $this->auth->user()->save(); return view('tag.done', ['user' => $this->auth->user(), 'dataset' => \App\Dataset::find($id), 'standard' => $standard]); } $standard = \App\StandardItem::find($batch->standard_item_id); $items = $standard->Items; $item = $items[$batch->remain_count - 1]; return view('tag.tag', ['user' => $this->auth->user(), 'dataset' => \App\Dataset::find($id), 'standard' => $standard, 'batch' => $batch, 'item' => $item]); }
/** * Due to a bug, this is not always called before 4.0, * see https://github.com/silverstripe/silverstripe-framework/pull/5173 * * @param SS_HTTPRequest $request * @param string $action * @param mixed $result (only in v4.0) */ public function afterCallActionHandler($request, $action, $result) { self::clearBuffer(); $class = get_class($this->owner); DebugBar::withDebugBar(function (DebugBar\DebugBar $debugbar) use($class, $action) { /* @var $timeData DebugBar\DataCollector\TimeDataCollector */ $timeData = $debugbar['time']; if (!$timeData) { return; } if ($timeData->hasStartedMeasure("action")) { $timeData->stopMeasure("action"); } $timeData->startMeasure("after_action", "{$class} after action {$action}"); }); }