Class Relations
- class: ::xotcl::Object
::xotcl::Object create ::xo::system_stats
Methods (to be applied on the object)
aggcpuinfo (scripted)
upvar $utime utimes $stime stimes $ttime ttimes
set pid [pid]
set varnames {utime utimes stime stimes}
foreach index [nsv_array names [self]] {
lassign [split $index ,] group kind
:aggregate $group [dict get $varnames $kind] [nsv_get [self] $index]
}
set threadInfo [ns_info threads]
if {[file readable /proc/$pid/statm] && [llength [lindex $threadInfo 0]] > 7} {
foreach t $threadInfo {
set s [:thread_info $pid [lindex $t 7]]
if {[dict exists $s stime]} {
set group [:thread_classify [lindex $t 0]]
:aggregate $group [dict get $varnames utime] [dict get $s utime]
:aggregate $group [dict get $varnames stime] [dict get $s stime]
}
}
}
foreach group [array names utimes] {
:aggregate $group ttimes [expr {$utimes($group) + $stimes($group)}]
}
aggregate (scripted)
upvar $time times
if {![info exists times($group)]} {set times($group) 0}
set times($group) [expr {$times($group) + $value}]
gettid (scripted)
set hex [ns_thread id]
foreach t [ns_info threads] {
if {[lindex $t 2] eq $hex} {
return [list name [lindex $t 0] tid [lindex $t 7]]
}
}
return ""
recordtimes (scripted)
set threadInfo [:gettid]
if {$threadInfo ne ""} {
set i [:thread_info [pid] [dict get $threadInfo tid]]
lappend i {*}$threadInfo
if {[dict exists $i stime]} {
set group [:thread_classify [dict get $i name]]
nsv_incr [self] $group,stime [dict get $i stime]
nsv_incr [self] $group,utime [dict get $i utime]
}
}
thread_classify (scripted)
switch -glob -- $name {
"-main-" { set group main }
"::*" { set group tcl:[string range $name 2 end]}
"-sched*" { set group scheds }
"-conn:*" { set group conns }
"-driver:*" { set group drivers }
"-asynclogwriter*" { set group logwriter }
"-writer*" { set group writers }
"-spooler*" { set group spoolers }
"-socks-" { set group socks }
"-nsproxy*" { set group nsproxy }
"-ns_job_*" { set group ns_job }
default { set group others }
}
return $group
thread_info (scripted)
set s ""
set fn /proc/$pid/task/$tid/stat
if {[ad_file readable $fn]} {
try {
set f [open $fn]
set s [read $f]
} on error err {
set errorMsg "IO error $err reading file $fn"
if {[info exists f]} { append errorMsg " (fh $f)" }
ns_log error $errorMsg
} finally {
close $f
}
} elseif {[file readable /proc/$pid/task/$pid/stat]} {
set fn /proc/$pid/task/$pid/stat
try {
set f [open $fn]
set s [read $f]
} on error err {
set errorMsg "IO error $err reading file $fn"
if {[info exists f]} { append errorMsg " (fh $f)" }
ns_log error $errorMsg
} finally {
close $f
}
}
if {$s ne ""} {
lassign $s tid comm state ppid pgrp session tty_nr tpgid flags minflt cminflt majflt cmajflt utime stime cutime cstime priority nice numthreads itrealval starttime vsize rss rsslim startcode endcode startstack kstkesp kstkeip signal blocked sigignore sigcatch wchan nswap cnswap ext_signal processor ...
return [list utime [expr {$utime*10}] stime [expr {$stime*10}]]
}