Skip to content

Commit

Permalink
[IM] rework position of logging for greater accuracy in measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Sep 15, 2021
1 parent 8b7b498 commit ca35165
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,6 @@ IXP_IRRDB_BGPQ3_PATH=/usr/local/bin/bgpq3
# PEERINGDB_OAUTH_CLIENT_SECRET="xxx"
# PEERINGDB_OAUTH_REDIRECT="https://www.example.com/auth/login/peeringdb/callback"

2FA_ENABLED=false


8 changes: 8 additions & 0 deletions app/Console/Commands/Router/GenerateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* http://www.gnu.org/licenses/gpl-2.0.html
*/

use Illuminate\Support\Facades\Log;
use IXP\Console\Commands\Command;

use IXP\Models\Router;
Expand Down Expand Up @@ -69,6 +71,12 @@ public function handle()
}

echo ( new RouterConfigurationGenerator( $router ) )->render();

Log::info( sprintf( "Generated router configuration for %s and used %0.1f MB ( %0.1f MB real) of memory in %0.3f seconds.",
$router->handle, memory_get_peak_usage()/1024/1024, memory_get_peak_usage( true )/1024/1024,
microtime(true) - LARAVEL_START )
);

return 0;
}
}
10 changes: 8 additions & 2 deletions app/Http/Controllers/Api/V4/RouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use Carbon\Carbon;

use Illuminate\Support\Facades\App;
use IXP\Models\Router;

use IXP\Tasks\Router\ConfigurationGenerator as RouterConfigurationGenerator;
Expand Down Expand Up @@ -63,9 +64,14 @@ public function genConfig( string $handle ): Response
abort( 404, "Unknown router handle" );
}

$configView = ( new RouterConfigurationGenerator( $router ) )->render();
$configView = ( new RouterConfigurationGenerator( $router ) )->render()->render();

return response( $configView->render(), 200 )
\Illuminate\Support\Facades\Log::info( sprintf( "Generated router configuration for %s and used %0.1f MB ( %0.1f MB real) of memory in %0.3f seconds.",
$router->handle, memory_get_peak_usage() / 1024 / 1024, memory_get_peak_usage( true ) / 1024 / 1024,
microtime( true ) - LARAVEL_START )
);

return response( $configView, 200 )
->header('Content-Type', 'text/plain; charset=utf-8');
}

Expand Down
5 changes: 0 additions & 5 deletions app/Tasks/Router/ConfigurationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ public function render(): ViewContract
]
);

Log::info( sprintf( "Generated router configuration for %s and used %0.1f MB ( %0.1f MB real) of memory in %0.3f seconds.",
$this->router()->handle, memory_get_peak_usage()/1024/1024, memory_get_peak_usage( true )/1024/1024,
microtime(true) - LARAVEL_START )
);

return $v;
}
}
4 changes: 3 additions & 1 deletion artisan
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));
if( !defined('LARAVEL_START') ) {
define('LARAVEL_START', microtime(true));
}

/*
|--------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ abstract class TestCase extends BaseTestCase
public function __construct( $name = null, array $data = [], $dataName = '' )
{
date_default_timezone_set('Europe/Dublin');
define( 'LARAVEL_START', microtime(true ) );

if( !defined('LARAVEL_START') ) {
define( 'LARAVEL_START', microtime(true ) );
}

parent::__construct( $name, $data, $dataName );
}

Expand Down

0 comments on commit ca35165

Please sign in to comment.