2017 © Pedro Peláez
 

joomla-package profiler

Joomla Profiler Package

image

joomla/profiler

Joomla Profiler Package

  • Saturday, July 14, 2018
  • by mbabker
  • Repository
  • 10 Watchers
  • 2 Stars
  • 7,041 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 10 Versions
  • 3 % Grown

The README.md

The Profiler Package Build Status

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

The Joomla Framework provides you a Profiler to profile the time that it takes to do certain tasks or reach various milestones as your extension runs., (*2)

Usage

use Joomla\Profiler\Profiler;

// Creating a Profiler having the name "Notes".
$profiler = new Profiler('Notes');

// Mark a point called "Start".
$profiler->mark('Start');

// Execute some code...

// Mark a point called "Middle".
$profiler->mark('Middle');

// Execute some code...

// Mark a point called "End".
$profiler->mark('End');

You must at least mark the first point which will be the reference., (*3)

Now, you can retrieve the elapsed time between two points :, (*4)

use Joomla\Profiler\Profiler;

// Return the elapsed time in seconds between two points (the order does not matter).
$elapsed = $profiler->getTimeBetween('Start', 'Middle');

You can also retrieve the amount of allocated memory between two points., (*5)

use Joomla\Profiler\Profiler;

// Return the amount of allocated memory between these two points.
$elapsed = $profiler->getMemoryBytesBetween('Start', 'Middle');

When you have finished, you can output the result., (*6)

// Will display the profiler results.
echo $profiler;

// Will render the profiler as a string.
$render = $profiler->render();

The output could look something like the following:, (*7)

Notes 0.000 seconds (+0.000); 0.00 MB (+0.000) - Start
Notes 1.000 seconds (+1.000); 3.00 MB (+3.000) - Middle
Notes 1.813 seconds (+0.813); 6.24 MB (+3.240) - End

You can see each line is qualified by the name you used when creating your profiler, and then the names you used for the mark., (*8)

The start point (the first marked point) is the reference, and by consequence has a null time and memory usage., (*9)

We can see that the code executed between the "Start" and the "Middle" point took 1 second to perform and increased the memory usage by 3 Mega Bytes., (*10)

Writing your own Renderer

You can write your own renderer if you need an other formatting. In order to do so, you need to implement the ProfilerRendererInterface., (*11)

namespace MyApp;

use Joomla\Profiler\ProfilerRendererInterface;
use Joomla\Profiler\ProfilerInterface;

class MyRenderer implements ProfilerRendererInterface
{
    /**
     * Renders a profiler.
     * We want to display the point names and the elapsed time in front of them.
     *
     * start : +0 seconds
     * middle : +x seconds
     * end : +y seconds.
     */
    public function render(ProfilerInterface $profiler)
    {
        // Prepare the string.
        $render = '';

        // Initialize a variable containing the last point.
        $lastPoint = null;

        // Get the points in the profiler.
        $points = $profiler->getPoints();

        foreach ($points as $point)
        {
            // Get the time of the last point (if any).
            $lastTime = $lastPoint ? $lastPoint->getTime() : 0;

            $render .= sprintf('%s: %f seconds.', $point->getName(), $point->getTime() - $lastTime);
            $render .= '<br/>';

            $lastPoint = $point;
        }

        return $render;
    }
}

Now you can set your renderer in the Profiler :, (*12)

$profiler->setRenderer(new MyRenderer);

echo $profiler;

It should output something like :, (*13)

Start: 0.000000 seconds.
Middle: 0.000172 seconds.
End: 0.000016 seconds.

Installation via Composer

Add "joomla/profiler": "~1.0" to the require block in your composer.json and then run composer install., (*14)

{
    "require": {
        "joomla/profiler": "~1.0"
    }
}

Alternatively, you can simply run the following from the command line:, (*15)

composer require joomla/profiler "~1.0"

The Versions

14/07 2018

dev-2.0-dev

dev-2.0-dev https://github.com/joomla-framework/profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php ~7.0

 

The Development Requires

framework profiler joomla

30/06 2018

dev-master

9999999-dev https://github.com/joomla-framework/profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php ^5.3.10|~7.0

 

The Development Requires

framework profiler joomla

31/01 2016

1.2.0

1.2.0.0 https://github.com/joomla-framework/profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10|>=7.0

 

The Development Requires

framework profiler joomla

09/02 2014

1.1.1

1.1.1.0 https://github.com/joomla-framework/profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla

23/10 2013

1.0

1.0.0.0 https://github.com/joomla/joomla-framework-profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla

23/10 2013

1.1.0

1.1.0.0 https://github.com/joomla/joomla-framework-profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla

22/10 2013

1.0-beta3

1.0.0.0-beta3 https://github.com/joomla/joomla-framework-profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla

16/08 2013

1.0-beta2

1.0.0.0-beta2 https://github.com/joomla/joomla-framework-profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla

16/08 2013

1.0-beta

1.0.0.0-beta https://github.com/joomla/joomla-framework-profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla

04/06 2013

1.0-alpha

1.0.0.0-alpha https://github.com/joomla/joomla-framework-profiler

Joomla Profiler Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

framework profiler joomla