Download the PHP package magdv/liveprof without Composer
On this page you can find all versions of the php package magdv/liveprof. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download magdv/liveprof
More information about magdv/liveprof
Files in magdv/liveprof
Package liveprof
Short Description A performance monitoring system for running on live sites
License MIT
Informations about the package liveprof
Live Profiler
Live Profiler is a system-wide performance monitoring system in use at Badoo that is built on top of XHProf or its forks (Uprofiler or Tideways). Live Profiler continually gathers function-level profiler data from production tier by running a sample of page requests under XHProf.
Live profiler UI then aggregates the profile data corresponding to individual requests by various dimensions such a time, page type, and can help answer a variety of questions such as: What is the function-level profile for a specific page? How expensive is function "foo" across all pages, or on a specific page? What functions regressed most in the last day/week/month? What is the historical trend for execution time of a page/function? and so on.
Here is a plugin for PhpStorm to see the method performance directly in IDE.
liveprof.org shows all features and can be used for test purposes.
System Requirements
- PHP version 5.4 or later / hhvm version 3.25.0 or later
-
One of XHProf, Uprofiler or Tideways to profile and collect the data. You can use other profiler which returns data in the follow format:
- Database extension to save profiling results to the database.
Installation
-
You can install Live Profiler via Composer:
- Prepere a storage for results depends on mode
[save data in database] If you use DB mode you need to prepare a database server. You can use any driver described here or implement the custom one. You need run a script to configure database. This script creates "details" table:
[save data in files] It's also possible to save profiling result into files. To do it prepare a directory with write permissions.
[send data to demo site] You need to visit liveprof.org , sign in and copy API key.
- Init a profiler before working code in the project entry point (usually public/index.php).
Usage
There is an example of usage a profiler with default parameters:
There is an example how to test Live Profiler without any extension and database. You can use a build-in profiler compatible with XHProf and liveprof.org as UI:
There is a full list of methods you can use to change options:
If you want to change the Label during running (for instance, after you got some information in the router or controller) you can call:
if you don't want to save profiling result you can reset it anytime:
After script ends it will call \Badoo\LiveProfiler\LiveProfiler::getInstance()->end();
on shutdown, but you can call it explicitly after working code.
Environment Variables
LIVE_PROFILER_CONNECTION_URL
: url for the database connection
LIVE_PROFILER_DB_TABLE_NAME
: name of db table that store logs
LIVE_PROFILER_PATH
: path to save profiles in \Badoo\LiveProfiler\LiveProfiler::MODE_FILES mode
LIVE_PROFILER_API_URL
: api url to send profiles in \Badoo\LiveProfiler\LiveProfiler::MODE_API mode and see demo on liveprof.org
Work flow
Live profiler allows to run profiling with custom frequency (for instance 1 of 1000 requests) grouped by app name ('Default' by default) and custom label (by default it's the url path or script name).
It's important to calculate the request divider properly to have enough data for aggregation. You should divide daily request count to have approximately 1 profile per minute. For instance, if you have 1M requests a day for the page /users the divider should be 1000000/(60*24) = 694, so divider = 700 is enough.
Also you have to calculate a total divider for all request profiling. It's important to control the whole system health. It can be calculated the same way as a divider calculation for particularly request, but in this case you should use count of all daily requests. For instance, if you have 10M requests a day - total_divider=10000000/(60*24) = 6940, so total_divider = 7000 is enough.
The profiler automatically detects which profiler extension you have (xhprof, uprofiler or tidyways). You have to set profiler callbacks if you use other profiler.
You can run the test script in the docker container with xhprof extension and look at the example of the server configuration in Dockerfile:
or you can build a docker container with xhprof using sampling:
or you can build a docker container with tideways extension:
or uprofiler extension:
or latest hhvm with included xhprof extension:
or if you want to use API with included xhprof extension:
If your server has php version 7.0 or later it's better to use Tideways as profiler.
Steps to install tideways extension:
Steps to install uprofiler:
Tests
Install Live Profiler with dev requirements:
In the project directory, run:
License
This project is licensed under the MIT open source license.
All versions of liveprof with dependencies
doctrine/dbal Version ~3.0
psr/log Version ^2
ext-json Version *
ext-zlib Version *
ext-curl Version *