Skip to content

Commit

Permalink
stats: added refresh rate option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Mar 4, 2013
1 parent fbc9f4c commit 534e70e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Bstools/Command/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

class Stats extends Base
{
private $refreshRate = 50000;
private $refreshRate = 0.5;

public function configure()
{
$this->setName('stats')
->setDescription('Print stats on [tube] or on all tubes if [tube] is omitted');
$this->addArgument('tube', InputArgument::OPTIONAL, 'the tube to show stats for');
$this->addOption('monitor', null, InputOption::VALUE_NONE, 'Monitor mode');
$this->addOption('rate', null, InputOption::VALUE_OPTIONAL, 'Refresh rate', $this->refreshRate);
}

public function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -24,19 +26,21 @@ public function execute(InputInterface $input, OutputInterface $output)
$tube = $input->getArgument('tube');
$monitor = $input->getOption('monitor');

if ( !$rate = (float)$input->getOption('rate') ) $rate = $this->refreshRate;

while(1) {
if ( $monitor ) $this->clearScreen();
$outputTable = $this->calc($pheanstalk, $tube);
$output->write($outputTable->render(), false);

if ( $monitor ) usleep($this->refreshRate);
if ( $monitor ) usleep($rate * 1000000);
else break;
}
}

private function clearScreen()
{
print chr(27) . "[2J" . chr(27) . "[;H";
print chr(27) . '[2J' . chr(27) . '[;H';
}

private function calc(\Pheanstalk_Pheanstalk $pheanstalk, $tube = null)
Expand Down

0 comments on commit 534e70e

Please sign in to comment.