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];
}
///////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Writes the graph structure of AIG for DOT.] Description [Useful for graph visualization using tools such as GraphViz: http://www.graphviz.org/] SideEffects [] SeeAlso [] ***********************************************************************/ void Aig_WriteDotAig( Aig_Man_t * pMan, char * pFileName, int fHaig, Vec_Ptr_t * vBold ) { FILE * pFile; Aig_Obj_t * pNode;//, * pTemp, * pPrev; int LevelMax, Level, i; if ( Aig_ManNodeNum(pMan) > 200 ) { fprintf( stdout, "Cannot visualize AIG with more than 200 nodes.\n" ); return; } if ( (pFile = fopen( pFileName, "w" )) == NULL ) { fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", pFileName ); return; } // mark the nodes if ( vBold ) Vec_PtrForEachEntry( vBold, pNode, i ) pNode->fMarkB = 1; // compute levels // LevelMax = 1 + Aig_ManSetLevels( pMan, fHaig ); LevelMax = 1 + Aig_ManLevels( pMan ); Aig_ManForEachPo( pMan, pNode, i ) pNode->Level = LevelMax; // write the DOT header fprintf( pFile, "# %s\n", "AIG structure generated by IVY package" ); fprintf( pFile, "\n" ); fprintf( pFile, "digraph AIG {\n" ); fprintf( pFile, "size = \"7.5,10\";\n" ); // fprintf( pFile, "ranksep = 0.5;\n" ); // fprintf( pFile, "nodesep = 0.5;\n" ); fprintf( pFile, "center = true;\n" ); // fprintf( pFile, "orientation = landscape;\n" ); // fprintf( pFile, "edge [fontsize = 10];\n" ); // fprintf( pFile, "edge [dir = none];\n" ); fprintf( pFile, "edge [dir = back];\n" ); fprintf( pFile, "\n" ); // labels on the left of the picture fprintf( pFile, "{\n" ); fprintf( pFile, " node [shape = plaintext];\n" ); fprintf( pFile, " edge [style = invis];\n" ); fprintf( pFile, " LevelTitle1 [label=\"\"];\n" ); fprintf( pFile, " LevelTitle2 [label=\"\"];\n" ); // generate node names with labels for ( Level = LevelMax; Level >= 0; Level-- ) { // the visible node name fprintf( pFile, " Level%d", Level ); fprintf( pFile, " [label = " ); // label name fprintf( pFile, "\"" ); fprintf( pFile, "\"" ); fprintf( pFile, "];\n" ); } // genetate the sequence of visible/invisible nodes to mark levels fprintf( pFile, " LevelTitle1 -> LevelTitle2 ->" ); for ( Level = LevelMax; Level >= 0; Level-- ) { // the visible node name fprintf( pFile, " Level%d", Level ); // the connector if ( Level != 0 ) fprintf( pFile, " ->" ); else fprintf( pFile, ";" ); } fprintf( pFile, "\n" ); fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); // generate title box on top fprintf( pFile, "{\n" ); fprintf( pFile, " rank = same;\n" ); fprintf( pFile, " LevelTitle1;\n" ); fprintf( pFile, " title1 [shape=plaintext,\n" ); fprintf( pFile, " fontsize=20,\n" ); fprintf( pFile, " fontname = \"Times-Roman\",\n" ); fprintf( pFile, " label=\"" ); fprintf( pFile, "%s", "AIG structure visualized by ABC" ); fprintf( pFile, "\\n" ); fprintf( pFile, "Benchmark \\\"%s\\\". ", "aig" ); // fprintf( pFile, "Time was %s. ", Extra_TimeStamp() ); fprintf( pFile, "\"\n" ); fprintf( pFile, " ];\n" ); fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); // generate statistics box fprintf( pFile, "{\n" ); fprintf( pFile, " rank = same;\n" ); fprintf( pFile, " LevelTitle2;\n" ); fprintf( pFile, " title2 [shape=plaintext,\n" ); fprintf( pFile, " fontsize=18,\n" ); fprintf( pFile, " fontname = \"Times-Roman\",\n" ); fprintf( pFile, " label=\"" ); fprintf( pFile, "The set contains %d logic nodes and spans %d levels.", Aig_ManNodeNum(pMan), LevelMax ); fprintf( pFile, "\\n" ); fprintf( pFile, "\"\n" ); fprintf( pFile, " ];\n" ); fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); // generate the COs fprintf( pFile, "{\n" ); fprintf( pFile, " rank = same;\n" ); // the labeling node of this level fprintf( pFile, " Level%d;\n", LevelMax ); // generate the CO nodes Aig_ManForEachPo( pMan, pNode, i ) { /* if ( fHaig || pNode->pEquiv == NULL ) fprintf( pFile, " Node%d%s [label = \"%d%s\"", pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":"") ); else fprintf( pFile, " Node%d%s [label = \"%d%s(%d%s)\"", pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":""), Aig_Regular(pNode->pEquiv)->Id, Aig_IsComplement(pNode->pEquiv)? "\'":"" ); */ fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); fprintf( pFile, ", shape = %s", "invtriangle" ); fprintf( pFile, ", color = coral, fillcolor = coral" ); fprintf( pFile, "];\n" ); } fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); // generate nodes of each rank for ( Level = LevelMax - 1; Level > 0; Level-- ) { fprintf( pFile, "{\n" ); fprintf( pFile, " rank = same;\n" ); // the labeling node of this level fprintf( pFile, " Level%d;\n", Level ); Aig_ManForEachObj( pMan, pNode, i ) { if ( (int)pNode->Level != Level ) continue; /* if ( fHaig || pNode->pEquiv == NULL ) fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); else fprintf( pFile, " Node%d [label = \"%d(%d%s)\"", pNode->Id, pNode->Id, Aig_Regular(pNode->pEquiv)->Id, Aig_IsComplement(pNode->pEquiv)? "\'":"" ); */ fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); fprintf( pFile, ", shape = ellipse" ); if ( vBold && pNode->fMarkB ) fprintf( pFile, ", style = filled" ); fprintf( pFile, "];\n" ); } fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); } // generate the CI nodes fprintf( pFile, "{\n" ); fprintf( pFile, " rank = same;\n" ); // the labeling node of this level fprintf( pFile, " Level%d;\n", 0 ); // generate constant node if ( Aig_ObjRefs(Aig_ManConst1(pMan)) > 0 ) { pNode = Aig_ManConst1(pMan); // check if the costant node is present fprintf( pFile, " Node%d [label = \"Const1\"", pNode->Id ); fprintf( pFile, ", shape = ellipse" ); fprintf( pFile, ", color = coral, fillcolor = coral" ); fprintf( pFile, "];\n" ); } // generate the CI nodes Aig_ManForEachPi( pMan, pNode, i ) { /* if ( fHaig || pNode->pEquiv == NULL ) fprintf( pFile, " Node%d%s [label = \"%d%s\"", pNode->Id, (Aig_ObjIsLatch(pNode)? "_out":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_out":"") ); else fprintf( pFile, " Node%d%s [label = \"%d%s(%d%s)\"", pNode->Id, (Aig_ObjIsLatch(pNode)? "_out":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_out":""), Aig_Regular(pNode->pEquiv)->Id, Aig_IsComplement(pNode->pEquiv)? "\'":"" ); */ fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); fprintf( pFile, ", shape = %s", "triangle" ); fprintf( pFile, ", color = coral, fillcolor = coral" ); fprintf( pFile, "];\n" ); } fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); // generate invisible edges from the square down fprintf( pFile, "title1 -> title2 [style = invis];\n" ); Aig_ManForEachPo( pMan, pNode, i ) fprintf( pFile, "title2 -> Node%d [style = invis];\n", pNode->Id ); // generate edges Aig_ManForEachObj( pMan, pNode, i ) { if ( !Aig_ObjIsNode(pNode) && !Aig_ObjIsPo(pNode) && !Aig_ObjIsBuf(pNode) ) continue; // generate the edge from this node to the next fprintf( pFile, "Node%d", pNode->Id ); fprintf( pFile, " -> " ); fprintf( pFile, "Node%d", Aig_ObjFaninId0(pNode) ); fprintf( pFile, " [" ); fprintf( pFile, "style = %s", Aig_ObjFaninC0(pNode)? "dotted" : "bold" ); // if ( Aig_NtkIsSeq(pNode->pMan) && Seq_ObjFaninL0(pNode) > 0 ) // fprintf( pFile, ", label = \"%s\"", Seq_ObjFaninGetInitPrintable(pNode,0) ); fprintf( pFile, "]" ); fprintf( pFile, ";\n" ); if ( !Aig_ObjIsNode(pNode) ) continue; // generate the edge from this node to the next fprintf( pFile, "Node%d", pNode->Id ); fprintf( pFile, " -> " ); fprintf( pFile, "Node%d", Aig_ObjFaninId1(pNode) ); fprintf( pFile, " [" ); fprintf( pFile, "style = %s", Aig_ObjFaninC1(pNode)? "dotted" : "bold" ); // if ( Aig_NtkIsSeq(pNode->pMan) && Seq_ObjFaninL1(pNode) > 0 ) // fprintf( pFile, ", label = \"%s\"", Seq_ObjFaninGetInitPrintable(pNode,1) ); fprintf( pFile, "]" ); fprintf( pFile, ";\n" ); /* // generate the edges between the equivalent nodes if ( fHaig && pNode->pEquiv && Aig_ObjRefs(pNode) > 0 ) { pPrev = pNode; for ( pTemp = pNode->pEquiv; pTemp != pNode; pTemp = Aig_Regular(pTemp->pEquiv) ) { fprintf( pFile, "Node%d", pPrev->Id ); fprintf( pFile, " -> " ); fprintf( pFile, "Node%d", pTemp->Id ); fprintf( pFile, " [style = %s]", Aig_IsComplement(pTemp->pEquiv)? "dotted" : "bold" ); fprintf( pFile, ";\n" ); pPrev = pTemp; } // connect the last node with the first fprintf( pFile, "Node%d", pPrev->Id ); fprintf( pFile, " -> " ); fprintf( pFile, "Node%d", pNode->Id ); fprintf( pFile, " [style = %s]", Aig_IsComplement(pPrev->pEquiv)? "dotted" : "bold" ); fprintf( pFile, ";\n" ); } */ } fprintf( pFile, "}" ); fprintf( pFile, "\n" ); fprintf( pFile, "\n" ); fclose( pFile ); // unmark nodes if ( vBold ) Vec_PtrForEachEntry( vBold, pNode, i ) pNode->fMarkB = 0; Aig_ManForEachPo( pMan, pNode, i ) pNode->Level = Aig_ObjFanin0(pNode)->Level; } /**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Aig_ManShow( Aig_Man_t * pMan, int fHaig, Vec_Ptr_t * vBold ) { extern void Abc_ShowFile( char * FileNameDot ); static Counter = 0; char FileNameDot[200]; FILE * pFile; // create the file name // Aig_ShowGetFileName( pMan->pName, FileNameDot ); sprintf( FileNameDot, "temp%02d.dot", Counter++ ); // check that the file can be opened if ( (pFile = fopen( FileNameDot, "w" )) == NULL ) { fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot ); return; } fclose( pFile ); // generate the file Aig_WriteDotAig( pMan, FileNameDot, fHaig, vBold ); // visualize the file Abc_ShowFile( FileNameDot ); } //////////////////////////////////////////////////////////////////////// /// END OF FILE /// ////////////////////////////////////////////////////////////////////////