public function __construct(DataContainer $data) { $this->data = $data; $panels = Config::get('panels'); include __DIR__ . '/../../../panels.php'; $this->panels = Panels::getValidPanels($panels, $this->data->getCollectorProvides()); }
/** * Register the service provider. * * @return void */ public function register() { $in_app_file = $this->app['path'] . '/config/packages/' . $this->packageName . '/profiler.php'; Config::init(file_exists($in_app_file) ? $in_app_file : null); // Stopwatch - must be registered so the application doesn't fail if the profiler is disabled $this->app['stopwatch'] = $this->app->share(function () { return new Stopwatch(defined('LARAVEL_START') ? LARAVEL_START * 1000 : null); }); // Must be enabled for the current environment if (!in_array($this->app->environment(), Config::get('environments'))) { return; } // Time collection is done anyway $this->collectors = new DataContainer(); $this->collectors->add(new TimeDataCollector()); // this will be executed anyway $this->app->after(array($this, 'onCloseHeaders')); $this->app['stopwatch']->start('Application initialisation.', 'section'); // Laravel 4.1 has a new routing layer, some stuff is different $is_4_0 = class_exists('\\Illuminate\\Routing\\Controllers\\Controller'); // Collect $this->collectors->add(new MonologDataCollector())->add(new FilesDataCollector())->add(new DatabaseDataCollector())->add(new VariablesDataCollector())->add($is_4_0 ? new RouterDataCollector() : new Router41DataCollector()); $this->app->before(array($this->collectors, 'register')); // Populate timeline if ($this->app->isBooted()) { $this->onBooting(); } else { $this->app->booting(array($this, 'onBooting')); } $this->app->booted(array($this, 'onBooted')); $this->app->before(array($this, 'onBefore')); $this->app->after(array($this, 'onAfter')); }
/** * @return mixed get the data to be serialized */ public function getData() { $queries = $duplicates = array(); $queryTotals = array('count' => 0, 'time' => 0); if (count(DB::getConnections())) { $threshold = Config::get('slow_query'); foreach (DB::getQueryLog() as $query) { $queryTotals['count'] += 1; //base informations $query['sql'] = str_replace("\n", '', $query['query']); $queryTotals['time'] += $query['time']; //duplicate queries $query['sql_simplified'] = $this->simplifiedQuery($query['sql']); if (array_key_exists($query['sql_simplified'], $duplicates)) { $duplicates[$query['sql_simplified']]['time'] += $query['time']; $duplicates[$query['sql_simplified']]['qty']++; } else { $duplicates[$query['sql_simplified']] = array('time' => $query['time'], 'qty' => 1); } if ($query['time'] >= $threshold) { $query['slow'] = 'slow'; } //TODO :: slow query threshold //TODO :: implement "explain" $queries[] = $query; } } foreach ($duplicates as $query => $duplicate) { if ($duplicate['qty'] == 1) { unset($duplicates[$query]); } } return array('database' => array('queries' => $queries, 'duplicates' => $duplicates, 'popup' => array('Total Queries' => $queryTotals['count'], 'Total Time' => Utils::getReadableTime($queryTotals['time'])))); }
<?php } ?> </div> <?php } ?> </div> </div> <?php if (Config::get('assets_auto', true)) { ?> <?php if (Config::get('assets_minified', true)) { ?> <script src="<?php echo asset('packages/onigoetz/profiler/js/script.min.js'); ?> "> </script> <link rel="stylesheet" href="<?php echo asset('packages/onigoetz/profiler/css/style.min.css'); ?> " /> <?php } else { ?> <script src="<?php echo asset('packages/onigoetz/profiler/js/script.js'); ?>