add this at the beginning of db_exec in 10-database-procs.tcl:
nsv_set_or_incr db_debug_counter $statement_name
where nsv_set_or_incr is defined as:
proc_doc nsv_set_or_incr {set key {delta 1}} {
if $key exists in $set, incr it, else set to $delta
} {
if [catch {
nsv_incr $set $key $delta
}] {
nsv_set $set $key $delta
}
}
Then getting a list of candidates for optimization is as simple as this page:
set l {}
foreach {key value} [nsv_array get db_debug_counter] {
lappend l [list $key $value]
}
set l [lsort -integer -index 1 $l]
ns_return 200 text/html "
<ul><li>[join $l <li>]</ul>
"
db_exec could easily be extended to time the queries as well.