blob: 47dff32b9075001fc2dd378e6d82dc2f62f3483f [file] [log] [blame]
drh860a95f2016-05-20 23:51:14 +00001#!/usr/bin/tclsh
2#
3# Run this script, redirecting input from cachegrind output, to compute the
4# number of CPU cycles used by each VDBE opcode.
5#
6# The cachegrind output should be configured so that it reports a single
7# column of Ir at the left margin. Ex:
8#
9# cg_annotation --show=Ir --auto=yes cachegrind.out.* | tclsh opcodesum.tcl
10#
11set currentop x
12set ncycle(x) 0
13while {![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}
24 }
25}
26unset ncycle(x)
27set results {}
28foreach op [lsort [array names ncycle]] {
29 if {$ncycle($op)==0} continue
30 lappend results [list $ncycle($op) $op]
31}
32foreach entry [lsort -index 0 -int -decr $results] {
33 puts [format {%-16s %10d} [lindex $entry 1] [lindex $entry 0]]
34}