cg_anno.tcl 2.3 KB

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