Report memory usage

This commit is contained in:
Daniil Gentili 2020-04-29 14:43:43 +02:00
parent 77a955c25e
commit 995a4228c9
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 20 additions and 3 deletions

View File

@ -19,6 +19,11 @@
* @link https://docs.madelineproto.xyz MadelineProto documentation * @link https://docs.madelineproto.xyz MadelineProto documentation
*/ */
if (function_exists('memprof_enable')) {
memprof_enable();
}
use Amp\Http\Server\HttpServer; use Amp\Http\Server\HttpServer;
use danog\MadelineProto\API; use danog\MadelineProto\API;
use danog\MadelineProto\APIWrapper; use danog\MadelineProto\APIWrapper;
@ -86,6 +91,10 @@ class MyEventHandler extends \danog\MadelineProto\EventHandler
$this->UPLOAD = \class_exists(HttpServer::class); $this->UPLOAD = \class_exists(HttpServer::class);
parent::__construct($API); parent::__construct($API);
} }
public function onStart()
{
$this->adminId = yield $this->getInfo(self::ADMIN)['bot_api_id'];
}
/** /**
* Handle updates from channels and supergroups. * Handle updates from channels and supergroups.
* *
@ -126,6 +135,13 @@ class MyEventHandler extends \danog\MadelineProto\EventHandler
if ($update['message']['message'] === '/start') { if ($update['message']['message'] === '/start') {
return $this->messages->sendMessage(['peer' => $peerId, 'message' => self::START, 'parse_mode' => 'Markdown', 'reply_to_msg_id' => $messageId]); return $this->messages->sendMessage(['peer' => $peerId, 'message' => self::START, 'parse_mode' => 'Markdown', 'reply_to_msg_id' => $messageId]);
} }
if ($update['message']['message'] === '/report' && $peerId === $this->adminId) {
memprof_dump_callgrind($stm = fopen("php://memory", "w"));
fseek($stm, 0);
yield $this->messages->sendMedia(['peer' => $peerId, 'media' => ['_' => 'inputMediaUploadedDocument', 'file' => $stm, 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'callgrind.out']]]]);
fclose($stm);
return;
}
if (isset($update['message']['media']['_']) && $update['message']['media']['_'] !== 'messageMediaWebPage') { if (isset($update['message']['media']['_']) && $update['message']['media']['_'] !== 'messageMediaWebPage') {
if ($this->UPLOAD && ($this->states[$peerId] ?? false) === $this->UPLOAD) { if ($this->UPLOAD && ($this->states[$peerId] ?? false) === $this->UPLOAD) {
unset($this->states[$peerId]); unset($this->states[$peerId]);

View File

@ -110,7 +110,8 @@ trait AuthKeyHandler
* *********************************************************************** * ***********************************************************************
* Compute p and q * Compute p and q
*/ */
$pq = (string) new BigInteger((string) $pq_bytes, 256); $pq = new BigInteger((string) $pq_bytes, 256);
$pqStr = (string) $pq;
foreach ([ foreach ([
'auto_single', 'auto_single',
'native_single_cpp', 'native_single_cpp',
@ -124,9 +125,9 @@ trait AuthKeyHandler
$q = new BigInteger(0); $q = new BigInteger(0);
try { try {
if ($method === 'wolfram') { if ($method === 'wolfram') {
$p = new BigInteger(yield from $this->wolframSingle($pq)); $p = new BigInteger(yield from $this->wolframSingle($pqStr));
} else { } else {
$p = new BigInteger(@PrimeModule::$method($pq)); $p = new BigInteger(@PrimeModule::$method($pqStr));
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->logger->logger("While factorizing with $method: $e"); $this->logger->logger("While factorizing with $method: $e");