phperf / percentiller
此包最新版本(v1.0)没有可用的许可信息。
流式化集群化统计数据收集器。
v1.0
2015-09-16 09:40 UTC
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-09-18 00:48:17 UTC
README
Percentiller 是一个用于捕获和分析数据分布的 PHP 类。轻量级,对 CPU 和内存消耗低。通过数据分桶近似百分位数。
安装
composer install phperf/percentiller
用法
$stats = new \Phperf\Percentiller(); // approximation level, more buckets - higher distribution definition for more CPU and memory $stats->maxBuckets = 10; // capture values and meta for 5 items with lowest values $stats->captureBottomItems = 5; // capture values and meta for 3 items with highest values $stats->captureTopItems = 3; ....... // somewhere in data streamer/iterator, replace $event with your data element $stats->add($event->getResponseTime(), $event->getQueryInfo()); ....... // statistics retrieval // 95% events had response time not greater than: $stats->bottomPercentile(0.95); // 10% events took longer or equal to: $stats->topPercentile(0.1); // get information on slowest events $stats->getTopMetas(); // get information on slowest events $stats->getBottomMetas(); // iterate through distribution foreach ($stats->buckets as $bucket) { print_r($bucket); /* Array ( [0] => 41.558 // minival value [1] => 50.95 // maximal value [2] => 137 // count [3] => Array // sample meta ( [somedata] => somevalue ) ) */ }