aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tools/profiler.pl
blob: 456f634bc6aae7348a82be09c837622a640dcc92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
# parse 'yosys -t' logfile and find slow passes

my $max_depth = 0;
my %last_line_by_depth;
my %last_time_by_depth;

my @lines_text;
my @lines_depth;
my @lines_time;

while (<>)
{
	chomp;
	next unless /^\[([0-9.]+)\] (([0-9]+\.)+)/;
	my ($this_time, $this_id, $this_header) = ($1, $2, $4);

	push @lines_text, $_;
	push @lines_depth, 0;
	push @lines_time, 0;

	my $depth = $this_id;
	$depth =~ s/[^.]//g;
	$depth = length $depth;
	$max_depth = $depth if $depth > $max_depth;

	for (my $i = $depth; $i <= $max_depth; $i++) {
		next unless exists $last_time_by_depth{$i};
		$lines_time[$last_line_by_depth{$i}] = $this_time-$last_time_by_depth{$i};
		delete $last_time_by_depth{$i};
		delete $last_header_by_depth{$i};
	}

	$last_time_by_depth{$depth} = $this_time;
	$last_line_by_depth{$depth} = $#lines_text;
	$lines_depth[$#lines_text] = $depth;
}

for (my $depth = 1; $depth <= $max_depth; $depth++) {
	printf "\nSlow passes on recursion depth %d:\n", $depth;
	my @lines;
	for (my $i = 0; $i <= $#lines_text; $i++) {
		next if $lines_depth[$i] != $depth or $lines_time[$i] < 1.0;
		push @lines, sprintf("%3d  %08.2f  %s\n", $lines_depth[$i], $lines_time[$i], $lines_text[$i]);
	}
	for my $line (sort {$b cmp $a} @lines) {
		print $line;
	}
}

printf "\nFull journal of headers:\n";
for (my $i = 0; $i <= $#lines_text; $i++) {
	printf "%3d  %08.2f  %s\n", $lines_depth[$i], $lines_time[$i], $lines_text[$i];
}