|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the sj-i/ package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) sji <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace PhpProfiler\Inspector\Output\TopLike; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
|
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Helper\TableCell; |
|
|
|
|
|
|
18
|
|
|
use Symfony\Component\Console\Helper\TableCellStyle; |
|
|
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
|
|
|
|
|
|
20
|
|
|
use Symfony\Component\Console\Terminal; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
final class TopLikeOutputter implements Outputter |
|
23
|
|
|
{ |
|
24
|
|
|
public function __construct( |
|
25
|
|
|
private ConsoleOutputInterface $output, |
|
26
|
|
|
private Terminal $terminal, |
|
27
|
|
|
) { |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function display(string $trace_target, Stat $stat): void |
|
31
|
|
|
{ |
|
32
|
|
|
$stat->updateStat(); |
|
33
|
|
|
$this->output($trace_target, $stat); |
|
34
|
|
|
$stat->clearCurrentSamples(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function output(string $trace_target, Stat $stat): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->output->write("\e[H\e[2J"); |
|
40
|
|
|
$this->output->writeln($trace_target); |
|
41
|
|
|
$this->output->writeln( |
|
42
|
|
|
sprintf( |
|
43
|
|
|
'samp_count=%d func_count=%d total_count=%d', |
|
44
|
|
|
$stat->sample_count, |
|
45
|
|
|
count($stat->function_entries), |
|
46
|
|
|
$stat->total_count |
|
47
|
|
|
) |
|
48
|
|
|
); |
|
49
|
|
|
$this->output->writeln(''); |
|
50
|
|
|
$count = 7; |
|
51
|
|
|
$width = $this->terminal->getWidth(); |
|
52
|
|
|
$height = $this->terminal->getHeight(); |
|
53
|
|
|
$padding_name = max(0, $width - 41); |
|
54
|
|
|
|
|
55
|
|
|
$rows = []; |
|
56
|
|
|
$align_right = new TableCellStyle(['align' => 'right']); |
|
57
|
|
|
$styled = fn (int|string $content, TableCellStyle $style): TableCell => |
|
58
|
|
|
new TableCell( |
|
59
|
|
|
(string)$content, |
|
60
|
|
|
['style' => $style] |
|
61
|
|
|
) |
|
62
|
|
|
; |
|
63
|
|
|
foreach ($stat->function_entries as $function_entry) { |
|
64
|
|
|
$name = $function_entry->name; |
|
65
|
|
|
$percent = number_format($function_entry->percent_exclusive, 2); |
|
66
|
|
|
$rows[] = [ |
|
67
|
|
|
$styled($function_entry->total_count_inclusive, $align_right), |
|
68
|
|
|
$styled($function_entry->total_count_exclusive, $align_right), |
|
69
|
|
|
$styled($function_entry->count_inclusive, $align_right), |
|
70
|
|
|
$styled($function_entry->count_exclusive, $align_right), |
|
71
|
|
|
$styled($percent, $align_right), |
|
72
|
|
|
$name, |
|
73
|
|
|
]; |
|
74
|
|
|
if (++$count > $height) { |
|
75
|
|
|
break; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$output = $this->output->section(); |
|
80
|
|
|
$table = new Table($output); |
|
81
|
|
|
$table->setColumnMaxWidth(5, max(4, $width - 41)); |
|
82
|
|
|
$table->setHeaders([ |
|
83
|
|
|
$styled('total_incl', $align_right), |
|
84
|
|
|
$styled('total_excl', $align_right), |
|
85
|
|
|
$styled('incl', $align_right), |
|
86
|
|
|
$styled('excl', $align_right), |
|
87
|
|
|
$styled('%', $align_right), |
|
88
|
|
|
str_pad('name', $padding_name), |
|
89
|
|
|
]); |
|
90
|
|
|
$table->setRows($rows); |
|
91
|
|
|
$table->setStyle('compact'); |
|
92
|
|
|
$table->getStyle()->setCellHeaderFormat('%s'); |
|
93
|
|
|
$table->render(); |
|
94
|
|
|
$output->overwrite( |
|
95
|
|
|
preg_replace( |
|
96
|
|
|
'/( *total_incl.*)/', |
|
97
|
|
|
'<bg=bright-white;fg=black>$1</>', |
|
98
|
|
|
preg_replace( |
|
99
|
|
|
'/\e[[][A-Za-z0-9]*;?[0-9]*m?/', |
|
100
|
|
|
'', |
|
101
|
|
|
$output->getContent() |
|
102
|
|
|
) |
|
103
|
|
|
) |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths