proxytrace2any.cc

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <ctype.h>
00005 #include <fcntl.h>
00006 #include <sys/stat.h>
00007 #include <sys/types.h>
00008 #include <tcl.h>
00009 
00010 #include "proxytrace.h"
00011 #include "my-endian.h"
00012  
00013 #ifdef PC
00014 #include <io.h>
00015 #endif
00016 
00017 void PrintEntry_Text(FILE *out_file, TEntry *entry, int noURL);
00018 void PrintEntry_Squid(FILE *out_file, TEntry *entry, int swap);
00019 
00020 enum { ifNone = 0, ifDECV1_0, ifDECV1_2 } InputFormat = ifNone;
00021 enum { ofNone = 0, ofDECText, ofSquid, ofSquidSwapped } OutputFormat = ofNone;
00022 
00023 int getInputFormat(char* argv[]) {
00024 
00025     if (strncmp("-i", argv[0], 3) != 0)
00026         return ifNone;
00027 
00028     if (strncmp("v1.0", argv[1], 5) == 0)
00029         InputFormat = ifDECV1_0;
00030     else
00031     if (strncmp("v1.2", argv[1], 5) == 0)
00032         InputFormat = ifDECV1_2;
00033     else
00034         InputFormat = ifNone;
00035 
00036     return InputFormat;
00037 }
00038 
00039 int getOutputFormat(char* argv[]) {
00040 
00041     if (strncmp("-o", argv[0], 3) != 0)
00042         return ofNone;
00043 
00044     if (strncmp("txt", argv[1], 4) == 0)
00045         OutputFormat = ofDECText;
00046     else
00047     if (strncmp("squid", argv[1], 6) == 0)
00048         OutputFormat = ofSquid;
00049     else
00050     if (strncmp("squidsw", argv[1], 8) == 0)
00051         OutputFormat = ofSquidSwapped;
00052     else
00053         OutputFormat = ofNone;
00054 
00055     return OutputFormat;
00056 }
00057 
00058 extern FILE *cf, *sf;
00059 extern double initTime;
00060 extern double duration;
00061 extern double startTime;
00062 extern ReqLog* rlog;
00063 extern unsigned int num_rlog, sz_rlog;
00064 extern Tcl_HashTable cidHash, sidHash, urlHash;
00065 
00066 double lf_analyze(TEntry& lfe);
00067 void sort_url();
00068 void sort_rlog();
00069 
00070 int main (int argc, char* argv[]) 
00071 {
00072     int    is_little_endian = 0;
00073     TEntry entry;
00074     double   ctime;
00075 
00076     // Init tcl
00077     Tcl_Interp *interp = Tcl_CreateInterp();
00078     if (Tcl_Init(interp) == TCL_ERROR) {
00079         printf("%s\n", interp->result);
00080         abort();
00081     }
00082     Tcl_InitHashTable(&cidHash, TCL_ONE_WORD_KEYS);
00083     Tcl_InitHashTable(&sidHash, TCL_ONE_WORD_KEYS);
00084     Tcl_InitHashTable(&urlHash, TCL_ONE_WORD_KEYS);
00085 
00086     if ((cf = fopen("reqlog", "w")) == NULL) {
00087         printf("cannot open request log.\n");
00088         exit(1);
00089     }
00090     if ((sf = fopen("pglog", "w")) == NULL) {
00091         printf("cannot open page log.\n");
00092         exit(1);
00093     }
00094 
00095     /* parse command line */
00096     if ((argc < 2) || (argc > 4)) {
00097         printf("Usage: %s <trace size> [<time duration>] [<start_time>]\n", argv[0]);
00098         return 1;
00099     }
00100     if (argc >= 3) {
00101         duration = strtod(argv[2], NULL);
00102         if (argc == 4) {
00103             startTime = strtod(argv[3], NULL);
00104             printf("start time = %f\n", startTime);
00105         }
00106     }
00107 
00108     sz_rlog = strtoul(argv[1], NULL, 10);
00109     rlog = new ReqLog[sz_rlog];
00110 
00111     /* determine endian-ness */
00112     is_little_endian = IsLittleEndian();
00113 
00114     /* read trace header */
00115     ReadHeader(stdin, 0);
00116 
00117     /* read entries untill EOF */
00118     while (ReadEntry(stdin, &entry)) {
00119         if ( !is_little_endian )
00120             ToOtherEndian(&entry);
00121         // Analyse one log entry
00122         ctime = lf_analyze(entry);
00123         if ((duration > 0) && (ctime > duration))
00124             break;
00125     }
00126 
00127     Tcl_DeleteHashTable(&cidHash);
00128     Tcl_DeleteHashTable(&sidHash);
00129 
00130     fprintf(stderr, "sort url\n");
00131     sort_url();
00132     fclose(sf);
00133 
00134     fprintf(stderr, "sort requests\n");
00135     sort_rlog();
00136     fclose(cf);
00137 
00138     return 0;
00139 }

Generated on Tue Mar 6 16:47:49 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6