#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <tcl.h>
#include "logparse.h"
Include dependency graph for ucb/tr-stat.cc:

Go to the source code of this file.
Data Structures | |
| struct | ReqLog |
| struct | URL |
Functions | |
| int | compare (const void *a1, const void *b1) |
| int | compare_url (const void *a1, const void *b1) |
| double | lf_analyze (lf_entry &lfe) |
| int | main (int argc, char **argv) |
| void | sort_rlog () |
| void | sort_url () |
Variables | |
| FILE * | cf |
| Tcl_HashTable | cidHash |
| int | client = 0 |
| double | duration = -1 |
| double | initTime = -1 |
| const unsigned long | MAX_FILESIZE = 10000000 |
| unsigned int | num_rlog = 0 |
| ReqLog * | rlog = NULL |
| int | server = 0 |
| FILE * | sf |
| Tcl_HashTable | sidHash |
| double | startTime = -1 |
| unsigned int | sz_rlog = 0 |
| int * | umap |
| int | url = 0 |
| Tcl_HashTable | urlHash |
|
||||||||||||
|
Definition at line 59 of file ucb/tr-stat.cc. 00060 { 00061 const ReqLog *a, *b; 00062 a = (const ReqLog*)a1, b = (const ReqLog*)b1; 00063 return (a->time > b->time) ? 1 : 00064 (a->time == b->time) ? 0 : -1; 00065 }
|
|
||||||||||||
|
Definition at line 81 of file ucb/tr-stat.cc. 00082 { 00083 const URL **a, **b; 00084 a = (const URL**)a1, b = (const URL**)b1; 00085 return ((*a)->access > (*b)->access) ? -1: 00086 ((*a)->access == (*b)->access) ? 0 : 1; 00087 }
|
|
|
Definition at line 117 of file ucb/tr-stat.cc. References URL::access, cidHash, client, URL::id, initTime, lf_convert_order(), MAX_FILESIZE, num_rlog, PB_CLNT_NO_CACHE, PB_SRVR_NO_CACHE, rlog, server, sidHash, startTime, url, lf_entry::url, and urlHash. 00118 { 00119 double time; 00120 int id[2], ne, cid, sid, uid; 00121 Tcl_HashEntry *he; 00122 00123 /* Because client/server pragma bits are in network order, we 00124 * do the filtering here 00125 * 00126 * We do not count in entries with "no-cache" flag 00127 */ 00128 if ((lfe.cprg != 0xff) && (lfe.cprg & PB_CLNT_NO_CACHE)) 00129 return -1; 00130 if ((lfe.sprg != 0xff) && (lfe.sprg & PB_SRVR_NO_CACHE)) 00131 return -1; 00132 00133 /* Convert to host order for size comparison, etc. */ 00134 lf_convert_order(&lfe); 00135 00136 /* We don't consider pages with size 0 */ 00137 if (lfe.rhl + lfe.rdl == 0) 00138 return -1; 00139 /* We don't consider file size larger than 10MB */ 00140 if (lfe.rhl + lfe.rdl > MAX_FILESIZE) 00141 return -1; 00142 00143 /* Analyze URL. *MUST* be done before anything else because this 00144 * filters out entries 00145 */ 00146 char *str, *idx = (char *)lfe.url, *tmp; 00147 tmp = strtok(idx, " "); 00148 if (strcmp(tmp, "GET") != 0) { 00149 /* We only count GETs */ 00150 return -1; 00151 } 00152 str = strtok(NULL, "."); /* This is the URL to be entered */ 00153 00154 time = (double)lfe.crs + (double)lfe.cru/(double)1000000.0; 00155 00156 if (initTime < 0) { 00157 initTime = time; 00158 time = 0; 00159 } else 00160 time -= initTime; 00161 00162 /* If a trace start time is required, don't do anything */ 00163 if ((startTime > 0) && (time < startTime)) 00164 return -1; 00165 00166 /* check client id */ 00167 if (!(he = Tcl_FindHashEntry(&cidHash, (const char *)lfe.cip))) { 00168 /* new client, allocate a client id */ 00169 he = Tcl_CreateHashEntry(&cidHash, (const char *)lfe.cip, &ne); 00170 client++; 00171 long clientValue = client; 00172 Tcl_SetHashValue(he, clientValue); 00173 cid = client; 00174 } else { 00175 /* existing entry, find its client seqno */ 00176 cid = (long)Tcl_GetHashValue(he); 00177 } 00178 00179 /* check server id */ 00180 id[0] = lfe.sip; 00181 id[1] = lfe.spt; 00182 if (!(he = Tcl_FindHashEntry(&sidHash, (const char *)id))) { 00183 /* new client, allocate a client id */ 00184 he = Tcl_CreateHashEntry(&sidHash, (const char *)id, &ne); 00185 server++; 00186 long serverValue = server; 00187 Tcl_SetHashValue(he, serverValue); 00188 sid = server; 00189 } else { 00190 /* existing entry, find its client seqno */ 00191 sid = (long)Tcl_GetHashValue(he); 00192 } 00193 00194 /* check url id */ 00195 if (!(he = Tcl_FindHashEntry(&urlHash, str))) { 00196 /* new client, allocate a client id */ 00197 he = Tcl_CreateHashEntry(&urlHash, str, &ne); 00198 URL* u = new URL(++url, sid, lfe.rhl+lfe.rdl); 00199 Tcl_SetHashValue(he, (const char*)u); 00200 uid = u->id; 00201 /* fprintf(sf, "%d %d %ld\n", sid, u->id, lfe.rhl+lfe.rdl); */ 00202 } else { 00203 /* existing entry, find its client seqno */ 00204 URL* u = (URL*)Tcl_GetHashValue(he); 00205 u->access++; 00206 uid = u->id; 00207 } 00208 00209 rlog[num_rlog++] = ReqLog(time, cid, sid, uid); 00210 /*fprintf(cf, "%f %d %d %d\n", time, cid, sid, uid); */ 00211 00212 if (startTime > 0) 00213 return time - startTime; 00214 else 00215 return time; 00216 }
Here is the call graph for this function: ![]() |
|
||||||||||||
|
Definition at line 218 of file ucb/tr-stat.cc. References abort(), cf, cidHash, client, duration, lf_analyze(), lf_get_next_entry(), rlog, server, sf, sidHash, sort_rlog(), sort_url(), startTime, sz_rlog, url, lf_entry::url, and urlHash. 00219 { 00220 lf_entry lfntree; 00221 int ret; 00222 double ctime; 00223 00224 /* Init tcl */ 00225 Tcl_Interp *interp = Tcl_CreateInterp(); 00226 if (Tcl_Init(interp) == TCL_ERROR) { 00227 printf("%s\n", interp->result); 00228 abort(); 00229 } 00230 Tcl_InitHashTable(&cidHash, TCL_ONE_WORD_KEYS); 00231 Tcl_InitHashTable(&sidHash, 2); 00232 Tcl_InitHashTable(&urlHash, TCL_STRING_KEYS); 00233 00234 if ((cf = fopen("reqlog", "w")) == NULL) { 00235 printf("cannot open request log.\n"); 00236 exit(1); 00237 } 00238 if ((sf = fopen("pglog", "w")) == NULL) { 00239 printf("cannot open page log.\n"); 00240 exit(1); 00241 } 00242 00243 if ((argc < 2) || (argc > 4)) { 00244 printf("Usage: %s <trace size> [<time duration>] [<start_time>]\n", argv[0]); 00245 return 1; 00246 } 00247 if (argc >= 3) { 00248 duration = strtod(argv[2], NULL); 00249 if (argc == 4) { 00250 startTime = strtod(argv[3], NULL); 00251 printf("start time = %f\n", startTime); 00252 } 00253 } 00254 00255 sz_rlog = strtoul(argv[1], NULL, 10); 00256 rlog = new ReqLog[sz_rlog]; 00257 00258 while(1) { 00259 if ((ret = lf_get_next_entry(0, &lfntree, 0)) != 0) { 00260 if (ret == 1) { 00261 /* EOF */ 00262 break; 00263 } 00264 fprintf(stderr, "Failed to get next entry.\n"); 00265 exit(1); 00266 } 00267 /* Analyse one log entry */ 00268 ctime = lf_analyze(lfntree); 00269 free(lfntree.url); 00270 if ((duration > 0) && (ctime > duration)) 00271 break; 00272 } 00273 Tcl_DeleteHashTable(&cidHash); 00274 Tcl_DeleteHashTable(&sidHash); 00275 00276 fprintf(stderr, "sort url\n"); 00277 sort_url(); 00278 fclose(sf); 00279 00280 fprintf(stderr, "sort requests\n"); 00281 sort_rlog(); 00282 fclose(cf); 00283 00284 fprintf(stderr, 00285 "%d unique clients, %d unique servers, %d unique urls.\n", 00286 client, server, url); 00287 return 0; 00288 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 67 of file ucb/tr-stat.cc. References cf, compare(), num_rlog, rlog, umap, and url. Referenced by main(). 00068 { 00069 qsort((void *)rlog, num_rlog, sizeof(ReqLog), compare); 00070 double t = rlog[0].time; 00071 for (unsigned int i = 0; i < num_rlog; i++) { 00072 rlog[i].time -= t; 00073 fprintf(cf, "%f %d %d %d\n", rlog[i].time, 00074 rlog[i].cid, rlog[i].sid, umap[rlog[i].url]); 00075 } 00076 delete []umap; 00077 /* Record trace duration and # of unique urls */ 00078 fprintf(cf, "i %f %u\n", rlog[num_rlog-1].time, url); 00079 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 89 of file ucb/tr-stat.cc. References compare_url(), sf, umap, url, and urlHash. Referenced by main(). 00090 { 00091 /* XXX use an interval member of Tcl_HashTable */ 00092 URL** tbl = new URL*[urlHash.numEntries]; 00093 Tcl_HashEntry *he; 00094 Tcl_HashSearch hs; 00095 int i = 0, sz = urlHash.numEntries; 00096 for (he = Tcl_FirstHashEntry(&urlHash, &hs); 00097 he != NULL; 00098 he = Tcl_NextHashEntry(&hs)) 00099 tbl[i++] = (URL*)Tcl_GetHashValue(he); 00100 Tcl_DeleteHashTable(&urlHash); 00101 00102 /* sort using access frequencies */ 00103 qsort((void *)tbl, sz, sizeof(URL*), compare_url); 00104 umap = new int[url]; 00105 /* write sorted url to page table */ 00106 for (i = 0; i < sz; i++) { 00107 umap[tbl[i]->id] = i; 00108 fprintf(sf, "%d %d %d %u\n", tbl[i]->sid, i, 00109 tbl[i]->size, tbl[i]->access); 00110 delete tbl[i]; 00111 } 00112 delete []tbl; 00113 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 44 of file ucb/tr-stat.cc. Referenced by SMAC::drop_CTS(), SMAC::drop_RTS(), SMAC::handleACK(), SMAC::handleCTS(), SMAC::handleRTS(), main(), SMAC::sendACK(), Mac802_11::sendCTS(), SMAC::sendCTS(), SMAC::sendRTS(), SMAC::sendSYNC(), SMAC::sentACK(), SMAC::sentCTS(), and sort_rlog(). |
|
|
Definition at line 28 of file ucb/tr-stat.cc. Referenced by lf_analyze(), and main(). |
|
|
Definition at line 29 of file ucb/tr-stat.cc. |
|
|
Definition at line 46 of file ucb/tr-stat.cc. Referenced by main(), and PrintEntry_Squid(). |
|
|
Definition at line 45 of file ucb/tr-stat.cc. Referenced by lf_analyze(). |
|
|
Definition at line 115 of file ucb/tr-stat.cc. |
|
|
Definition at line 57 of file ucb/tr-stat.cc. Referenced by lf_analyze(), and sort_rlog(). |
|
|
Definition at line 56 of file ucb/tr-stat.cc. Referenced by lf_analyze(), main(), and sort_rlog(). |
|
|
Definition at line 32 of file ucb/tr-stat.cc. |
|
|
Definition at line 44 of file ucb/tr-stat.cc. Referenced by XcpSink::ack(), SatTrace::format_hdlc(), HDLC::handleREJ(), HDLC::handleRR(), HDLC::handleSREJ(), SMAC::handleSYNC(), main(), HDLC::recvSframe(), HDLC::sendREJ(), HDLC::sendRR(), HDLC::sendSREJ(), and sort_url(). |
|
|
Definition at line 31 of file ucb/tr-stat.cc. Referenced by lf_analyze(), and main(). |
|
|
Definition at line 47 of file ucb/tr-stat.cc. Referenced by lf_analyze(), and main(). |
|
|
Definition at line 57 of file ucb/tr-stat.cc. Referenced by main(). |
|
|
Definition at line 36 of file ucb/tr-stat.cc. |
|
|
Definition at line 35 of file ucb/tr-stat.cc. |
|
|
Definition at line 34 of file ucb/tr-stat.cc. Referenced by lf_analyze(), main(), and sort_url(). |
1.4.6