A new era of
PHP profiler

by Sandro Keil

IT-Consultant / Senior Software Developer @prooph_software

Author, Blogger, Open Source Evangelist

https://sandro-keil.de

Agenda

  1. Motivation
  2. Explanation of terms
  3. Deep Dive Profiler
  4. Pitfalls

Why
profiling?

Time
is
money

Detect
Bottlenecks

DB , Filesystem , API , Bad code

80-20
rule

Agenda

  1. Motivation
  2. Explanation of terms
  3. Deep Dive Profiler
  4. Pitfalls

Callers, Callees, Call Graph
Oh My ...

Callers
calls the function

Callees
called
by the function

info about
execution time, function calls
& memory

Call graph
hierarchical visualisation
of function calls

How to
profile?

sort by
exclusive time

sort by
function calls

Profiling
vs.
Bench
marking

Profiling
relative
performance

Benchmarks
current
performance

ab, Apache JMeter, Siege, Gatling

Agenda

  1. Motivation
  2. Explanation of terms
  3. Deep Dive Profiler
  4. Pitfalls

History

Zend
(Server)
Z-Ray

Realtime
analysis
in Browser

DB Queries , Filter / Sort
Execution Time , Request info
Erros / Exceptions

Z-Ray
History / Live

Plugins
are
awesome

written in plain PHP

zray.php

                    <?php
    // Allocate ZRayExtension for namespace "doctrine2"
    $zre = new \ZRayExtension('doctrine2', true);

    // Doctrine\DBAL
    $zre->traceFunction(
        'Doctrine\DBAL\Connection::execute', // <-- analyze this
        function(){ /* before */ },
        function(){ /* after */}
    );

    // rendering via phtml files


Z-Ray Doctrine 2 Plugin

SensioLabs
Blackfire

Interactive
Call Graph

with

Different
visualizations

Time, I/O Wait, CPU Time, Memory, Network, (HTTP, SQL)

Comparing
of
profiles

PHP SDK available

                    <?php

// start profiling
$blackfire = new Blackfire\Client(
    new \Blackfire\ClientConfiguration($clientId, $clientToken)
);
$probe = $blackfire->createProbe();

// user application code ...

// end profiling
$blackfire->endProbe($probe);
                
PHPUnit, Guzzle and Goutte integration

Much more
features
in paid version

Tideways

Timeline
Tracing
and
Customization

detailed
Call graph

Application
Performance
Monitoring

Custom Instrumentation

Transaction names, Collecting timespans
Metadata to root spans, Detecting Exceptions

extension API example

                    <?php
// Collecting Timespans
$span = \Tideways\Profiler::createSpan('sql');
$span->startTimer();
$span->annotate(array('title' => 'insert users'));

$pdo->query('INSERT INTO users (id, name) values (1, "foo")');

$span->stopTimer();

// wrap spans around function calls
\Tideways\Profiler::start();

\Tideways\Profiler::watch('Acme\Library::doSomething');
                

Error tracking

Alerts and Notifications

Agenda

  1. Motivation
  2. Explanation of terms
  3. Deep Dive Profiler
  4. Pitfalls

Pitfalls

Profiiling overhead

More details

Micro
optimizations

Not
to change
technology



Questions ?

Visit My Website