File Annotation
Not logged in
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: # Management of statistics for an import run.
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: # Requirements
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: package require Tcl 8.4
18251642f3 2007-09-14       aku: package require vc::tools::log  ; # User feedback
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: namespace eval ::vc::fossil::import::stats {
18251642f3 2007-09-14       aku:     vc::tools::log::system stats
18251642f3 2007-09-14       aku:     namespace import ::vc::tools::log::write
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: # API
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: #     vc::fossil::import::stats
18251642f3 2007-09-14       aku: #         setup n m  - Initialize module, expect n changesets, of m.
18251642f3 2007-09-14       aku: #         done       - Write final statistics.
18251642f3 2007-09-14       aku: #         csbegin id - Import of identified changeset begins.
18251642f3 2007-09-14       aku: #         csend x    - It took x seconds to import the changeset.
18251642f3 2007-09-14       aku: #
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: # API Implementation - Functionality
18251642f3 2007-09-14       aku: 
b504674c5f 2007-09-15       aku: proc ::vc::fossil::import::stats::setup {n m} {
b504674c5f 2007-09-15       aku:     variable run_format    %[string length $n]s
b504674c5f 2007-09-15       aku:     variable max_format    %[string length $m]s
18251642f3 2007-09-14       aku:     variable total_csets   $n
18251642f3 2007-09-14       aku:     variable total_running 0
18251642f3 2007-09-14       aku:     variable total_seconds 0.0
18251642f3 2007-09-14       aku:     return
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::done {} {
18251642f3 2007-09-14       aku:     variable total_csets
18251642f3 2007-09-14       aku:     variable total_seconds
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku:     write 0 stats "========= [string repeat = 61]"
18251642f3 2007-09-14       aku:     write 0 stats "Imported $total_csets [expr {($total_csets == 1) ? "changeset" : "changesets"}]"
b504674c5f 2007-09-15       aku:     write 0 stats "Within [F $total_seconds] seconds (avg [F [Avg]] seconds/changeset)"
18251642f3 2007-09-14       aku:     return
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::csbegin {cset} {
b504674c5f 2007-09-15       aku:     variable max_format
b504674c5f 2007-09-15       aku:     variable run_format
b504674c5f 2007-09-15       aku:     variable total_running
b504674c5f 2007-09-15       aku:     variable total_csets
b504674c5f 2007-09-15       aku: 
330f2da791 2007-09-20       aku:     incr total_running
330f2da791 2007-09-20       aku: 
b504674c5f 2007-09-15       aku:     write 0 stats "ChangeSet [format $max_format $cset] @ [format $run_format $total_running]/$total_csets ([F6 [expr {$total_running*100.0/$total_csets}]]%)"
18251642f3 2007-09-14       aku:     return
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::csend {seconds} {
18251642f3 2007-09-14       aku:     variable total_csets
18251642f3 2007-09-14       aku:     variable total_seconds
18251642f3 2007-09-14       aku:     variable total_running
18251642f3 2007-09-14       aku: 
b504674c5f 2007-09-15       aku:     set  total_seconds [expr {$total_seconds + $seconds}]
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku:     set avg [Avg]
18251642f3 2007-09-14       aku:     set end [expr {$total_csets * $avg}]
18251642f3 2007-09-14       aku:     set rem [expr {$end - $total_seconds}]
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku:     write 2 stats "Imported in        [F7 $seconds] seconds"
18251642f3 2007-09-14       aku:     write 3 stats "Average Time/Cset  [F7 $avg] seconds"
18251642f3 2007-09-14       aku:     write 3 stats "Current Runtime    [FTime $total_seconds]"
18251642f3 2007-09-14       aku:     write 3 stats "Total Runtime  (E) [FTime $end]"
18251642f3 2007-09-14       aku:     write 3 stats "Remaining Time (E) [FTime $rem]"
18251642f3 2007-09-14       aku:     # (E) for Estimated.
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku:     return
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: # Internal helper commands.
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::FTime {s} {
18251642f3 2007-09-14       aku:     set m [expr {$s / 60}]
18251642f3 2007-09-14       aku:     set h [expr {$s / 3600}]
18251642f3 2007-09-14       aku:     return "[F7 $s] sec [F6 $m] min [F5 $h] hr"
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::F  {x} { format %.2f  $x }
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::F5 {x} { format %5.2f $x }
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::F6 {x} { format %6.2f $x }
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::F7 {x} { format %7.2f $x }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: proc ::vc::fossil::import::stats::Avg {} {
18251642f3 2007-09-14       aku:     variable total_seconds
18251642f3 2007-09-14       aku:     variable total_running
18251642f3 2007-09-14       aku:     return [expr {$total_seconds/$total_running}]
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: namespace eval ::vc::fossil::import::stats {
b504674c5f 2007-09-15       aku:     variable total_csets   0 ; # Number of changesets to expect to be imported
b504674c5f 2007-09-15       aku:     variable total_running 0 ; # Number of changesets which have been imported so far
b504674c5f 2007-09-15       aku:     variable total_seconds 0 ; # Current runtime in seconds
b504674c5f 2007-09-15       aku:     variable max_format   %s ; # Format to print changeset id, based on the largest id.
b504674c5f 2007-09-15       aku:     variable run_format   %s ; # Format to print the number of imported csets.
b504674c5f 2007-09-15       aku: 
b504674c5f 2007-09-15       aku:     namespace export setup done csbegin csend
18251642f3 2007-09-14       aku: }
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: # -----------------------------------------------------------------------------
18251642f3 2007-09-14       aku: # Ready
18251642f3 2007-09-14       aku: 
18251642f3 2007-09-14       aku: package provide vc::fossil::import::stats 1.0
18251642f3 2007-09-14       aku: return