Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

adambanaszkiewicz/code-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CodeTimer

Simple PHP library to measuring code execution time with memory usage.

Installation - via composer.json

"requtize/code-timer": "^0.1.0"

Usage

use Requtize\CodeTimer\CodeTimer;

$timer = new CodeTimer;

// Sets category color which is displayed on some timeline preview.
$timer->setCategoryColor('handle-request', 'green');
$timer->setCategoryColor('controller', 'red');


// Starts and stops recording the request.
// Between those two methods call, all rest methods should be called.
$timer->begin();
$timer->end();

// Opens and closes section.
$timer->openSection('section-name', 'handle-request');
$timer->closeSection('section-name');

// Starts and stops some event to measure its duration and memory.
// It will be attached to current opened section
$timer->start('some event', 'controller');
$timer->stop('some event');


// Exports collected data to predefined formats.
$data = $timer->exportToArray();
$data = $timer->exportToJson();

Result array

$data = [
    'total-time' => [
        'start'    => 15623363564,
        'end'      => 15623373668,
        'duration' => 10104
    ],
    'sections' => [
        [
            'name'     => 'section-name',
            'start'    => 10,
            'duration' => 154,
            'memory'   => 17431234,
            'category' => 'handle-request',
            'category-color' => 'green'
        ],
        // Rest of sections...
    ],
    'stops' => [
        [
            'name'     => 'some event',
            'start'    => 20,
            'duration' => 30,
            'memory'   => 17431234,
            'category' => null,
            'category-color' => null,
            'section'  => 'section2'
        ],
        // Rest of stops...
    ]
]

TimeLine drawing - Preview

Source data returned from this library can be used to draw the Time Line of execution. Please find dedicated JavaScript timeline drawer here: requtize/timeline-drawer.

Licence

This code is licensed under MIT License.

About

Simple PHP library to measuring code execution time with memory usage.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages