ns::stats::SQLiteHistory method history allocator (public)
<instance of ns::stats::SQLiteHistory> history allocator \ -from from -to to [ -limit limit ] [ -cursor cursor ]
Read compact process-wide allocator history from the configured owner server using one bounded sample SELECT. New samples provide stored projections; old rows without a projection are decoded once in this read. No topology loading or full-window payload rescan is performed. Preserve missing gauges as absent dictionary keys. Timestamps are epoch microseconds; instance and intervalSeconds allow callers to preserve restart boundaries and gaps. Reading does not collect or write samples. Coverage complete and windowExamined remain false: this projection does not certify window boundaries or absence of eviction/write failures. Use history query when full-window coverage assessment is required. Timings distinguish checkout, sample SQL read, decoding and total time.
- Switches:
- -from (required, integer)
- Inclusive lower bound in epoch seconds; must be nonnegative.
- -to (required, integer)
- Exclusive upper bound in epoch seconds; after from, at most 24 hours later and no later than now.
- -limit (optional, integer, defaults to
"10000")- Maximum compact records per page, 1..10000; default 10000.
- -cursor (optional, integer, defaults to
"0")- Nonnegative timestamp cursor in microseconds, default 0; pass nextCursor unchanged for continuation.
- Returns:
- Dictionary containing compact records (timestamp, instance, sampling.intervalSeconds and memory), more, nextCursor, legacyDecoded, timings in milliseconds and conservative coverage metadata.
- Testcases:
- No testcase defined.
Source code: set started [clock microseconds] if {$from < 0 || $to <= $from || $to-$from > 86400 || $to > [clock seconds] || $limit < 1 || $limit > 10000 || $cursor < 0} { error "expected an epoch window up to 24 hours, limit 1..10000 and nonnegative cursor" } set config [nsv_get ns_stats history] if {$config eq ""} {error "history is not configured"} if {[dict get $config owner] ne [ns_info server]} {error "query history from its configured owner server"} set db [:historyConnect $config] set checkedOut [clock microseconds] set transaction false try { :sql $db {BEGIN} set transaction true set columns [lmap row [:sql $db {SELECT name FROM pragma_table_info('ns_stats_samples')}] {dict get $row name}] if {"allocator" in $columns} { set projection {coalesce(allocator,'') AS allocator,CASE WHEN allocator IS NULL THEN payload ELSE '' END AS legacy} } else { set projection {'' AS allocator,payload AS legacy} } set low [expr {$from*1000000}]; set high [expr {$to*1000000}] set beforeRead [clock microseconds] set rows [:sql $db "SELECT at,instance,$projection FROM ns_stats_samples WHERE at >= $low AND at < $high AND at > $cursor ORDER BY at LIMIT [expr {$limit+1}]"] set afterRead [clock microseconds] set more [expr {[llength $rows]>$limit}] set records {}; set legacy 0 foreach row [lrange $rows 0 [expr {$limit-1}]] { if {[dict get $row allocator] eq ""} { set point [:allocatorPoint [:unpack [dict get $row legacy]]] incr legacy } else { set point [dict get $row allocator] } lappend records $point } set decoded [clock microseconds] :sql $db {COMMIT} set transaction false return [dict create schemaVersion 1 source sqlite projection allocator from $from to $to records $records more $more nextCursor [expr {$more ? [dict get [lindex $rows $limit-1] at] : ""}] legacyDecoded $legacy coverage [dict create complete false windowExamined false incompleteReasons [expr {$more ? {allocator-projection-not-certified more-pages} : {allocator-projection-not-certified}}]] timings [dict create checkoutMs [expr {($checkedOut-$started)/1000.0}] readMs [expr {($afterRead-$beforeRead)/1000.0}] decodeMs [expr {($decoded-$afterRead)/1000.0}] totalMs [expr {([clock microseconds]-$started)/1000.0}]]] } finally { if {$transaction} {catch {:sql $db {ROLLBACK}}} ns_db releasehandle $db }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)