Giter VIP home page Giter VIP logo

bvanhoekelen / performance Goto Github PK

View Code? Open in Web Editor NEW
519.0 23.0 38.0 6.32 MB

⏱ PHP performance tool analyser your script on time, memory usage and db query. Support Laravel and Composer for web, web console and command line interfaces.

License: Apache License 2.0

PHP 96.12% CSS 2.65% JavaScript 1.23%
php performance command-line command-line-tool composer laravel export performance-testing performance-analysis analyzer

performance's Introduction

⏱ PHP Performance tool 🛠

Hex.pm GitHub release Packagist Github issues Travis branch Travis branch Build: Master|Develop

PHP performance tool

Highlight

Easy to use

// Add namespace at the top
use Performance\Performance;

// Set measure point
Performance::point();

//
// Run test code
//

// Finish all tasks and show test results
Performance::results();

See the function overview for more functions.

Web preview

PHP performance tool for web

Command line preview

PHP performance tool for command line

See how to use query logging.

Web console

PHP performance tool with full date review

See how to use query logging.

See how to export data.

See more info over data review.

Functions

Set measuring point with or without label

Performance::point( <optional:label> );

Finish previous measuring point

Performance::finish();

Finish all measuring points and return test results

Performance::results();

See the function overview for more.

Command line

Run the performance test for the command line

// Normal
$ php your_script.php

// Or live version
$ php your_script.php --live 

Help, docs and links

Backlog & Feedback

If you have any suggestions to improve this performance tool? Please add your feature, bug or improvement to the BACKLOG.dm. Or create a issues.

Installation

Install with Laravel

Get PHP performance tool by running the Composer command in the command line.

 $ composer require bvanhoekelen/performance

Open your file for the performance test.

// Add namespace at the top
use Performance\Performance;

// Set measure point
Performance::point();

//
// Run test code
//

// Finish all tasks and show test results
Performance::results();

Install with Composer

Get PHP performance by running the Composer command in the command line.

 $ composer require bvanhoekelen/performance

Open your file for the performance test.

// Require vender autoload
require_once('../vendor/autoload.php');

// Add namespace at the top
use Performance\Performance;

// Set measure point
Performance::point();

//
// Run test code
//

// Finish all tasks and show test results
Performance::results();

performance's People

Contributors

bart-digitalenterprises avatar bvanhoekelen avatar jazz-man avatar lex111 avatar marouanerag avatar nunomaduro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

performance's Issues

Mysql query logging via https://dev.mysql.com/doc/refman/8.0/en/query-log.html

Who wants it? Can we have it?!

https://dev.mysql.com/doc/refman/8.0/en/query-log.html

use XXX\Database;
use Performance\Config;
use Performance\Performance;
Performance::point('Overall start', TRUE);
Database::setActiveConnection('default');
$db = Database::getConnection();
$db->query("SET GLOBAL general_log = 'ON'");

//
// Run test code
//

Performance::finish();
Performance::results();

// SQL results from mysql general log.

$db->query("SET GLOBAL general_log = 'OFF'");

Instead of log file get logs through mysql table via https://tableplus.com/blog/2018/10/how-to-show-queries-log-in-mysql.html

Console output on Windows too narrow

On Windows, the commandLineWidth property in /bvanhoekelen/performance/src/Lib/Presenters/ConsolePresenter.php is set to 60. That makes it very narrow, making it very hard to recognize point labels and impossible to see any queries being run.

Screenshot 2021-08-12 113442

It would be very practical to be able to set the width of the command line or the number of characters that should be displayed through \Performance\Config

is it possible to extract only the total ?

I love this package and use it a lot when debugging. I like both the console and web presenter. But I'm finding myself in a situation where I would like to log the data that is shown in the console/web presenter in a readable format into the database

I tried using the export handler which gives you access to the points and its metrics, but what I really want is the data that's in the presenter when you use ->results()

I'd like to be able to do something like

$export = Performance::export();

JobLog::create([
  'execution_time' => $export->get('total'),
]);

Currently I find that the contents of $export->get()
are not very friendly.. unless I'm missing something.. it seems like a lot of calculations and transforming is applied to that data between what is available in the export and what is displayed in the console/web presenters

Any way we can access what's displayed in the presenter in an easy-to-access format like a json object?

thanks!

Ability to fix units in result to force set kb and ms in output numbers

Now library tries to automatically pick up best units to display value in pretty way. It looks good, but sometimes it is not useful, because we can't quickly reveal high numbers in list of numbers with different units.
For example, in Time column there are numbers:

298.98 μs
123.53 μs
 46.02 ms
 41.43 μs
 42.24 μs
194.53 μs

Can you quickly catch most longest operation via quick look? Not so easy! But if we fix units to ms, we can easily catch this problem, here is example:

 0.29 ms
 0.12 ms
46.02 ms
 0.04 ms
 0.04 ms
 0.19 ms

Same problem is with memory usage too.
So will be good to add an option to fix measure units to needed values, or maybe auto-detect them between whole list of data, not for each value separately. What do you think about this idea?

Improve usability by replacing private with protected

I'm trying to use this library to run some performance tests of our own by integrating it in a symfony console.

There is however no pretty way to create (and set) your own presenter, or even extend one of the current ones, as almost everything required to do so is either a private function or property.

I think this is also one of the reasons this library is forked a lot, even though there are some configuration options, if you for example only wish to not clear the console screen in the presenter, you have to pretty much fork the entire library otherwise it cannot be done.

My suggestion:

  • Do a global replace of private to protected
  • Do a global replace of self:: to static::

This already resolves a lot of issues with making minor adjustments to the library and extending on it without having to fork.

imcompatible with php 7.4 because of implode deprecation

There is an issue with the dependency bvanhoekelen/terminal-style which throws this error on php 7.4:

 ErrorException  : implode(): Passing glue string after array is deprecated. Swap the parameters

  at /vendor/bvanhoekelen/terminal-style/src/terminal-style.php:140
    136|             die(' > terminal_style(): Text color "' . $color . '" does not exist. You can only use the following text colors' . PHP_EOL);
    137|         }
    138|
    139|         // Set background
  > 140|         return "\e[" . implode($code, ';') . "m" . $message . "\e[0m";
    141|     }
    142| }

Any chance you could push a fix for this please : )

Feature: Add Point manually

It would be nice to add points manually. This way it would be possible to keep the measurement running when hitting another point. For example whole site duration or multiple tasks. Or you could finish a point by its label. For example

Performance::point("site:start");
//run code
Performance::point("cache");
//run code
Performance::finish(); // finish cache point
//run code
Performance::finish(); // finish site:start

Or 

Performance::finish("cache");
Performance::finish("site:start");

overriding my date configuration

I just noticed that when I have am using your package to benchmark, my timezone is overwritten

By default I have it set to Singapore

in my config/app.php

I have

'timezone' => 'Asia/Singapore',

I was running benchmarking on aggregate queries that use the dates and I was noticing that my graphs were off and different from my production data even though I am using the same database data

I think it's because of this line:

    private function setDefaultTimeZone()
    {
        // Check date function
        if( ! ini_get('date.timezone'))
            date_default_timezone_set('UTC');
    }

In your ConfigHandler.php

Is this really necessary ? Shouldn't your benchmarking work regardless of what timezone is set?

Add CPU cycles load (CPU user and system time) measurement to report

Not only memory and time are give performance problems, very often CPU usage is also the problem. But now we don't measure it.
Will be good to add measurement of CPU usage time too!
In PHP we can easily get them via this code:

$rUsage = getrusage();
$cpuTimeUser = $rUsage["ru_utime.tv_usec"]; // user time used (microseconds)
$cpuTimeSystem = $rUsage["ru_stime.tv_usec"]; // system time used (microseconds)

Also there are many other metrics that can be useful, so maybe store full result of that function, instead of several values, and allow to manually add needed ones to report?

Use exceptions instead of die

I think, library should use exceptions instead of die for generating errors, they have next benefits:

  • do not stop app immediately
  • provides backtrace
  • allows to change error handling in future

I encountered the following problem when I tried to use the library. I tried to profile one API route and created several points with the same name, which is not allowed in the library and throws an error. But for some time I could not understand what the error was, since the route returned the code 200. When I saw the text of the error, I could not understand for a long time exactly where I had made the error. Exceptions in such cases are more expected and convenient.

Performance inside Loop

Is it possible to have the performance inside a loop?

A very basic example:

\Performance\Performance::point('Test Root');   
sleep(3);  
for ($i = 1; $i <= 10; $i++) {  
    $sleepTime = rand(1,4);   
    \Performance\Performance::point('Sub ' . $i . ' (' . $sleepTime . ')');   
    sleep($sleepTime);   
    \Performance\Performance::finish();   
}   
\Performance\Performance::finish();   
\Performance\Performance::results();

Test Root should contain all the sleep() seconds combined, because that is what it take to run the whole for loop. But it just gives 3s, so the next Point stops the previous one.

Shouldn't it be possible to take the real performance time?

possible to reset during long running process of multiple jobs?

I'm deploying multiple jobs using $this->call('my:command', []); and I'm using the 'sync' queue

Each job has performance points with a ->results() at the end of it

I've noticed that all subsequent ->results() include the points and totals from all previous jobs

I would have preferred if each job was calculated separately. Is there a way to ->reset() this tool or set it to null somehow so it restarts from scratch during a long running process ?

I thought ->results() would do this by default but it looks like it doesn't

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.