Posted to tcl by miguel at Fri Oct 26 02:19:42 GMT 2007view raw
- proc stats {fname order {sense {decreasing}}} {
- #
- # Get the raw data from the file passed as argument
- #
- set f [open $fname]
- set raw [read $f]
- close $f
- set omit {};#{6 102}
- foreach line [split $raw \n] {
- lassign $line inst time count
- if {[string is integer -strict $inst] && ($inst ni $omit)} {
- incr times($inst) $time
- incr counts($inst) $count
- incr totaltime $time
- }
- }
- foreach inst [lsort -integer -increasing [array names times]] {
- lappend stats [list \
- $inst \
- [format %.2f [expr {double($times($inst)*100)/$totaltime}]] \
- [format %.2f [expr {double($times($inst))/$counts($inst)}]]\
- [format %10i $counts($inst)]]
- }
- set stats [lsort -real -$sense -index $order $stats]
- foreach line $stats {
- puts [join $line \t]
- }
- }
- set orders {inst time avg count}
- lassign $argv fname order
- if {$order ni $orders} {
- set order inst
- }
- if {$order eq "inst"} {
- set sense increasing
- } else {
- set sense decreasing
- }
- stats $fname [lsearch $orders $order] $sense