Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the parent-child call count on the graph #500

Open
wants to merge 1 commit into
base: 0.23.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'],
];
}

Expand Down
11 changes: 6 additions & 5 deletions tests/Profile/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -396,7 +396,7 @@ public function testGetCallgraph(): void
[
'source' => 'eat_burger()',
'target' => 'strlen()',
'callCount' => 2,
'callCount' => 1,
],
[
'source' => 'main()',
Expand All @@ -411,11 +411,12 @@ public function testGetCallgraph(): void
[
'source' => 'drink_beer()',
'target' => 'strlen()',
'callCount' => 2,
'callCount' => 1,
],
],
];
$result = $profile->getCallgraph();

$this->assertEquals($expected, $result);
}

Expand Down Expand Up @@ -462,7 +463,7 @@ public function testGetCallgraphNoDuplicates(): void
[
'source' => 'load_file()',
'target' => 'open()',
'callCount' => 2,
'callCount' => 1,
],
[
'source' => 'open()',
Expand All @@ -477,7 +478,7 @@ public function testGetCallgraphNoDuplicates(): void
[
'source' => 'parse_string()',
'target' => 'open()',
'callCount' => 2,
'callCount' => 1,
],
],
];
Expand Down