0
0
mirror of https://github.com/sqlite/sqlite.git synced 2024-11-22 03:40:55 +01:00
sqlite/tool/opcodesum.tcl
drh 860a95fd01 Add a simple TCL script for summing cachegrind information for each VDBE
opcdoe.

FossilOrigin-Name: 96cf821b6a69e2e8df33271b7bb674bd12a1ef7b
2016-05-20 23:51:14 +00:00

35 lines
1.1 KiB
Tcl

#!/usr/bin/tclsh
#
# Run this script, redirecting input from cachegrind output, to compute the
# number of CPU cycles used by each VDBE opcode.
#
# The cachegrind output should be configured so that it reports a single
# column of Ir at the left margin. Ex:
#
# cg_annotation --show=Ir --auto=yes cachegrind.out.* | tclsh opcodesum.tcl
#
set currentop x
set ncycle(x) 0
while {![eof stdin]} {
set line [string map {\173 x \175 x \042 x} [gets stdin]]
if {[regexp { \. case OP_.*:} $line]} {
regexp {OP_(.+):} $line all currentop
set ncycle($currentop) 0
} elseif {[lindex $line 1]=="default:"
&& [regexp {really OP_Noop and OP_Explain} $line]} {
break
} elseif {[lindex $line 0]!="."} {
regsub -all {[^0-9]} [lindex $line 0] {} n
if {$n!=""} {incr ncycle($currentop) $n}
}
}
unset ncycle(x)
set results {}
foreach op [lsort [array names ncycle]] {
if {$ncycle($op)==0} continue
lappend results [list $ncycle($op) $op]
}
foreach entry [lsort -index 0 -int -decr $results] {
puts [format {%-16s %10d} [lindex $entry 1] [lindex $entry 0]]
}