#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 nlanr/tr-stat.cc:

Go to the source code of this file.
Compounds | |
| struct | ReqLog |
| struct | URL |
Functions | |
| int | compare (const void *a1, const void *b1) |
| void | sort_rlog () |
| int | compare_url (const void *a1, const void *b1) |
| void | sort_url () |
| double | lf_analyze (lf_entry &lfe) |
| int | main (int argc, char **argv) |
Variables | |
| Tcl_HashTable | cidHash |
| int | client = 0 |
| Tcl_HashTable | sidHash |
| int | server = 0 |
| Tcl_HashTable | urlHash |
| int | url = 0 |
| int * | umap |
| FILE * | cf |
| FILE * | sf |
| double | initTime = -1 |
| double | duration = -1 |
| double | startTime = -1 |
| ReqLog * | rlog = NULL |
| unsigned int | num_rlog = 0 sz_rlog = 0 |
|
||||||||||||
|
Definition at line 57 of file nlanr/tr-stat.cc. References ReqLog::time. Referenced by DRR::enque(), and sort_rlog().
|
|
||||||||||||
|
Definition at line 78 of file nlanr/tr-stat.cc. Referenced by sort_url().
|
|
|
Definition at line 111 of file nlanr/tr-stat.cc. References URL::access, cidHash, client, URL::id, initTime, num_rlog, rlog, server, sidHash, startTime, url, lf_entry_st::url, and urlHash.
00112 {
00113 double time;
00114 int ne, cid, sid, uid;
00115 Tcl_HashEntry *he;
00116
00117 time = lfe.rt;
00118
00119 if (initTime < 0) {
00120 initTime = time;
00121 time = 0;
00122 } else
00123 time -= initTime;
00124
00125 // If a trace start time is required, don't do anything
00126 if ((startTime > 0) && (time < startTime))
00127 return -1;
00128
00129 // Ignore pages with size 0
00130 if (lfe.size == 0)
00131 return -1;
00132
00133 // check client id
00134 if (!(he = Tcl_FindHashEntry(&cidHash, (const char *)lfe.cid))) {
00135 // new client, allocate a client id
00136 he = Tcl_CreateHashEntry(&cidHash, (const char *)lfe.cid, &ne);
00137 Tcl_SetHashValue(he, ++client);
00138 cid = client;
00139 } else {
00140 // existing entry, find its client seqno
00141 cid = (int)Tcl_GetHashValue(he);
00142 }
00143
00144 // check server id
00145 if (!(he = Tcl_FindHashEntry(&sidHash, lfe.sid))) {
00146 // new server, assign a server id
00147 he = Tcl_CreateHashEntry(&sidHash, lfe.sid, &ne);
00148 Tcl_SetHashValue(he, ++server);
00149 sid = server;
00150 } else {
00151 // existing entry, find its client seqno
00152 sid = (int)Tcl_GetHashValue(he);
00153 }
00154
00155 // check url id
00156 if (!(he = Tcl_FindHashEntry(&urlHash, lfe.url))) {
00157 // new client, allocate a client id
00158 he = Tcl_CreateHashEntry(&urlHash, lfe.url, &ne);
00159 URL* u = new URL(++url, sid, lfe.size);
00160 Tcl_SetHashValue(he, (const char*)u);
00161 uid = u->id;
00162 //fprintf(sf, "%d %d %ld\n", sid, u->id, lfe.rhl+lfe.rdl);
00163 } else {
00164 // existing entry, find its client seqno
00165 URL* u = (URL*)Tcl_GetHashValue(he);
00166 u->access++;
00167 uid = u->id;
00168 }
00169
00170 rlog[num_rlog++] = ReqLog(time, cid, sid, uid);
00171 //fprintf(cf, "%f %d %d %d\n", time, cid, sid, uid);
00172
00173 if (startTime > 0)
00174 return time - startTime;
00175 else
00176 return time;
00177 }
|
|
||||||||||||
|
Definition at line 179 of file nlanr/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_st::url, and urlHash.
00180 {
00181 lf_entry lfntree;
00182 int ret;
00183 double ctime;
00184
00185 // Init tcl
00186 Tcl_Interp *interp = Tcl_CreateInterp();
00187 if (Tcl_Init(interp) == TCL_ERROR) {
00188 printf("%s\n", interp->result);
00189 abort();
00190 }
00191 Tcl_InitHashTable(&cidHash, TCL_ONE_WORD_KEYS);
00192 Tcl_InitHashTable(&sidHash, TCL_STRING_KEYS);
00193 Tcl_InitHashTable(&urlHash, TCL_STRING_KEYS);
00194
00195 if ((cf = fopen("reqlog", "w")) == NULL) {
00196 printf("cannot open request log.\n");
00197 exit(1);
00198 }
00199 if ((sf = fopen("pglog", "w")) == NULL) {
00200 printf("cannot open page log.\n");
00201 exit(1);
00202 }
00203
00204 if ((argc < 2) || (argc > 4)) {
00205 printf("Usage: %s <trace size> [<time duration>] [<start_time>]\n", argv[0]);
00206 return 1;
00207 }
00208 if (argc >= 3) {
00209 duration = strtod(argv[2], NULL);
00210 if (argc == 4) {
00211 startTime = strtod(argv[3], NULL);
00212 printf("start time = %f\n", startTime);
00213 }
00214 }
00215
00216 sz_rlog = strtoul(argv[1], NULL, 10);
00217 rlog = new ReqLog[sz_rlog];
00218
00219 while(1) {
00220 ret = lf_get_next_entry(stdin, lfntree);
00221 if (ret > 0) {
00222 if (ret == 1) {
00223 /* EOF */
00224 break;
00225 }
00226 fprintf(stderr, "Failed to get next entry.\n");
00227 exit(1);
00228 } else if (ret < 0) {
00229 // Unusable entry, i.e., cache miss, cgi-bin, etc.
00230 continue;
00231 }
00232 // Analyse one log entry
00233 ctime = lf_analyze(lfntree);
00234 delete []lfntree.url;
00235 delete []lfntree.sid;
00236 if ((duration > 0) && (ctime > duration))
00237 break;
00238 }
00239 Tcl_DeleteHashTable(&cidHash);
00240 Tcl_DeleteHashTable(&sidHash);
00241
00242 fprintf(stderr, "sort url\n");
00243 sort_url();
00244 fclose(sf);
00245
00246 fprintf(stderr, "sort requests\n");
00247 sort_rlog();
00248 fclose(cf);
00249
00250 fprintf(stderr,
00251 "%d unique clients, %d unique servers, %d unique urls.\n",
00252 client, server, url);
00253 return 0;
00254 }
|
Here is the call graph for this function:

|
|
Definition at line 64 of file nlanr/tr-stat.cc. References cf, compare(), num_rlog, rlog, ReqLog::time, umap, and url.
00065 {
00066 qsort((void *)rlog, num_rlog, sizeof(ReqLog), compare);
00067 double t = rlog[0].time;
00068 for (unsigned int i = 0; i < num_rlog; i++) {
00069 rlog[i].time -= t;
00070 fprintf(cf, "%f %d %d %d\n", rlog[i].time,
00071 rlog[i].cid, rlog[i].sid, umap[rlog[i].url]);
00072 }
00073 delete []umap;
00074 // Record trace duration and # of unique urls
00075 fprintf(cf, "i %f %u\n", rlog[num_rlog-1].time, url);
00076 }
|
Here is the call graph for this function:

|
|
Definition at line 85 of file nlanr/tr-stat.cc. References compare_url(), sf, umap, url, and urlHash.
00086 {
00087 // XXX use an interval member of Tcl_HashTable
00088 URL** tbl = new URL*[urlHash.numEntries];
00089 Tcl_HashEntry *he;
00090 Tcl_HashSearch hs;
00091 int i = 0, sz = urlHash.numEntries;
00092 for (he = Tcl_FirstHashEntry(&urlHash, &hs);
00093 he != NULL;
00094 he = Tcl_NextHashEntry(&hs))
00095 tbl[i++] = (URL*)Tcl_GetHashValue(he);
00096 Tcl_DeleteHashTable(&urlHash);
00097
00098 // sort using access frequencies
00099 qsort((void *)tbl, sz, sizeof(URL*), compare_url);
00100 umap = new int[url];
00101 // write sorted url to page table
00102 for (i = 0; i < sz; i++) {
00103 umap[tbl[i]->id] = i;
00104 fprintf(sf, "%d %d %d %u\n", tbl[i]->sid, i,
00105 tbl[i]->size, tbl[i]->access);
00106 delete tbl[i];
00107 }
00108 delete []tbl;
00109 }
|
Here is the call graph for this function:

|
|
Definition at line 42 of file nlanr/tr-stat.cc. |
|
|
Definition at line 26 of file nlanr/tr-stat.cc. |
|
|
Definition at line 27 of file nlanr/tr-stat.cc. Referenced by HttpApp::add_cnc(), HttpApp::command(), HttpApp::delete_cnc(), MediaServer::get_piq(), LogWebTrafPool::launchReq(), lf_analyze(), HttpApp::lookup_cnc(), main(), and LogWebTrafPool::processLog(). |
|
|
Definition at line 44 of file nlanr/tr-stat.cc. |
|
|
Definition at line 43 of file nlanr/tr-stat.cc. |
|
|
Definition at line 55 of file nlanr/tr-stat.cc. |
|
|
Definition at line 54 of file nlanr/tr-stat.cc. |
|
|
Definition at line 30 of file nlanr/tr-stat.cc. Referenced by LogWebTrafPool::launchReq(), lf_analyze(), main(), and LogWebTrafPool::processLog(). |
|
|
Definition at line 42 of file nlanr/tr-stat.cc. |
|
|
Definition at line 29 of file nlanr/tr-stat.cc. |
|
|
Definition at line 45 of file nlanr/tr-stat.cc. |
|
|
Definition at line 34 of file nlanr/tr-stat.cc. Referenced by sort_rlog(), and sort_url(). |
|
|
Definition at line 33 of file nlanr/tr-stat.cc. Referenced by lf_analyze(), main(), PrintEntry_Text(), ReadEntryV1(), ReqLog::ReqLog(), sort_rlog(), sort_url(), and ToOtherEndian(). |
|
|
Definition at line 32 of file nlanr/tr-stat.cc. |
1.3.3