diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b43524..45b46db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ There are next changes: +## 1.2.17 + +There are next changes: + +- made /profiler/method-used-apps.json compatible to phpstorm plugin + ## 1.2.16 There are next changes: diff --git a/src/www/index.php b/src/www/index.php index 746fe7f..72085ce 100644 --- a/src/www/index.php +++ b/src/www/index.php @@ -133,8 +133,37 @@ /** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */ $Page = $App->getPage('ajax_pages'); + $method_data = $Page->getMethodUsedApps($method); - echo json_encode($Page->getMethodUsedApps($method)); + $result = []; + if ($method_data) { + foreach ($method_data as $item) { + if (empty($item['fields']) || empty($item['fields']['calls_count'])) { + continue; + } + + $item['cpu'] = $item['fields']['cpu'] / 1000; + $item['ct'] = $item['fields']['ct']; + $item['calls_count'] = (int)$item['fields']['calls_count']; + unset($item['fields']); + // Keep 1 app with maximum cpu + if (isset($result[$item['app']]) && $result[$item['app']]['cpu'] > $item['cpu']) { + continue; + } + $result[$item['app']] = $item; + } + + uasort( + $result, + static function ($a, $b) { + return $b['cpu'] <=> $a['cpu']; + } + ); + + $result = array_values($result); + } + + echo json_encode($result); break; case '/profiler/all-methods.json':