📄 isag
字号:
#set sar_elim(b) "tps"set sar_elim(B) "pgpgin"set sar_elim(c) "proc"set sar_elim(q) "runq-sz"set sar_elim(r) "kbmemfree"set sar_elim(R) "frmpg"set sar_elim(u) "user"set sar_elim(v) "dentunusd"set sar_elim(w) "cswch"set sar_elim(W) "pswpin"# Functions which are responsible for data source selection and processing# funcs are referred from GUIproc fill_file_menu {} { global sar_data_path sar_data_mask set fp [open "| sh -c \"ls $sar_data_path/$sar_data_mask\""] menu .file.menu.m -tearoff false while {[gets $fp line] != -1} { set l [string last "/" $line] set line [string range $line [expr $l + 1] end] .file.menu.m add command -label "$line" -command "set_file $line" } catch {close $fp} }proc set_file {name} { global sag_if_archive last_graph set sag_if_archive $name .file.lbl configure -text "Data Source: $name" if {"" != $last_graph} { new_chart $last_graph }}################################################################################ GUI## $Id: isag.GUI.m4,v 1.14 2004/03/02 20:28:00 david Exp $# $State: Exp $# $Log: isag.GUI.m4,v $# Revision 1.14 2004/03/02 20:28:00 david# replaced <> by () in mangled e-mails## Revision 1.13 2004/02/24 07:40:14 david# replaced (at) and (dot) in most e-mail addresses## Revision 1.12 2003/01/26 20:41:48 david# partially renamed variables, 1st implementation of "Save Graph"## Revision 1.11 2002/10/31 15:07:21 david# fixed bad behaviour with OpenMotif WM## Revision 1.10 2002/03/24 15:18:26 david# added## Revision 1.9 2002/03/04 20:23:26 david# fixed whole day functionality## Revision 1.8 2002/03/04 18:36:37 david# grid feature implemented## Revision 1.7 2001/03/17 17:43:06 sarrep# About dialog modify## Revision 1.6 2001/03/17 17:30:11 sarrep# CVSizing, unified headers of each element file##################################################################################set isag_title "System Activity Grapher"wm title . $isag_titleframe .menu -relief raised -borderwidth 2pack .menu -side top -fill xmenubutton .menu.file -text "Program" -menu .menu.file.m -underline 0menu .menu.file.m -tearoff false.menu.file.m add command -label "Redraw" -underline 0 \ -command "set isag_gr_scale_old 0;redraw_graph" -accelerator "F5".menu.file.m add command -label "Save Picture" -underline 0 \ -command "sag_save_graph".menu.file.m add separator.menu.file.m add command -label "Exit Program" -underline 0 \ -command "exit_program" -accelerator "Alt-X"menubutton .menu.chart -text "Chart" -menu .menu.chart.m -underline 0menu .menu.chart.m -tearoff true# creates for each sar-switch menu item with apropriate commandforeach l $prog_swtch { .menu.chart.m add command -label $view_n($l) \ -command "new_chart $l" -accelerator $l bind all $l "new_chart $l"}menubutton .menu.opt -text "Options" -menu .menu.opt.m -underline 0menu .menu.opt.m -tearoff false.menu.opt.m add checkbutton -label "Whole Day (00:00-23:59)" -underline 0 \ -variable sag_opt_whole_day \ -command "set isag_gr_scale_old 0;redraw_graph".menu.opt.m add checkbutton -label "Show Grid" -underline 0 \ -variable sag_opt_grid -command "set isag_gr_scale_old 0;redraw_graph" menubutton .menu.help -text "Help" -menu .menu.help.m -underline 0menu .menu.help.m -tearoff false.menu.help.m add command -label "About" -underline 0 \ -command {About}pack .menu.file .menu.chart .menu.opt -side leftpack .menu.help -side rightframe .file -relief raisedpack .file -side top -fill xlabel .file.lbl -text "(No File)" -borderwidth 2menubutton .file.menu -relief raised -borderwidth 2 -text "-" -menu .file.menu.mfill_file_menupack .file.lbl .file.menu -side leftframe .graphpack .graph -side top -expand true -fill both# this var contains a current valueset sag_gr_scale 0scale .graph.scale -orient vertical -length $sag_graph_ht -to 0 -from 1 -variable sag_gr_scalebind .graph.scale <Leave> "redraw_graph"canvas .graph.canv -width $sag_graph_wd -height $sag_graph_htpack .graph.scale -side left -fill ypack .graph.canv -side right -expand true -fill both#bind all <Enter> "%W configure -highlightbackground blue"#bind all <Leave> "%W configure -highlightbackground white"bind all <Alt-x> "exit_program"bind all <F5> "set isag_gr_scale_old 0;redraw_graph"################################################################################# this function normalizes max val and sets scale and so on.# this part is most common for draw_? functionsproc set_cur_max {l} { global val_max sag_gr_scale val_cur set norm [num_norm $val_max($l)] set val_max($l) [lindex $norm 0] .graph.scale configure -from $val_max($l) -resolution [lindex $norm 1] unset norm set val_cur($l) $sag_gr_scale if {$val_cur($l) == 0} { set val_cur($l) $val_max($l) set sag_gr_scale $val_cur($l) }}################################################################################# this function is called when mouse leaves a graph-scale widget# and here is local variable isag_gr_scale_old## this can be also as flag, is set to 0 after resizingset isag_gr_scale_old 0proc redraw_graph {} { global last_graph sag_gr_scale isag_gr_scale_old sag_if_archive if {($last_graph == "") || ($sag_if_archive == "")} { return } if {$isag_gr_scale_old != $sag_gr_scale} { set isag_gr_scale_old $sag_gr_scale sag_draw $last_graph }}################################################################################# this function is called from menu-view and decides which graph will be drawn#proc new_chart {l} { global last_graph val_cur sag_gr_scale if {$last_graph != "$l"} { set m [.graph.scale configure -from] if {$m < $val_cur($l)} { .graph.scale configure -from $val_cur($l) } set sag_gr_scale $val_cur($l) set last_graph "$l" unset m } sag_draw $l}################################################################################# About message box#proc About {} { global version out_msg About "Sar Grapher\n\nBuild info:$version\n\nhttp://www.volny.cz/linux_monitor/isag/index.html\ne-mail: linux_monitor(at)volny(dot)cz"}# $Source: /var/CVSROOT/cvs/i-sag/isag/isag.GUI.m4,v $################################################################################ Resizing graph window## $Id: isag.ResizeAll.m4,v 1.7 2003/01/26 20:41:48 david Exp $# $State: Exp $# $Log:##################################################################################bind . <Configure> {ResizeAll}set isag_enResizing 0# first time this function is emptyproc gnuplot {w} {}proc ResizeAll {} { global isag_enResizing isag_gr_scale_old set width [winfo width .] set height [winfo height .] set w [expr [winfo width .graph.scale] + [winfo width .graph.canv]] set h [expr [winfo height .menu] + [winfo height .file] + [winfo height .graph.scale]] if {($w >= $width) && ($h == $height)} { incr isag_enResizing return } if {0 == $isag_enResizing} { return } set isag_enResizing 0 if {$w <= $width} {# number two look as magic number .graph.canv configure -width [expr $width - [winfo width .graph.scale] - 2] } if {$h != $height} { set h1 [expr [winfo height .menu] + [.file cget -height]] .graph.canv configure -height [expr $height - $h1] .graph.scale configure -length [expr $height - $h1] }# set isag_gr_scale_old 0# redraw_graph## not reliable WHY? gnuplot .graph.canv #set isag_enResizing 1}# $Source: /var/CVSROOT/cvs/i-sag/isag/isag.ResizeAll.m4,v $################################################################################ Other functions## $Id: isag.Other.Funcs.m4,v 1.20 2004/03/22 19:39:14 david Exp $# $State: Exp $# $Log: isag.Other.Funcs.m4,v $# Revision 1.20 2004/03/22 19:39:14 david# fully avoided shell script, i hope the temp file issue is fixed#################################################################################################################################################################proc strrep {str old new} { set l [string length $old] for {set n [string first $old $str]} {$n != -1} {set n [string first $old $str]} { set str "[string range $str 0 [expr $n - 1]]$new[string range $str [expr $n + $l] end]" } return $str}# eof: strrep.m4# normalizes time if HH:MM:SS PM to 00-24 `format' for gnuplotproc time_normalize {time} { set n [string first "AM" $time] if {$n > 0} { set time [string trim [string range $time 0 [expr $n - 1]]] set hours [string range $time 0 1]# if hour is 12 then time is after midnight if {$hours == 12} { set time "[format %02d [expr $hours - 12]][string range $time 2 end]" } else { return [string trim [string range $time 0 [expr $n - 1]]] } unset hours } set n [string first "PM" $time] if {$n > 0} { set time [string trim [string range $time 0 [expr $n - 1]]] set hours [string range $time 0 1] # if hours string looks like 07, then is evaluated as octal number # in case of 08 and 09 generates an error if {"0" == [string range $hours 0 0]} { set hours [string range $hours 1 1] } if {$hours < 12} { set time "[format %02d [expr $hours + 12]][string range $time 2 end]" } unset hours } unset n return $time}# tokens are divided by one or more space(s)proc parse_line {ln} { global needed_version tcl_version set res "" if {$tcl_version > $needed_version} { # this is a more effective set rest [string map { \t " " } [string trim $ln]] } else { set rest [strrep [string trim $ln] \t " "] } for {} {[string length $rest] > 0} {} { set a [string first " " $rest] if {$a == -1} { lappend res "$rest" set rest "" } else { set token [string trim [string range $rest 0 [expr $a - 1]]] set rest [string trim [string range $rest [expr $a + 1] end]] lappend res "$token" } } unset rest return $res}# normalizes number to 2valid digits representation# and returns lis of norm number and step for listproc num_norm {num} { if {$num < 10.0} { return [list 10 1] } set l [expr int ([expr log10 ($num)])] set n [expr int ([expr pow (10, [expr $l - 1])])] set m [expr int ([expr ($num - 1) / $n]) + 1] set max [expr $m * $n] set step [expr int ([expr pow (10, [expr $l - 2])])] if {$step < 1} { set step 1 } unset l n m return [list $max $step] }#### Parameters## gp_term - gnuplot terminal (currently used: tkcanvas & jpeg)## ext - out filename extension (related to gp_term)## fn - file name base for resulting file## title - graph title/name## xlabel - xlabel text## ylabel - primary ylabel text## y2label - secondary ylabel text (scale 0-100%)## yrange - yrange (y-maximum)## plot_str - gplot command which produces desired output graph## f_grid - flag if grid should be drawn##proc create_gnuplot_file {gp_term ext fn title xlabel ylabel y2label yrange plot_str f_grid} { global sag_graph_wd sag_graph_ht # Y2 percentage set fp [open $fn.gp "w"] # not consistent workaround if { $gp_term == "jpeg" } { puts $fp "set term $gp_term transparent interlace size $sag_graph_wd,$sag_graph_ht" } else { puts $fp "set term $gp_term" }# puts $fp "set title \"$title\""# puts $fp "set xlabel \"$xlabel\"" puts $fp "set ylabel \"$ylabel\"" if {$y2label != ""} { puts $fp "set y2label \"$y2label\"" puts $fp "set y2range \[0:100\]" } puts $fp "set timefmt \"%H:%M:%S\"" puts $fp "set xdata time" puts $fp "set format x \"%H:%M\"" if {$yrange != ""} { puts $fp "set yrange $yrange" } puts $fp "set output \"$fn.$ext\"" if { 0 != $f_grid } { puts $fp "set grid" } puts $fp "plot $plot_str" close $fp}# $Source: /var/CVSROOT/cvs/i-sag/isag/isag.Other.Funcs.m4,v $################################################################################# Remaining graph paramaters## plotstr array# in future - this string will not be fixed but functions will coming# SGo 2006-04-14: update fields for options -B, -q, -r, -R, -u, -v.set plotstr(b) "\"__FNGR__\" using 1:2 t \"rtps\" with line, \"__FNGR__\" using 1:3 t \"wtps\" with line, \"__FNGR__\" using 1:4 t \"bread/s\" with line, \"__FNGR__\" using 1:5 t \"bwrtn/s\" with line"set plotstr(B) "\"__FNGR__\" using 1:2 t \"pgpgin/s\" with line, \"__FNGR__\" using 1:3 t \"pgpgout/s\" with line, \"__FNGR__\" using 1:4 t \"fault/s\" with line, \"__FNGR__\" using 1:5 t \"majflt/s\" with line"set plotstr(c) "\"__FNGR__\" using 1:2 t \"proc/s\" with line"set plotstr(n) ""set plotstr(q) "\"__FNGR__\" using 1:2 t \"runq-sz\" with line, \"__FNGR__\" using 1:3 t \"plist-sz\" with line, \"__FNGR__\" using 1:4 t \"ldavg-1\" with line, \"__FNGR__\" using 1:5 t \"ldavg-5\" with line, \"__FNGR__\" using 1:6 t \"ldavg-15\" with line"set plotstr(r) "\"__FNGR__\" using 1:2 t \"kbmemfree\" with line, \"__FNGR__\" using 1:3 t \"kbmemused\" with line, \"__FNGR__\" using 1:4 t \"kbbuffers\" with line, \"__FNGR__\" using 1:5 t \"kbcached\" with line, \"__FNGR__\" using 1:6 t \"kbswpfree\" with line, \"__FNGR__\" using 1:7 t \"kbswpused\" with line, \"__FNGR__\" using 1:8 t \"kbswpcad\" with line"set plotstr(R) "\"__FNGR__\" using 1:2 t \"frmpg/s\" with line, \"__FNGR__\" using 1:3 t \"bufpg/s\" with line, \"__FNGR__\" using 1:4 t \"campg/s\" with line"set plotstr(u) "\"__FNGR__\" using 1:2 t \"%user\" with line, \"__FNGR__\" using 1:3 t \"%nice\" with line, \"__FNGR__\" using 1:4 t \"%system\" with line, \"__FNGR__\" using 1:5 t \"%iowait\" with line, \"__FNGR__\" using 1:6 t \"%steal\" with line"set plotstr(v) "\"__FNGR__\" using 1:2 t \"dentunusd\" with line, \"__FNGR__\" using 1:3 t \"file-sz\" with line, \"__FNGR__\" using 1:4 t \"inode-sz\" with line, \"__FNGR__\" using 1:5 t \"super-sz\" with line, \"__FNGR__\" using 1:6 t \"dquot-sz\" with line, \"__FNGR__\" using 1:7 t \"rtsig-sz\" with line"set plotstr(w) "\"__FNGR__\" using 1:2 t \"cswch/s\" with line"set plotstr(W) "\"__FNGR__\" using 1:2 t \"pswpin/s\" with line, \"__FNGR__\" using 1:3 t \"pswpout/s\" with line"################################################################################ Performance data processing## $Id: isag.perf_data_procs.m4,v 1.11 2003/01/26 20:41:48 david Exp $# $State: Exp $# $Log: isag.perf_data_procs.m4,v $# Revision 1.11 2003/01/26 20:41:48 david# partially renamed variables, 1st implementation of "Save Graph"## Revision 1.10 2002/03/24 15:18:26 david# added## Revision 1.9 2002/03/04 20:23:26 david# fixed whole day functionality## Revision 1.8 2001/03/30 16:42:26 sarrep# Fixed bug about _last_time, (mangled graph)## Revision 1.7 2001/03/17 17:30:16 sarrep# CVSizing, unified headers of each element file## Revision 1.6 2001/03/17 16:55:27 sarrep# LINUX RESTART zeroes all counters.################################################################################# CPU measurement specific line processing# SGo 2006-04-14: take into account time spent in iowait and steal modesproc sag_if_proc_line_u {fp line} { global val_cur val_max sag_if_last_time sag_if_reboot_flag set rval 0 set a [string first "all" $line] if {$a != -1} { set time [string trim [string range $line 0 [expr $a - 1]]] set time [time_normalize "$time"] set rest [string trim [string range $line [expr $a + 3] end]] if {1 == $sag_if_reboot_flag} {# after reboot, set to zero also, all charts are with lines
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -