plot-usage

来自「EM算法的改进」· 代码 · 共 293 行

TXT
293
字号
#!/bin/csh## $Id: plot-usage 1339 2006-09-21 19:46:28Z tbailey $# $Log$# Revision 1.2  2005/10/05 06:18:35  nadya# use full path for "rm". Asssume everybody has /bin/rm.## Revision 1.1.1.1  2005/07/29 00:01:33  nadya# Importing from meme-3.0.14, and adding configure/make##set months = "JanFebMarAprMayJunJulAugSepOctNovDec"set format = "meme" set t = 0set ts = "runs"set pgm = $0; set pgm = $pgm:tset args = ($*)if ($#argv < 0) then  usage:  more << USAGE  USAGE:        $pgm [<logfile>] [-meme] [-mast] [-metameme] [-r] [-u] [-m] [-c] [-s] 	[<logfile>]	MEME server log file; default: read standard input	[-meme]		log file is in MEME format; (default)	[-mast]		log file is in MAST format; default: MEME format	[-metameme]	log file is in MetaMEME format; default: MEME format	[-r]		plot number of runs (default)	[-u]            plot number of users; default: number of runs	[-m]		plot maximum runs by any user; default: number of runs	[-c]		plot cpu time for all runs; default: number of runs			note: meme only; cpu time not recorded in mast-log	[-s]            plot to screen         Plot the number of runs or users of MEME, MAST or MetaMEME	month-by-month.        Number of users is based on the number of distinct email addresses        given for MEME and MAST.        Number of users is based on the number of distinct IP addresses        for MetaMEME.	Creates files:		$pgm.<type>[.<logfile>].[ps tex]	where <type> is "runs", "max", "users" or "cpu".USAGE  exit 1endifunlimit cputimeonintr cleanup# get input argumentsset logfile = ""set name = ""while ("$1" != "")  switch ($1)  case -h:    goto usage    break  case -meme:    breaksw  case -mast:    set format = "mast";    breaksw  case -metameme:    set format = "metameme";    breaksw  case -r:    breaksw  case -u:    set t = 1    set ts = "users"    breaksw  case -m:    set t = 2    set ts = "max"    breaksw  case -c:     set t = 3    set ts = "cpu"    breaksw  case -s:     set s = 1    breaksw  default:    set logfile = $1    set name = ".$1"  endsw  shiftend# set name to meme/mast/metameme if input is standard inputif ($logfile == "") then  set name = ".$format"endifif ($t == 3 && $format == "mast") then  echo "CPU time is not recorded in mast-log so -c not available"  exit 1endifset gawk = $pgm.$$.gawk.tmpcat << "END" > $gawkBEGIN {  big = 100000;   little = -1;  min_year = min_month = big;   max_year = max_month = -1;  for (i=0; i<12; i++) smonth[i+1] = substr(months, 3*i+1, 1);}# read next record in fileNF >= 4 {  ok = 1;  if (format == "meme" || format == "metameme") {	# meme format    # check for missing host and repair it    if ($2 == "submit:") {      for (i=NF+1; i>=2; i--) {        $i = $(i-1);			# shift everything 1 right      }      $1 = "host";    }    # check for a bad MEME record where the submit date is missing    # and try to repair it by using start date/time for submit date/time    if ($4 == "start:") {      # insert the start time in place of the submit time      for (i=NF+2; i>=6; i--) {        $i = $(i-2);			# shift everything 2 right      }      $4 = $7;				# copy start time & date      $5 = $8;     }    # check for a bad Meta-MEME record where the start date is missing    # and try to repair it by using submit date/time for start date/time    if ($6 == "end:") {      # insert the submit time in place of the start time      for (i=NF+3; i>=9; i--) {        $i = $(i-3);			# shift everything 3 right      }      $6 = "start:";      $7 = $10;				# copy start time & date      $7 = $11;     }    # check for a bad Meta-MEME record where the "start" is missing    if (0 && $8 == "end:") {      # insert the "start:"       for (i=NF+2; i>=9; i--) {        $i = $(i-1);			# shift everything 1 right      }      $6 = $9;				# copy start time & date      $7 = $10;     }    # check for "end" instead of "end:"    if ($9 == "end") {$9 = "end:";}    # check for bad record     if ($3 != "submit:" || $6 != "start:" || $9 != "end:") {      print "bad record number", NR, "\n" > "/dev/stderr"      print $0, "\n" > "/dev/stderr"      ok = 0;    }     date = $4;    if (format == "meme") {      day = substr(date, 1, 2) + 0;      imonth = substr(date, 4, 2) + 0;    } else {      day = substr(date, 4, 2) + 0;      imonth = substr(date, 1, 2) + 0;    }    year = substr(date, 7, 2) + 0;    if (year < 96) {year = 2000 + year;} else {year = 1900 + year;}    if (t == 3) {				# get cpu time      start = $8;				# start time hh:mm:ss      sex1 = substr(start,7,2)+60*(substr(start,4,2)+(60*substr(start,1,2)));      end = $11;				# end time hh:mm:ss      sex2 = substr(end,7,2)+60*(substr(end,4,2)+(60*substr(end,1,2)));      cpu_hrs = sex2-sex1;			# elapsed sconds      if (cpu_hrs < 0) cpu_hrs += 24*60*60;	# day change      cpu_hrs /= 3600;			# convert to hours      #print $2, cpu_hrs;    }  } else {					# mast format    month = $4;    year = $8;    imonth = int(index(months, month)/3)+1;     # get index of month  }  if (ok) {    user = $NF;    runs[year,imonth]++;			# increment runs    if (t==3) cpu[year,imonth] += cpu_hrs;	# increase cpu time    if (!(users[year,imonth,user])) {      nusers[year,imonth]++;      users[year,imonth,user] = 1;    }    nruns[year,imonth,user]++;    if (nruns[year,imonth,user] > maxruns[year,imonth]) {      maxruns[year,imonth] = nruns[year,imonth,user];    }    # save minimum date    if (year < min_year) {      min_year = year;       min_month = imonth;    }    if (year == min_year && imonth < min_month) min_month = imonth;    # save maximum date    if (year > max_year) {      #print "new year: ", year, " new month:, imonth, NR > "/dev/stderr";      max_year = year;      max_month = imonth;    }    if (year == max_year && imonth > max_month) max_month = imonth;  } # ok}END {  # print number of runs/users/cpu_time for each month  # print "min", min_year, min_month, "max", max_year, max_month > plotdata  x = 1;  ymax = 0;  printf("set xtics (") > com;  #print "max_year", max_year, "max_month", max_month;  for (year=min_year; year<=max_year; year++) {    if (year==min_year) { min = min_month; } else { min = 1; }    if (year==max_year) { max = max_month; } else { max = 12; }    for (imonth=min; imonth<=max; imonth++) {      printf("\'%s\' %d", smonth[imonth], x) > com;      if (! (year==max_year && imonth==max) ) printf(", ") > com;      if (t == 1) {        y = nusers[year,imonth];      } else if (t == 2) {          y = maxruns[year,imonth];      } else if (t == 3) {          y = cpu[year,imonth];      } else {        y = runs[year,imonth];      }      if (y > ymax) ymax = y;       print x, y+.001 > plotdata;      x++;    }  }  printf(")\n") > com;  print "set xlabel '", min_year, "-", max_year, "' 0,-1 font '1,40'" > com  if (t == 1) {    print "set ylabel 'USERS PER MONTH' font '1,40'" > com  } else if (t == 2) {      print "set ylabel 'MAX RUNS PER MONTH' font '1,40'" > com  } else if (t == 3) {      print "set ylabel 'CPU HOURS PER MONTH' font '1,40'" > com  } else {    print "set ylabel 'RUNS PER MONTH' font '1,40'" > com  }  print "set xrange [0:", x, "]" > com  print "set yrange [0:", ymax, "]" > com  print "set data style boxes" > com  print "plot '" plotdata "' notitle" > com  # print pointsize  point = int(784/(x-1));  if (point > 30) {point = 30;}  print point;}"END"# create file to hold pointsset plotdata = $pgm.$$.plotdata.tmpset com = $pgm.$$.com.tmp# execute scriptset point = `gawk -v format=$format -v plotdata=$plotdata -v com=$com -v months=$months -v t=$t -f $gawk $logfile`#echo point = $point#cat $com#echo $plotdata#cat $plotdata# set up for screen or postscriptif ($?s) then  set ps = "-ps _screen_" else  set ps = "-ps $pgm.$ts$name"endifplotgen -f -nocat -color \  -point $point \  -file $com \  $psif (!($?s)) then  /bin/rm $pgm.$ts$name.texendifcleanup:/bin/rm $pgm.$$.*.tmp

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?