#include <pagepool.h>
Inheritance diagram for TracePagePool:


Public Member Functions | |
| TracePagePool (const char *fn) | |
| virtual | ~TracePagePool () |
| virtual int | command (int argc, const char *const *argv) |
| int | num_pages () const |
| int | num_pages () const |
Protected Member Functions | |
| ServerPage * | load_page (FILE *fp) |
| void | change_time () |
| int | add_page (const char *pgname, ServerPage *pg) |
| ServerPage * | get_page (int id) |
| TclObject * | lookup_obj (const char *name) |
| TclObject * | lookup_obj (const char *name) |
Protected Attributes | |
| Tcl_HashTable * | namemap_ |
| Tcl_HashTable * | idmap_ |
| RandomVariable * | ranvar_ |
| int | num_pages_ |
| double | start_time_ |
| double | end_time_ |
| int | duration_ |
|
|
Definition at line 151 of file pagepool.cc. References abort(), change_time(), idmap_, load_page(), and namemap_.
00151 : 00152 PagePool(), ranvar_(0) 00153 { 00154 FILE *fp = fopen(fn, "r"); 00155 if (fp == NULL) { 00156 fprintf(stderr, 00157 "TracePagePool: couldn't open trace file %s\n", fn); 00158 abort(); // What else can we do? 00159 } 00160 00161 namemap_ = new Tcl_HashTable; 00162 Tcl_InitHashTable(namemap_, TCL_STRING_KEYS); 00163 idmap_ = new Tcl_HashTable; 00164 Tcl_InitHashTable(idmap_, TCL_ONE_WORD_KEYS); 00165 00166 while (load_page(fp)); 00167 change_time(); 00168 } |
Here is the call graph for this function:

|
|
Definition at line 170 of file pagepool.cc. References idmap_, and namemap_.
|
|
||||||||||||
|
Definition at line 246 of file pagepool.cc. References Page::id(), idmap_, and namemap_. Referenced by load_page().
00247 {
00248 int newEntry = 1;
00249 Tcl_HashEntry *he = Tcl_CreateHashEntry(namemap_,
00250 (const char *)name,
00251 &newEntry);
00252 if (he == NULL)
00253 return -1;
00254 if (newEntry)
00255 Tcl_SetHashValue(he, (ClientData)pg);
00256 else
00257 fprintf(stderr, "TracePagePool: Duplicate entry %s\n",
00258 name);
00259
00260 Tcl_HashEntry *hf =
00261 Tcl_CreateHashEntry(idmap_, (const char *)pg->id(), &newEntry);
00262 if (hf == NULL) {
00263 Tcl_DeleteHashEntry(he);
00264 return -1;
00265 }
00266 if (newEntry)
00267 Tcl_SetHashValue(hf, (ClientData)pg);
00268 else
00269 fprintf(stderr, "TracePagePool: Duplicate entry %d\n",
00270 pg->id());
00271
00272 return 0;
00273 }
|
Here is the call graph for this function:

|
|
Definition at line 182 of file pagepool.cc. References PagePool::duration_, PagePool::end_time_, idmap_, ServerPage::mtime(), ServerPage::num_mtime(), and PagePool::start_time_. Referenced by TracePagePool().
00183 {
00184 Tcl_HashEntry *he;
00185 Tcl_HashSearch hs;
00186 ServerPage *pg;
00187 int i, j;
00188
00189 for (i = 0, he = Tcl_FirstHashEntry(idmap_, &hs);
00190 he != NULL;
00191 he = Tcl_NextHashEntry(&hs), i++) {
00192 pg = (ServerPage *) Tcl_GetHashValue(he);
00193 for (j = 0; j < pg->num_mtime(); j++)
00194 pg->mtime(j) -= (int)start_time_;
00195 }
00196 end_time_ -= start_time_;
00197 start_time_ = 0;
00198 duration_ = (int)end_time_;
00199 }
|
Here is the call graph for this function:

|
||||||||||||
|
Reimplemented from PagePool. Definition at line 285 of file pagepool.cc. References abort(), PagePool::command(), PagePool::duration_, PagePool::end_time_, get_page(), Scheduler::instance(), ServerPage::mtime(), ServerPage::num_mtime(), PagePool::num_pages_, ranvar_, ServerPage::size(), PagePool::start_time_, Random::uniform(), and RandomVariable::value().
00286 {
00287 Tcl &tcl = Tcl::instance();
00288
00289 if (argc == 2) {
00290 if (strcmp(argv[1], "get-poolsize") == 0) {
00291 /*
00292 * <pgpool> get-poolsize
00293 * Get the number of pages currently in pool
00294 */
00295 tcl.resultf("%d", num_pages_);
00296 return TCL_OK;
00297 } else if (strcmp(argv[1], "get-start-time") == 0) {
00298 tcl.resultf("%.17g", start_time_);
00299 return TCL_OK;
00300 } else if (strcmp(argv[1], "get-duration") == 0) {
00301 tcl.resultf("%d", duration_);
00302 return TCL_OK;
00303 }
00304 } else if (argc == 3) {
00305 if (strcmp(argv[1], "gen-pageid") == 0) {
00306 /*
00307 * <pgpool> gen-pageid <client_id>
00308 * Randomly generate a page id from page pool
00309 */
00310 double tmp = ranvar_ ? ranvar_->value() :
00311 Random::uniform();
00312 // tmp should be in [0, num_pages_-1]
00313 tmp = (tmp < 0) ? 0 : (tmp >= num_pages_) ?
00314 (num_pages_-1):tmp;
00315 if ((int)tmp >= num_pages_) abort();
00316 tcl.resultf("%d", (int)tmp);
00317 return TCL_OK;
00318 } else if (strcmp(argv[1], "gen-size") == 0) {
00319 /*
00320 * <pgpool> gen-size <pageid>
00321 */
00322 int id = atoi(argv[2]);
00323 ServerPage *pg = get_page(id);
00324 if (pg == NULL) {
00325 tcl.add_errorf("TracePagePool %s: page %d doesn't exists.\n",
00326 name_, id);
00327 return TCL_ERROR;
00328 }
00329 tcl.resultf("%d", pg->size());
00330 return TCL_OK;
00331 } else if (strcmp(argv[1], "ranvar") == 0) {
00332 /*
00333 * <pgpool> ranvar <ranvar>
00334 * Set a random var which is used to randomly pick
00335 * a page from the page pool.
00336 */
00337 ranvar_ = (RandomVariable *)TclObject::lookup(argv[2]);
00338 return TCL_OK;
00339 } else if (strcmp(argv[1], "set-start-time") == 0) {
00340 double st = strtod(argv[2], NULL);
00341 start_time_ = st;
00342 end_time_ += st;
00343 } else if (strcmp(argv[1], "gen-init-modtime") == 0) {
00344 tcl.resultf("%.17g", Scheduler::instance().clock());
00345 return TCL_OK;
00346 }
00347 } else {
00348 if (strcmp(argv[1], "gen-modtime") == 0) {
00349 /*
00350 * <pgpool> get-modtime <pageid> <modtime>
00351 *
00352 * Return next modtime that is larger than modtime
00353 * To retrieve the first modtime (creation time), set
00354 * <modtime> to -1 in the request.
00355 */
00356 int id = atoi(argv[2]);
00357 double mt = strtod(argv[3], NULL);
00358 ServerPage *pg = get_page(id);
00359 if (pg == NULL) {
00360 tcl.add_errorf("TracePagePool %s: page %d doesn't exists.\n",
00361 name_, id);
00362 return TCL_ERROR;
00363 }
00364 for (int i = 0; i < pg->num_mtime(); i++)
00365 if (pg->mtime(i) > mt) {
00366 tcl.resultf("%.17g",
00367 pg->mtime(i)+start_time_);
00368 return TCL_OK;
00369 }
00370 // When get to the last modtime, return -1
00371 tcl.resultf("%d", INT_MAX);
00372 return TCL_OK;
00373 }
00374 }
00375 return PagePool::command(argc, argv);
00376 }
|
Here is the call graph for this function:

|
|
Definition at line 275 of file pagepool.cc. References idmap_, and PagePool::num_pages_. Referenced by command().
00276 {
00277 if ((id < 0) || (id >= num_pages_))
00278 return NULL;
00279 Tcl_HashEntry *he = Tcl_FindHashEntry(idmap_, (const char *)id);
00280 if (he == NULL)
00281 return NULL;
00282 return (ServerPage *)Tcl_GetHashValue(he);
00283 }
|
|
|
Definition at line 201 of file pagepool.cc. References add_page(), PagePool::end_time_, ServerPage::num_mtime(), PagePool::num_pages_, ServerPage::set_mtime(), PagePool::start_time_, and TRACEPAGEPOOL_MAXBUF. Referenced by TracePagePool().
00202 {
00203 static char buf[TRACEPAGEPOOL_MAXBUF];
00204 char *delim = " \t\n";
00205 char *tmp1, *tmp2;
00206 ServerPage *pg;
00207
00208 // XXX Use internal variables of struct Page
00209 if (!fgets(buf, TRACEPAGEPOOL_MAXBUF, fp))
00210 return NULL;
00211
00212 // URL
00213 tmp1 = strtok(buf, delim);
00214 // Size
00215 tmp2 = strtok(NULL, delim);
00216 pg = new ServerPage(atoi(tmp2), num_pages_++);
00217
00218 if (add_page(tmp1, pg)) {
00219 delete pg;
00220 return NULL;
00221 }
00222
00223 // Modtimes, assuming they are in ascending time order
00224 int num = 0;
00225 int *nmd = new int[5];
00226 while ((tmp1 = strtok(NULL, delim)) != NULL) {
00227 if (num >= 5) {
00228 int *tt = new int[num+5];
00229 memcpy(tt, nmd, sizeof(int)*num);
00230 delete []nmd;
00231 nmd = tt;
00232 }
00233 nmd[num] = atoi(tmp1);
00234 if (nmd[num] < start_time_)
00235 start_time_ = nmd[num];
00236 if (nmd[num] > end_time_)
00237 end_time_ = nmd[num];
00238 num++;
00239 }
00240 pg->num_mtime() = num;
00241 pg->set_mtime(nmd, num);
00242 delete []nmd;
00243 return pg;
00244 }
|
Here is the call graph for this function:

|
|
Definition at line 242 of file pagepool.h.
00242 {
00243 TclObject* obj = Tcl::instance().lookup(name);
00244 if (obj == NULL)
00245 fprintf(stderr, "Bad object name %s\n", name);
00246 return obj;
00247 }
|
|
|
Definition at line 30 of file persconn.h. Referenced by WebTrafPool::command(), EmpWebTrafPool::command(), EmpFtpTrafPool::command(), WebTrafPool::lookup_rv(), EmpWebTrafPool::lookup_rv(), EmpFtpTrafPool::lookup_rv(), WebTrafPool::picksink(), EmpWebTrafPool::picksink(), EmpFtpTrafPool::picksink(), WebTrafPool::picktcp(), EmpWebTrafPool::picktcp(), and EmpFtpTrafPool::picktcp().
00030 {
00031 TclObject* obj = Tcl::instance().lookup(name);
00032 if (obj == NULL)
00033 fprintf(stderr, "Bad object name %s\n", name);
00034 return obj;
00035 }
|
|
|
Definition at line 233 of file pagepool.h. References PagePool::num_pages_.
00233 { return num_pages_; }
|
|
|
Definition at line 21 of file persconn.h. References PagePool::num_pages_.
00021 { return num_pages_; }
|
|
|
Definition at line 239 of file pagepool.h. Referenced by change_time(), ProxyTracePagePool::command(), CompMathPagePool::command(), MathPagePool::command(), command(), MediaPagePool::command(), ProxyTracePagePool::find_info(), and MediaPagePool::MediaPagePool(). |
|
|
Definition at line 238 of file pagepool.h. Referenced by change_time(), CompMathPagePool::command(), MathPagePool::command(), command(), MediaPagePool::command(), load_page(), and PagePool::PagePool(). |
|
|
Definition at line 262 of file pagepool.h. Referenced by add_page(), change_time(), get_page(), TracePagePool(), and ~TracePagePool(). |
|
|
Definition at line 262 of file pagepool.h. Referenced by add_page(), TracePagePool(), and ~TracePagePool(). |
|
|
|
Definition at line 263 of file pagepool.h. Referenced by command(). |
|
|
Definition at line 237 of file pagepool.h. Referenced by change_time(), ProxyTracePagePool::command(), CompMathPagePool::command(), MathPagePool::command(), command(), MediaPagePool::command(), load_page(), ProxyTracePagePool::load_req(), and PagePool::PagePool(). |
1.3.3