/**********************************************************************/ /* burst.c - this program computes the burstiness parameters a and */ /* b for an HTTP log, according to Chap. 10 of the book "Capacity */ /* Planning for Web Services: metrics, models, and methods" */ /* Prentice Hall, Upper Saddle River, NJ, 2002. */ /* */ /* This program has three parameters: -f , that specifies */ /* the name of the file containing an HTTP typical log; */ /* -e that specifies the number of epochs of the */ /* interval, according to definitions in Chap. 10; */ /* -r that specifies the number of requests in the log */ /* to be processed. If this parameter is not specified, its */ /* value is assumed to be equal to the variable maxreq (10000) */ /* */ /**********************************************************************/ /* (c) 1998-2002 by Virgilio Almeida and Daniel A. Menasce #include #include #include #include #include #include #define MAXLINE 256 #define MAXLOG 16281 time_t timevet[MAXLOG]; int numtime = 0; double drand48(); char * cname = 0; int epochs = 17; #define MAXEPOCH 100 int maxreq = 10000; /* number of requests processed by default */ /* if the parameter r is omitted */ int getMonth(char * month){ if(!strcmp("Jan",month)) return 0; if(month[0] == 'F') return 1; if(!strcmp("Mar",month)) return 2; if(!strcmp("Apr",month)) return 3; if(!strcmp("May",month)) return 4; if(!strcmp("Jun",month)) return 5; if(!strcmp("Jul",month)) return 6; if(!strcmp("Aug",month)) return 7; if(month[0] == 'S') return 8; if(month[0] == 'O') return 9; if(month[0] == 'N') return 10; if(month[0] == 'D') return 11; return(-1); } //format of pstr: "day/month/year:hour:min:sec" void strptime2(char * pstr, struct tm* tm){ char * aux = (char *) malloc (sizeof(char) * strlen(pstr)); strncpy(aux,pstr,2); aux[2] ='\0'; sscanf(aux,"%d",&(tm->tm_mday)); strncpy(aux,&(pstr[3]),3); aux[3] ='\0'; tm->tm_mon = getMonth(aux); strncpy(aux,&(pstr[7]),4); aux[4] ='\0'; sscanf(aux,"%d",&(tm->tm_year)); tm->tm_year = tm->tm_year - 1900; strncpy(aux,&(pstr[12]),2); aux[2] ='\0'; sscanf(aux,"%d",&(tm->tm_hour)); strncpy(aux,&(pstr[15]),2); aux[2] ='\0'; sscanf(aux,"%d",&(tm->tm_min)); strncpy(aux,&(pstr[18]),2); aux[2] ='\0'; sscanf(aux,"%d",&(tm->tm_sec)); tm->tm_yday = tm->tm_mday; switch(tm->tm_mon){ case 0 : tm->tm_yday += 0; break; case 1 : tm->tm_yday += 31; break; case 2 : tm->tm_yday += 59; break; case 3 : tm->tm_yday += 90; break; case 4 : tm->tm_yday += 120; break; case 5 : tm->tm_yday += 151; break; case 6 : tm->tm_yday += 181; break; case 7 : tm->tm_yday += 212; break; case 8 : tm->tm_yday += 243; break; case 9 : tm->tm_yday += 273; break; case 10 : tm->tm_yday += 304; break; case 11 : tm->tm_yday += 334; break; default : tm->tm_yday = 0; } /*leap year*/ if (!tm->tm_year%4 && (tm->tm_year%100 || !tm->tm_year%400)){ tm->tm_yday++; } tm->tm_isdst = 1; /*day of week set to Sunday.*/ tm->tm_wday = 0; free(aux); } int getline(FILE *fp, char * line){ int pos,ch; memset((void*)line,0,MAXLINE); pos = 0; while (((ch=fgetc(fp)) != '\n') && !feof(fp)){ line[pos] = ch; pos++; } line[pos] = 0; return pos; } void usage(){ printf("burst - Calculates the burstiness parameters\n"); printf("Options: \n"); printf(" -f (input file name) \n"); printf(" -e (number of epochs) \n"); printf(" -r (number of requests) \n"); } void parse_args(argc,argv) int argc; char ** argv; { int c=1; while (c < argc) { /* data file name */ if (!strcmp("-f",argv[c])){ cname = strdup(argv[c+1]); } /* epochs */ if (!strcmp("-e",argv[c])){ epochs = atoi(argv[c+1]); if (epochs > MAXEPOCH) { epochs = MAXEPOCH; fprintf(stderr,"Number of epochs must be less than %d\n", MAXEPOCH); } } /* requests */ if(!strcmp("-r",argv[c])){ maxreq = atoi(argv[c+1]); } if(!strcmp("-h",argv[c])){ usage(); exit(1); } c += 2; } } int main(int argc, char ** argv){ int i,j; int cc; FILE * file_in; struct tm tm; char * pstr; char line[MAXLINE]; int Arr[MAXEPOCH], ArrPlus, ArrPlusCount, ArrMinus, ArrMinusCount; double Lambda_k[MAXEPOCH]; double Lambda, totalduration,epochduration, a, b; time_t limit; parse_args(argc,argv); file_in = fopen(cname, "r"); if (file_in == (FILE *) 0) { fprintf (stderr, "fopen failed opening input file %s",cname); exit(-1); } while (numtime < maxreq && getline(file_in,line) != 0){ pstr = strstr(line,"]"); *pstr = 0; pstr = strstr(line,"["); pstr ++; /* original call: strptime(pstr,"%d/%b/%Y:%T%t",&tm); * at DOS, strptime doesn't exists... Use strptime2 defined * above.*/ strptime2(pstr,&tm); timevet[numtime] = mktime(&tm); numtime ++; } fclose(file_in); Lambda = (double)(numtime)/(timevet[numtime-1]-timevet[0]); totalduration = (double)(timevet[numtime-1]-timevet[0]); epochduration = totalduration/epochs; ArrPlus = ArrPlusCount = ArrMinus = ArrMinusCount = cc = 0; j = 0; for (i=0; i Lambda){ ArrPlus ++; ArrPlusCount += Arr[i]; } if (Lambda_k[i] <= Lambda) { ArrMinus ++; ArrMinusCount += Arr[i]; } } b = (double)(ArrPlus)/epochs; a = (double)(ArrPlusCount)/(b*numtime); printf("burstiness parameter a = %f\n",a); printf("burstiness parameter b = %f\n",b); return 0; }