|
|
|
|
|
|
|
|
exec tclsh "$0" ${1+"$@"} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set in [open "|cg_annotate --show=Ir --auto=yes --context=40 $argv" r] |
|
|
set dest ! |
|
|
set out(!) {} |
|
|
set linenum 0 |
|
|
set cntlines 0 |
|
|
set seenSqlite3 0 |
|
|
while {![eof $in]} { |
|
|
set line [string map {\t { }} [gets $in]] |
|
|
if {[regexp {^-- Auto-annotated source: (.*)} $line all name]} { |
|
|
set dest $name |
|
|
if {[string match */sqlite3.c $dest]} { |
|
|
set cntlines 1 |
|
|
set seenSqlite3 1 |
|
|
} else { |
|
|
set cntlines 0 |
|
|
} |
|
|
} elseif {[regexp {^-- line (\d+) ------} $line all ln]} { |
|
|
set line [lreplace $line 2 2 {#}] |
|
|
set linenum [expr {$ln-1}] |
|
|
} elseif {[regexp {^The following files chosen for } $line]} { |
|
|
set dest ! |
|
|
} |
|
|
append out($dest) $line\n |
|
|
if {$cntlines} { |
|
|
incr linenum |
|
|
if {[regexp {^ *([0-9,]+) } $line all x]} { |
|
|
set x [string map {, {}} $x] |
|
|
set cycles($linenum) $x |
|
|
} |
|
|
} |
|
|
} |
|
|
foreach x [lsort [array names out]] { |
|
|
puts $out($x) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 %14d %8.3f%%} TOTAL $sum 100] |
|
|
foreach entry [lsort -index 0 -integer -decreasing $lx] { |
|
|
foreach {cnt fn} $entry break |
|
|
puts [format {%20s %14d %8.3f%%} $fn $cnt [expr {$cnt*100.0/$sum}]] |
|
|
} |
|
|
} |
|
|
|