Skip to content

Commit f961278

Browse files
author
prophet777
committed
Add profiling option argument
1 parent 6a019a6 commit f961278

File tree

8 files changed

+20
-37
lines changed

8 files changed

+20
-37
lines changed

Command/ServerCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\Console\Input\InputArgument;
66
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Output\OutputInterface;
89

910
/**
@@ -18,7 +19,8 @@ protected function configure()
1819
$this
1920
->setName('gos:server')
2021
->setDescription('Starts the web socket servers')
21-
->addArgument('name', InputArgument::OPTIONAL, 'Server name');
22+
->addArgument('name', InputArgument::OPTIONAL, 'Server name')
23+
->addOption('profile', 'p', InputOption::VALUE_NONE, 'Profiling server');
2224
}
2325

2426
/**

Command/WebsocketServerCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Command\Command;
99
use Symfony\Component\Console\Input\InputArgument;
1010
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
1112
use Symfony\Component\Console\Output\OutputInterface;
1213

1314
class WebsocketServerCommand extends Command
@@ -39,7 +40,8 @@ protected function configure()
3940
$this
4041
->setName('gos:websocket:server')
4142
->setDescription('Starts the web socket servers')
42-
->addArgument('name', InputArgument::OPTIONAL, 'Server name');
43+
->addArgument('name', InputArgument::OPTIONAL, 'Server name')
44+
->addOption('profile', 'p', InputOption::VALUE_NONE, 'Profiling server');
4345
}
4446

4547
/**
@@ -48,6 +50,6 @@ protected function configure()
4850
*/
4951
protected function execute(InputInterface $input, OutputInterface $output)
5052
{
51-
$this->entryPoint->launch($input->getArgument('name'));
53+
$this->entryPoint->launch($input->getArgument('name'), $input->getOption('profile'));
5254
}
5355
}

DependencyInjection/CompilerPass/DevCompilerPass.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

GosWebSocketBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Gos\Bundle\WebSocketBundle;
44

5-
use Gos\Bundle\WebSocketBundle\DependencyInjection\CompilerPass\DevCompilerPass;
65
use Gos\Bundle\WebSocketBundle\DependencyInjection\CompilerPass\PeriodicCompilerPass;
76
use Gos\Bundle\WebSocketBundle\DependencyInjection\CompilerPass\PingableDriverCompilerPass;
87
use Gos\Bundle\WebSocketBundle\DependencyInjection\CompilerPass\RpcCompilerPass;
@@ -26,6 +25,5 @@ public function build(ContainerBuilder $container)
2625
$container->addCompilerPass(new TopicCompilerPass());
2726
$container->addCompilerPass(new PeriodicCompilerPass());
2827
$container->addCompilerPass(new PingableDriverCompilerPass());
29-
$container->addCompilerPass(new DevCompilerPass());
3028
}
3129
}

Periodic/PeriodicMemoryUsage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(LoggerInterface $logger)
2525
*/
2626
public function tick()
2727
{
28-
$this->logger->debug('Memory usage : ' . round((memory_get_usage() / (1024 * 1024)), 2) . 'Mo');
28+
$this->logger->info('Memory usage : ' . round((memory_get_usage() / (1024 * 1024)), 4) . 'Mo');
2929
}
3030

3131
/**

Server/EntryPoint.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public function __construct(ServerRegistry $serverRegistry)
2424
}
2525

2626
/**
27-
* Launches the relevant servers needed by Gos WebSocket.
27+
* @param string $serverName
28+
* @param bool $profile
2829
*/
29-
public function launch($serverName)
30+
public function launch($serverName, $profile)
3031
{
3132
$servers = $this->serverRegistry->getServers();
3233

@@ -45,6 +46,6 @@ public function launch($serverName)
4546
$server = $servers[$serverName];
4647
}
4748

48-
$server->launch();
49+
$server->launch($profile);
4950
}
5051
}

Server/Type/ServerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface ServerInterface
77
/**
88
* Launches the server loop.
99
*/
10-
public function launch();
10+
public function launch($profile);
1111

1212
/**
1313
* Returns a string of the host:port for debugging / display purposes.

Server/Type/WebSocketServer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Gos\Bundle\WebSocketBundle\Event\Events;
66
use Gos\Bundle\WebSocketBundle\Event\ServerEvent;
77
use Gos\Bundle\WebSocketBundle\Periodic\PeriodicInterface;
8+
use Gos\Bundle\WebSocketBundle\Periodic\PeriodicMemoryUsage;
89
use Gos\Bundle\WebSocketBundle\Server\App\Registry\OriginRegistry;
910
use Gos\Bundle\WebSocketBundle\Server\App\Registry\PeriodicRegistry;
1011
use Gos\Bundle\WebSocketBundle\Server\App\WampApplication;
@@ -107,7 +108,7 @@ public function setSessionHandler(\SessionHandlerInterface $sessionHandler)
107108
$this->sessionHandler = $sessionHandler;
108109
}
109110

110-
public function launch()
111+
public function launch($profile)
111112
{
112113
$this->logger->info('Starting web socket');
113114

@@ -119,6 +120,11 @@ public function launch()
119120
$server = new Server($loop);
120121
$server->listen($this->port, $this->host);
121122

123+
if (true === $profile) {
124+
$memoryUsagePeriodicTimer = new PeriodicMemoryUsage($this->logger);
125+
$this->periodicRegistry->addPeriodic($memoryUsagePeriodicTimer);
126+
}
127+
122128
/** @var PeriodicInterface $periodic */
123129
foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
124130
$loop->addPeriodicTimer($periodic->getTimeout(), [$periodic, 'tick']);

0 commit comments

Comments
 (0)