14
14
use File::Basename;
15
15
use Getopt::Std qw( getopts ) ;
16
16
use Getopt::Long;
17
- # use Smart::Comments;
18
17
use POSIX ();
19
18
use POSIX qw( strftime) ;
20
19
21
20
use Term::ANSIColor;
21
+ my $DEBUG = 0;
22
+ if ($DEBUG ) {
23
+ eval q{
24
+ use Smart::Comments;
25
+ } ;
26
+ die $@ if $@ ;
27
+ }
22
28
23
29
my %opts ;
24
30
my ($interval , $count );
55
61
' P|p=s' => \$opts {P },
56
62
' version|V' => \$opts {V })
57
63
or die print &usage();
58
- # # %opts
64
+ # ## %opts
59
65
60
66
my $nr = &get_cpu_nr();
61
- # # $nr
67
+ # ## $nr
62
68
my $actflags = 0;
63
69
my $actset = 0;
64
70
my $flags = 0;
65
71
my $cpu_bitmap = 0;
66
72
($actflags , $flags , $cpu_bitmap ) = &deal_opt(\%opts , $nr );
67
- # # $actflags
73
+ # ## $actflags
68
74
69
75
if (@ARGV >= 3) {
70
76
print " The problem of command line parameters too much!\n " ;
81
87
my $curr = 1;
82
88
83
89
my ($row , $col ) = &get_winsize();
84
- # # $row
85
- # # $col
90
+ # ## $row
91
+ # ## $col
86
92
# ------main-------
87
93
&main();
88
94
# print "\n";
89
95
# ----------------------end----------------------------
90
96
91
97
sub main {
92
98
$hz = POSIX::sysconf( &POSIX::_SC_CLK_TCK ) || 100;
93
- # # $hz
99
+ # ## $hz
94
100
$irqcpu_nr = &get_irqcpu_nr($INTERRUPTS , NR_IRQCPU_PREALLOC);
95
- # # $irqcpu_nr
101
+ # ## $irqcpu_nr
96
102
$softirqcpu_nr = &get_irqcpu_nr($SOFTIRQS , NR_IRQCPU_PREALLOC);
97
- # # $softirqcpu_nr
103
+ # ## $softirqcpu_nr
98
104
99
105
$mp_tstamp [0] = localtime ();
100
106
# print the infomation header.
@@ -116,9 +122,9 @@ sub rw_mpstat_loop {
116
122
# ## @uptime0
117
123
}
118
124
$st_cpu [0] = &read_stat_cpu($nr );
119
- # # @st_cpu
125
+ # ## @st_cpu
120
126
# @st_cpu = &read_stat_cpu($nr);
121
- # # @st_cpu
127
+ # ## @st_cpu
122
128
# if (! $uptime0[0] and scalar @st_cpu > 1) {
123
129
# $uptime0[0] = $st_cpu[1]->{"user"} + $st_cpu[1]->{"nice"} +
124
130
# $st_cpu[1]->{"sys"} + $st_cpu[1]->{"idle"} +
@@ -143,7 +149,7 @@ sub rw_mpstat_loop {
143
149
# ## @uptime
144
150
if (&get_bit($actflags , M_D_IRQ_SUM)) {
145
151
@st_irq = &read_stat_irq($nr );
146
- # # @st_irq
152
+ # ## @st_irq
147
153
}
148
154
149
155
if (&get_bit($actflags , M_D_IRQ_SUM) ||
@@ -158,17 +164,17 @@ sub rw_mpstat_loop {
158
164
if ($interval and $interval > 0) {
159
165
$running = -1;
160
166
$mp_tstamp [2] = $mp_tstamp [0];
161
- # # @mp_tstamp
167
+ # ## @mp_tstamp
162
168
$uptime [2] = $uptime [0];
163
- # # @uptime
169
+ # ## @uptime
164
170
$uptime0 [2] = $uptime0 [0];
165
- # # @uptime0
171
+ # ## @uptime0
166
172
$st_cpu [2] = $st_cpu [0];
167
- # # @st_cpu
173
+ # ## @st_cpu
168
174
$st_irq [2] = $st_irq [0];
169
- # # @st_irq
175
+ # ## @st_irq
170
176
$st_irqcpu [2] = $st_irqcpu [0];
171
- # # @st_irqcpu
177
+ # ## @st_irqcpu
172
178
if (&get_bit($actflags , M_D_SOFTIRQS)) {
173
179
$st_softirqcpu [2] = $st_softirqcpu [0];
174
180
}
@@ -193,7 +199,7 @@ sub rw_mpstat_loop {
193
199
194
200
if (&get_bit($actflags , M_D_IRQ_SUM)) {
195
201
@st_irq = &read_stat_irq($nr );
196
- # # @st_irq
202
+ # ## @st_irq
197
203
}
198
204
199
205
if (&get_bit($actflags , M_D_IRQ_SUM) ||
@@ -301,15 +307,15 @@ sub get_irqcpu_nr {
301
307
302
308
sub read_uptime {
303
309
my $HZ = shift ;
304
- # # $HZ
310
+ # ## $HZ
305
311
my $UPTIME = " /proc/uptime" ;
306
312
307
313
open (my $fd , " <" , $UPTIME );
308
314
return 0 unless $fd ;
309
315
310
316
my ($second , $cent ) = split (" " , <$fd >);
311
- # # $second
312
- # # $cent
317
+ # ## $second
318
+ # ## $cent
313
319
close ($fd );
314
320
315
321
return ($second * $HZ + $cent * $HZ / 100);
@@ -351,15 +357,15 @@ sub read_stat_cpu {
351
357
$st_cpu -> {" idle" }, $st_cpu -> {" iowait" }, $st_cpu -> {" hardirq" },
352
358
$st_cpu -> {" softirq" }, $st_cpu -> {" steal" }, $st_cpu -> {" guest" },
353
359
$st_cpu -> {" guest_nice" }) = split (/ \s +/ , $_ );
354
- # # $st_cpu
360
+ # ## $st_cpu
355
361
push (@arrays , $st_cpu );
356
362
} elsif ($_ =~ / cpu\d / ) {
357
363
# print $_;
358
364
(undef , $st_cpu -> {" user" }, $st_cpu -> {" nice" }, $st_cpu -> {" sys" },
359
365
$st_cpu -> {" idle" }, $st_cpu -> {" iowait" }, $st_cpu -> {" hardirq" },
360
366
$st_cpu -> {" softirq" }, $st_cpu -> {" steal" }, $st_cpu -> {" guest" },
361
367
$st_cpu -> {" guest_nice" }) = split (/ \s +/ , $_ );
362
- # # $st_cpu
368
+ # ## $st_cpu
363
369
push (@arrays , $st_cpu );
364
370
} else {
365
371
last ;
@@ -543,8 +549,8 @@ sub deal_opt {
543
549
my $cpu_bitmap = 0;
544
550
545
551
while (my ($k , $v ) = each %$opts ) {
546
- # # $k
547
- # # $v
552
+ # ## $k
553
+ # ## $v
548
554
if ($k =~ / ^I$ / ) {
549
555
if ($v ) {
550
556
$actset = 1;
@@ -650,9 +656,9 @@ sub print_gal_header {
650
656
my $nr = shift ;
651
657
my $time = ` date +"%m /%d /%Y "` ;
652
658
chomp ($time );
653
- # # $time
659
+ # ## $time
654
660
my @sysinfo = split (" " , ` uname -a` );
655
- # # @sysinfo
661
+ # ## @sysinfo
656
662
print " $sysinfo [0] $sysinfo [2] ($sysinfo [1])\t $time \t _$sysinfo [11]_ ($nr CPU)\n " ;
657
663
}
658
664
0 commit comments