ns::stats::SQLiteHistory method historyWindowCoverage (protected)

 <instance of ns::stats::SQLiteHistory[i]> historyWindowCoverage db \
    low high

Defined in

Inspect the whole window on the final page, including its boundary neighbors. Read compressed payloads in bounded batches so coverage does not depend on client-carried state or retain all snapshots.

Parameters:
db (required)
low (required)
high (required)

Testcases:
No testcase defined.
Source code:
set previous {}
set prior [:scalar $db "SELECT payload FROM ns_stats_samples WHERE at < $low ORDER BY at DESC LIMIT 1"]
if {$prior ne ""} {
    set previous [:unpack $prior]
}
set gaps {}
set restarts {}
set resets 0
set cursor [expr {$low-1}]
set finished false
while {!$finished} {
    set rows [:sql $db "SELECT at,payload FROM ns_stats_samples WHERE at > $cursor ORDER BY at LIMIT 128"]
    if {$rows eq ""} {
        break
    }
    foreach row $rows {
        set cursor [dict get $row at]
        set record [:unpack [dict get $row payload]]
        if {$cursor<$high && ![dict get $record sampling ready]} {
            incr resets
        }
        if {$previous ne ""} {
            if {$cursor<$high && [dict get $previous instance] ne [dict get $record instance]} {
                lappend restarts [dict get $record sampling to]
            }
            set delta [expr {($cursor-[dict get $previous timestamp])/1000000.0}]
            if {$delta>1.5*max([dict get $previous sampling intervalSeconds],
                               [dict get $record sampling intervalSeconds])
                || ($cursor>=$high && (![dict get $record sampling ready]
                    || [dict get $previous instance] ne [dict get $record instance]))} {
                lappend gaps [dict create from [dict get $previous sampling to] to [dict get $record sampling to]]
            }
        }
        if {$cursor >= $high} {
            set finished true
            break
        }
        set previous $record
    }
}
return [dict create gaps $gaps restartBoundaries $restarts resetSamples $resets]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: