public function handle(Request $request, Response $response) { $headers = array_change_key_case($request->getHeaders(), CASE_LOWER); // Only enable when the X-Blackfire-Query header is present if (!isset($headers['x-blackfire-query'])) { return array(); } $probe = new \BlackfireProbe($headers['x-blackfire-query']); // Stop if it failed if (!$probe->enable()) { return array(); } // Stop profiling once the request ends $response->on('end', array($probe, 'close')); // Return the header $header = explode(':', $probe->getResponseLine(), 2); return array('x-' . $header[0] => $header[1]); }
<?php /* * This file is part of the Blackfire SDK package. * * (c) SensioLabs <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ if (!class_exists('BlackfireProbe', false) && !extension_loaded('blackfire')) { require __DIR__ . '/BlackfireProbe.php'; BlackfireProbe::getMainInstance(); }
/** * @internal */ private function profilerDisable() { self::$profilerIsEnabled = false; if (is_string($this->profiler)) { $p = $this->profiler . '_disable'; $this->debug($p); return $p(); } elseif (is_array($this->profiler)) { $this->debug('data array profiler_disable'); return $this->profiler; } else { $this->info('No profiler to disable'); return array(); } }
public static function pause($timerName) { if (!self::$_enabled) { return; } $time = microtime(true); // Get current time as quick as possible to make more accurate calculations if (empty(self::$_timers[$timerName])) { self::reset($timerName); } if (false !== self::$_timers[$timerName]['start']) { self::$_timers[$timerName]['sum'] += $time - self::$_timers[$timerName]['start']; self::$_timers[$timerName]['start'] = false; if (self::$_memory_get_usage) { self::$_timers[$timerName]['realmem'] += memory_get_usage(true) - self::$_timers[$timerName]['realmem_start']; self::$_timers[$timerName]['emalloc'] += memory_get_usage() - self::$_timers[$timerName]['emalloc_start']; } } $probeName = filter_input(INPUT_GET, 'probe', FILTER_SANITIZE_STRING); $probeName = rawurldecode($probeName); if (in_array($timerName, explode(',', $probeName))) { $probe = BlackfireProbe::getMainInstance(); $probe->disable(); } }