Snapshot of upstream SQLite 3.26.0
[sqlcipher.git] / tool / opcodesum.tcl
blob47dff32b9075001fc2dd378e6d82dc2f62f3483f
1 #!/usr/bin/tclsh
3 # Run this script, redirecting input from cachegrind output, to compute the
4 # number of CPU cycles used by each VDBE opcode.
6 # The cachegrind output should be configured so that it reports a single
7 # column of Ir at the left margin. Ex:
9 # cg_annotation --show=Ir --auto=yes cachegrind.out.* | tclsh opcodesum.tcl
11 set currentop x
12 set ncycle(x) 0
13 while {![eof stdin]} {
14 set line [string map {\173 x \175 x \042 x} [gets stdin]]
15 if {[regexp { \. case OP_.*:} $line]} {
16 regexp {OP_(.+):} $line all currentop
17 set ncycle($currentop) 0
18 } elseif {[lindex $line 1]=="default:"
19 && [regexp {really OP_Noop and OP_Explain} $line]} {
20 break
21 } elseif {[lindex $line 0]!="."} {
22 regsub -all {[^0-9]} [lindex $line 0] {} n
23 if {$n!=""} {incr ncycle($currentop) $n}
26 unset ncycle(x)
27 set results {}
28 foreach op [lsort [array names ncycle]] {
29 if {$ncycle($op)==0} continue
30 lappend results [list $ncycle($op) $op]
32 foreach entry [lsort -index 0 -int -decr $results] {
33 puts [format {%-16s %10d} [lindex $entry 1] [lindex $entry 0]]