Download the PHP package makinacorpus/profiling without Composer

On this page you can find all versions of the php package makinacorpus/profiling. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package profiling

Profiling toolbox

Profiling and metrics toolbox.

Contains many features:

Timers uses the monotonic high resolution timer if available using the PHP \hrtime() function for timings, which yields more precision and is resilient to system clock changes in opposition to \microtime() Using \hrtime() function makes this API being suitable for running discretly in production.

Setup

Installation

Simply run:

For registering the Symfony bundle, add to your config/bundles.php:

Enable it by setting this environment variable:

Enable prometheus support can be done as well:

Then copy the src/Bridge/Symfony/Resources/packages/profiling.yaml in this package in the config/packages/ directory. You may read it and modify following your needs. All configuration options are documented within the sample configuration file itself.

Storage configuration

Default storage is a PostgreSQL database implementation that uses makinacorpus/query-builder for writing SQL queries.

It can create automatically the missing tables at runtime, although this unperformant and disabled per default. In order to allow automatic table creation, you can set the PROFILING_PROMETHEUS_SCHEMA_AUTOCREATE=1 environment variable.

Recommended method is to run the profiling:prometheus:create-schema console command at least once:

Usage

Important notes:

Timers

Basic usage

Here is a code sample:

Timer advanced usage

There are many methods on the MakinaCorpus\Profiling\Timer interface, all are documented.

Timer trace handlers

Timer trace handlers are components that listen to all timers being emited, then can log information. A few handlers are provided by default:

Handlers can be configured to accept timers from all channels, some channels, or all channels but some channels.

See the example configuration file for more information about handler configuration.

Prometheus metrics

Setup

First, enable it using an environment variable:

Then compute a random access token, with any method of your choice, then set it into your environments variables:

In order to setup the prometheus HTTP endpoint, add into config/routes.yaml:

Then for fetching metrics, simply hit the following URL:

Also, please note that if you configured some firewalls, you probably need to put the ^/prometheus/ path into a non-secured firewall.

Default configuration simply works, aside for the driver that needs to be configured. Default is in_memory which means it simply stores nothing.

Define your own metrics

Each sample must be defined in the schema configuration section. If a sample is not defined in this file, then it will simply be a no-op if you attempt collecting it.

Edit your config/packages/profiling.yaml file:

Then, at the point in code where you need to profile, inject the MakinaCorpus\Profiling\Profiler service and use it.

Gauge

Use the gauge() method:

Counter

Use the counter() method:

Summary

Use the summary method in conjonction with a timer:

Of course, you could measure something else than a duration, any value which yield some meanings to you can be added to summaries.

Important note: histogram are much more performant to use than summaries in both output rendering and storage. Avoid summaries when you know in advance expected values span.

Histogram

Use the histogram method in conjonction with a timer:

Of course, you could measure something else than a duration, any value which yield some meanings to you can be added to summaries.

Important note: histogram are much more performant to use than summaries in both output rendering and storage. Always prefer histogram over summary when when you know in advance expected values span.

Exposed metrics

HTTP requests

Console commands

Messenger

Not implemented yet. It will probably be:

Monolog

Not implemented yet. It will probably be:

System information

If you don't have system monitoring, this bundle can collect a few system information samples.

Please see complete documentation in the src/Bridge/Symfony/Resources/config/packages/profiling.yaml file.

CPU load average samples:

Memory usage samples:

Disk usage samples:

Per default, if you don't configure any disk, the current project directory mount point is targeted, and NAME is app.

Warning: because the probes are only collecting data when a request happen you can chose to run the profiling:prometheus:sys-info console command to run as a cron job for collecting system information regularily.

Inject profiler into your services

When working in a Symfony project, the recommended way for registering the profiler onto a service is the following:

By using the \MakinaCorpus\Profiling\ProfilerAwareTrait you allow your code to be resilient in case of misinitialisation:

You can then use the profiler:

And that's pretty much it.

Memory usage

The timer class also measure memory usage, but beware that those results will be biased by this API itself consuming memory.

CLI killswitch

If you are working in CLI, and with to disable profiling for long running tasks or migration batches, simply add the PROFILING_ENABLE=0 environment variable in your command line.

This will not completely disable the bundle, this is a soft-disable and will only prevent profiliers from being created during this runtime, for example:

Roadmap


All versions of profiling with dependencies

PHP Build Version
Package Version
Requires php Version >= 8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package makinacorpus/profiling contains the following files

Loading the files please wait ....