Imported Upstream version 3.3.0
[debian/amanda] / amplot / amplot.awk
1 #
2 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 # Copyright (c) 1992-1998, 2000 University of Maryland at College Park
4 # All Rights Reserved.
5 #
6 # Permission to use, copy, modify, distribute, and sell this software and its
7 # documentation for any purpose is hereby granted without fee, provided that
8 # the above copyright notice appear in all copies and that both that
9 # copyright notice and this permission notice appear in supporting
10 # documentation, and that the name of U.M. not be used in advertising or
11 # publicity pertaining to distribution of the software without specific,
12 # written prior permission.  U.M. makes no representations about the
13 # suitability of this software for any purpose.  It is provided "as is"
14 # without express or implied warranty.
15 #
16 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #
23 # Author: Olafur Gudumundsson, ogud@tis.com
24 # formerly at:     Systems Design and Analysis Group
25 #                  Computer Science Department
26 #                  University of Maryland at College Park
27 #
28 # An awk program to parse the amdump file and output the information
29 # in a form at the gnuplot program amplot.g wants
30 #
31 #       Creation Date: April 1992
32 #       modified: Aug 1993
33 #       Modified for Amanda-2.2: Dec 1993
34 #       Modified for Amanda-2.2: Mar 1994 and May 1994 and June 1994
35 #       Enhanced: April 1995
36 #       Input: One amdump file 
37 #       Output: Number of files that get fed into gnuplot
38 #
39 BEGIN{
40 # The folowing parameters may have to be set to suit each site, both 
41 # parameters are expressed in HOUR's. 
42 # If your average amanda dump is more than 3 hours you should increase the
43 # value of maxtime, similary if your dumps are finishing in less than 2 hours
44 # you should decrease the value of maxtime.
45 # This is now setable from amplot's command line.
46 #       maxtime  = 4;                   # how long to plot graph for in hours
47
48 # Min host controls the reporting of hosts that take long in dumping
49 # This varible can be set explicity or as a fraction of maxtime
50 # If you are seeing too many hosts reported increase the value of this 
51 # constant
52 #
53         min_host = maxtime * 0.75;      # good rule of thumb
54 #       min_host = 2.5;                 # expicit cutoff value in hours
55
56 #
57 # DO NOT CHANGE ANYTHING BELOW THIS LINE
58 #
59         time_scale = 60;        # display in minutes DO NOT CHANGE
60         maxtime  *= time_scale; # convert to minutes
61         min_host *= time_scale *time_scale; # convert to seconds
62                                                 # dumping than this 
63         disk_raise = 120;       # scaling factors for Holding disk graph
64         tape_raise = 90;
65         dump_shift = 7.5;       # scaling factors for Dumpers idle graph
66         dump_raise = 0;
67         que_raise  = 300;       # scaling factors for the queue's
68         count_scale= 1.0/3.0;   # new scale 
69                                 # scaling factors for the x axis 
70         bandw_raise = 250;
71         bandw_scale = 30/300;   # default calculated below 
72
73         holding_disk = -1;      # uninitialized
74                 
75         cnt        = 0;         # default values for counters
76         din        = 0;         # number of dumps to holding disk
77         dout       = 0;         # number of dumps to tape 
78         tapeq      = 0;         # how many dumps in tape queue
79         tape_err   = 0;         # how many tape errors
80         tout       = 0;         # data written out to tape 
81         quit       = 0;         # normal end of run
82         plot_fmt   = "%7.2f %6.2f\n%7.2f %6.2f\n";  # format of files for gnuplot
83         plot_fmt1  = "%7.2f %6.2f\n";  # format of files for gnuplot
84 }
85         
86 {               # state machine for processing input lines lines
87         if( $1 == "driver:") {
88                 if($2=="result")            do_result();
89                 else if( $2=="state")       do_state();
90                 else if( $2=="interface-state") ;
91                 else if( $2=="hdisk-state") do_hdisk++;
92                 else if( $2=="flush" && $3=="size" ) {
93                         flush_size = $4;
94                 }
95                 else if( $2=="start" && $3=="time")       do_start();
96                 else if( $2=="send-cmd") { 
97                         if( $7=="FILE-DUMP"){
98                           file_dump++;
99                           dmpr_strt[$6]=$4;
100                           host[$6]=$10;
101                           disk[$6]=$12;
102                           level[$6]=$14;
103                         }
104                         else if( $7 == "FILE-WRITE") file_write++;
105                         else if( $7 == "START-TAPER") fil = $9;
106                 }
107                 else if( $2=="finished-cmd") cmd_fin++;
108                 else if( $2=="started")      forked++;
109                 else if( $2=="QUITTING")     do_quit();
110                 else if( $2=="find_diskspace:") ; #eat this line
111                 else if( $2=="assign_holdingdisk:") ; #eat this line
112                 else if( $2=="adjust_diskspace:") ; #eat this line
113                 else if( $2=="tape" && $3=="size") ; #eat this line
114                 else if( $2=="dump" && $3=="failed") ; #eat this line
115                 else if( $2=="taper" && $3=="failed") ; #eat this line
116                 else if( $2=="dumping" || $2 == "adding" || $2 == "holding-disks:") 
117                   dumping++; # eat this line
118                 else if( $2!="FINISHED" && $2 != "pid" && $2 != "taper-tryagain"&& $2!="startaflush:")
119                   print fil,"Unknown statement#",$0;
120         }
121         else if ( $1 == "planner:") {
122                 if( $2 == "SKIPPED" || $2 == "FAILED") {
123                         failed++;
124                         print fil, "INFO#", $0;
125                 }
126         }
127         else if( $1 == "GENERATING")        sched_start=NR;
128         else if( $1 == "ENDFLUSH")          sched_start=NR;
129         else if( $1 == "DELAYING")          do_moves();    # find estimated size
130         else if( $1 == "dumper:") {
131                 if($4 != "starting" && $2 != "pid" && $2 != "stream_client:" && $2 != "dgram_bind:") 
132                     print fil, "INFO#", $0;
133         }
134         else if( $1 == "taper:") {
135                 if($3 != "label" && $3 != "end" && $2 != "DONE" && $2 != "pid" && $2 != "slot" && $2 != "reader-side:" && $2 != "page" && $2 != "buffer" && $3 != "at" && $3 != "switching" && $2 != "slot:" && $2 != "status")
136                     print fil, "INFO#", $0;
137         }
138         else if( $1 == "FLUSH") {
139                 no_flush++;
140         }
141         else if( NF==1 && sched_start > 0 && NR-sched_start > 1) { # new style end of schedule
142                 no_disks = NR-sched_start-2; # lets hope there are no extra lines
143                 sched_start = 0;
144         }
145 }
146
147 function do_state(){            # state line is printed out after driver
148                                 # finishes pondering new actions
149                                 # it reports the state as seen be driver
150 # fields in the state line 
151 # $2 = "state"          # $3 = "time"           # $4 = time_val
152 # $5 = "free"           # $6 = "kps:"           # $7 =  free_kps
153 # $8 = "space:"         # $9 = space            # $10 = "taper:"
154 # $11 = "writing"/"idle"# $12 = "idle-dumpers:"
155 # $13 = #idle           # $14 = "qlen"          # $15 = "tapeq:"
156 # $16 = #waiting        # $17 = "runq:"         # $18 = #not started 
157 # $19 = "roomq"         # $20 = #roomq          # $21 = "wakeup:"
158 # $22 = #wakeup         # $23 = "driver-idle:"  # $23 = status
159
160         cnt++;                                  # number of event
161         time = $4/time_scale;
162         #Check overflow in driver ouput (big value instead of negative)
163         if($7>0 && $7 < 0x7fffffff)
164                 unused = (bandw - $7)*bandw_scale+bandw_raise;
165         else
166                 unused = bandw_raise;
167         if( unused != unused_old) 
168                 printf plot_fmt, time, unused_old, time,unused >>"bandw_free";
169         unused_old = unused;
170
171         if(holding_disk_old != $9) {
172                 disk_alloc_time[disk_a] = time;
173                 disk_alloc_space[disk_a] = holding_disk_old;
174                 disk_a++;
175                 disk_alloc_time[disk_a] = time;
176                 disk_alloc_space[disk_a] = $9;
177                 disk_a++;
178                 holding_disk_old = $9;
179         }
180
181         twait = tsize;
182         if(twait_old != twait) {
183                 twait_time[twait_a] = time;
184                 twait_wait[twait_a] = twait_old;
185                 twait_a++;
186                 twait_time[twait_a] = time;
187                 twait_wait[twait_a] = twait;
188                 twait_a++;
189                 twait_old = twait;
190         }
191
192         active = (dumpers-$13)*dump_shift+dump_raise;
193         if( active != active_old )
194                 printf plot_fmt, time, active_old, time, active >> "dump_idle";
195         active_old = active;
196
197 # tape on or off
198         if($11=="writing")state = tape_raise+10;
199         else              state = tape_raise;
200         if( state != state_old )
201                 printf plot_fmt, time, state_old, time, state >> "tape_idle";
202         state_old = state;
203
204         run = $18*count_scale+que_raise;
205         if( run != run_old )
206                 printf plot_fmt, time, run_old, time, run >> "run_queue";
207         run_old = run;
208
209         finish = written * count_scale+que_raise;
210         if( finish != finish_old )
211                 printf plot_fmt, time, finish_old, time, finish >> "finished";
212         finish_old = finish;
213
214         tapeQ = $16 * count_scale+que_raise;
215         if( tapeQ != tapeQ_old )
216                 printf plot_fmt, time, tapeQ_old, time, tapeQ >> "tape_queue";
217         tapeQ_old = tapeQ;
218
219 }
220
221 function do_start() {           # get configuration parameters
222         dumpers    = $6;        # how many 
223         day        = $14;
224         dump_shift = 75/dumpers; 
225         bandw      = $8;                
226         bandw_scale = (30/bandw);
227         unused_old = bandw_raise;
228         print 0, unused_old > "bandw_free";
229         if( sched_start >0 ) {
230                 no_disks = NR-sched_start-1; # backward compatability
231                 sched_start =0;
232                 print "do_start: no_disks", no_disks, $0;
233         }
234         no_disks += no_flush;
235         size        = $10/1024;        # size of holding disk in MB
236         holding_disk= $10 + flush_size;
237         init_holding_disk= $10 + flush_size;
238         holding_disk_old = $10;
239         disk_a = 0;
240         disk_alloc_time[disk_a] = 0;
241         disk_alloc_space[disk_a] = holding_disk_old;
242         disk_a++;
243         tsize = flush_size;
244         twait_old = tsize;
245         twait_a = 0;
246         twait_time[twait_a] = 0;
247         twait_wait[twait_a] = twait_old;
248         twait_a++;
249         if( NF==14) {           # original file was missing this
250                 policy="FIFO";
251                 alg   ="InOrder";
252         }
253         else if(NF>=18) {               # newer files have this format
254                 policy = $18;
255                 alg = $16;
256                 if( alg=="drain-ends") big = $20; 
257         }
258         
259         start = $4;     # this is the start time of the first dump 
260                         # taper idle to this point should not be included
261         run_old = no_disks*cont_scale+que_raise;
262         print 0, run_old                >"run_queue";
263         finish_old = tapeQ_old = que_raise;
264         print 0, finish_old             >"finished";    
265         print 0, tapeQ_old              >"tape_queue" ; 
266         state_old = tape_raise;
267         print 0, state_old              > "tape_idle";
268         active_old = dump_raise;
269         print 0,active_old              >"dump_idle";
270
271 }
272
273 function do_quit(){             # this is issued by driver at the end
274                                 # when it has nothing more to do
275         cnt++;
276         quit = 1;
277         tim  = $4 / time_scale;
278
279         disk_alloc_time[disk_a] = tim;
280         disk_alloc_space[disk_a] = holding_disk_old;
281         disk_a++;
282         max_space=disk_alloc_space[0];
283         for(a=0; a<disk_a; a++) {
284                 if(disk_alloc_space[a] > max_space) {
285                         max_space = disk_alloc_space[a];
286                 }
287         }
288
289         space_change = 0;
290         if(max_space > holding_disk) {
291                 space_change = max_space - holding_disk;
292                 holding_disk = max_space;
293         }
294
295         twait_time[twait_a] = tim;
296         twait_wait[twait_a] = twait_old;
297         twait_a++;
298         min_wait=twait_wait[0];
299         for(a=0; a<twait_a; a++) {
300                 if(twait_wait[a] < min_wait) {
301                         min_wait = twait_wait[a];
302                 }
303         }
304         if(min_wait < 0) {
305                 if(flush_size == 0) {
306                         holding_disk -= min_wait;
307                         holding_disk -= space_change;
308                 }
309                 for(a=0; a<twait_a; a++) {
310                         twait_wait[a] -= min_wait;
311                 }
312         }
313         if (holding_disk != 0) {
314                 const = 100/holding_disk;
315         }
316         else {
317                 const = 100;
318         }
319         for(a=0; a<disk_a; ++a) {
320                 space = (holding_disk - disk_alloc_space[a])*const+disk_raise
321                 printf plot_fmt1, disk_alloc_time[a], space >> "disk_alloc";
322         }
323         for(a=0; a<twait_a; ++a) {
324                 space = (twait_wait[a])*const+disk_raise
325                 printf plot_fmt1, twait_time[a], space >> "tape_wait";
326         }
327
328         printf plot_fmt, tim, active_old, tim, dump_raise >>"dump_idle";
329         printf plot_fmt, tim, state_old, tim, tape_raise >>"tape_idle"; 
330         printf plot_fmt, tim, unused_old, tim, bandw_raise >>"bandw_free";
331         printf plot_fmt, tim, finish_old, tim, written*count_scale+que_raise >>"finished";
332         printf plot_fmt, tim, run_old, tim, run_old >>"run_queue";
333 }
334
335 function do_result(){           # process lines driver: result
336         if($7=="DONE" ) {
337                 if( $6=="taper:"){              # taper done
338                         tsize -= $14;   
339                         tout  += $14;
340                         tcnt--; written++;
341                 }
342                 else {                          # dumperx done 
343                   tsize += (int($15/32)+1)*32;  # in tape blocks 
344                   tcnt++;       done++;
345                   xx = host[$6];
346                   d = disk[$6];
347                   l = level[$6];
348                   host_time[xx]+= ( tt = $4 - dmpr_strt[$6]);
349                   if(xx in disk_list) disk_list[xx] = disk_list[xx] "\n";
350                   disk_list[xx] = disk_list[xx] \
351                                   xx ":" d "/" l "\t" \
352                                   pr_time(dmpr_strt[$6]) \
353                                   " - " pr_time($4) \
354                                   " = "  pr_time(tt);
355 #                 print host[$6], disk[host[$6]];
356 #                       print host[$6], $4, dmpr_strt[$6], host_time[host[$6]]
357                 }
358         }
359         else if ($6=="taper:") {                # something else than DONE
360                 if($7=="TAPE-ERROR" || $7=="TRY-AGAIN") {
361                         tape_err= 1;
362                         err_time=$4/time_scale;
363                 }
364                 else if ($7=="TAPER-OK") tape_err=0;
365                 else if ($7=="PORT")    tape_err=0;
366                 else if ($7=="REQUEST-NEW-TAPE")    tape_err=0;
367                 else if ($7=="NEW-TAPE")    tape_err=0;
368                 else if ($7=="PARTDONE")    tape_err=0;
369                 else if ($7=="DUMPER-STATUS")    tape_err=0;
370                 else print fil, "UNKNOWN STATUS# "$0 ;
371         }
372         else {                                  # something bad from dumper 
373                 if ($7=="FAILED") { failed++;}
374                 else if ($7=="TRY-AGAIN"){ try++;}
375                 else if ($7=="PORT") ;  # ignore from chunker
376                 else if ($7=="RQ-MORE-DISK") ;  # FIXME: ignore for now
377                 else if ($7=="NO-ROOM")  
378                   print fil, pr_time($4),"#"  ++no_room, $0;
379                 else if( $7=="ABORT-FINISHED") print fil, "#" ++no_abort, $0;
380                 else print fil, "UNKNOWN STATUS# " $0;
381         }
382 }
383
384 function do_moves() { # function that extracts the estimated size of dumps
385                       # by processing DELAYING and promoting lines
386         est_size=$6;
387         getline ;                       # eat get next line print out planner msg
388         while (NF > 0 && (($1 == "delay:") || ($1 == "planner:")) ) {
389           if( $1 == "delay:") est_size = $NF;   # processing delay lines
390           else print fil, "DELAY#", $0;
391           getline;
392         }
393         getline ;                       # eating blank line
394         if( $1== "PROMOTING") {         # everything is dandy 
395                 getline;                # get first promote line
396                 while ( NF>0 && ($1 == "promote:" || $1 == "planner:" || $1 == "no" || $1 == "try") ) {
397                         if( $2 == "moving") {
398                                 est_size=$8;
399                                 print fil, "PROMOTING#", $1, $3;
400                         }
401                         else if($2 != "checking" && $2 != "can't" && $3 != "too" &&  $1 != "no" && $1 != "try" && $2 != "time")
402                              print fil,"PROMOTING#", $0;
403                         getline ;       # get next promote line
404                 }
405         }
406         else print fil, "DID NOT FIND PROMOTING LINE IN THE RIGHT PLACE",NR,$0;
407 }
408
409
410 END {
411         if( holding_disk == -1) {               # bad input file 
412                 print fil,": MISSING SPACE DECLARATION" ;
413                 exit;
414         }
415 # print headers of each graph  this is for the gnulot version 
416         if( tim >maxtime && extend==0)# if graph will extend beond borders
417           printf "Graph extends beond borders %s taking %7.3f > (max = %7.3f)\n",
418                         fil, tim, maxtime ;
419         print_t();                      # print titles
420         if( no_room + no_abort > 0) 
421              printf "NO-ROOM=%5d ABORT-FINISHED=%5d\n",  no_room, no_abort;
422         max_out = 20;
423         old_t = min_host * min_host;  # Some thing big
424         print "Longest dumping hosts   Times", min_host;
425         print "Host:disk/lev  \t start  -   end   =   run\t=> total";
426         while ( max_out-- > 0 && old_t > min_host) {
427           t = 0;
428           for (j in host_time) {
429             if( t < host_time[j] && host_time[j] <old_t){
430               t = host_time[d=j];
431             }
432           }
433           printf "%s\t=> %s\n\n", disk_list[d], pr_time(host_time[d]);
434 #         printf "%-20.20s Total Dump time %s\n", d, pr_time(host_time[d]);
435           old_t = t;
436         }
437 }
438
439 function print_t(){             # printing out the labels for the graph 
440         label=0;                # calculating where labels go and 
441                                 # range for x and y axes
442         maxy = int(no_disks/60+1)*20+que_raise;
443         printf "set yrange[0:%d]\n",maxy >"title";
444         if( maxtime < tim && extend !=0) {
445                 printf "set xrange[0:%d]\n", tim+30 >>"title";
446                 first_col = 10;
447                 second_col = (tim+30) * 0.45;
448                 key_col = (tim+30) * 1.042;
449                 third_col = (tim+30) * 1.0125;
450         }
451         else {
452                 printf "set xrange[0:%d]\n", maxtime >>"title";
453                 first_col = maxtime * 0.042
454                 second_col = maxtime * 0.45
455                 key_col = maxtime;
456                 third_col = maxtime*1.0125;
457         }
458         label_shift = (7 + int(no_disks/100));
459         lab = label_start = maxy+(6*label_shift) ;  # showing 6 labels
460         printf "set key at %d, %d\n", key_col, lab+4 >>"title";
461         printf "set label %d \"Amanda Dump %s\" at %d,%d\n", ++label,fil, 
462                 first_col,lab >"title";
463         lab -= label_shift;
464         printf "set label %d \"Bandwidth = %d\" at %d,%d\n",++label,bandw,
465                 first_col,lab >>"title";
466
467         lab -= label_shift;
468         printf "set label %d \"Holding disk = %d\" at %d,%d\n",++label,size,
469                 first_col,lab >>"title";
470
471         lab -= label_shift;
472         printf "set label %d \"Tape Policy = %s\" at %d,%d\n",++label,policy,
473                 first_col,lab >>"title";
474
475         lab -= label_shift;
476         printf "set label %d \"Dumpers= %d\" at %d,%d\n",++label,dumpers,
477                 first_col,lab >>"title";
478
479         lab -= label_shift;
480         if( alg =="drain-ends") 
481                 printf "set label %d \"Driver alg = %s At big end %d\" at %d,%d\n",
482                         ++label,alg, big,first_col,lab >>"title";
483         else #if( alg =="InOrder")  # other special cases
484                 printf "set label %d \"Driver alg = %s\" at %d,%d\n",
485                         ++label,alg,first_col, lab >>"title";
486
487         lab = label_start;
488         printf "set label %d \"Elapsed Time = %s\" at %d,%d\n",
489                 ++label,pr_time(tim*60),second_col,lab >>"title";
490
491         lab -= label_shift;
492         if( tape_err==1)        stm = "TAPE ERROR";
493         else if( quit ==1)      stm = "SUCCESS";
494         else  {                 stm = "UNKNOWN";
495                 print "Unknown terminating status",fil;
496         }
497         printf "set label %d \"Final status = %s\" at %d,%d\n",
498                 ++label,stm, second_col,lab >> "title";
499
500         lab -= label_shift;
501         printf "set label %d \"Dumped/Failed = %3d/%d\" at %d,%d\n",
502                 ++label,done,(failed+(try/2)), second_col,lab >>"title";
503
504         lab -= label_shift; 
505         printf "set label %d \"Output data size = %d\" at %d, %d\n",
506                 ++label,int(tout/1024+0.49999),second_col,lab >>"title";
507         if( est_size >0) {
508                 lab -= label_shift; 
509                 printf "set label %d \"Estimated data size = %d\" at %d, %d\n",
510                         ++label,int(est_size/1024+0.49999),second_col,lab >>"title";
511         }
512
513         if (gnuplot==0) {
514                 printf "set output \"%s.ps\"\n",fil >>"title";
515                 if(bw==1) {
516                         if(paper==1) printf "set term postscript landscape \"Times-Roman\" 10\n" >>"title";
517                         else printf "set term postscript portrait \"Times-Roman\" 10\n" >>"title";
518                 }
519                 else {
520                         if(paper==1) printf "set term postscript landscape color \"Times-Roman\" 10\n" >>"title";
521                         else printf "set term postscript portrait color \"Times-Roman\" 10\n" >>"title";
522                 }
523         } else {
524                 printf "set term x11\n" >> "title";
525         }
526         printf "set ylabel """";" >>"title";    # make sure there is no ylabel
527         fmt= "set label %d \"%s\" at "third_col", %d\n";
528         printf fmt, ++label,"%DUMPERS", 40 >>"title";
529         printf fmt, ++label,"TAPE",  95 >>"title";
530         printf fmt, ++label,"HOLDING",180 >>"title";
531         printf fmt, ++label,"DISK", 160 >>"title";
532         printf fmt, ++label,"%BANDWIDTH", 260 >>"title";
533         printf fmt, ++label,"QUEUES",(que_raise+maxy)/2 >>"title";
534         if((paper+gnuplot) > 0) print "set size 0.9, 0.9;"  >>"title";
535         else                    print "set size 0.7,1.3;"   >>"title";
536 }
537
538 function pr_time(pr_a){ #function to pretty print time
539   pr_h = int(pr_a/3600);
540   pr_m = int(pr_a/60)%60;
541   pr_s = int(pr_a+0.5) %60;
542   if( pr_m < 10 && pr_s < 10 ) return  pr_h":0"pr_m":0"pr_s;
543   else if( pr_s < 10)          return  pr_h":" pr_m":0"pr_s;
544   else if( pr_m < 10)          return  pr_h":0"pr_m":" pr_s;
545   else                         return  pr_h":" pr_m":" pr_s;
546 }