Posted to tcl by miguel at Fri Oct 26 02:19:42 GMT 2007view raw

  1. proc stats {fname order {sense {decreasing}}} {
  2. #
  3. # Get the raw data from the file passed as argument
  4. #
  5.  
  6. set f [open $fname]
  7. set raw [read $f]
  8. close $f
  9.  
  10. set omit {};#{6 102}
  11. foreach line [split $raw \n] {
  12. lassign $line inst time count
  13. if {[string is integer -strict $inst] && ($inst ni $omit)} {
  14. incr times($inst) $time
  15. incr counts($inst) $count
  16. incr totaltime $time
  17. }
  18. }
  19.  
  20. foreach inst [lsort -integer -increasing [array names times]] {
  21. lappend stats [list \
  22. $inst \
  23. [format %.2f [expr {double($times($inst)*100)/$totaltime}]] \
  24. [format %.2f [expr {double($times($inst))/$counts($inst)}]]\
  25. [format %10i $counts($inst)]]
  26. }
  27.  
  28. set stats [lsort -real -$sense -index $order $stats]
  29.  
  30. foreach line $stats {
  31. puts [join $line \t]
  32. }
  33. }
  34.  
  35.  
  36. set orders {inst time avg count}
  37. lassign $argv fname order
  38. if {$order ni $orders} {
  39. set order inst
  40. }
  41. if {$order eq "inst"} {
  42. set sense increasing
  43. } else {
  44. set sense decreasing
  45. }
  46.  
  47. stats $fname [lsearch $orders $order] $sense