Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

proxytrace2any.cc File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <tcl.h>
#include "proxytrace.h"
#include "my-endian.h"

Include dependency graph for proxytrace2any.cc:

Include dependency graph

Go to the source code of this file.

Enumerations

enum  { ifNone = 0, ifDECV1_0, ifDECV1_2 }
enum  { ofNone = 0, ofDECText, ofSquid, ofSquidSwapped }

Functions

void PrintEntry_Text (FILE *out_file, TEntry *entry, int noURL)
void PrintEntry_Squid (FILE *out_file, TEntry *entry, int swap)
int getInputFormat (char *argv[])
int getOutputFormat (char *argv[])
double lf_analyze (TEntry &lfe)
void sort_url ()
void sort_rlog ()
int main (int argc, char *argv[])

Variables

enum { ... }  InputFormat
enum { ... }  OutputFormat
FILE * cf
FILE * sf
double initTime
double duration
double startTime
ReqLogrlog
unsigned int num_rlog
unsigned int sz_rlog
Tcl_HashTable cidHash
Tcl_HashTable sidHash
Tcl_HashTable urlHash


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
ifNone 
ifDECV1_0 
ifDECV1_2 

Definition at line 20 of file proxytrace2any.cc.

anonymous enum
 

Enumeration values:
ofNone 
ofDECText 
ofSquid 
ofSquidSwapped 

Definition at line 21 of file proxytrace2any.cc.


Function Documentation

int getInputFormat char *  argv[]  ) 
 

Definition at line 23 of file proxytrace2any.cc.

References ifDECV1_0, ifDECV1_2, ifNone, and InputFormat.

00023                                  {
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 }

int getOutputFormat char *  argv[]  ) 
 

Definition at line 39 of file proxytrace2any.cc.

References ofDECText, ofNone, ofSquid, ofSquidSwapped, and OutputFormat.

00039                                   {
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 }

double lf_analyze TEntry lfe  ) 
 

Definition at line 103 of file dec/tr-stat.cc.

00104 {
00105         double time;
00106         int ne, cid, sid, uid;
00107         Tcl_HashEntry *he;
00108 
00109         // Filter out entries with 'post', 'head' etc. only keep 'get'
00110         // Also filter out 
00111         if (lfe.tail.method != METHOD_GET)
00112                 return -1;
00113         if ((lfe.tail.flags & QUERY_FOUND_FLAG) || 
00114             (lfe.tail.flags & CGI_BIN_FLAG))
00115                 return -1;
00116         if ((lfe.tail.status != 200) && (lfe.tail.status != 304))
00117                 return -1;
00118 
00119         // We don't consider pages with size 0
00120         if (lfe.head.size == 0)
00121                 return -1;
00122         // We don't consider file size larger than 10MB
00123         if (lfe.head.size > MAX_FILESIZE)
00124                 return -1;
00125 
00126         time = (double)lfe.head.time_sec + (double)lfe.head.time_usec/(double)1000000.0;
00127 
00128         if (initTime < 0) {
00129                 initTime = time;
00130                 time = 0;
00131         } else 
00132                 time -= initTime;
00133 
00134         // If a trace start time is required, don't do anything
00135         if ((startTime > 0) && (time < startTime)) 
00136                 return -1;
00137 
00138         // check client id
00139         if (!(he = Tcl_FindHashEntry(&cidHash, (const char *)lfe.head.client))) {
00140                 // new client, allocate a client id
00141                 he = Tcl_CreateHashEntry(&cidHash, (const char *)lfe.head.client, &ne);
00142                 Tcl_SetHashValue(he, ++client);
00143                 cid = client;
00144         } else {
00145                 // existing entry, find its client seqno
00146                 cid = (int)Tcl_GetHashValue(he);
00147         }
00148 
00149         // check server id
00150         if (!(he = Tcl_FindHashEntry(&sidHash, (const char *)lfe.head.server))) {
00151                 // new client, allocate a client id
00152                 he = Tcl_CreateHashEntry(&sidHash, (const char *)lfe.head.server, &ne);
00153                 Tcl_SetHashValue(he, ++server);
00154                 sid = server;
00155         } else {
00156                 // existing entry, find its client seqno
00157                 sid = (int)Tcl_GetHashValue(he);
00158         }
00159 
00160         // check url id
00161         if (!(he = Tcl_FindHashEntry(&urlHash, (const char*)lfe.url))) {
00162                 // new client, allocate a client id
00163                 he = Tcl_CreateHashEntry(&urlHash, (const char*)lfe.url, &ne);
00164                 URL* u = new URL(++url, sid, lfe.head.size);
00165                 Tcl_SetHashValue(he, (const char*)u);
00166                 uid = u->id;
00167         } else {
00168                 // existing entry, find its client seqno
00169                 URL* u = (URL*)Tcl_GetHashValue(he);
00170                 u->access++;
00171                 uid = u->id;
00172         }
00173 
00174         rlog[num_rlog++] = ReqLog(time, cid, sid, uid);
00175         //fprintf(cf, "%f %d %d %d\n", time, cid, sid, uid);
00176 
00177         if (startTime > 0) 
00178                 return time - startTime;
00179         else 
00180                 return time;
00181 }

int main int  argc,
char *  argv[]
 

Definition at line 70 of file proxytrace2any.cc.

References abort(), cf, cidHash, duration, IsLittleEndian(), lf_analyze(), ReadEntry(), ReadHeader(), rlog, sf, sidHash, sort_rlog(), sort_url(), startTime, sz_rlog, ToOtherEndian(), and urlHash.

00071 {
00072         int    is_little_endian = 0;
00073         TEntry entry;
00074         int      ret;
00075         double   ctime;
00076 
00077         // Init tcl
00078         Tcl_Interp *interp = Tcl_CreateInterp();
00079         if (Tcl_Init(interp) == TCL_ERROR) {
00080                 printf("%s\n", interp->result);
00081                 abort();
00082         }
00083         Tcl_InitHashTable(&cidHash, TCL_ONE_WORD_KEYS);
00084         Tcl_InitHashTable(&sidHash, TCL_ONE_WORD_KEYS);
00085         Tcl_InitHashTable(&urlHash, TCL_ONE_WORD_KEYS);
00086 
00087         if ((cf = fopen("reqlog", "w")) == NULL) {
00088                 printf("cannot open request log.\n");
00089                 exit(1);
00090         }
00091         if ((sf = fopen("pglog", "w")) == NULL) {
00092                 printf("cannot open page log.\n");
00093                 exit(1);
00094         }
00095 
00096         /* parse command line */
00097         if ((argc < 2) || (argc > 4)) {
00098                 printf("Usage: %s <trace size> [<time duration>] [<start_time>]\n", argv[0]);
00099                 return 1;
00100         }
00101         if (argc >= 3) {
00102                 duration = strtod(argv[2], NULL);
00103                 if (argc == 4) {
00104                         startTime = strtod(argv[3], NULL);
00105                         printf("start time = %f\n", startTime);
00106                 }
00107         }
00108 
00109         sz_rlog = strtoul(argv[1], NULL, 10);
00110         rlog = new ReqLog[sz_rlog];
00111 
00112         /* determine endian-ness */
00113         is_little_endian = IsLittleEndian();
00114 
00115         /* read trace header */
00116         ReadHeader(stdin, 0);
00117 
00118         /* read entries untill EOF */
00119         while (ReadEntry(stdin, &entry)) {
00120                 if ( !is_little_endian )
00121                         ToOtherEndian(&entry);
00122                 // Analyse one log entry
00123                 ctime = lf_analyze(entry);
00124                 if ((duration > 0) && (ctime > duration))
00125                         break;
00126         }
00127 
00128         Tcl_DeleteHashTable(&cidHash);
00129         Tcl_DeleteHashTable(&sidHash);
00130 
00131         fprintf(stderr, "sort url\n");
00132         sort_url();
00133         fclose(sf);
00134 
00135         fprintf(stderr, "sort requests\n");
00136         sort_rlog();
00137         fclose(cf);
00138 
00139         return 0;
00140 }

Here is the call graph for this function:

void PrintEntry_Squid FILE *  out_file,
TEntry entry,
int  swap
 

Definition at line 24 of file formsquid.cc.

References CGI_BIN_FLAG, _TEntry::client, duration, _TEntry::event_duration, EXTENSION_SPECIFIED_FLAG, ExtensionStr(), _TEntry::flags, make_port(), make_query(), _TEntry::method, MethodStr(), _TEntry::port, PORT_SPECIFIED_FLAG, _TEntry::protocol, ProtocolStr, QUERY_FOUND_FLAG, _TEntry::server, _TEntry::size, _TEntry::status, swap(), _TEntry::time_sec, _TEntry::time_usec, and u_4bytes.

00024                                                                {
00025 
00026         u_4bytes duration = ((entry -> head.event_duration+500)/1000); /* milliseconds */
00027 
00028         fprintf(stdout, "%9d.%06u %d %d %s/%d %d %s %s://%d%s/%s%d%s%s %s %s/%d\n",
00029                 entry -> head.time_sec, entry -> head.time_usec,
00030                 (( swap) ? entry -> head.client : duration),
00031                 ((!swap) ? entry -> head.client : duration),
00032                 "NONE", /* Log Tag is missing */
00033                 entry -> tail.status,
00034                 entry -> head.size,
00035                 MethodStr(entry -> tail.method),
00036         ProtocolStr(entry -> tail.protocol),
00037                 entry -> head.server,
00038                 ((entry -> tail.flags & PORT_SPECIFIED_FLAG) ? make_port(entry -> head.port) : ""),
00039                 ((entry -> tail.flags & CGI_BIN_FLAG) ? "cgi_bin/" : ""),
00040                 entry -> head.path,
00041                 ((entry -> tail.flags & EXTENSION_SPECIFIED_FLAG) ? ExtensionStr(entry -> tail.type) : ""),
00042                 ((entry -> tail.flags & QUERY_FOUND_FLAG) ? make_query(entry -> head.query) : ""),
00043                 "-", /* Ident is missing */
00044                 "DIRECT", /* assuming direct retrieval */
00045                 entry -> head.server);
00046 }

Here is the call graph for this function:

void PrintEntry_Text FILE *  out_file,
TEntry entry,
int  noURL
 

Definition at line 16 of file formtxt.cc.

References _TEntry::client, _TEntry::event_duration, ExtensionTypeStr(), _TEntry::flags, _TEntry::last_mod, _TEntry::method, MethodStr(), out_file, _TEntry::path, _TEntry::port, PrintHeader(), _TEntry::protocol, ProtocolStr, _TEntry::query, _TEntry::server, _TEntry::server_duration, _TEntry::size, _TEntry::status, _TEntry::time_sec, _TEntry::time_usec, _TEntry::type, and url.

00016                                                                {
00017 
00018         static int entry_count = 0;
00019 
00020         if (!entry_count++)
00021                 PrintHeader(out_file, noURL);
00022 
00023         fprintf(out_file, "%9d%06u %8d %8d %5d %7d %9d %6d %6s %6s %6d %6d %6s %6d %6d %6d",
00024                 entry -> head.time_sec, entry -> head.time_usec, 
00025                 entry -> head.event_duration, entry -> head.server_duration,
00026                 entry -> head.client, entry -> head.size,  entry -> head.last_mod,
00027                 entry -> tail.status,
00028                 MethodStr(entry -> tail.method),
00029                 ProtocolStr(entry -> tail.protocol),
00030                 entry -> head.server, entry -> head.port, 
00031                 ExtensionTypeStr(entry -> tail.type),
00032         entry -> tail.flags,
00033                 entry -> head.path, entry -> head.query);
00034 
00035         if (noURL)
00036                 fprintf(out_file, "\n");
00037         else
00038                 fprintf(out_file, " %6d\n", entry -> url);
00039 }

Here is the call graph for this function:

void sort_rlog  ) 
 

Definition at line 51 of file dec/tr-stat.cc.

References cf, compare(), num_rlog, rlog, ReqLog::time, umap, and url.

Referenced by main().

00052 {
00053         qsort((void *)rlog, num_rlog, sizeof(ReqLog), compare);
00054         double t = rlog[0].time;
00055         for (unsigned int i = 0; i < num_rlog; i++) {
00056                 rlog[i].time -= t;
00057                 fprintf(cf, "%f %d %d %d\n", rlog[i].time, 
00058                         rlog[i].cid, rlog[i].sid, umap[rlog[i].url]);
00059         }
00060         // Record trace duration and # of unique urls
00061         fprintf(cf, "i %f %u\n", rlog[num_rlog-1].time, url);
00062 
00063         fprintf(stderr, 
00064                 "%d unique clients, %d unique servers, %d unique urls.\n", 
00065                 client, server, url);
00066 }

Here is the call graph for this function:

void sort_url  ) 
 

Definition at line 75 of file dec/tr-stat.cc.

References compare_url(), sf, umap, url, and urlHash.

Referenced by main().

00076 {
00077         // XXX use an interval member of Tcl_HashTable
00078         URL** tbl = new URL*[urlHash.numEntries];
00079         Tcl_HashEntry *he;
00080         Tcl_HashSearch hs;
00081         int i = 0, sz = urlHash.numEntries;
00082         for (he = Tcl_FirstHashEntry(&urlHash, &hs);
00083              he != NULL;
00084              he = Tcl_NextHashEntry(&hs))
00085                 tbl[i++] = (URL*)Tcl_GetHashValue(he);
00086         Tcl_DeleteHashTable(&urlHash);
00087 
00088         // sort using access frequencies
00089         qsort((void *)tbl, sz, sizeof(URL*), compare_url);
00090         umap = new int[url];
00091         // write sorted url to page table
00092         for (i = 0; i < sz; i++) {
00093                 umap[tbl[i]->id] = i;
00094                 fprintf(sf, "%d %d %d %u\n", tbl[i]->sid, i,
00095                         tbl[i]->size, tbl[i]->access);
00096                 delete tbl[i];
00097         }
00098         delete []tbl;
00099 }

Here is the call graph for this function:


Variable Documentation

FILE* cf
 

Definition at line 58 of file proxytrace2any.cc.

Referenced by SMAC::drop_CTS(), SMAC::drop_RTS(), SMAC::handleACK(), SMAC::handleCTS(), SMAC::handleRTS(), main(), SMAC::sendACK(), SMAC::sendCTS(), Mac802_11::sendCTS(), SMAC::sendRTS(), SMAC::sendSYNC(), SMAC::sentACK(), SMAC::sentCTS(), and sort_rlog().

Tcl_HashTable cidHash
 

Definition at line 64 of file proxytrace2any.cc.

Referenced by lf_analyze(), and main().

double duration
 

Definition at line 60 of file proxytrace2any.cc.

Referenced by main(), CMUTrace::nam_format(), PrintEntry_Squid(), SMAC::sendACK(), and SMAC::sendCTS().

double initTime
 

Definition at line 59 of file proxytrace2any.cc.

Referenced by lf_analyze().

enum { ... } InputFormat
 

Referenced by getInputFormat().

unsigned int num_rlog
 

Definition at line 63 of file proxytrace2any.cc.

Referenced by lf_analyze(), and sort_rlog().

enum { ... } OutputFormat
 

Referenced by getOutputFormat().

ReqLog* rlog
 

Definition at line 62 of file proxytrace2any.cc.

Referenced by lf_analyze(), main(), and sort_rlog().

FILE * sf
 

Definition at line 58 of file proxytrace2any.cc.

Referenced by TcpSink::ack(), QSTcpSink::ack(), SMAC::handleSYNC(), main(), and sort_url().

Tcl_HashTable sidHash
 

Definition at line 64 of file proxytrace2any.cc.

Referenced by lf_analyze(), and main().

double startTime
 

Definition at line 61 of file proxytrace2any.cc.

Referenced by lf_analyze(), and main().

unsigned int sz_rlog
 

Definition at line 63 of file proxytrace2any.cc.

Referenced by main().

Tcl_HashTable urlHash
 

Definition at line 64 of file proxytrace2any.cc.

Referenced by lf_analyze(), main(), and sort_url().


Generated on Tue Apr 20 12:26:35 2004 for NS2.26SourcesOriginal by doxygen 1.3.3