-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbstop
executable file
·2330 lines (1961 loc) · 76.3 KB
/
pbstop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# Copyright 2002, 2003, 2004 University of Southern California
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Latest version of this software may be found at:
# http://www-rcf.usc.edu/~garrick/perl-PBS
# Please send comments to garrick@usc.edu.
# configurable defaults
# Don't change the defaults here, instead make yourself a config file, see pbstop(1)
my $columns = 30; # columns in grid
my $sleeptime = 1; # seconds between refreshes
my $colorize = 1; # 1 or 0
my $show_summary = 1; # 1 or 0
my $compact_summary = 1; # 1 or 0
my $show_grid = 1; # 1 or 0
my $show_queue = 1; # 1 or 0
my $show_qqueue = 1; # 1 or 0
my $show_jobs = 1; # 1 or 0
my $show_user = "all"; # show only a given user's jobs
my @show_cpu = ("0"); # list of cpu numbers
my @host = (); # leave empty for localhost
my $maxrows = 300; # maximum number of rows
my $maxcolumns = 200; # maximum number of columns
my $maxnodegrid = 7; # maximum number of CPUs on a node before it gets
# its own grid.
my $qmgr = "/usr/local/pbs/bin/qmgr";
my $qstat = "/usr/local/pbs/bin/qstat";
my $pbsnodes = "/usr/local/pbs/bin/pbsnodes";
#########################################################
### Nothing else to adjust below here
# Here's some neat perl magic... we'll use PBS if we have it.
# And if we have it, we might just find it not-yet-installed
# if we are running it out of the source directory. And if
# we _are_ running it out of the source tree, assume we are just
# testing it and enable warnings!
BEGIN {
use vars qw/$use_perlPBS/;
use ExtUtils::testlib;
use Data::Dumper;
eval "use PBS qw/:monitor/";
if ($@) {
$use_perlPBS=0;
} else {
$use_perlPBS=1;
}
}
# enable warnings if running under testing.
if ( -d $INC[0] ) {
$^W=1;
}
use strict;
use vars qw/$VERSION/;
use lib '/mnt/lustre/users/pbstop_kara/Curses-1.33/lib64/perl5';
use Curses;
$VERSION = "4.05LS1";
# init a few global vars
my %Job_of_letter;
my @Colors = ();
my $masterletters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
my $letters = $masterletters;
my $underline = 0;
my %searchobject=();
my ( $y, $x, $Y, $X, $py, $px, $ly, $lx, $subY, $subX ) = ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
if ($use_perlPBS) {
my $defaulthost=pbs_default();
if ($defaulthost) {
@host=($defaulthost);
}
undef $defaulthost;
}
readrc("/etc/pbstoprc");
readrc("$ENV{HOME}/.pbstoprc");
if (!$use_perlPBS) {
-e $qmgr or chomp( $qmgr = `which qmgr 2>/dev/null` );
-e $qmgr or die "qmgr: Command not found\n";
-e $qstat or chomp( $qstat = `which qstat 2>/dev/null` );
-e $qstat or die "qstat: Command not found\n";
-e $pbsnodes or chomp( $pbsnodes = `which pbsnodes 2>/dev/null` );
-e $pbsnodes or die "pbsnodes: Command not found\n";
}
# argument processing
my @argvhosts=();
while ( my $arg = shift @ARGV ) {
if ( $arg eq '-c' ) {
$columns = shift @ARGV;
$columns =~ /^\d+$/ or $ARGV[0] = '-h';
$columns > 0 or $ARGV[0] = '-h';
}
elsif ( $arg eq '-s' ) {
$sleeptime = shift @ARGV;
$sleeptime =~ /^\d+$/ or $ARGV[0] = '-h';
$sleeptime > 0 or $ARGV[0] = '-h';
}
elsif ( $arg eq '-m' ) {
$maxnodegrid = shift @ARGV;
$maxnodegrid =~ /^\d+$/ or $ARGV[0] = '-h';
$maxnodegrid > 0 or $ARGV[0] = '-h';
}
elsif ( $arg eq '-C' ) {
$colorize = !$colorize;
}
elsif ( $arg eq '-S' ) {
$show_summary = !$show_summary;
}
elsif ( $arg eq '-G' ) {
$show_grid = !$show_grid;
}
elsif ( $arg eq '-Q' ) {
$show_queue = !$show_queue;
}
elsif ( $arg eq '-t' ) {
$show_qqueue = !$show_qqueue;
}
elsif ( $arg eq '-J' ) {
$show_jobs = !$show_jobs;
}
elsif ( $arg eq '-u' ) {
if (defined $ARGV[0] and $ARGV[0] =~ /^([^-]+)/) {
$show_user=join(' ', split(',', shift));
} else {
$ARGV[0] = '-h';
}
}
elsif ( $arg =~ /^-(\d+)$/ ) {
@show_cpu = split ( //, $1 );
}
elsif ( $arg =~ /^@(.*)/ ) {
push(@argvhosts, $1);
}
elsif ( $arg eq '-V' ) {
print
"pbstop $VERSION\nCopyright 2002, 2003, 2004 University of Southern California\n";
exit(0);
}
else {
print "Usage: pbstop [-c columns] [-s seconds] [-m numcpus] [options] [\@host ...]\n";
print " Version: $VERSION\n";
print " Copyright 2002, 2003, 2004 University of Southern California\n";
print " garrick\@usc.edu http://www-rcf.usc.edu/~garrick/pbstop\n";
print " grep FIXME `which pbstop` if you want to help out\n\n";
print " -s seconds between refreshes\n";
print " -c number of columns to display in the grid\n";
print " -m max number of cpus in a node before it gets its own grid\n";
print " -u show only a user's jobs\n";
print " -C toggle colorization\n";
print " -S toggle state summary display\n";
print " -G toggle grid display\n";
print " -Q toggle queue display\n";
print " -t toggle showing queued jobs in queue display\n";
print " -[0-9]... cpu numbers for grid display\n";
print " -J toggle jobs in grid display\n";
print " -V print version and exit\n";
exit(1);
}
}
if(scalar @argvhosts > 0) {
@host=@argvhosts;
}
undef @argvhosts;
if (!$use_perlPBS) {
defined($host[0]) or $host[0] = defined $ENV{"PBS_DEFAULT"}
? $ENV{"PBS_DEFAULT"}
: `hostname`;
}
chomp( @host );
if ($show_user eq "all") {
$show_user=0;
} elsif ($show_user =~ /\bme\b/) {
$show_user=~ s/\bme\b/$ENV{USER}/;
}
use vars qw/$SIGWINCH/;
$SIGWINCH=0;
$SIG{'WINCH'} = sub {$SIGWINCH=1; };
$SIG{'INT'} = sub { endwin; exit(0); };
$SIG{'TERM'} = sub { endwin; exit(0); };
#FIXME# Can someone tell me how to use filter() correctly?
-t STDOUT or filter();
# Is this portable?
my $CTRL_B=chr(ord("B")-ord("@"));
my $CTRL_F=chr(ord("F")-ord("@"));
my $CTRL_L=chr(ord("L")-ord("@"));
my $CTRL_G=chr(ord("G")-ord("@"));
my $CTRL_H=chr(ord("H")-ord("@"));
initscr;
cbreak;
noecho;
getmaxyx( $Y, $X );
start_color;
$colorize=$colorize && has_colors();
my $pr = 0;
# This is every possible color combo list below. Over time, I've commented out
# color pairs that don't look very good. If your eyes disagree with my eyes,
# you are free to play around with this list. But don't forget... only the
# first $COLOR_PAIRS uncommented combos apply. $COLOR_PAIRS is set by your
# curses implementation. pbstop's help screen (hit 'h' in pbstop) will tell
# you the value of $COLOR_PAIRS.
init_pair( ++$pr, COLOR_RED, COLOR_BLACK );
init_pair( ++$pr, COLOR_GREEN, COLOR_BLACK );
init_pair( ++$pr, COLOR_YELLOW, COLOR_BLACK );
init_pair( ++$pr, COLOR_BLUE, COLOR_BLACK );
init_pair( ++$pr, COLOR_MAGENTA, COLOR_BLACK );
init_pair( ++$pr, COLOR_CYAN, COLOR_BLACK );
init_pair( ++$pr, COLOR_WHITE, COLOR_BLACK );
#init_pair( ++$pr, COLOR_BLACK, COLOR_BLACK );
#init_pair( ++$pr, COLOR_RED, COLOR_WHITE );
#init_pair( ++$pr, COLOR_GREEN, COLOR_WHITE );
#init_pair( ++$pr, COLOR_YELLOW, COLOR_WHITE );
#init_pair( ++$pr, COLOR_BLUE, COLOR_WHITE );
#init_pair( ++$pr, COLOR_MAGENTA, COLOR_WHITE );
#init_pair( ++$pr, COLOR_CYAN, COLOR_WHITE );
#init_pair( ++$pr, COLOR_WHITE, COLOR_WHITE );
init_pair( ++$pr, COLOR_BLACK, COLOR_WHITE );
#init_pair( ++$pr, COLOR_RED, COLOR_YELLOW );
#init_pair( ++$pr, COLOR_GREEN, COLOR_YELLOW );
#init_pair( ++$pr, COLOR_YELLOW, COLOR_YELLOW );
#init_pair( ++$pr, COLOR_BLUE, COLOR_YELLOW );
init_pair( ++$pr, COLOR_MAGENTA, COLOR_YELLOW );
#init_pair( ++$pr, COLOR_CYAN, COLOR_YELLOW );
#init_pair( ++$pr, COLOR_WHITE, COLOR_YELLOW );
#init_pair( ++$pr, COLOR_BLACK, COLOR_YELLOW );
init_pair( ++$pr, COLOR_RED, COLOR_CYAN );
#init_pair( ++$pr, COLOR_GREEN, COLOR_CYAN );
init_pair( ++$pr, COLOR_YELLOW, COLOR_CYAN );
#init_pair( ++$pr, COLOR_BLUE, COLOR_CYAN );
init_pair( ++$pr, COLOR_MAGENTA, COLOR_CYAN );
#init_pair( ++$pr, COLOR_CYAN, COLOR_CYAN );
init_pair( ++$pr, COLOR_WHITE, COLOR_CYAN );
init_pair( ++$pr, COLOR_BLACK, COLOR_CYAN );
init_pair( ++$pr, COLOR_RED, COLOR_MAGENTA );
init_pair( ++$pr, COLOR_GREEN, COLOR_MAGENTA ); # current 16th
init_pair( ++$pr, COLOR_YELLOW, COLOR_MAGENTA );
init_pair( ++$pr, COLOR_BLUE, COLOR_MAGENTA );
#init_pair( ++$pr, COLOR_MAGENTA, COLOR_MAGENTA );
init_pair( ++$pr, COLOR_CYAN, COLOR_MAGENTA );
init_pair( ++$pr, COLOR_WHITE, COLOR_MAGENTA );
#init_pair( ++$pr, COLOR_BLACK, COLOR_MAGENTA );
#init_pair( ++$pr, COLOR_RED, COLOR_RED );
init_pair( ++$pr, COLOR_GREEN, COLOR_RED );
init_pair( ++$pr, COLOR_YELLOW, COLOR_RED );
init_pair( ++$pr, COLOR_BLUE, COLOR_RED );
init_pair( ++$pr, COLOR_MAGENTA, COLOR_RED );
init_pair( ++$pr, COLOR_CYAN, COLOR_RED );
init_pair( ++$pr, COLOR_WHITE, COLOR_RED );
init_pair( ++$pr, COLOR_BLACK, COLOR_RED );
init_pair( ++$pr, COLOR_RED, COLOR_GREEN );
#init_pair( ++$pr, COLOR_GREEN, COLOR_GREEN );
#init_pair( ++$pr, COLOR_YELLOW, COLOR_GREEN );
init_pair( ++$pr, COLOR_BLUE, COLOR_GREEN );
#init_pair( ++$pr, COLOR_MAGENTA, COLOR_GREEN );
init_pair( ++$pr, COLOR_CYAN, COLOR_GREEN );
init_pair( ++$pr, COLOR_WHITE, COLOR_GREEN );
init_pair( ++$pr, COLOR_BLACK, COLOR_GREEN );
sub init_colors {
return ( 1 .. ($COLOR_PAIRS-1 > $pr ? $pr : $COLOR_PAIRS-1) );
}
my $pad = newpad( $maxrows, $maxcolumns );
my $cmdwin = newwin( 1, $X - 1, $Y - 1, 0 );
keypad( $cmdwin, 1 );
my $subwin=0;
main_loop(\@host);
# The original color set that I actually spent some time planning
# "\033[07;34m", "\033[07;35m", "\033[07;36m",
# "\033[07;37m", "\033[01;37m", "\033[35m",
# "\033[36m", "\033[37m", "\033[34m",
# "\033[33m", "\033[32m", "\033[01;36;45m",
# "\033[01;30;47m", "\033[01;30;46m", "\033[36;45m",
# "\033[30;47m", "\033[30;46m", "\033[01;33m",
# "\033[01;34m", "\033[01;35m", "\033[01;36m",
# "\033[01;31m", "\033[01;32m",
###############################################################
## All subroutines below here
###############################################################
# main_loop() will 1) gather all of our data from pbs_server, 2) prep it a bit
# in letterize() and colorize(), 3) call update_display to draw our pretty
# grids and stuff, and finally calls 4) top_sleep which is where we spend most
# of our time.
# 1) We have two ways of gathering data: calling the perl-PBS module which
# connects directly to pbs_server and requests the desired data, or parsing the
# output of qmgr and qstat. Clearly the former is desired. The latter is only
# called if perl-PBS can't be found. These subroutines are get_info_modPBS()
# and get_info_cmdline(). Since this data is kept between cycles around the
# main loop, we take some care to remove old data. The result is two large structures, one for Jobs and one for Nodes, which will carry us through the rest of the entire program.
# 2) letterize() and colorize() are fairly unexciting, but they do assign
# letters and colors to each running job. This info is stored in the large Job
# structure. letterize() has probably the only original code left.
# 3) update_display(), by itself, is pretty coring. It calls the functions
# responsible for the summary, colorful grid, and the job listing at the
# bottom. show_grid() is pretty exciting; it first finds every node over
# $maxnodegrid, calls them "timesharing" and shoves them aside, draws a big
# colorful grid for what's left, and draws another colorful grid for the
# timesharing nodes.
# 4) top_sleep() is a big giant mess. It is far too monolithic. If anyone
# wants chop it up a bit, feel free to send me patches! Anyways, it loops
# around on user input until the time expires and it is time to return back up
# to main_loop(). In the meantime, it does everything the user requests,
# including griding through the main data structures looking for stuff. All of
# the code responsible for moving around the giant pad is here.
sub main_loop {
my $host = shift;
my $maxlen;
my %Nodes;
my %Jobs;
my %State_count;
# temp vars
my $node;
# Main event loop.
while (1) {
%State_count = ();
$State_count{_nodes} = 0;
$State_count{_anodes} = 0;
$State_count{_procs} = 0;
$State_count{_aprocs} = 0;
$State_count{_mprocs} = 0;
$State_count{_rjobs} = 0;
$State_count{_njobs} = 0;
foreach my $server (@$host) {
if ($use_perlPBS) {
get_info_modPBS($server, \%Nodes, \%Jobs, \%State_count);
} else {
get_info_cmdline($server, \%Nodes, \%Jobs, \%State_count);
}
# trim out old nodes that are no longer seen
foreach my $node (keys %{$Nodes{$server}}) {
if ($Nodes{$server}{$node}{seen} != 1) {
delete $Nodes{$server}{$node};
} else {
$Nodes{$server}{$node}{seen}=0;
}
}
}
# trim out old jobs that are no longer seen
foreach my $job (keys %Jobs) {
if (!exists $Jobs{$job}{seen} or !defined $Jobs{$job}{seen} or $Jobs{$job}{seen} != 1) {
delete $Jobs{$job};
} else {
$Jobs{$job}{seen}=0;
}
}
$maxlen |= getmaxkeylen( \%Nodes );
letterize( \%Jobs );
colorize( \%Jobs );
update_display( \%State_count, \%Nodes, \%Jobs, $maxlen,
$State_count{"_mprocs"} );
-t STDOUT or do { endwin; exit; };
top_sleep( \%State_count, \%Nodes, \%Jobs, $maxlen,
$State_count{"_mprocs"} );
}
}
sub get_info_modPBS {
my ($server, $Nodes, $Jobs, $State_count) = @_;
my $con=pbs_connect($server);
if ($con <= 0) {
printwarning("Connect to $server failed: $PBS::pbs_errno\n");
return;
}
my $qmgr=pbs_statnode($con, undef, undef, undef);
my $qstat=pbs_statjob($con, undef, undef, undef);
pbs_disconnect($con);
my $jobs;
my $status;
my $statuses;
my $node;
my $job;
my $name;
my $value;
my $node="";
foreach (@{$qmgr}) {
$node=$_->{name};
delete $Nodes->{$server}{$node};
$Nodes->{$server}{$node}{seen}=1;
$State_count->{_nodes}++;
foreach (@{ $_->{attribs} }) {
$name=$_->{name};
$value=$_->{value};
$name eq $PBS::ATTR_NODE_np and do {
$Nodes->{$server}{$node}{np} = $value;
$State_count->{_procs} += $value;
$State_count->{_mprocs} = $State_count->{_mprocs} > $value
? $State_count->{_mprocs}
: $value;
};
$name eq $PBS::ATTR_NODE_state and do {
$Nodes->{$server}{$node}{state} = $value;
$State_count->{$value}++;
};
$name eq $PBS::ATTR_NODE_properties and $Nodes->{$server}{$node}{properties} = $value;
$name eq $PBS::ATTR_NODE_ntype and $Nodes->{$server}{$node}{ntype} = $value;
$name eq $PBS::ATTR_NODE_jobs and do {
$State_count->{"_anodes"}++;
foreach my $job ( split ( /, /, $value ) ) {
if ( $job =~ m{(\d+)/(\d+)} ) {
$Nodes->{$server}{$node}{job}{$1} = $2;
$State_count->{"_aprocs"}++;
}
}
};
$name eq $PBS::ATTR_NODE_status and do {
foreach my $status ( split ( /,/, $value ) ) {
if ( $status =~ m{(.+)=(.+)} ) {
$Nodes->{$server}{$node}{status}{$1} = $2;
}
}
};
}
}
my $job;
foreach (@{ $qstat }) {
( $job = $_->{name} ) =~ s/\..*//;
$Jobs->{$job}{seen}=1;
foreach (@{ $_->{attribs} }) {
$_->{name} eq $PBS::ATTR_server and $Jobs->{$job}{server} = $_->{value};
$_->{name} eq $PBS::ATTR_owner and ($Jobs->{$job}{user} = $_->{value})=~s/\@.*//;
$_->{name} eq $PBS::ATTR_queue and $Jobs->{$job}{queue} = $_->{value};
$_->{name} eq $PBS::ATTR_N and $Jobs->{$job}{jname} = $_->{value};
$_->{name} eq "$PBS::ATTR_l.nodect" and $Jobs->{$job}{ncount} = $_->{value};
$_->{name} eq "$PBS::ATTR_l.walltime" and $Jobs->{$job}{reqt} = $_->{value};
$_->{name} eq $PBS::ATTR_state and $Jobs->{$job}{state} = $_->{value};
$_->{name} eq "$PBS::ATTR_used.walltime" and $Jobs->{$job}{elpt} = $_->{value};
}
if (exists $Jobs->{$job}{state} and $Jobs->{$job}{state} eq "R") {
$State_count->{"_rjobs"}++;
}
$State_count->{"_njobs"}++;
}
}
sub get_info_cmdline {
my ($server, $Nodes, $Jobs, $State_count) = @_;
my @qmgr = `$qmgr -c 'l n \@$server' $server 2>/dev/null`; # find out everything
$? and do { printwarning("Connection to $server failed.") };
my @qstat = `$qstat -a \@$server 2>/dev/null`;
$? and do { printwarning("Connection to $server failed.") };
my $jobs;
my $eatingjobs=0;
my $status;
my $statuses;
my $eatingstatus=0;
my $node="";
foreach (@qmgr) {
chomp;
#FIXME# Should store node names in an array to preserve order.
if (/^Node /) {
$node = $';
delete $Nodes->{$server}{$node};
$Nodes->{$server}{$node}{seen}=1;
$State_count->{_nodes}++;
$eatingjobs=0;
$eatingstatus=0;
}
elsif (/\s+np = (.*)/) {
$Nodes->{$server}{$node}{np} = $1;
$State_count->{_procs} += $1;
$State_count->{_mprocs} =
$State_count->{_mprocs} > $1
? $State_count->{_mprocs}
: $1;
$eatingstatus=0;
$eatingjobs=0;
}
elsif (/\s+properties = (.*)/) {
$Nodes->{$server}{$node}{properties} = $1;
$eatingstatus=0;
$eatingjobs=0;
}
elsif (/\s+ntype = (.*)/) {
$Nodes->{$server}{$node}{ntype} = $1;
$eatingstatus=0;
$eatingjobs=0;
}
elsif (/\s+state = (.*)/) {
$Nodes->{$server}{$node}{state} = (split /,\s*/, $1)[0];
$State_count->{$1}++;
$eatingstatus=0;
$eatingjobs=0;
}
elsif (/\s+jobs = (.*)/) {
$eatingjobs=1;
$eatingstatus=0;
$jobs = $1;
$State_count->{"_anodes"}++;
foreach my $job ( split ( /, /, $jobs ) ) {
if ( $job =~ m{(\d+)\/(\d+)(?:\[\d+\])?} ) {
$Nodes->{$server}{$node}{job}{$1} = $2;
$State_count->{"_aprocs"}++;
}
}
}
elsif (/\s+status = (.*)/) {
$eatingstatus=1;
$eatingjobs=0;
$statuses = $1;
foreach my $status ( split ( /,/, $statuses ) ) {
if ( $status =~ m{(.+)=(.+)} ) {
$Nodes->{$server}{$node}{status}{$1} = $2;
}
}
}
elsif ($eatingjobs) {
if ($_ =~ /\w/) {
/^\s+(.*)$/;
$jobs = $1;
foreach my $job ( split ( /, /, $jobs ) ) {
if ( $job =~ m{(\d+)\/(\d+)(?:\[\d+\])?} ) {
$Nodes->{$server}{$node}{job}{$1} = $2;
$State_count->{"_aprocs"}++;
}
}
}
else {
$eatingjobs=0;
}
}
elsif ($eatingstatus) {
if ($_ =~ /\w/) {
/^\s+(.*)$/;
$statuses = $1;
foreach my $status ( split ( /,/, $statuses ) ) {
if ( $status =~ m{(.+)=(.+)} ) {
$Nodes->{$server}{$node}{status}{$1} = $2;
}
}
}
else {
$eatingstatus=0;
}
}
}
my $job;
foreach (@qstat) {
my @qs = split ( " ", $_ );
if ( scalar @qs == 11 and $qs[0] =~ /^\d+/ ) {
( $job = $qs[0] ) =~ s/(\d+)(?:\[\])?\.[a-z0-9A-Z-.]+/$1/;
( $server = $qs[0] ) =~ s/\d+(?:\[\])?\.([a-z0-9A-Z-.]+)/$1/;
$Jobs->{$job}{seen}=1;
$Jobs->{$job}{server} = $server;
$Jobs->{$job}{user} = $qs[1];
$Jobs->{$job}{queue} = $qs[2];
$Jobs->{$job}{jname} = $qs[3];
$Jobs->{$job}{ncount} = $qs[5];
$Jobs->{$job}{reqt} = $qs[8];
$Jobs->{$job}{state} = $qs[9];
$Jobs->{$job}{elpt} = $qs[10];
$qs[9] eq "R" and $State_count->{"_rjobs"}++;
$State_count->{"_njobs"}++;
}
}
}
sub update_display {
my $foo;
move( $pad, 0, 0 );
getmaxyx( $Y, $X );
$y = 0, $x = 0;
title();
$show_summary and show_state_summary( $_[0] );
$show_grid and show_grid( $_[2], $_[1], $_[3], $_[4] );
$show_queue and show_queue( $_[2] );
$show_grid
and addstr( $pad, ++$y, 0,
"[?] unknown [@] busy [*] down [.] idle [%] offline [!] other" );
getyx( $pad, $ly, $foo );
clrtobot($pad);
pnoutrefresh( $pad, $py, $px, 0, 0, $Y - 2, $X - 1 );
mvwin( $cmdwin, $Y - 1, 0 );
refresh($cmdwin);
update_subwin(@_);
doupdate();
}
sub title {
addstr $pad, " " x 22;
addstr $pad,
sprintf(
"ATI Kara Cluster Live Usage"
);
move( $pad, ++$y, $x = 0 );
addstr $pad, " " x 16;
addstr $pad,
sprintf(
"pbstop modified by Laurence Stant 2016"
);
move( $pad, $y=$y + 2, $x = 0 );
}
sub show_state_summary {
my $t = 1;
my $t2 = 1;
addstr $pad,
sprintf(
" Usage Totals: %d/%d %s, %d/%d %s, %d/%d %s",
${ $_[0] }{_aprocs},
${ $_[0] }{_procs},
"Procs",
${ $_[0] }{_anodes},
${ $_[0] }{_nodes},
"Nodes",
${ $_[0] }{_rjobs},
${ $_[0] }{_njobs},
"Jobs Running"
);
my ( $y1, $x1 );
#getyx( $pad, $y1, $x1 );
#addstr $pad, " " x ( $X - $x1 - 8 );
# Asbed asked for the time
#addstr $pad, sprintf( "%02d:%02d:%02d", ( localtime() )[ 2, 1, 0 ] );
my $line;
my @states = sort grep !/^_/, keys %{ $_[0] };
if ( $compact_summary ) {
move( $pad, ++$y, $x = 0 );
addstr $pad, " " x 16;
addstr $pad, "Node States:";
for ( my $i = 0 ; defined $states[$i] ; $i++ ) {
$line= " ".${ $_[0] }{ $states[$i] }." ". $states[$i];
$line.= defined $states[$i+1] ? "," : "";
getyx( $pad, $y1, $x1 );
if ( $X-$x1-1 < length($line) ) {
clrtoeol($pad);
move( $pad, ++$y, $x = 0 );
addstr ($pad, " " x 12);
}
addstr ($pad, $line);
}
move( $pad, ++$y, $x = 0 );
clrtoeol($pad);
} else {
for ( my $i = 0 ; defined $states[$i] ; $i++ ) {
move( $pad, ++$y, $x = 0 );
$line = " " x 14;
$line.= sprintf( "%4s %-20s", ${ $_[0] }{ $states[$i] }, $states[$i] );
$i++;
$line .= sprintf( "%4s %-20s", ${ $_[0] }{ $states[$i] }, $states[$i] )
if defined $states[$i];
$line .= " " x ( $X - ( length($line) + 14 ) );
clrtoeol($pad);
addstr $pad, $line;
}
addstr $pad, "Node States:";
move( $pad, ++$y, $x = 0 );
}
}
sub show_grid {
my ( $jobs, $allnodes, $maxlen, $maxprocs ) = @_;
my ( $foo, $tmpx );
$lx = 0;
clrtoeol($pad);
move( $pad, ++$y, $x = 0 );
if ( !scalar @show_cpu ) {
addstr $pad, " No CPUs selected!";
clrtoeol($pad);
return;
}
printvcpuline($maxlen);
foreach my $server (keys %$allnodes ) {
my (@cluster, @ts);
foreach my $node ( sort keys %{$allnodes->{$server}} ) {
$$allnodes{$server}{$node}{np} > $maxnodegrid
? push(@ts, $node)
: push(@cluster, $node);
}
# loop through each node, in lines and columns
my $col = 0;
if(defined $cluster[0]) {
my $headerspaces = scalar @show_cpu;
printnumberline ( $maxlen, $headerspaces, $columns );
printdashline( $maxlen, $headerspaces, $columns );
foreach my $node ( @cluster ) {
$col = 0 if $col >= $columns;
(addstr $pad, sprintf " %${maxlen}s ", $node) if $col == 0;
addstr $pad, " " if ( $col != 0 and $col % 10 == 0 );
foreach my $this_cpu (@show_cpu) {
if ( $this_cpu > $$allnodes{$server}{$node}{np} - 1 ) {
addstr $pad, " ";
} else {
my $state = $$allnodes{$server}{$node}{state};
if (exists $$allnodes{$server}{$node}{job}{$this_cpu}) {
my $job = $$allnodes{$server}{$node}{job}{$this_cpu};
if (exists $$jobs{$job} and exists $$jobs{$job}{letter}
and ($show_user ? $show_user =~ /\b$$jobs{$job}{user}\b/ : 1)) {
my $letter= $$jobs{$job}{letter};
my $color = $$jobs{$job}{color};
my $underline = $jobs->{$job}{underline};
printcpustate($job, $letter, $state, $color, $underline);
} else {
# The job was deleted in between the time we captured
# the node info and the job info from pbs.
printcpustate(0,0,$state,0,0);
}
} else {
printcpustate(0,0,$state,0,0);
}
}
}
addstr $pad, " ";
$col++;
getyx( $pad, $foo, $tmpx );
$lx = $lx > $tmpx ? $lx : $tmpx;
clrtoeol($pad);
move( $pad, ++$y, $x = 0 ) if $col >= $columns;
#return if $y >= $Y;
}
#clrtoeol($pad);
#move( $pad, ++$y, $x = 0 ) if $col != $columns;
#printdashline( $maxlen, $headerspaces, $columns );
clrtoeol($pad);
move( $pad, ++$y, $x = 0 );
}
my $headerspaces=1;
printnumberline ( $maxlen, $headerspaces, $columns );
printdashline( $maxlen, $headerspaces, $columns );
foreach my $node (@ts) {
#my $headerspaces=1;
#printnumberline ( $maxlen, $headerspaces, $columns );
#printdashline( $maxlen, $headerspaces, $columns );
my $col = 0;
foreach my $this_cpu (0 .. $$allnodes{$server}{$node}{np}-1) {
$col = 0 if $col >= $columns;
(addstr $pad, sprintf " %${maxlen}s ", $node) if $col == 0;
addstr $pad, " " if ( $col != 0 and $col % 14 == 0 and substr($node,0,3) ne "gpu");
addstr $pad, " " if ( $col != 0 and $col % 8 == 0 and substr($node,0,3) eq "gpu");
my $state = $$allnodes{$server}{$node}{state};
if (exists $$allnodes{$server}{$node}{job}{$this_cpu}) {
my $job = $$allnodes{$server}{$node}{job}{$this_cpu};
if (exists $$jobs{$job} and exists $$jobs{$job}{letter}
and ($show_user ? $show_user =~ /\b$$jobs{$job}{user}\b/ : 1)) {
my $letter= $jobs->{$job}{letter};
my $color = $jobs->{$job}{color};
my $underline = $jobs->{$job}{underline};
printcpustate($job, $letter, $state, $color, $underline);
} else {
printcpustate(0,0,$state,0,0);
}
} else {
printcpustate(0,0,$state,0,0);
}
addstr $pad, " ";
$col++;
getyx( $pad, $foo, $tmpx );
$lx = $lx > $tmpx ? $lx : $tmpx;
clrtoeol($pad);
move( $pad, ++$y, $x = 0 ) if $col >= $columns;
}
clrtoeol($pad);
#move( $pad, ++$y, $x = 0 ) if $col != $columns;
#printdashline( $maxlen, 1, $columns );
#clrtoeol($pad);
move( $pad, ++$y, $x = 0 );
if ($node eq "gpu2") {
printdashline( $maxlen, $headerspaces, $columns );
}
}
}
clrtoeol($pad);
}
# Print out the job queue
sub show_queue {
my $jobs = shift;
move( $pad, ++$y, $x = 0 );
#return if $y >= $Y;
attron( $pad, A_BOLD );
addstr( $pad,
" Job# Username Queue Jobname Nodes S Elapsed/Requested"
);
attroff( $pad, A_BOLD );
clrtoeol($pad);
move( $pad, ++$y, $x = 0 );
# Note: we never print our the server name, it is expected that the user will
# recognize jobs by their jobid or queue name.
foreach my $job (
# Sort first by server, then by queue, last by jobid
sort {
defined $jobs->{$a}{server}
&& defined $jobs->{$b}{server}
&& $jobs->{$a}{server} cmp $jobs->{$b}{server} or
defined $jobs->{$a}{queue}
&& defined $jobs->{$b}{queue}
&& $jobs->{$a}{queue} cmp $jobs->{$b}{queue} or
$a <=> $b
} keys %{$jobs} ) {
my $l = $jobs->{$job}{letter};
my $color = $jobs->{$job}{color};
my $underline = $jobs->{$job}{underline};
if ( defined $jobs->{$job}{user} ) {
next unless $show_user ? $show_user =~ /\b$jobs->{$job}{user}\b/ : 1;
if ( !( $jobs->{$job}{state} =~ /Q|H/ and !$show_qqueue ) ) {
addstr $pad, " ";
if ( defined $l and $jobs->{$job}{state} eq "R" ) {
print_colored_letter($l, $color, $underline);
addstr $pad, " = ";
}
else {
addstr $pad, " ";
}
# The job is erroring, grab an eyeball
if ($jobs->{$job}{state} eq "E") {
attron($pad, A_REVERSE);
}
addstr $pad,
sprintf(
"%-5s %-8.8s %-8.8s %-10.10s %5.5s %1s %8.8s/%8.8s ",
$job,
$jobs->{$job}{user},
$jobs->{$job}{queue},
$jobs->{$job}{jname},
exists $jobs->{$job}{ncount} ? $jobs->{$job}{ncount} : "",
$jobs->{$job}{state},
exists $jobs->{$job}{elpt} ? $jobs->{$job}{elpt} : "",
exists $jobs->{$job}{reqt} ? $jobs->{$job}{reqt} : "");
if ($jobs->{$job}{state} eq "E") {
attroff($pad, A_REVERSE);
}
clrtoeol($pad);
move( $pad, ++$y, $x = 0 );
}
}
}
clrtoeol($pad);
}
# Pass in a reference to all jobs, and we'll assign a letter to each one.
sub letterize {
my $Jobs = shift;
# The original pbstop only used one letter per job, and this info was held
# in %Job_of_letter. Now that we've thrown out that limitation, it is only
# used to note the fact that _someone_ is using that letter. If a job gets
# a letter that is already assigned, the second one will be noted in
# %Job_of_letter, but that's ok because we don't care _who_ has that letter.
# remove info about old jobs and jobs already assigned a letter
foreach my $l ( keys %Job_of_letter ) {
delete $Job_of_letter{$l} if ( exists $Jobs->{ $Job_of_letter{$l} }{user} );
}
# pick a letter if not already choosen
foreach my $job ( keys %{$Jobs} ) {
next if !defined $Jobs->{$job}{state};
next if $Jobs->{$job}{state} eq "Q";
my $user = $Jobs->{$job}{user};
if ( !exists $Jobs->{$job}{letter} ) {
# find a letter that isn't already taken
my $l = substr( $user, 0, 1 );
if ( exists $Job_of_letter{$l} ) {
$l = uc($l);
if ( exists $Job_of_letter{$l} ) {
if (length $letters <= 0) {
# replenish our supply of letters
$colorize or printwarning("Reusing letters on B&W terminal.");
$letters = $masterletters;
$underline=!$underline;
}
$letters =~ s/(.)//;
$l = $1;
}
}
$Job_of_letter{$l} = $job;
$Jobs->{$job}{letter} = $l;
$Jobs->{$job}{underline} = $underline;
$letters =~ s/$l//;
}
}
}
# Pass in a reference to all jobs, and we'll assign a color to each one.
sub colorize {
my $Jobs = shift or return;
foreach my $job ( keys %{$Jobs} ) {
next if defined $Jobs->{$job}{color};