1. Go to this page and download the library: Download duckstery/process-analyzer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
duckstery / process-analyzer example snippets
// Start of code
$uid = Analyzer::start("Do a simple math");
// Calculating
$output = 1 + 1;
// Print output to screen
echo $output;
// End of code
Analyzer::stop($uid);
// Flush to get report
Analyzer::flush();
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => ServiceProvider::defaultProviders()->merge([
/*
* Package Service Providers...
*/
Duckstery\Laravel\Analyzer\ProcessAnalyzerServiceProvider::class, // ** //
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
])->toArray(),
use Duckstery\Analyzer\AnalyzerConfig;
class MyAnalyzerConfig extends AnalyzerConfig
{
// Todo
}
use Duckstery\Analyzer\AnalyzerConfig;
class MyAnalyzerConfig extends AnalyzerConfig
{
// Property override
protected bool $prettyPrint;
// Function override
public function prettyPrint(): bool
{
return true;
}
}
use Duckstery\Analyzer\Analyzer;
Analyzer::tryToInit(new MyAnalyzerConfig());
[
"Default" => [
"peak" => [
// Metrics method name's or callback array
"handler" => "memory_get_peak_usage",
// Formatter
"formatter" => [Utils::class, "appendB"],
// Get at the start
"start" => true,
// Get at the end
"stop" => true,
// Calculate difference
"diff" => true
]
]
]
use Duckstery\Analyzer\AnalysisPrinter;
use Duckstery\Analyzer\Interfaces\IAProfile;
class MyPrinter extends AnalysisPrinter
{
public function onPreprocessProfile(IAProfile $profile): void
{
// Todo
}
}
use Duckstery\Analyzer\Analyzer;
public class SomeController
{
public function handle(): void
{
// Use Profile: SomeController and start recording
Analyzer::profile("SomeController")->start("handle");
// Execute process A
$this->processA();
// Execute process B
$this->processB();
// Execute process C
$this->processC();
// Stop the latest recording of Profile
Analyzer::profile("SomeController")->stop();
// Flush
Analyzer::flush("SomeController");
// Or Analyzer::flush(); to flush all Profile
}
public function processA(): void
{
// Use Profile: SomeController and start recording
Analyzer::profile("SomeController")->start("processA");
// Use 5kb
// Stop the latest recording of Profile
Analyzer::profile("SomeController")->stop();
}
public function processB(): void
{
// Use Profile: SomeController and start recording
Analyzer::profile("SomeController")->start("processA");
// Use 0kb
// Stop the latest recording of Profile
Analyzer::profile("SomeController")->stop();
}
public function processC(): void
{
// Use Profile: SomeController and start recording
Analyzer::profile("SomeController")->start("processA");
// Executed for 5s
// Stop the latest recording of Profile
Analyzer::profile("SomeController")->stop();
}
}
$profileExtras = [
"Default" => [
"peak" => [
// Metrics method name's or callback array
"handler" => "memory_get_peak_usage",
// Formatter
"formatter" => [Utils::class, "appendB"],
// Get at the start
"start" => true,
// Get at the end
"stop" => true,
// Calculate difference
"diff" => true
]
]
]
use Duckstery\Analyzer\Analyzer;
public class SomeController
{
public function handle(): void
{
$uid = Analyzer::start("SomeController::handle");
// Or Analyzer::start("SomeController::handle");
// Todo
Analyzer::stop($uid);
// Or Analyzer::stop();
// Flush
Analyzer::flush();
}
}
use Duckstery\Analyzer\Analyzer;
public class SomeController
{
public function handle(): void
{
$uid = Analyzer::start();
// Or Analyzer::start();
// Todo
Analyzer::stop($uid);
// Or Analyzer::stop();
// Flush
Analyzer::flush();
}
}
use Duckstery\Analyzer\Analyzer;
public class SomeController
{
public function handle(): void
{
$uid = Analyzer::startProfile("Profile 1");
// Or Analyzer::startProfile("Profile 1");
$this->todo();
Analyzer::stopProfile("Profile 1", $uid);
// Or Analyzer::stopProfile("Profile 1");
// Flush
Analyzer::flush();
}
public function todo(): void
{
$uid = Analyzer::startProfile("Profile 2");
// Or Analyzer::startProfile("Profile 2");
$this->todo();
Analyzer::stopProfile("Profile 2", $uid);
// Or Analyzer::stopProfile("Profile 2");
}
}