Class ::nsmcp::LogSummaryReader (public)
::nx::Class ::nsmcp::LogSummaryReader
Defined in /usr/local/ns/tcl/nsmcp/log-traffic-summary.tcl
- Testcases:
- No testcase defined.
Source code: :property channel:required :property limit:required :property maxBytes:required :property offset:required :variable buffer {} :variable index 0 :variable lookahead {} :variable readMicroseconds 0 :variable readBytes 0 :variable readCalls 0 :public method statistics {} { # # Report source-channel reads for this summary slice. # # These are channel operations, including buffered lookahead; they do # not identify cache hits or physical device I/O. # # @return Read time in microseconds and channel byte/call counts. # return [dict create readMicroseconds ${:readMicroseconds} readBytes ${:readBytes} readCalls ${:readCalls}] } :method line {} { if {${:offset}>=${:limit}} { return {} } set start ${:offset} set sample {} set terminated false set clipped false while {${:offset}<${:limit}} { if {${:index} >= [string length ${:buffer}]} { set started [clock clicks -microseconds] set :buffer [read ${:channel} [expr {min(65536,${:limit}-${:offset})}]] incr :readMicroseconds [expr {max(0,[clock clicks -microseconds]-$started)}] incr :readBytes [string length ${:buffer}] incr :readCalls set :index 0 if {${:buffer} eq ""} { break } } set end [string first \n ${:buffer} ${:index}] if {$end<0} { set end [string length ${:buffer}] } else { set terminated true } set count [expr {$end-${:index}}] set room [expr {max(0,${:maxBytes}-[string length $sample])}] if {$count>$room} { set clipped true } if {$room>0} { append sample [string range ${:buffer} ${:index} [expr {min($end-1,${:index}+$room-1)}]] } set consumed [expr {$count+($terminated ? 1 : 0)}] incr :offset $consumed incr :index $consumed if {$terminated} { break } } set text [encoding convertfrom utf-8 [string trimright $sample \r]] regsub -all {\x1b\[[0-9;]*m} $text {} text return [dict create start $start end ${:offset} text $text truncated $clipped terminated $terminated] } :public method next {} { # # Read the next logical system-log event. # # Combine supported continuation lines and retain lookahead for the # following event. # # @return The event dictionary, or an empty result at end of input. # if {${:lookahead} ne ""} { set line ${:lookahead} set :lookahead {} } else { set line [:line] } if {$line eq ""} { error "unexpected end of system log during summary scan" } set event [dict create offset [dict get $line start] endOffset [dict get $line end] message [dict get $line text] truncated [dict get $line truncated] complete false] while {${:offset}<${:limit}} { set line [:line] if {$line eq ""} { break } if {![::nsmcp::logRecordParser continuation [dict get $event message] [dict get $line text]]} { set :lookahead $line dict set event complete true return $event } set text "\n[dict get $line text]" set room [expr {max(0,${:maxBytes}-[string length [dict get $event message]])}] if {[string length $text]>$room || [dict get $line truncated]} { dict set event truncated true } if {$room>0} { dict append event message [string range $text 0 [expr {$room-1}]] } dict set event endOffset [dict get $line end] } return $event }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)