Skip to content

Commit cec3628

Browse files
authored
Merge pull request #500 from matthewmincher/bugfix/track-parent-calls
2 parents 85d6a51 + 75b0c98 commit cec3628

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/Profile.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ private function process(): void
7272
} else {
7373
$result[$func] = $values;
7474
$result[$func]['parents'] = [$parent];
75+
$result[$func]['parents_calls'] = [];
76+
}
77+
78+
if ($parent) {
79+
$result[$func]['parents_calls'][$parent] = ($result[$func]['parents_calls'][$parent] ?? 0) + $values['ct'];
7580
}
7681

7782
// Build the indexed data.
@@ -622,7 +627,7 @@ private function callgraphData($parentName, $main, $metric, $threshold, $parentI
622627
$this->links[] = [
623628
'source' => $parentName,
624629
'target' => $childName,
625-
'callCount' => $metrics['ct'],
630+
'callCount' => $metrics['parents_calls'][$parentName] ?? $metrics['ct'],
626631
];
627632
}
628633

tests/Profile/ProfileTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function testGet(): void
189189

190190
$expected = $fixture['profile']['main()'];
191191
$result = $profile->get('main()');
192-
unset($result['parents']);
192+
unset($result['parents'], $result['parents_calls']);
193193
$this->assertEquals($expected, $result);
194194

195195
$this->assertNull($profile->get('main()', 'derp'));
@@ -396,7 +396,7 @@ public function testGetCallgraph(): void
396396
[
397397
'source' => 'eat_burger()',
398398
'target' => 'strlen()',
399-
'callCount' => 2,
399+
'callCount' => 1,
400400
],
401401
[
402402
'source' => 'main()',
@@ -411,11 +411,12 @@ public function testGetCallgraph(): void
411411
[
412412
'source' => 'drink_beer()',
413413
'target' => 'strlen()',
414-
'callCount' => 2,
414+
'callCount' => 1,
415415
],
416416
],
417417
];
418418
$result = $profile->getCallgraph();
419+
419420
$this->assertEquals($expected, $result);
420421
}
421422

@@ -462,7 +463,7 @@ public function testGetCallgraphNoDuplicates(): void
462463
[
463464
'source' => 'load_file()',
464465
'target' => 'open()',
465-
'callCount' => 2,
466+
'callCount' => 1,
466467
],
467468
[
468469
'source' => 'open()',
@@ -477,7 +478,7 @@ public function testGetCallgraphNoDuplicates(): void
477478
[
478479
'source' => 'parse_string()',
479480
'target' => 'open()',
480-
'callCount' => 2,
481+
'callCount' => 1,
481482
],
482483
],
483484
];

0 commit comments

Comments
 (0)