Example #1
0
Run traces defined for a project in a caperfile

Usage: run [--show-class-names] [<script>...]

Reads configuration from caper.yml (see `caper help caperfile`
for more information) and runs 

DOCOPT;
$options = caper_opt_handle($usage);
$cwd = getcwd();
$configFile = "{$cwd}/caper.yml";
if (!file_exists($configFile)) {
    die("Config file not found\n");
}
$showClassNames = $options['--show-class-names'];
$config = \Caper\Config::fromYaml(file_get_contents($configFile), $cwd);
$runner = new \Caper\Trace\Runner();
$parser = new \Caper\Trace\Parser();
caper_header($cli);
scripts:
if ($options['<script>']) {
    foreach ($options['<script>'] as $script) {
        $cli->bold()->cyan()->out("Running script: {$script}")->br();
        $runner->run($config, $script);
    }
} else {
    $cli->bold()->cyan()->out("Running all scripts")->br();
    $runner->runAll($config);
}
parse:
$collector = new \Caper\Stack\Collector($config, $parser);
Example #2
0
    foreach ($options['<file>'] as $file) {
        $handle = fopen_arg($file, 'r');
        foreach ($parser->stackIterator($handle) as list($traceId, $popped, $stack)) {
            $out = (array) $popped;
            $out['trace'] = $traceId;
            $out['stack'] = $stack;
            $out['file'] = $file;
            echo json_encode($out) . "\n";
        }
    }
} elseif ($options['calls']) {
    $withSignatures = true;
    $showClassNames = $options['--show-class-names'];
    $cwd = getcwd();
    if ($options['--config']) {
        $config = \Caper\Config::fromYaml(file_get_contents($options['--config']), $cwd);
    } else {
        // TODO: config from args
        $filter = new \Caper\Filter();
        $filter->add(true, 'namespace', []);
        $config = new \Caper\Config($cwd, $filter);
        $withSignatures = false;
    }
    $traceFiles = $options['<file>'];
    parse:
    $collector = new \Caper\Stack\Collector($config, $parser);
    $cli->br()->bold()->cyan()->out("Parsing trace (this may take a while)")->br();
    foreach ($traceFiles as $file) {
        $collector->collect($file);
    }
    if ($withSignatures) {