/** * Generate image according to DOT script. This function will spawn a process * with "dot" command and pipe the "dot_script" to it and pipe out the * generated image content. * * @param dot_script, string, the script for DOT to generate the image. * @param type, one of the supported image types, see * $xhprof_legal_image_types. * @returns, binary content of the generated image on success. empty string on * failure. * * @author cjiang */ function xhprof_generate_image_by_dot($dot_script, $type) { $errorFile = ERROR_FILE; $tmpDirectory = TMP_DIRECTORY; $dotBinary = DOT_BINARY; // detect windows if (stristr(PHP_OS, 'WIN') && !stristr(PHP_OS, 'Darwin')) { return xhprof_generate_image_by_dot_on_win($dot_script, $type, $errorFile, $tmpDirectory, $dotBinary); } // parts of the original source $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $errorFile, "a")); $cmd = ' "' . $dotBinary . '" -T' . $type; $process = proc_open($cmd, $descriptorspec, $pipes, $tmpDirectory, array()); if (is_resource($process)) { fwrite($pipes[0], $dot_script); fclose($pipes[0]); $output = stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($process); if ($output == "" && filesize($errorFile) > 0) { die("Error producing callgraph, check {$errorFile}"); } return $output; } print "failed to shell execute cmd=\"{$cmd}\"\n"; exit; }
/** * Generate image according to DOT script. This function will spawn a process * with "dot" command and pipe the "dot_script" to it and pipe out the * generated image content. * * @param dot_script, string, the script for DOT to generate the image. * @param type, one of the supported image types, see * $xhprof_legal_image_types. * @returns, binary content of the generated image on success. empty string on * failure. * * @author cjiang */ function xhprof_generate_image_by_dot($dot_script, $type) { // get config => yep really dirty - but unobstrusive global $_xhprof; $errorFile = $_xhprof['dot_errfile']; $tmpDirectory = $_xhprof['dot_tempdir']; $dotBinary = $_xhprof['dot_binary']; // detect windows if (stristr(PHP_OS, 'WIN') && !stristr(PHP_OS, 'Darwin')) { return xhprof_generate_image_by_dot_on_win($dot_script, $type, $errorFile, $tmpDirectory, $dotBinary); } // parts of the original source $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", $errorFile, "a")); $cmd = ' "' . $dotBinary . '" -T' . $type; $process = proc_open($cmd, $descriptorspec, $pipes, $tmpDirectory, array()); if (is_resource($process)) { fwrite($pipes[0], $dot_script); fclose($pipes[0]); $output = stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($process); if ($output == "" && filesize($errorFile) > 0) { die("Error producing callgraph, check {$errorFile}"); } return $output; } print "failed to shell execute cmd=\"{$cmd}\"\n"; exit; }