/** * Collate Xenon traces and publish to Redis. * * To use ArcLamp, pass this function as the callback parameter to * register_shutdown_function: * * <code> * require_once('ArcLamp.php'); * register_shutdown_function('ArcLamp\logXenonData', ['localhost', 6379]); * </code> * * @param Redis|array|string $redis A Redis instance, a Redis server name, * or an array of arguments for Redis::connect. */ function logXenonData($redis = 'localhost') { if (!extension_loaded('xenon')) { return; } $data = \HH\xenon_get_data(); if (!is_array($data) || !count($data)) { return; } if ($redis instanceof \Redis) { $conn = $redis; } else { $conn = new \Redis(); call_user_func_array(array($conn, 'connect'), (array) $redis); } if (!$conn) { return; } foreach (combineSamples($data) as $stack => $count) { $conn->publish('xenon', "{$stack} {$count}"); } }
}); } else { // 1:1000 request profiling // $wgProfiler = array( // 'class' => 'ProfilerXhprof', // 'exclude' => array( 'section.*', 'run_init*' ), // 'flags' => ( XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_NO_BUILTINS ), // 'output' => 'stats', // 'prefix' => 'xhprof', // 'sampling' => 10000, // ); } } if (extension_loaded('xenon') && ini_get('hhvm.xenon.period')) { register_shutdown_function(function () { $data = HH\xenon_get_data(); if (empty($data)) { return; } $entryPoint = basename($_SERVER['SCRIPT_NAME']); // Collate stack samples and fold into single lines. // This is the format expected by FlameGraph. $stacks = array(); foreach ($data as $sample) { $stack = array(); if (empty($sample['phpStack'])) { continue; } foreach ($sample['phpStack'] as $frame) { if ($frame['function'] === 'include') { // For file scope, just use the path as the name.