dec/tr-stat.cc File Reference

#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 "proxytrace.h"

Include dependency graph for dec/tr-stat.cc:

Go to the source code of this file.

Functions

static int compare (const void *a1, const void *b1)
static int compare_url (const void *a1, const void *b1)
double lf_analyze (TEntry &lfe)
void sort_rlog ()
void sort_url ()

Variables

FILE * cf
Tcl_HashTable cidHash
static int client = 0
double duration = -1
double initTime = -1
const unsigned long MAX_FILESIZE = 10000000
unsigned int num_rlog = 0
ReqLogrlog = NULL
static int server = 0
FILE * sf
Tcl_HashTable sidHash
double startTime = -1
unsigned int sz_rlog = 0
static int * umap
static int url = 0
Tcl_HashTable urlHash


Function Documentation

static int compare const void *  a1,
const void *  b1
[static]
 

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

References a, and b.

Referenced by DRR::enque(), ll_del(), ll_find(), ll_sorted_insert(), and sort_rlog().

00045 {
00046     const ReqLog *a = (const ReqLog*)a1, *b = (const ReqLog*)b1;
00047     return (a->time > b->time) ? 1 : 
00048         (a->time == b->time) ? 0 : -1;
00049 }

static int compare_url const void *  a1,
const void *  b1
[static]
 

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

References a, and b.

Referenced by sort_url().

00069 {
00070     const URL **a = (const URL**)a1, **b = (const URL**)b1;
00071     return ((*a)->access > (*b)->access) ? -1:
00072         ((*a)->access == (*b)->access) ? 0 : 1;
00073 }

double lf_analyze TEntry lfe  ) 
 

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

References URL::access, CGI_BIN_FLAG, cidHash, client, TEntryHeader::client, TEntryTail::flags, TEntry::head, URL::id, initTime, MAX_FILESIZE, TEntryTail::method, METHOD_GET, num_rlog, QUERY_FOUND_FLAG, rlog, server, TEntryHeader::server, sidHash, TEntryHeader::size, startTime, TEntryTail::status, TEntry::tail, TEntryHeader::time_sec, TEntryHeader::time_usec, url, TEntry::url, and urlHash.

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     long clientKey = lfe.head.client;
00140     if (!(he = Tcl_FindHashEntry(&cidHash, (const char *)clientKey))) {
00141         // new client, allocate a client id
00142         he = Tcl_CreateHashEntry(&cidHash, (const char *)clientKey, &ne);
00143         client++;
00144         long clientValue = client;
00145         Tcl_SetHashValue(he, clientValue);
00146         cid = client;
00147     } else {
00148         // existing entry, find its client seqno
00149         cid = (long)Tcl_GetHashValue(he);
00150     }
00151 
00152     // check server id
00153     long serverKey = lfe.head.server;
00154     if (!(he = Tcl_FindHashEntry(&sidHash, (const char *)serverKey))) {
00155         // new client, allocate a client id
00156         he = Tcl_CreateHashEntry(&sidHash, (const char *)serverKey, &ne);
00157         server++;
00158         long serverValue = server;
00159         Tcl_SetHashValue(he, serverValue);
00160         sid = server;
00161     } else {
00162         // existing entry, find its client seqno
00163         sid = (long)Tcl_GetHashValue(he);
00164     }
00165 
00166     // check url id
00167     long urlKey = lfe.url;
00168     if (!(he = Tcl_FindHashEntry(&urlHash, (const char*)urlKey))) {
00169         // new client, allocate a client id
00170         he = Tcl_CreateHashEntry(&urlHash, (const char*)urlKey, &ne);
00171         URL* u = new URL(++url, sid, lfe.head.size);
00172         Tcl_SetHashValue(he, (const char*)u);
00173         uid = u->id;
00174     } else {
00175         // existing entry, find its client seqno
00176         URL* u = (URL*)Tcl_GetHashValue(he);
00177         u->access++;
00178         uid = u->id;
00179     }
00180 
00181     rlog[num_rlog++] = ReqLog(time, cid, sid, uid);
00182     //fprintf(cf, "%f %d %d %d\n", time, cid, sid, uid);
00183 
00184     if (startTime > 0) 
00185         return time - startTime;
00186     else 
00187         return time;
00188 }

void sort_rlog  ) 
 

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

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

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.

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 26 of file dec/tr-stat.cc.

Tcl_HashTable cidHash
 

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

int client = 0 [static]
 

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

Referenced by HttpApp::add_cnc(), HttpApp::delete_cnc(), MediaServer::get_piq(), LogWebTrafPool::launchReq(), lf_analyze(), HttpApp::lookup_cnc(), main(), and LogWebTrafPool::processLog().

double duration = -1
 

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

double initTime = -1
 

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

const unsigned long MAX_FILESIZE = 10000000
 

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

Referenced by lf_analyze().

unsigned int num_rlog = 0
 

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

ReqLog* rlog = NULL
 

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

int server = 0 [static]
 

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

Referenced by LogWebTrafPool::launchReq(), lf_analyze(), main(), and LogWebTrafPool::processLog().

FILE * sf
 

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

Tcl_HashTable sidHash
 

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

double startTime = -1
 

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

unsigned int sz_rlog = 0
 

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

int* umap [static]
 

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

Referenced by sort_rlog(), and sort_url().

int url = 0 [static]
 

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

Referenced by lf_analyze(), main(), PrintEntry_Text(), ReadEntryV1(), sort_rlog(), sort_url(), and ToOtherEndian().

Tcl_HashTable urlHash
 

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


Generated on Tue Mar 6 17:01:41 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6