Imported Upstream version 2.4.4p3
[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")       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 = $8;
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=="dumping" || $2 == "adding" || $2 == "holding-disks:") 
111                   dumping++; # eat this line
112                 else if( $2!="FINISHED" && $2 != "pid" && $2 != "taper-tryagain"&& $2!="startaflush:")
113                   print fil,"Unknown statement#",$0;
114         }
115         else if ( $1 == "planner:") {
116                 if( $2 == "SKIPPED" || $2 == "FAILED") {
117                         failed++;
118                         print fil, "INFO#", $0;
119                 }
120         }
121         else if( $1 == "GENERATING")        sched_start=NR;
122         else if( $1 == "ENDFLUSH")          sched_start=NR;
123         else if( $1 == "DELAYING")          do_moves();    # find estimated size
124         else if( $1 == "dumper:") {
125                 if($4 != "starting" && $2 != "pid" && $2 != "stream_client:" && $2 != "dgram_bind:") 
126                     print fil, "INFO#", $0;
127         }
128         else if( $1 == "taper:") {
129                 if($3 != "label" && $3 != "end" && $2 != "DONE" && $2 != "pid" && $2 != "slot" && $2 != "reader-side:" && $2 != "page" && $2 != "buffer" && $3 != "at")
130                     print fil, "INFO#", $0;
131         }
132         else if( $1 == "FLUSH") {
133                 no_flush++;
134         }
135         else if( NF==1 && sched_start > 0 && NR-sched_start > 1) { # new style end of schedule
136                 no_disks = NR-sched_start-2; # lets hope there are no extra lines
137                 sched_start = 0;
138         }
139 }
140
141 function do_state(){            # state line is printed out after driver
142                                 # finishes pondering new actions
143                                 # it reports the state as seen be driver
144 # fields in the state line 
145 # $2 = "state"          # $3 = "time"           # $4 = time_val
146 # $5 = "free"           # $6 = "kps:"           # $7 =  free_kps
147 # $8 = "space:"         # $9 = space            # $10 = "taper:"
148 # $11 = "writing"/"idle"# $12 = "idle-dumpers:"
149 # $13 = #idle           # $14 = "qlen"          # $15 = "tapeq:"
150 # $16 = #waiting        # $17 = "runq:"         # $18 = #not started 
151 # $19 = "stoppedq:"     # $20 = #stopped
152
153         cnt++;                                  # number of event
154         time = $4/time_scale;
155         unused = (bandw - $7)*bandw_scale+bandw_raise;
156         if( unused != unused_old) 
157                 printf plot_fmt, time, unused_old, time,unused >>"bandw_free";
158         unused_old = unused;
159
160         if(holding_disk_old != $9) {
161                 disk_alloc_time[disk_a] = time;
162                 disk_alloc_space[disk_a] = holding_disk_old;
163                 disk_a++;
164                 disk_alloc_time[disk_a] = time;
165                 disk_alloc_space[disk_a] = $9;
166                 disk_a++;
167                 holding_disk_old = $9;
168         }
169
170         twait = tsize;
171         if(twait_old != twait) {
172                 twait_time[twait_a] = time;
173                 twait_wait[twait_a] = twait_old;
174                 twait_a++;
175                 twait_time[twait_a] = time;
176                 twait_wait[twait_a] = twait;
177                 twait_a++;
178                 twait_old = twait;
179         }
180
181         active = (dumpers-$13)*dump_shift+dump_raise;
182         if( active != active_old )
183                 printf plot_fmt, time, active_old, time, active >> "dump_idle";
184         active_old = active;
185
186 # tape on or off
187         if($11=="writing")state = tape_raise+10;
188         else              state = tape_raise;
189         if( state != state_old )
190                 printf plot_fmt, time, state_old, time, state >> "tape_idle";
191         state_old = state;
192
193         run = $18*count_scale+que_raise;
194         if( run != run_old )
195                 printf plot_fmt, time, run_old, time, run >> "run_queue";
196         run_old = run;
197
198         finish = written * count_scale+que_raise;
199         if( finish != finish_old )
200                 printf plot_fmt, time, finish_old, time, finish >> "finished";
201         finish_old = finish;
202
203         tapeQ = $16 * count_scale+que_raise;
204         if( tapeQ != tapeQ_old )
205                 printf plot_fmt, time, tapeQ_old, time, tapeQ >> "tape_queue";
206         tapeQ_old = tapeQ;
207
208 }
209
210 function do_start() {           # get configuration parameters
211         dumpers    = $6;        # how many 
212         day        = $14;
213         dump_shift = 75/dumpers; 
214         bandw      = $8;                
215         bandw_scale = (30/bandw);
216         unused_old = bandw_raise;
217         print 0, unused_old > "bandw_free";
218         if( sched_start >0 ) {
219                 no_disks = NR-sched_start-1; # backward compatability
220                 sched_start =0;
221                 print "do_start: no_disks", no_disks, $0;
222         }
223         no_disks += no_flush;
224         size        = $10/1024;        # size of holding disk in MB
225         holding_disk= $10 + flush_size;
226         init_holding_disk= $10 + flush_size;
227         holding_disk_old = $10;
228         disk_a = 0;
229         disk_alloc_time[disk_a] = 0;
230         disk_alloc_space[disk_a] = holding_disk_old;
231         disk_a++;
232         tsize = flush_size;
233         twait_old = tsize;
234         twait_a = 0;
235         twait_time[twait_a] = 0;
236         twait_wait[twait_a] = twait_old;
237         twait_a++;
238         if( NF==14) {           # original file was missing this
239                 policy="FIFO";
240                 alg   ="InOrder";
241         }
242         else if(NF>=18) {               # newer files have this format
243                 policy = $18;
244                 alg = $16;
245                 if( alg=="drain-ends") big = $20; 
246         }
247         
248         start = $4;     # this is the start time of the first dump 
249                         # taper idle to this point should not be included
250         run_old = no_disks*cont_scale+que_raise;
251         print 0, run_old                >"run_queue";
252         finish_old = tapeQ_old = que_raise;
253         print 0, finish_old             >"finished";    
254         print 0, tapeQ_old              >"tape_queue" ; 
255         state_old = tape_raise;
256         print 0, state_old              > "tape_idle";
257         active_old = dump_raise;
258         print 0,active_old              >"dump_idle";
259
260 }
261
262 function do_quit(){             # this is issued by driver at the end
263                                 # when it has nothing more to do
264         cnt++;
265         quit = 1;
266         tim  = $4 / time_scale;
267
268         disk_alloc_time[disk_a] = tim;
269         disk_alloc_space[disk_a] = holding_disk_old;
270         disk_a++;
271         max_space=disk_alloc_space[0];
272         for(a=0; a<disk_a; a++) {
273                 if(disk_alloc_space[a] > max_space) {
274                         max_space = disk_alloc_space[a];
275                 }
276         }
277
278         space_change = 0;
279         if(max_space > holding_disk) {
280                 space_change = max_space - holding_disk;
281                 holding_disk = max_space;
282         }
283
284         twait_time[twait_a] = tim;
285         twait_wait[twait_a] = twait_old;
286         twait_a++;
287         min_wait=twait_wait[0];
288         for(a=0; a<twait_a; a++) {
289                 if(twait_wait[a] < min_wait) {
290                         min_wait = twait_wait[a];
291                 }
292         }
293         if(min_wait < 0) {
294                 if(flush_size == 0) {
295                         holding_disk -= min_wait;
296                         holding_disk -= space_change;
297                 }
298                 for(a=0; a<twait_a; a++) {
299                         twait_wait[a] -= min_wait;
300                 }
301         }
302         if (holding_disk != 0) {
303                 const = 100/holding_disk;
304         }
305         else {
306                 const = 100;
307         }
308         for(a=0; a<disk_a; ++a) {
309                 space = (holding_disk - disk_alloc_space[a])*const+disk_raise
310                 printf plot_fmt1, disk_alloc_time[a], space >> "disk_alloc";
311         }
312         for(a=0; a<twait_a; ++a) {
313                 space = (twait_wait[a])*const+disk_raise
314                 printf plot_fmt1, twait_time[a], space >> "tape_wait";
315         }
316
317         printf plot_fmt, tim, active_old, tim, dump_raise >>"dump_idle";
318         printf plot_fmt, tim, state_old, tim, tape_raise >>"tape_idle"; 
319         printf plot_fmt, tim, unused_old, tim, bandw_raise >>"bandw_free";
320         printf plot_fmt, tim, finish_old, tim, written*count_scale+que_raise >>"finished";
321         printf plot_fmt, tim, run_old, tim, run_old >>"run_queue";
322 }
323
324 function do_result(){           # process lines driver: result
325         if($7=="DONE" ) {
326                 if( $6=="taper:"){              # taper done
327                         tsize -= $14;   
328                         tout  += $14;
329                         tcnt--; written++;
330                 }
331                 else {                          # dumperx done 
332                   tsize += (int($15/32)+1)*32;  # in tape blocks 
333                   tcnt++;       done++;
334                   xx = host[$6];
335                   d = disk[$6];
336                   l = level[$6];
337                   host_time[xx]+= ( tt = $4 - dmpr_strt[$6]);
338                   if(xx in disk_list) disk_list[xx] = disk_list[xx] "\n";
339                   disk_list[xx] = disk_list[xx] \
340                                   xx ":" d "/" l "\t" \
341                                   pr_time(dmpr_strt[$6]) \
342                                   " - " pr_time($4) \
343                                   " = "  pr_time(tt);
344 #                 print host[$6], disk[host[$6]];
345 #                       print host[$6], $4, dmpr_strt[$6], host_time[host[$6]]
346                 }
347         }
348         else if ($6=="taper:") {                # something else than DONE
349                 if($7=="TAPE-ERROR" || $7=="TRY-AGAIN") {
350                         tape_err= 1;
351                         err_time=$4/time_scale;
352                 }
353                 else if ($7=="TAPER-OK") tape_err=0;
354                 else if ($7=="PORT")    tape_err=0;
355                 else print fil, "UNKNOWN STATUS# "$0 ;
356         }
357         else {                                  # something bad from dumper 
358                 if ($7=="FAILED") { failed++;}
359                 else if ($7=="TRY-AGAIN"){ try++;}
360                 else if ($7=="RQ-MORE-DISK") ;  # FIXME: ignore for now
361                 else if ($7=="NO-ROOM")  
362                   print fil, pr_time($4),"#"  ++no_room, $0;
363                 else if( $7=="ABORT-FINISHED") print fil, "#" ++no_abort, $0;
364                 else print fil, "UNKNOWN STATUS# " $0;
365         }
366 }
367
368 function do_moves() { # function that extracts the estimated size of dumps
369                       # by processing DELAYING and promoting lines
370         est_size=$6;
371         getline ;                       # eat get next line print out planner msg
372         while (NF > 0 && (($1 == "delay:") || ($1 == "planner:")) ) {
373           if( $1 == "delay:") est_size = $NF;   # processing delay lines
374           else print fil, "DELAY#", $0;
375           getline;
376         }
377         getline ;                       # eating blank line
378         if( $1== "PROMOTING") {         # everything is dandy 
379                 getline;                # get first promote line
380                 while ( NF>0 && ($1 == "promote:" || $1 == "planner:" || $1 == "no" || $1 == "try") ) {
381                         if( $2 == "moving") {
382                                 est_size=$8;
383                                 print fil, "PROMOTING#", $1, $3;
384                         }
385                         else if($2 != "checking" && $2 != "can't" && $3 != "too" &&  $1 != "no" && $1 != "try" && $2 != "time")
386                              print fil,"PROMOTING#", $0;
387                         getline ;       # get next promote line
388                 }
389         }
390         else print fil, "DID NOT FIND PROMOTING LINE IN THE RIGHT PLACE",NR,$0;
391 }
392
393
394 END {
395         if( holding_disk == -1) {               # bad input file 
396                 print fil,": MISSING SPACE DECLARATION" ;
397                 exit;
398         }
399 # print headers of each graph  this is for the gnulot version 
400         if( tim >maxtime && extend==0)# if graph will extend beond borders
401           printf "Graph extends beond borders %s taking %7.3f > (max = %7.3f)\n",
402                         fil, tim, maxtime ;
403         print_t();                      # print titles
404         if( no_room + no_abort > 0) 
405              printf "NO-ROOM=%5d ABORT-FINISHED=%5d\n",  no_room, no_abort;
406         max_out = 20;
407         old_t = min_host * min_host;  # Some thing big
408         print "Longest dumping hosts   Times", min_host;
409         print "Host:disk/lev  \t start  -   end   =   run\t=> total";
410         while ( max_out-- > 0 && old_t > min_host) {
411           t = 0;
412           for (j in host_time) {
413             if( t < host_time[j] && host_time[j] <old_t){
414               t = host_time[d=j];
415             }
416           }
417           printf "%s\t=> %s\n\n", disk_list[d], pr_time(host_time[d]);
418 #         printf "%-20.20s Total Dump time %s\n", d, pr_time(host_time[d]);
419           old_t = t;
420         }
421 }
422
423 function print_t(){             # printing out the labels for the graph 
424         label=0;                # calculating where labels go and 
425                                 # range for x and y axes
426         maxy = int(no_disks/60+1)*20+que_raise;
427         printf "set yrange[0:%d]\n",maxy >"title";
428         if( maxtime < tim && extend !=0) {
429                 printf "set xrange[0:%d]\n", tim+30 >>"title";
430                 second_col = tim*0.5;
431                 key_col = tim;
432                 third_col = tim +13;
433         }
434         else {
435                 printf "set xrange[0:%d]\n", maxtime >>"title";
436                 second_col = (maxtime-10) * 0.5;
437                 key_col = (maxtime-10) ;
438                 third_col = maxtime +3;
439         }
440         label_shift = (7 + int(no_disks/100));
441         lab = label_start = maxy+(6*label_shift) ;  # showing 6 labels
442         printf "set key %d, %d\n", key_col, lab >>"title";
443         printf "set label %d \"Amanda Dump %s\" at 10,%d\n", ++label,fil, 
444                 lab >"title";
445         lab -= label_shift;
446         printf "set label %d \"Bandwidth = %d\" at 10,%d\n",++label,bandw,
447                 lab >>"title";
448
449         lab -= label_shift;
450         printf "set label %d \"Holding disk = %d\" at 10,%d\n",++label,size,
451                 lab >>"title";
452
453         lab -= label_shift;
454         printf "set label %d \"Tape Policy = %s\" at 10,%d\n",++label,policy,
455                 lab >>"title";
456
457         lab -= label_shift;
458         printf "set label %d \"Dumpers= %d\" at 10,%d\n",++label,dumpers,
459                 lab >>"title";
460
461         lab -= label_shift;
462         if( alg =="drain-ends") 
463                 printf "set label %d \"Driver alg = %s At big end %d\" at 10,%d\n",
464                         ++label,alg, big,lab >>"title";
465         else #if( alg =="InOrder")  # other special cases
466                 printf "set label %d \"Driver alg = %s\" at 10,%d\n",
467                         ++label,alg, lab >>"title";
468
469         lab = label_start;
470         printf "set label %d \"Elapsed Time = %s\" at %d,%d\n",
471                 ++label,pr_time(tim*60),second_col,lab >>"title";
472
473         lab -= label_shift;
474         if( tape_err==1)        stm = "TAPE ERROR";
475         else if( quit ==1)      stm = "SUCCESS";
476         else  {                 stm = "UNKNOWN";
477                 print "Unknown terminating status",fil;
478         }
479         printf "set label %d \"Final status = %s\" at %d,%d\n",
480                 ++label,stm, second_col,lab >> "title";
481
482         lab -= label_shift;
483         printf "set label %d \"Dumped/Failed = %3d/%d\" at %d,%d\n",
484                 ++label,done,(failed+(try/2)), second_col,lab >>"title";
485
486         lab -= label_shift; 
487         printf "set label %d \"Output data size = %d\" at %d, %d\n",
488                 ++label,int(tout/1024+0.49999),second_col,lab >>"title";
489         if( est_size >0) {
490                 lab -= label_shift; 
491                 printf "set label %d \"Estimated data size = %d\" at %d, %d\n",
492                         ++label,int(est_size/1024+0.49999),second_col,lab >>"title";
493         }
494
495         if (gnuplot==0) {
496                 printf "set output \"%s.ps\"\n",fil >>"title";
497                 if(bw==1) {
498                         if(paper==1) printf "set term postscript landscape \"Times-Roman\" 10\n" >>"title";
499                         else printf "set term postscript portrait \"Times-Roman\" 10\n" >>"title";
500                 }
501                 else {
502                         if(paper==1) printf "set term postscript landscape color \"Times-Roman\" 10\n" >>"title";
503                         else printf "set term postscript portrait color \"Times-Roman\" 10\n" >>"title";
504                 }
505         }
506         printf "set ylabel """";" >>"title";    # make sure there is no ylabel
507         fmt= "set label %d \"%s\" at "third_col", %d\n";
508         printf fmt, ++label,"%DUMPERS", 40 >>"title";
509         printf fmt, ++label,"TAPE",  95 >>"title";
510         printf fmt, ++label,"HOLDING",180 >>"title";
511         printf fmt, ++label,"DISK", 160 >>"title";
512         printf fmt, ++label,"%BANDWIDTH", 260 >>"title";
513         printf fmt, ++label,"QUEUES",(que_raise+maxy)/2 >>"title";
514         if((paper+gnuplot) > 0) print "set size 0.9, 0.9;"  >>"title";
515         else                    print "set size 0.7,1.3;"   >>"title";
516 }
517
518 function pr_time(pr_a){ #function to pretty print time
519   pr_h = int(pr_a/3600);
520   pr_m = int(pr_a/60)%60;
521   pr_s = int(pr_a+0.5) %60;
522   if( pr_m < 10 && pr_s < 10 ) return  pr_h":0"pr_m":0"pr_s;
523   else if( pr_s < 10)          return  pr_h":" pr_m":0"pr_s;
524   else if( pr_m < 10)          return  pr_h":0"pr_m":" pr_s;
525   else                         return  pr_h":" pr_m":" pr_s;
526 }