sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | #!/bin/sh |
| 2 | # \ |
| 3 | exec tclsh "$0" ${1+"$@"} |
| 4 | # |
| 5 | # A wrapper around cg_annotate that sets appropriate command-line options |
| 6 | # and rearranges the output so that annotated files occur in a consistent |
| 7 | # sorted order. Used by the speed-check.tcl script. |
| 8 | # |
| 9 | |
| 10 | set in [open "|cg_annotate --show=Ir --auto=yes --context=40 $argv" r] |
| 11 | set dest ! |
| 12 | set out(!) {} |
| 13 | set linenum 0 |
| 14 | set cntlines 0 ;# true to remember cycle counts on each line |
| 15 | set seenSqlite3 0 ;# true if we have seen the sqlite3.c file |
| 16 | while {![eof $in]} { |
| 17 | set line [string map {\t { }} [gets $in]] |
| 18 | if {[regexp {^-- Auto-annotated source: (.*)} $line all name]} { |
| 19 | set dest $name |
| 20 | if {[string match */sqlite3.c $dest]} { |
| 21 | set cntlines 1 |
| 22 | set seenSqlite3 1 |
| 23 | } else { |
| 24 | set cntlines 0 |
| 25 | } |
| 26 | } elseif {[regexp {^-- line (\d+) ------} $line all ln]} { |
| 27 | set line [lreplace $line 2 2 {#}] |
| 28 | set linenum [expr {$ln-1}] |
| 29 | } elseif {[regexp {^The following files chosen for } $line]} { |
| 30 | set dest ! |
| 31 | } |
| 32 | append out($dest) $line\n |
| 33 | if {$cntlines} { |
| 34 | incr linenum |
| 35 | if {[regexp {^ *([0-9,]+) } $line all x]} { |
| 36 | set x [string map {, {}} $x] |
| 37 | set cycles($linenum) $x |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | foreach x [lsort [array names out]] { |
| 42 | puts $out($x) |
| 43 | } |
| 44 | |
| 45 | # If the sqlite3.c file has been seen, then output a summary of the |
| 46 | # cycle counts for each file that went into making up sqlite3.c |
| 47 | # |
| 48 | if {$seenSqlite3} { |
| 49 | close $in |
| 50 | set in [open sqlite3.c] |
| 51 | set linenum 0 |
| 52 | set fn sqlite3.c |
| 53 | set pattern1 {^/\*+ Begin file ([^ ]+) \*} |
| 54 | set pattern2 {^/\*+ Continuing where we left off in ([^ ]+) \*} |
| 55 | while {![eof $in]} { |
| 56 | set line [gets $in] |
| 57 | incr linenum |
| 58 | if {[regexp $pattern1 $line all newfn]} { |
| 59 | set fn $newfn |
| 60 | } elseif {[regexp $pattern2 $line all newfn]} { |
| 61 | set fn $newfn |
| 62 | } elseif {[info exists cycles($linenum)]} { |
| 63 | incr fcycles($fn) $cycles($linenum) |
| 64 | } |
| 65 | } |
| 66 | close $in |
| 67 | puts {**********************************************************************} |
| 68 | set lx {} |
| 69 | set sum 0 |
| 70 | foreach {fn cnt} [array get fcycles] { |
| 71 | lappend lx [list $cnt $fn] |
| 72 | incr sum $cnt |
| 73 | } |
| 74 | puts [format {%20s %14d %8.3f%%} TOTAL $sum 100] |
| 75 | foreach entry [lsort -index 0 -integer -decreasing $lx] { |
| 76 | foreach {cnt fn} $entry break |
| 77 | puts [format {%20s %14d %8.3f%%} $fn $cnt [expr {$cnt*100.0/$sum}]] |
| 78 | } |
| 79 | } |