From 75b0c98b2a6671e4f7b2530b42992ea670512496 Mon Sep 17 00:00:00 2001 From: Matthew Mincher Date: Tue, 27 Aug 2024 14:58:43 +0100 Subject: [PATCH] Show the parent-child call count on the graph --- src/Profile.php | 7 ++++++- tests/Profile/ProfileTest.php | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Profile.php b/src/Profile.php index fcae099e2..6c179a702 100644 --- a/src/Profile.php +++ b/src/Profile.php @@ -72,6 +72,11 @@ private function process(): void } else { $result[$func] = $values; $result[$func]['parents'] = [$parent]; + $result[$func]['parents_calls'] = []; + } + + if ($parent) { + $result[$func]['parents_calls'][$parent] = ($result[$func]['parents_calls'][$parent] ?? 0) + $values['ct']; } // Build the indexed data. @@ -622,7 +627,7 @@ private function callgraphData($parentName, $main, $metric, $threshold, $parentI $this->links[] = [ 'source' => $parentName, 'target' => $childName, - 'callCount' => $metrics['ct'], + 'callCount' => $metrics['parents_calls'][$parentName] ?? $metrics['ct'], ]; } diff --git a/tests/Profile/ProfileTest.php b/tests/Profile/ProfileTest.php index 27f9ecb01..2f540706d 100644 --- a/tests/Profile/ProfileTest.php +++ b/tests/Profile/ProfileTest.php @@ -189,7 +189,7 @@ public function testGet(): void $expected = $fixture['profile']['main()']; $result = $profile->get('main()'); - unset($result['parents']); + unset($result['parents'], $result['parents_calls']); $this->assertEquals($expected, $result); $this->assertNull($profile->get('main()', 'derp')); @@ -396,7 +396,7 @@ public function testGetCallgraph(): void [ 'source' => 'eat_burger()', 'target' => 'strlen()', - 'callCount' => 2, + 'callCount' => 1, ], [ 'source' => 'main()', @@ -411,11 +411,12 @@ public function testGetCallgraph(): void [ 'source' => 'drink_beer()', 'target' => 'strlen()', - 'callCount' => 2, + 'callCount' => 1, ], ], ]; $result = $profile->getCallgraph(); + $this->assertEquals($expected, $result); } @@ -462,7 +463,7 @@ public function testGetCallgraphNoDuplicates(): void [ 'source' => 'load_file()', 'target' => 'open()', - 'callCount' => 2, + 'callCount' => 1, ], [ 'source' => 'open()', @@ -477,7 +478,7 @@ public function testGetCallgraphNoDuplicates(): void [ 'source' => 'parse_string()', 'target' => 'open()', - 'callCount' => 2, + 'callCount' => 1, ], ], ];