blackfireio / php-sdk

The Blackfire PHP SDK
https://blackfire.io
MIT License
150 stars 22 forks source link

Add support to define custom metric argument capture #39

Closed ibarkowski closed 5 years ago

ibarkowski commented 5 years ago

From now it's possible to define via SDK custom argument capture settings like in .blackfire.yml file, ex.

use Blackfire\Profile\Metric;

// define a custom metric
$metric = new Metric('cache.write_calls', '=Cache::write', '1', '^');

// add it to the profile configuration
// to  be able to use it in assertions
$config->defineMetric($metric);

its equal to the same definition in .blackfire.yml file:

metrics:
  cache.write: # metric name
    label: "Cache::write() calls"
    matching_calls:
      php:
        - callee:
            selector: '=Cache::write' # aggregate the costs of all Cache::write calls
            argument: { 1: "^" }  # but create separate nodes by the first argument value
iamluc commented 5 years ago

Thanks for you PR @ibarkowski !

The issue I see is that the second argument of Metric::__construct can be an array. So the captured argument will be applied to all selectors.

If I'm not mistaken, you could use instead

use Blackfire\Profile\Metric;

// define a custom metric
$metric = new Metric('cache.write_calls');
$metric->addCallee('=Cache::write')->selectArgument('1', '^')

$config->defineMetric($metric);
ibarkowski commented 5 years ago

You have right. It works like a charm. It was my mistake - I didn't found that in documentation before. You can simply reject this PR.