Index: src/vdbeaux.c ================================================================== --- src/vdbeaux.c +++ src/vdbeaux.c @@ -1172,11 +1172,11 @@ if( pOut==0 ) pOut = stdout; zP4 = displayP4(pOp, zPtr, sizeof(zPtr)); #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS displayComment(pOp, zP4, zCom, sizeof(zCom)); #else - zCom[0] = 0 + zCom[0] = 0; #endif /* NB: The sqlite3OpcodeName() function is implemented by code created ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the ** information from the vdbe.c source text */ fprintf(pOut, zFormat1, pc, @@ -2550,10 +2550,20 @@ fprintf(out, "---- "); for(i=0; inOp; i++){ fprintf(out, "%02x", p->aOp[i].opcode); } fprintf(out, "\n"); + if( p->zSql ){ + char c, pc = 0; + fprintf(out, "-- "); + for(i=0; (c = p->zSql[i])!=0; i++){ + if( pc=='\n' ) fprintf(out, "-- "); + putc(c, out); + pc = c; + } + if( pc!='\n' ) fprintf(out, "\n"); + } for(i=0; inOp; i++){ fprintf(out, "%6d %10lld %8lld ", p->aOp[i].cnt, p->aOp[i].cycles, p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0 ADDED tool/vdbe_profile.tcl Index: tool/vdbe_profile.tcl ================================================================== --- /dev/null +++ tool/vdbe_profile.tcl @@ -0,0 +1,82 @@ +#!/bin/tclsh +# +# Run this script in the same directory as the "vdbe_profile.out" file. +# This script summarizes the results contained in that file. +# +if {![file readable vdbe_profile.out]} { + error "run this script in the same directory as the vdbe_profile.out file" +} +set in [open vdbe_profile.out r] +set stmt {} +set allstmt {} +while {![eof $in]} { + set line [gets $in] + if {$line==""} continue + if {[regexp {^---- } $line]} { + set stmt [lindex $line 1] + if {[info exists cnt($stmt)]} { + incr cnt($stmt) + set firsttime 0 + } else { + set cnt($stmt) 1 + set sql($stmt) {} + set firsttime 1 + lappend allstmt $stmt + } + continue; + } + if {[regexp {^-- } $line]} { + if {$firsttime} { + append sql($stmt) [string range $line 3 end]\n + } + continue + } + if {![regexp {^ *\d+ *\d+ *\d+ *\d+ ([A-Z].*)} $line all detail]} continue + set c [lindex $line 0] + set t [lindex $line 1] + set addr [lindex $line 3] + set op [lindex $line 4] + if {[info exists opcnt($op)]} { + incr opcnt($op) $c + incr opcycle($op) $t + } else { + set opcnt($op) $c + set opcycle($op) $t + } + if {[info exists stat($stmt,$addr)]} { + foreach {cx tx detail} $stat($stmt,$addr) break + incr cx $c + incr tx $t + set stat($stmt,$addr) [list $cx $tx $detail] + } else { + set stat($stmt,$addr) [list $c $t $detail] + } +} +close $in + +foreach stmt $allstmt { + puts "********************************************************************" + puts [string trim $sql($stmt)] + puts "Execution count: $cnt($stmt)" + for {set i 0} {[info exists stat($stmt,$i)]} {incr i} { + foreach {cx tx detail} $stat($stmt,$i) break + if {$cx==0} { + set ax 0 + } else { + set ax [expr {$tx/$cx}] + } + puts [format {%8d %12d %12d %4d %s} $cx $tx $ax $i $detail] + } +} +puts "********************************************************************" +puts "OPCODES:" +foreach op [lsort [array names opcnt]] { + set cx $opcnt($op) + set tx $opcycle($op) + if {$cx==0} { + set ax 0 + } else { + set ax [expr {$tx/$cx}] + } + puts [format {%8d %12d %12d %s} $cx $tx $ax $op] +}