2019-03-19 11:35:18 +00:00
# !/bin/sh
# \
exec tclsh " $ 0 " $ { 1 + " $ @ " }
2015-11-09 12:44:19 +00:00
#
# A wrapper around cg_annotate that sets appropriate command-line options
# and rearranges the output so that annotated files occur in a consistent
2016-12-08 18:36:19 +00:00
# sorted order. Used by the speed-check.tcl script.
2015-11-09 12:44:19 +00:00
#
set in [ open " | c g _ a n n o t a t e - - s h o w = I r - - a u t o = y e s - - c o n t e x t = 4 0 $ a r g v " r]
set dest !
set out( ! ) { }
2016-12-08 18:36:19 +00:00
set linenum 0
set cntlines 0 ; # true to remember cycle counts on each line
set seenSqlite3 0 ; # true if we have seen the sqlite3.c file
2015-11-09 12:44:19 +00:00
while { ! [ eof $in ] } {
set line [ string map { \ t { } } [ gets $in ] ]
if { [ regexp { ^ -- Auto-annotated source: ( . * ) } $line all name] } {
set dest $name
2016-12-08 18:36:19 +00:00
if { [ string match * / sqlite3.c $dest ] } {
set cntlines 1
set seenSqlite3 1
} else {
set cntlines 0
}
} elseif { [ regexp { ^ -- line ( \ d + ) - - - - - - } $line all ln] } {
2015-11-09 12:44:19 +00:00
set line [ lreplace $line 2 2 { # }]
2016-12-08 18:36:19 +00:00
set linenum [ expr { $ln-1 } ]
2015-11-09 12:44:19 +00:00
} elseif { [ regexp { ^ The following files chosen for } $line ] } {
set dest !
}
append out( $dest ) $line \ n
2016-12-08 19:04:36 +00:00
if { $cntlines } {
2016-12-08 18:36:19 +00:00
incr linenum
if { [ regexp { ^ * ( [ 0-9 , ] + ) } $line all x] } {
set x [ string map { , { } } $x ]
set cycles( $linenum ) $x
}
}
2015-11-09 12:44:19 +00:00
}
foreach x [ lsort [ array names out] ] {
puts $out ( $x )
}
2016-12-08 18:36:19 +00:00
# If the sqlite3.c file has been seen, then output a summary of the
# cycle counts for each file that went into making up sqlite3.c
#
if { $seenSqlite3 } {
close $in
set in [ open sqlite3.c]
set linenum 0
set fn sqlite3.c
set pattern1 { ^ / \ * + Begin file ( [ ^ ] + ) \ * }
set pattern2 { ^ / \ * + Continuing where we left off in ( [ ^ ] + ) \ * }
while { ! [ eof $in ] } {
set line [ gets $in ]
incr linenum
if { [ regexp $pattern1 $line all newfn] } {
set fn $newfn
} elseif { [ regexp $pattern2 $line all newfn] } {
set fn $newfn
} elseif { [ info exists cycles( $linenum ) ] } {
incr fcycles( $fn ) $cycles ( $linenum )
}
}
close $in
puts { ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** }
set lx { }
set sum 0
foreach { fn cnt} [ array get fcycles] {
lappend lx [ list $cnt $fn ]
incr sum $cnt
}
puts [ format { % 20s % 14 d % 8.3 f% % } TOTAL $sum 100 ]
foreach entry [ lsort - index 0 - integer - decreasing $lx ] {
foreach { cnt fn} $entry break
puts [ format { % 20s % 14 d % 8.3 f% % } $fn $cnt [ expr { $cnt * 100.0 / $sum } ] ]
}
}