bench_read.tcl

Go to the documentation of this file.
00001 /*  bench_read.tcl --*/
00002 /* */
00003 /*  Management of benchmarks, reading results in various formats.*/
00004 /* */
00005 /*  Copyright (c) 2005 by Andreas Kupries <andreas_kupries@users.sourceforge.net>*/
00006 /*  library derived from runbench.tcl application (C) Jeff Hobbs.*/
00007 /* */
00008 /*  See the file "license.terms" for information on usage and redistribution*/
00009 /*  of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00010 /*  */
00011 /*  RCS: @(#) $Id: bench_read.tcl,v 1.3 2006/06/13 23:20:30 andreas_kupries Exp $*/
00012 
00013 /*  ### ### ### ######### ######### ######### ###########################*/
00014 /*  Requisites - Packages and namespace for the commands and data.*/
00015 
00016 package require Tcl 8.2
00017 package require csv
00018 
00019 namespace ::bench::in {}
00020 
00021 /*  ### ### ### ######### ######### ######### ###########################*/
00022 /*  Public API - Result reading*/
00023 
00024 /*  ::bench::in::read --*/
00025 /* */
00026 /*  Read a bench result in any of the raw/csv/text formats*/
00027 /* */
00028 /*  Arguments:*/
00029 /*  path to file to read*/
00030 /* */
00031 /*  Results:*/
00032 /*  DATA dictionary, internal representation of the bench results.*/
00033 
00034 ret  ::bench::in::read (type file) {
00035 
00036     set f [open $file r]
00037     set head [gets $f]
00038 
00039     if {![string match "# -\\*- tcl -\\*- bench/*" $head]} {
00040     return -code error "Bad file format, not a benchmark file"
00041     } else {
00042     regexp {bench/(.*)$} $head -> format
00043 
00044     switch -exact -- $format {
00045         raw - csv - text {
00046         set res [RD$format $f]
00047         }
00048         default {
00049         return -code error "Bad format \"$val\", expected text, csv, or raw"
00050         }
00051     }
00052     }
00053     close $f
00054     return $res
00055 }
00056 
00057 /*  ### ### ### ######### ######### ######### ###########################*/
00058 /*  Internal commands*/
00059 
00060 ret  ::bench::in::RDraw (type chan) {
00061     return [string trimright [::read $chan]]
00062 }
00063 
00064 ret  ::bench::in::RDcsv (type chan) {
00065     # Lines                                     Format
00066     # First line is number of interpreters #n.  int
00067     # Next to 1+n is interpreter data.          id,ver,path
00068     # Beyond is benchmark results.              id,desc,res1,...,res#n
00069 
00070     array set DATA {}
00071 
00072     # #Interp ...
00073 
00074     set nip [lindex [csv::split [gets $chan]] 0]
00075 
00076     # Interp data ...
00077 
00078     set iplist {}
00079     for {set i 0} {$i < $nip} {incr i} {
00080     foreach {__ ver ip} [csv::split [gets $chan]] break
00081 
00082     set DATA([list interp $ip]) $ver
00083     lappend iplist $ip
00084     }
00085 
00086     # Benchmark data ...
00087 
00088     while {[gets $chan line] >= 0} {
00089     set line [string trim $line]
00090     if {$line == {}} break
00091     set line [csv::split $line]
00092     set desc [lindex $line 1]
00093 
00094     set DATA([list desc $desc]) {}
00095     foreach val [lrange $line 2 end] ip $iplist {
00096         if {$val == {}} continue
00097         set DATA([list usec $desc $ip]) $val
00098     }
00099     }
00100 
00101     return [array get DATA]
00102 }
00103 
00104 ret  ::bench::in::RDtext (type chan) {
00105     array set DATA {}
00106 
00107     # Interp data ...
00108 
00109     # Empty line     - ignore
00110     # "id: ver path" - interp data.
00111     # Empty line     - separator before benchmark data.
00112 
00113     set n 0
00114     set iplist {}
00115     while {[gets $chan line] >= 0} {
00116     set line [string trim $line]
00117     if {$line == {}} {
00118         incr n
00119         if {$n == 2} break
00120         continue
00121     }
00122 
00123     regexp {[^:]+: ([^ ]+) (.*)$} $line -> ver ip
00124     set DATA([list interp $ip]) $ver
00125     lappend iplist $ip
00126     }
00127 
00128     # Benchmark data ...
00129 
00130     # '---' -> Ignore.
00131     # '|' column separators. Remove spaces around it. Then treat line
00132     # as CSV data with a particular separator.
00133     # Ignore the INTERP line.
00134 
00135     while {[gets $chan line] >= 0} {
00136     set line [string trim $line]
00137     if {$line == {}}                     continue
00138     if {[string match "+---*"    $line]} continue
00139     if {[string match "*INTERP*" $line]} continue
00140 
00141     regsub -all "\\| +" $line {|} line
00142     regsub -all " +\\|" $line {|} line
00143     set line [csv::split [string trim $line |] |]
00144     set desc [lindex $line 1]
00145 
00146     set DATA([list desc $desc]) {}
00147     foreach val [lrange $line 2 end] ip $iplist {
00148         if {$val == {}} continue
00149         set DATA([list usec $desc $ip]) $val
00150     }
00151     }
00152 
00153     return [array get DATA]
00154 }
00155 
00156 /*  ### ### ### ######### ######### ######### ###########################*/
00157 /*  Initialize internal data structures.*/
00158 
00159 /*  ### ### ### ######### ######### ######### ###########################*/
00160 /*  Ready to run*/
00161 
00162 package provide bench::in 0.1
00163 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1