Changeset 6705


Ignore:
Timestamp:
Jan 4, 2019 3:14:36 PM (5 years ago)
Author:
clarksm
Message:

Enable "ionhelper" to execute jobs and immediately put results in cache.
This includes reporting run.xml location with absolute path.

Location:
branches/1.7
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/1.7/gui/apps/execute.tcl

    r6702 r6705  
    3737    value -tool ""
    3838    value -status ""
     39    value -stdOutput ""
     40    value -stdError ""
    3941    value -output ""
    4042    value -cleanup no
     
    101103    set TaskObj [Rappture::Task ::#auto $toolobj $installdir]
    102104}
    103 set LogFid ""
     105set LogStdoutFid ""
     106set LogStderrFid ""
    104107
    105108# Define some things that we need for logging status...
    106109# ----------------------------------------------------------------------
     110proc log_error {message} {
     111    global LogStderrFid
     112
     113    if {$LogStderrFid ne ""} {
     114        puts -nonewline $LogStderrFid $message
     115    }
     116}
     117
    107118proc log_output {message} {
    108     global LogFid
    109 
    110     if {$LogFid ne ""} {
    111         #
    112         # Scan through and pick out any =RAPPTURE-PROGRESS=> messages.
    113         #
    114         set percent ""
    115         while {[regexp -indices \
    116                 {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \
    117                  match percent mesg]} {
    118 
    119             foreach {i0 i1} $percent break
    120             set percent [string range $message $i0 $i1]
    121 
    122             foreach {i0 i1} $mesg break
    123             set mesg [string range $message $i0 $i1]
    124 
    125             foreach {i0 i1} $match break
    126             set message [string replace $message $i0 $i1]
    127         }
    128         if {$percent ne ""} {
    129             # report the last percent progress found
    130             log_append progress "$percent% - $mesg"
     119    global LogStdoutFid
     120
     121    if {$LogStdoutFid ne ""} {
     122        if {$LogStdoutFid eq "stdout"} {
     123            puts -nonewline $LogStdoutFid $message
     124            flush $LogStdoutFid
     125        } else {
     126            #
     127            # Scan through and pick out any =RAPPTURE-PROGRESS=> messages.
     128            #
     129            set percent ""
     130            while {[regexp -indices \
     131                    {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \
     132                     match percent mesg]} {
     133   
     134                foreach {i0 i1} $percent break
     135                set percent [string range $message $i0 $i1]
     136   
     137                foreach {i0 i1} $mesg break
     138                set mesg [string range $message $i0 $i1]
     139   
     140                foreach {i0 i1} $match break
     141                set message [string replace $message $i0 $i1]
     142            }
     143            if {$percent ne ""} {
     144                # report the last percent progress found
     145                log_append progress "$percent% - $mesg"
     146            }
    131147        }
    132148    }
     
    135151# Actually write to the log file
    136152proc log_append {level message} {
    137     global LogFid
    138 
    139     if {$LogFid ne ""} {
     153    global LogStdoutFid
     154
     155    if {$LogStdoutFid ne ""} {
    140156        set date [clock format [clock seconds] -format {%Y-%m-%dT%H:%M:%S%z}]
    141157        set host [info hostname]
    142         puts $LogFid "$date $host rappture [pid] \[$level\] $message"
    143         flush $LogFid
     158        puts $LogStdoutFid "$date $host rappture [pid] \[$level\] $message"
     159        flush $LogStdoutFid
    144160    }
    145161}
     
    156172# Apply effects of all other command line options
    157173# ----------------------------------------------------------------------
     174if {$params(-stdOutput) ne ""} {
     175    if {$params(-stdOutput) eq "@stdout"} {
     176        set LogStdoutFid "stdout"
     177    } else {
     178        set LogStdoutFid [open $params(-stdOutput) w]
     179    }
     180    lappend args -stdout log_output
     181}
     182if {$params(-stdError) ne ""} {
     183    if {$params(-stdError) eq "@stderr"} {
     184        set LogStderrFid "stderr"
     185    } else {
     186        set LogStderrFid [open $params(-stdError) w]
     187    }
     188    lappend args -stderr log_error
     189}
     190
    158191if {$params(-status) ne ""} {
    159     set LogFid [open $params(-status) w]
    160     $TaskObj configure -logger {log_append status} -jobstats log_stats
     192    if {$params(-status) ne "@default"} {
     193        if {$LogStdoutFid eq ""} {
     194            set LogStdoutFid [open $params(-status) w]
     195        }
     196        $TaskObj configure -logger {log_append status} -jobstats log_stats
     197    }
    161198}
    162199
     
    182219
    183220if {$params(-status) ne ""} {
    184     # recording status? then look through output for progress messages
    185     lappend args -output log_output
     221    if {$params(-status) ne "@default"} {
     222        # recording status? then look through output for progress messages
     223        lappend args -output log_output
     224    }
    186225}
    187226
     
    222261}
    223262
    224 log_append status "exit $status"
     263if {$params(-status) ne ""} {
     264    if {$params(-status) ne "@default"} {
     265       log_append status "exit $status"
     266    }
     267}
    225268exit $status
  • branches/1.7/gui/apps/launcher.tcl

    r6700 r6705  
    2929set loadlist ""
    3030set toolxml ""
     31set stdOutput ""
     32set stdError ""
     33set status "rappture.status"
    3134
    3235# ----------------------------------------------------------------------
     
    191194                set argv [lrange $argv 1 end]
    192195            }
     196            -status {
     197                set status [lindex $argv 0]
     198                set argv [lrange $argv 1 end]
     199            }
     200            -stdOutput {
     201                set stdOutput [lindex $argv 0]
     202                set argv [lrange $argv 1 end]
     203            }
     204            -stdError {
     205                set stdError [lindex $argv 0]
     206                set argv [lrange $argv 1 end]
     207            }
    193208            default {
    194209                puts stderr "usage:"
     
    244259            # report status, clean up, and save output to data/results.
    245260            # This helps the web services interface do its thing.
    246             set alist [list \
    247                 -output @default \
    248                 -status rappture.status \
    249                 -cleanup yes \
    250                 -xmlSource toolParameters]
     261            set alist [list -output @default \
     262                            -status $status \
     263                            -stdOutput $stdOutput \
     264                            -stdError $stdError \
     265                            -cleanup yes \
     266                            -xmlSource toolParameters]
    251267        }
    252268        "" - "-input" {
  • branches/1.7/gui/scripts/analyzer.tcl

    r6474 r6705  
    7474    protected method _fixNotebook {}
    7575    protected method _simState {state args}
     76    protected method _simLogError {message}
     77    protected method _simLogOutput {message}
    7678    protected method _simOutput {message}
    7779    protected method _resultTooltip {}
     
    461463    pack forget $itk_component(progress)
    462464    lappend args -output [itcl::code $this _simOutput]
     465    lappend args -stderr [itcl::code $this _simLogError]
     466#   lappend args -stdout [itcl::code $this _simLogOutput]
    463467
    464468    _simState off
     
    11121116}
    11131117
     1118itcl::body Rappture::Analyzer::_simLogError {message} {
     1119    puts -nonewline stderr $message
     1120}
     1121
     1122itcl::body Rappture::Analyzer::_simLogOutput {message} {
     1123    puts -nonewline stdout $message
     1124    flush stdout
     1125}
     1126
    11141127# ----------------------------------------------------------------------
    11151128# USAGE: _simOutput <message>
  • branches/1.7/lang/tcl/scripts/result.tcl

    r3728 r6705  
    6565
    6666    if {$status == 0} {
    67         puts "=RAPPTURE-RUN=>$oname"
     67        set fileName [file join [pwd] $oname]
     68        puts "=RAPPTURE-RUN=>$fileName"
    6869    }
    6970}
  • branches/1.7/lang/tcl/scripts/task.tcl

    r6702 r6705  
    2626    private method GetDriverFile {}
    2727    private method GetSignal { signal }
     28    private method GetCacheHelperCommand { driverFile }
    2829    private method GetSimulationCommand { driverFile }
    2930    private method GetUQErrors {}
     
    3132    private method GetUQTemplateFile {}
    3233    private method IsCacheable {}
     34    private method IsCacheHelperEligible {}
    3335    private method LogCachedSimulationUsage {}
    3436    private method LogSimulationUsage {}
     
    5456    public method save {xmlobj {name ""}}
    5557
     58    protected method OnError {data}
    5659    protected method OnOutput {data}
    5760    protected method Log {args}
     
    6366    private variable _origxml ""     ;# copy of original XML (for reset)
    6467    private variable _installdir ""  ;# installation directory for this tool
     68    private variable _errorcb ""     ;# callback for tool error
    6569    private variable _outputcb ""    ;# callback for tool output
    6670    private common jobnum 0          ;# counter for unique job number
     
    7377
    7478    public common _resources
    75     public proc setAppName {name}    { set _resources(-appname) $name }
    76     public proc setHubName {name}    { set _resources(-hubname) $name }
    77     public proc setHubURL {name}     { set _resources(-huburl) $name }
    78     public proc setSession {name}    { set _resources(-session) $name }
    79     public proc setJobPrt {name}     { set _resources(-jobprotocol) $name }
    80     public proc setResultDir {name}  { set _resources(-resultdir) $name }
    81     public proc setCacheHosts {name} { set _resources(-cachehosts) $name }
     79    public proc setAppName {name}         { set _resources(-appname) $name }
     80    public proc setHubName {name}         { set _resources(-hubname) $name }
     81    public proc setHubURL {name}          { set _resources(-huburl) $name }
     82    public proc setSession {name}         { set _resources(-session) $name }
     83    public proc setJobPrt {name}          { set _resources(-jobprotocol) $name }
     84    public proc setResultDir {name}       { set _resources(-resultdir) $name }
     85    public proc setCacheHosts {name}      { set _resources(-cachehosts) $name }
     86    public proc setCacheUser {name}       { set _resources(-cacheuser) $name }
     87    public proc setCacheWriteHost {name}  { set _resources(-cachewritehost) $name }
    8288
    8389    # default method for -jobstats control
     
    95101        job_protocol      Rappture::Task::setJobPrt \
    96102        results_directory Rappture::Task::setResultDir \
    97         cache_hosts       Rappture::Task::setCacheHosts
     103        cache_hosts       Rappture::Task::setCacheHosts \
     104        cache_user        Rappture::Task::setCacheUser \
     105        cache_write_host  Rappture::Task::setCacheWriteHost
    98106}
    99107
     
    208216
    209217    # if there are any args, use them to override parameters
     218    set _errorcb ""
    210219    set _outputcb ""
    211220    set _uq(type) ""
     
    214223    set _uq(paramsFile) ""
    215224    foreach {path val} $args {
    216         if {$path == "-output"} {
     225        if {$path == "-stdout"} {
    217226            set _outputcb $val
     227        } elseif {$path == "-stderr"} {
     228            set _errorcb $val
    218229        } elseif {$path == "-uq_type"} {
    219230            set _uq(type) $val
    220231        } elseif {$path == "-uq_args"} {
    221232            set _uq(args) $val
    222         } else {
     233        } elseif {$path != "-output"} {
    223234            $_xmlobj put $path.current $val
     235        }
     236    }
     237    foreach {path val} $args {
     238        if {$path == "-output"} {
     239            if {$_outputcb == ""} {
     240                set _outputcb $val
     241            }
    224242        }
    225243    }
     
    238256
    239257    SetCpuResourceLimit
     258
     259    set helperEligible [IsCacheHelperEligible]
     260
    240261    set driverFile [GetDriverFile]
    241262    set cached 0
     
    244265        set cached [CheckForCachedRunFile $driverFile]
    245266     } ]"
    246 puts stderr "checking cache=$cached"
     267puts stderr "checking cached=$cached"
    247268    }
    248269    if { !$cached } {
     
    250271            set _uq(tFile) [GetUQTemplateFile]
    251272        }
     273        global env
    252274        if { $_uq(type) == "" } {
    253             set cmd [GetSimulationCommand $driverFile]
    254             global env
     275            if { $helperEligible } {
     276                set cmd [GetCacheHelperCommand $driverFile]
     277            } else {
     278                set cmd [GetSimulationCommand $driverFile]
     279            }
    255280            set ::env(RAPPTURE_UQ) False
    256281        } else {
    257282            set cmd [GetUQSimulationCommand $driverFile]
    258             global env
    259283            set ::env(RAPPTURE_UQ) True
    260284        }
     
    417441        # use the runfile name generated by the last run
    418442        if {$_job(runfile) ne ""} {
    419             set filename [file join $rdir $_job(runfile)]
     443            set filename [file join $rdir [file tail $_job(runfile)]]
    420444        } else {
    421445            set filename [file join $rdir run.xml]
     
    456480    if {[string length $_outputcb] > 0} {
    457481        uplevel #0 $_outputcb [list $data]
     482    }
     483}
     484
     485# ----------------------------------------------------------------------
     486# USAGE: OnError <data>
     487#
     488# Used internally to send each bit of error <data> coming from the
     489# tool onto the caller, so the user can see progress.
     490# ----------------------------------------------------------------------
     491itcl::body Rappture::Task::OnError {data} {
     492    if {[string length $_errorcb] > 0} {
     493        uplevel #0 $_errorcb [list $data]
    458494    }
    459495}
     
    504540        set state [$_xmlobj get "tool.cache"]
    505541    }
    506     puts stderr "cache tag is \"$state\""
    507     if { $state == ""  || ![string is boolean $state] } {
     542    if { $state ne "" } {
     543        puts stderr "cache tag is \"$state\""
     544    }
     545    if { $state eq "" || ![string is boolean $state] } {
    508546        return 1;                       # Default is to allow caching.
    509547    }
    510548    return $state
     549}
     550
     551itcl::body Rappture::Task::IsCacheHelperEligible {} {
     552    global env
     553    if { ![info exists env(IONHELPER_ALLOWED)] } {
     554        set helperEligible 0
     555    } else {
     556        if { $env(IONHELPER_ALLOWED) ne "1" } {
     557            set helperEligible 0
     558        } else {
     559            if { $_uq(type) == "" } {
     560#               puts stderr "cache_user exists       = [info exists _resources(-cacheuser)]"
     561#               puts stderr "cache_write_host exists = [info exists _resources(-cachewritehost)]"
     562                if { ![info exists _resources(-cacheuser)] || ![info exists _resources(-cachewritehost)] } {
     563                    set helperEligible 0
     564                } else {
     565                    if { ![info exists env(USER)] } {
     566                        set helperEligible 0
     567                    } else {
     568#                       puts stderr "env(USER)  = $env(USER)"
     569#                       puts stderr "cache_user = $_resources(-cacheuser)"
     570                        if { $env(USER) eq $_resources(-cacheuser) } {
     571                            set helperEligible 0
     572                        } else {
     573                            set toolId    [$_xmlobj get tool.id]
     574                            set toolVers  [$_xmlobj get tool.version.application.revision]
     575                            set toolDir   [$_xmlobj get tool.version.application.directory(top)]
     576                            set verifyDir [file join / apps ${toolId} r${toolVers}]
     577#                           puts stderr "toolDir     = $toolDir"
     578#                           puts stderr "verifyDir   = $verifyDir"
     579                            if { $toolDir eq $verifyDir } {
     580                                if { [ catch { file readlink [file join / apps ${toolId} current] } currentVers ] != 0 } {
     581                                    set helperEligible 0
     582                                } else {
     583#                                   puts stderr "currentVers = $currentVers"
     584                                    if { "r$toolVers" eq $currentVers } {
     585                                        set helperEligible 1
     586                                    } else {
     587                                        set helperEligible 0
     588                                    }
     589                                }
     590                            } else {
     591                               set helperEligible 0
     592                            }
     593                        }
     594                    }
     595                }
     596            } else {
     597                set helperEligible 0
     598            }
     599        }
     600    }
     601#   puts stderr "helperEligible = $helperEligible"
     602
     603    return $helperEligible
    511604}
    512605
     
    585678}
    586679
     680itcl::body Rappture::Task::GetCacheHelperCommand { driverFile } {
     681    set cmd ""
     682    set helperDriverDir [file join / var ion drivers]
     683    if { [file exists $helperDriverDir] } {
     684        set cacheHelperCommand [file join / apps bin iondrive]
     685        if { [file exists $cacheHelperCommand] } {
     686            file copy -force $driverFile $helperDriverDir
     687            set cmd $cacheHelperCommand
     688        }
     689    }
     690
     691    return $cmd
     692}
     693
    587694itcl::body Rappture::Task::GetCommand { } {
    588695    set cmd [$_xmlobj get tool.command]
     
    681788            -keepnewline yes \
    682789            -killsignal  SIGTERM \
     790            -onerror     [list [itcl::code $this OnError]] \
    683791            -onoutput    [list [itcl::code $this OnOutput]] \
    684792            -output      [list [itcl::scope _job(stdout)]] \
     
    749857    # Need to save job info? then invoke the callback
    750858    if { [string length $jobstats] > 0} {
    751         lappend args \
    752             "job"      [incr jobnum] \
    753             "event"    $simulation \
    754             "start"    $times(start) \
    755             "walltime" $times(walltime) \
    756             "cputime"  $times(cputime) \
    757             "status"   $_job(exitcode)
     859        lappend args "job"      [incr jobnum] \
     860                     "event"    $simulation \
     861                     "start"    $times(start) \
     862                     "walltime" $times(walltime) \
     863                     "cputime"  $times(cputime) \
     864                     "status"   $_job(exitcode)
    758865        uplevel #0 $jobstats $args
    759866    }
     
    852959# [click] messages go here
    853960    if { [string length $jobstats] > 0} {
    854         lappend args \
    855             "job"      [incr jobnum] \
    856             "event"    "\[click\]" \
    857             "start"    $times(start) \
    858             "walltime" 0 \
    859             "cputime"  0 \
    860             "status"   0
    861         uplevel #0 $jobstats $args
     961        set recordJobstats 1
     962        if { [info exists _resources(-cacheuser)] } {
     963            global env
     964            if { $env(USER) eq $_resources(-cacheuser) } {
     965                set recordJobstats 0
     966            }
     967        }
     968        if { $recordJobstats } {
     969            lappend args "job"      [incr jobnum] \
     970                         "event"    "\[click\]" \
     971                         "start"    $times(start) \
     972                         "walltime" 0 \
     973                         "cputime"  0 \
     974                         "status"   0
     975            uplevel #0 $jobstats $args
     976        }
    862977    }
    863978
     
    8941009        set data(start) [expr { $times(start) + $data(start) }]
    8951010
     1011#       puts stderr "event subsimulation start = $data(start)"
     1012
    8961013        set details ""
    8971014        foreach key {job event start walltime cputime status} {
     
    9331050
    9341051    if { [string length $jobstats] > 0} {
    935         lappend args \
    936             "job"      [incr jobnum] \
    937             "event"    "\[click-uq\]" \
    938             "start"    $times(start) \
    939             "walltime" 0 \
    940             "cputime"  0 \
    941             "status"   0
     1052        lappend args "job"      [incr jobnum] \
     1053                     "event"    "\[click-uq\]" \
     1054                     "start"    $times(start) \
     1055                     "walltime" 0 \
     1056                     "cputime"  0 \
     1057                     "status"   0
    9421058        uplevel #0 $jobstats $args
    9431059    }
     
    9601076        error "Can't create rappture library: $xmlobj"
    9611077    }
    962     # Get the session from runfile
    963     set session [$xmlobj get "output.session"]
    964     if { [catch {exec submit --cache $session} result] != 0 } {
    965        puts stderr "submit --cache failed: $result"
    966     }
    9671078    set _job(xmlobj) $xmlobj
    9681079}
     
    9811092        http::geturl $url -query $query -timeout 6000 -binary yes
    9821093    } token] != 0 } {
    983         puts stderr "error performing cache query: token=$token"
     1094        puts stderr "error performing cache query: driverFile=$driverFile url=$url token=$token"
    9841095        return 0
    9851096    }
     
    9901101#   puts stderr "meta   = [::http::meta $token]"
    9911102
     1103    set squid ""
    9921104    foreach {key value} [::http::meta $token] {
    9931105        set headers([string tolower $key]) $value
    9941106        if { [string tolower $key] == "etag" } {
    995             set guid $value
     1107            set squid $value
    9961108        }
    9971109    }
    9981110#   puts stderr "SQUID = $headers(etag)"
    999 #   puts stderr "SQUID = $guid"
     1111#   puts stderr "SQUID = $squid"
     1112    if { [resources -jobprotocol] == "submit" } {
     1113        if { $squid != "" } {
     1114            # If the code is 200, we'll assume it's a cache hit.
     1115            if { [http::ncode $token] == 200} {
     1116                if { [catch {exec submit --cacheHit $squid} result] != 0 } {
     1117                    puts stderr "submit --cacheHit $squid failed: $result"
     1118                }
     1119#               puts stderr "submit --cacheHit $squid"
     1120            } else {
     1121                if { [catch {exec submit --cacheMiss $squid} result] != 0 } {
     1122                    puts stderr "submit --cacheMiss $squid failed: $result"
     1123                }
     1124#               puts stderr "submit --cacheMiss $squid"
     1125            }
     1126        } else {
     1127            puts stderr "cache squid could not be determined."
     1128        }
     1129    }
    10001130
    10011131    # If the code isn't 200, we'll assume it's a cache miss.
  • branches/1.7/src/core/RpLibrary.cc

    r6313 r6705  
    2828#include <iterator>
    2929#include <cctype>
     30#include <limits.h>
     31#include <unistd.h>
    3032
    3133#ifdef _POSIX_SOURCE
     
    20482050    }
    20492051    if ((compress == RPLIB_COMPRESS) ||
    2050         (Rappture::encoding::isBinary(fileBuf.bytes(), fileBuf.size()))) {     
     2052        (Rappture::encoding::isBinary(fileBuf.bytes(), fileBuf.size()))) {
    20512053        putData(path, fileBuf.bytes(), fileBuf.size(), append);
    20522054    } else {
     
    22272229    struct tm* timeinfo;
    22282230    std::stringstream outputFile;
     2231    char currentWorkingDirectory[PATH_MAX+1];
     2232    char *cwd;
    22292233    std::string timestamp;
    22302234    std::string username;
     
    22332237
    22342238    if (this->root == NULL) {
    2235         return;                         /* No tree available */
    2236     }
    2237 
    2238     t = time(NULL);                     /* This is presumably the time the
    2239                                         * simulation finished. */
     2239        return;            /* No tree available */
     2240    }
     2241
     2242    t = time(NULL);        /* This is presumably the time the
     2243                            * simulation finished. */
    22402244#ifdef HAVE_GETTIMEOFDAY
    22412245    /* If the posix function gettimeofday is available, use it to produce
     
    22472251    outputFile << "run" << (int)t << ".xml";
    22482252#endif
     2253    // get current working directory
     2254    cwd = getcwd(currentWorkingDirectory,PATH_MAX);
     2255
    22492256    file.open(outputFile.str().c_str(),std::ios::out);
    22502257   
     
    22532260    put("tool.version.rappture.revision", SVN_VERSION);
    22542261    put("tool.version.rappture.modified",
    2255         "$LastChangedDate$");
     2262        "$LastChangedDate$");
    22562263    if ( "" == get("tool.version.rappture.language") ) {
    2257         put("tool.version.rappture.language","c++");
     2264        put("tool.version.rappture.language","c++");
    22582265    }
    22592266    // generate a timestamp for the run file
     
    22702277    user = getenv("USERNAME");
    22712278    if (user != NULL) {
    2272         username = std::string(user);
     2279        username = std::string(user);
    22732280    } else {
    2274         user = getenv("LOGNAME");
    2275         if (user != NULL) {
    2276             username = std::string(user);
    2277         }
     2281        user = getenv("LOGNAME");
     2282        if (user != NULL) {
     2283            username = std::string(user);
     2284        }
    22782285    }
    22792286#else
     
    22812288    user = getenv("USER");
    22822289    if (user != NULL) {
    2283         username = std::string(user);
     2290        username = std::string(user);
    22842291    } else {
    2285         user = getenv("LOGNAME");
    2286         if (user != NULL) {
    2287             username = std::string(user);
    2288         }
     2292        user = getenv("LOGNAME");
     2293        if (user != NULL) {
     2294            username = std::string(user);
     2295        }
    22892296    }
    22902297#endif
     
    22972304   
    22982305    if ( file.is_open() ) {
    2299         xmlText = xml();
    2300         if (!xmlText.empty()) {
    2301             file << xmlText;
    2302         }
    2303         // check to make sure there were no
    2304         // errors while writing the run.xml file.
    2305         if (   (!file.good())
    2306                || ((long)xmlText.length() != ((long)file.tellp()-(long)1))
    2307                ) {
    2308             status.error("Error while writing run file");
    2309             status.addContext("RpLibrary::result()");
    2310         }
    2311         file.close();
     2306        xmlText = xml();
     2307        if (!xmlText.empty()) {
     2308            file << xmlText;
     2309        }
     2310        // check to make sure there were no
     2311        // errors while writing the run.xml file.
     2312        if (   (!file.good()) || ((long)xmlText.length() != ((long)file.tellp()-(long)1))) {
     2313            status.error("Error while writing run file");
     2314            status.addContext("RpLibrary::result()");
     2315        }
     2316        file.close();
    23122317    } else {
    2313         status.error("Error while opening run file");
    2314         status.addContext("RpLibrary::result()");
    2315     }
    2316     std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << std::endl;
     2318        status.error("Error while opening run file");
     2319        status.addContext("RpLibrary::result()");
     2320    }
     2321    if ( cwd != NULL ) {
     2322        std::string currentDirectory(currentWorkingDirectory);
     2323        std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << "/" << currentDirectory << std::endl;
     2324    } else {
     2325        std::cout << "=RAPPTURE-RUN=>" << outputFile.str() << std::endl;
     2326    }
    23172327}
    23182328
  • branches/1.7/src/core/RpResult.cc

    r5679 r6705  
    1919#include <RpLibrary.h>
    2020#include <errno.h>
     21#include <limits.h>
     22#include <unistd.h>
    2123
    2224void
     
    2426{
    2527    char outputFile[100];
     28    char currentWorkingDirectory[PATH_MAX+1];
     29    char *cwd;
    2630    std::string xtext;
    2731    FILE* fp;
     
    2933
    3034    xtext = lib->xml();
     35
     36    // get current working directory
     37    cwd = getcwd(currentWorkingDirectory,PATH_MAX);
    3138
    3239    // create output filename
     
    4249    if (fsize != (int)xtext.length()) {
    4350        fprintf(stderr, "short write: can't save results: %s\n",
    44                 strerror(errno));
     51        strerror(errno));
    4552        fclose(fp);
    4653        return;
     
    4855    fclose(fp);
    4956    // tell Rappture the file name
    50     printf("=RAPPTURE-RUN=>%s\n", outputFile);
     57    if (cwd != NULL) {
     58        printf("=RAPPTURE-RUN=>%s/%s\n", currentWorkingDirectory, outputFile);
     59    } else {
     60        printf("=RAPPTURE-RUN=>%s\n", outputFile);
     61    }
    5162}
Note: See TracChangeset for help on using the changeset viewer.