Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
tweaks to the command line profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Feb 6, 2014
1 parent b518890 commit b7e4d34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 18 additions & 3 deletions CommandListener.php
Expand Up @@ -108,7 +108,19 @@ private function isProfileOption(ConsoleCommandEvent $event)
public function onCommand(ConsoleCommandEvent $event)
{
$command = $event->getCommand()->getName();
if ('list' == $command || 'help' == $command) {
$system = array(
'list',
'help',
'assetic:dump',
'assets:install',
'config:dump-reference',
'container:debug',
'router:debug',
'cache:clear',
'cache:warmup',
'cache:create-cache-class',
);
if (in_array($command, $system)) {
return;
}
if ('off' == $this->mode ||
Expand All @@ -122,7 +134,10 @@ public function onCommand(ConsoleCommandEvent $event)
}
}

$this->collector->startProfiling();

if ($this->collector->startProfiling()) {
$event->getOutput()->writeln("XHProf starting run\n---");
}
}

/**
Expand All @@ -141,7 +156,7 @@ public function onTerminate(ConsoleTerminateEvent $event)


$event->getOutput()->writeln(sprintf(
"\n\n---\nXHProf run link <info>%s</info>",
"\n---\nXHProf run link <info>%s</info>",
$this->collector->getXhprofUrl()
));
}
Expand Down
6 changes: 5 additions & 1 deletion DataCollector/XhprofCollector.php
Expand Up @@ -51,11 +51,13 @@ public function collect(Request $request, Response $response, \Exception $except

/**
* Start profiling with probability according to sample size.
*
* @return boolean whether profiling was started or not.
*/
public function startProfiling()
{
if (mt_rand(1, $this->container->getParameter('jns_xhprof.sample_size')) != 1) {
return;
return false;
}

$this->collecting = true;
Expand All @@ -64,6 +66,8 @@ public function startProfiling()
if ($this->logger) {
$this->logger->debug('Enabled XHProf');
}

return true;
}

/**
Expand Down

0 comments on commit b7e4d34

Please sign in to comment.