2017 © Pedro Peláez
 

library php-profiler

PHP profiler

image

petrknap/php-profiler

PHP profiler

  • Thursday, June 29, 2017
  • by petrknap
  • Repository
  • 1 Watchers
  • 2 Stars
  • 14,897 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

PHP profiler for short-term & long-term profiling

This tool allows you to monitor performance and detect memory leaks as well as inconsistent performance behavior of your application over time., (*1)

Basic profiling

For basic profiling you can use a profiling helper. The Profiling will allow you to profile between start and finish methods calls., (*2)

namespace PetrKnap\Profiler;

$profiling = Profiling::start();
// do something
$profile = $profiling->finish();

printf('It took %.1f s to do something.', $profile->getDuration());

The Profiling is simple and cannot be turned on and off easily. So a profiler was created for the purpose of hard-coded more complex profiling., (*3)

Complex profiling

Request a profiler as a dependency and call a profile method on it., (*4)

namespace PetrKnap\Profiler;

function doSomething(ProfilerInterface $profiler): string {
    return $profiler->profile(function (): string {
        return 'something';
    })->process(fn (ProfileInterface $profile) => printf(
        'It took %.1f s to do something.',
        $profile->getDuration(),
    ));
}

How to enable / disable it

It can be easily enabled, or disabled through the DI, which provides either the Profiler or the NullProfiler., (*5)

namespace PetrKnap\Profiler;

echo doSomething(new Profiler());
echo doSomething(new NullProfiler());

Useful features

Take snapshot

If you need to measure the current values, just call the takeSnapshot method on the Profiling, or a profiler., (*6)

namespace PetrKnap\Profiler;

$profiling = Profiling::start();
// do something
$profiling->takeSnapshot();
// do something more
$profile = $profiling->finish();

printf('There are %d memory usage records.', count($profile->getMemoryUsages()));

If you want to automate it then take snapshot on tick. Or you can use a more practical cascade profiling., (*7)

Take snapshot on tick

For greater precision, you can take snapshot on each N tick., (*8)

declare(ticks=2); // this declaration is important (N=2)

namespace PetrKnap\Profiler;

$profiling = Profiling::start(takeSnapshotOnTick: true);
(fn () => 'something')();
$profile = $profiling->finish();

printf('There are %d memory usage records.', count($profile->getMemoryUsages()));

This will result in very detailed code tracking, which can degrade the performance of the monitored application., (*9)

Cascade profiling

The profile method provides you a nested profiler that you can use for more detailed cascade profiling., (*10)

namespace PetrKnap\Profiler;

$profile = (new Profiler())->profile(function (ProfilerInterface $profiler): void {
    // do something
    $profiler->profile(function (): void {
        // do something more
    });
});

printf('There are %d memory usage records.', count($profile->getMemoryUsages()));

Run composer require petrknap/profiler to install it. You can support this project via donation. The project is licensed under the terms of the LGPL-3.0-or-later., (*11)

The Versions

29/06 2017

dev-master

9999999-dev https://petrknap.github.io/docs/php-profiler.html

PHP profiler

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

29/05 2017

v1.3.0

1.3.0.0 https://petrknap.github.io/docs/php-profiler.html

PHP profiler

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

16/03 2017

dev-backup/2017-03-16_master

dev-backup/2017-03-16_master https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

21/09 2016

v1.2.0

1.2.0.0 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

21/09 2016

v1.1.1

1.1.1.0 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

19/09 2016

v1.1.0

1.1.0.0 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

16/09 2016

v1.0.0

1.0.0.0 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

22/01 2016

v0.2.0.0

0.2.0.0 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

19/12 2015

v0.1.0.2

0.1.0.2 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

19/12 2015

v0.0.0.1

0.0.0.1 https://github.com/petrknap/php-profiler

PHP profiler by Petr Knap

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires