Skip to content

Commit e699384

Browse files
committed
update code add debug mode.
1 parent bcf9cc4 commit e699384

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

bashrc/_bashrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ mono*:echo*:g++*:vim*:cscope*:ctags*:boch*:rm*:gvim*:ll*:\
109109
ddd*:hg*:git*:tar*:mkdir*:mv*:unzip*:objdump*:tree*:chmod*:\
110110
python*:gopen*:ping*:grep*;*:&:"
111111

112-
export LANG="zh_CN.UTF-8"
112+
#export LANG="zh_CN.UTF-8"
113113

114-
function gvim {
115-
/usr/bin/gvim -geom 85x55 -f $* > /dev/null 2> /dev/null & disown
116-
}
114+
#function gvim {
115+
# /usr/bin/gvim -geom 85x55 -f $* > /dev/null 2> /dev/null & disown
116+
#}
117117

118118
# Set colors for man pages
119119
man() {

mpstat.pl

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
use File::Basename;
1515
use Getopt::Std qw( getopts );
1616
use Getopt::Long;
17-
#use Smart::Comments;
1817
use POSIX ();
1918
use POSIX qw(strftime);
2019

2120
use Term::ANSIColor;
21+
my $DEBUG = 0;
22+
if ($DEBUG) {
23+
eval q{
24+
use Smart::Comments;
25+
};
26+
die $@ if $@;
27+
}
2228

2329
my %opts;
2430
my ($interval, $count);
@@ -55,16 +61,16 @@
5561
'P|p=s' => \$opts{P},
5662
'version|V' => \$opts{V})
5763
or die print &usage();
58-
## %opts
64+
### %opts
5965

6066
my $nr = &get_cpu_nr();
61-
## $nr
67+
### $nr
6268
my $actflags = 0;
6369
my $actset = 0;
6470
my $flags = 0;
6571
my $cpu_bitmap = 0;
6672
($actflags, $flags, $cpu_bitmap) = &deal_opt(\%opts, $nr);
67-
## $actflags
73+
### $actflags
6874

6975
if(@ARGV >= 3) {
7076
print "The problem of command line parameters too much!\n";
@@ -81,20 +87,20 @@
8187
my $curr = 1;
8288

8389
my ($row, $col) = &get_winsize();
84-
## $row
85-
## $col
90+
### $row
91+
### $col
8692
#------main-------
8793
&main();
8894
#print "\n";
8995
#----------------------end----------------------------
9096

9197
sub main {
9298
$hz = POSIX::sysconf( &POSIX::_SC_CLK_TCK ) || 100;
93-
## $hz
99+
### $hz
94100
$irqcpu_nr = &get_irqcpu_nr($INTERRUPTS, NR_IRQCPU_PREALLOC);
95-
## $irqcpu_nr
101+
### $irqcpu_nr
96102
$softirqcpu_nr = &get_irqcpu_nr($SOFTIRQS, NR_IRQCPU_PREALLOC);
97-
## $softirqcpu_nr
103+
### $softirqcpu_nr
98104

99105
$mp_tstamp[0] = localtime();
100106
# print the infomation header.
@@ -116,9 +122,9 @@ sub rw_mpstat_loop {
116122
### @uptime0
117123
}
118124
$st_cpu[0] = &read_stat_cpu($nr);
119-
## @st_cpu
125+
### @st_cpu
120126
#@st_cpu = &read_stat_cpu($nr);
121-
## @st_cpu
127+
### @st_cpu
122128
#if (! $uptime0[0] and scalar @st_cpu > 1) {
123129
# $uptime0[0] = $st_cpu[1]->{"user"} + $st_cpu[1]->{"nice"} +
124130
# $st_cpu[1]->{"sys"} + $st_cpu[1]->{"idle"} +
@@ -143,7 +149,7 @@ sub rw_mpstat_loop {
143149
### @uptime
144150
if(&get_bit($actflags, M_D_IRQ_SUM)) {
145151
@st_irq = &read_stat_irq($nr);
146-
## @st_irq
152+
### @st_irq
147153
}
148154

149155
if(&get_bit($actflags, M_D_IRQ_SUM) ||
@@ -158,17 +164,17 @@ sub rw_mpstat_loop {
158164
if($interval and $interval > 0) {
159165
$running = -1;
160166
$mp_tstamp[2] = $mp_tstamp[0];
161-
## @mp_tstamp
167+
### @mp_tstamp
162168
$uptime[2] = $uptime[0];
163-
## @uptime
169+
### @uptime
164170
$uptime0[2] = $uptime0[0];
165-
## @uptime0
171+
### @uptime0
166172
$st_cpu[2] = $st_cpu[0];
167-
## @st_cpu
173+
### @st_cpu
168174
$st_irq[2] = $st_irq[0];
169-
## @st_irq
175+
### @st_irq
170176
$st_irqcpu[2] = $st_irqcpu[0];
171-
## @st_irqcpu
177+
### @st_irqcpu
172178
if(&get_bit($actflags, M_D_SOFTIRQS)) {
173179
$st_softirqcpu[2] = $st_softirqcpu[0];
174180
}
@@ -193,7 +199,7 @@ sub rw_mpstat_loop {
193199

194200
if(&get_bit($actflags, M_D_IRQ_SUM)) {
195201
@st_irq = &read_stat_irq($nr);
196-
## @st_irq
202+
### @st_irq
197203
}
198204

199205
if(&get_bit($actflags, M_D_IRQ_SUM) ||
@@ -301,15 +307,15 @@ sub get_irqcpu_nr {
301307

302308
sub read_uptime {
303309
my $HZ = shift;
304-
## $HZ
310+
### $HZ
305311
my $UPTIME = "/proc/uptime";
306312

307313
open(my $fd, "<", $UPTIME);
308314
return 0 unless $fd;
309315

310316
my ($second, $cent) = split(" ", <$fd>);
311-
## $second
312-
## $cent
317+
### $second
318+
### $cent
313319
close($fd);
314320

315321
return ($second * $HZ + $cent * $HZ / 100);
@@ -351,15 +357,15 @@ sub read_stat_cpu {
351357
$st_cpu->{"idle"}, $st_cpu->{"iowait"}, $st_cpu->{"hardirq"},
352358
$st_cpu->{"softirq"}, $st_cpu->{"steal"}, $st_cpu->{"guest"},
353359
$st_cpu->{"guest_nice"}) = split(/\s+/, $_);
354-
## $st_cpu
360+
### $st_cpu
355361
push(@arrays, $st_cpu);
356362
} elsif ($_ =~ /cpu\d/) {
357363
# print $_;
358364
(undef, $st_cpu->{"user"}, $st_cpu->{"nice"}, $st_cpu->{"sys"},
359365
$st_cpu->{"idle"}, $st_cpu->{"iowait"}, $st_cpu->{"hardirq"},
360366
$st_cpu->{"softirq"}, $st_cpu->{"steal"}, $st_cpu->{"guest"},
361367
$st_cpu->{"guest_nice"}) = split(/\s+/, $_);
362-
## $st_cpu
368+
### $st_cpu
363369
push(@arrays, $st_cpu);
364370
} else {
365371
last;
@@ -543,8 +549,8 @@ sub deal_opt {
543549
my $cpu_bitmap = 0;
544550

545551
while (my ($k, $v) = each %$opts) {
546-
## $k
547-
## $v
552+
### $k
553+
### $v
548554
if($k =~ /^I$/) {
549555
if($v) {
550556
$actset = 1;
@@ -650,9 +656,9 @@ sub print_gal_header {
650656
my $nr = shift;
651657
my $time = `date +"%m/%d/%Y"`;
652658
chomp($time);
653-
## $time
659+
### $time
654660
my @sysinfo = split(" ", `uname -a`);
655-
## @sysinfo
661+
### @sysinfo
656662
print "$sysinfo[0] $sysinfo[2] ($sysinfo[1])\t$time\t_$sysinfo[11]_ ($nr CPU)\n";
657663
}
658664

0 commit comments

Comments
 (0)