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

estimator.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00004  *
00005  * License is granted to copy, to use, and to make and to use derivative
00006  * works for research and evaluation purposes, provided that Xerox is
00007  * acknowledged in all documentation pertaining to any such copy or
00008  * derivative work. Xerox grants no other licenses expressed or
00009  * implied. The Xerox trade name should not be used in any advertising
00010  * without its written permission. 
00011  *
00012  * XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
00013  * MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
00014  * FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
00015  * express or implied warranty of any kind.
00016  *
00017  * These notices must be retained in any copies of any part of this
00018  * software. 
00019  */
00020 #ifndef lint
00021 static const char rcsid[] =
00022         "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/adc/estimator.cc,v 1.7 1999/03/13 03:52:47 haoboy Exp $";
00023 #endif
00024 
00025 #include "estimator.h"
00026 
00027 Estimator::Estimator() : meas_mod_(0),avload_(0.0),est_timer_(this), measload_(0.0), tchan_(0), omeasload_(0), oavload_(0)
00028 {
00029         bind("period_",&period_);
00030         bind("src_", &src_);
00031         bind("dst_", &dst_);
00032 
00033         avload_.tracer(this);
00034         avload_.name("\"Estimated Util.\"");
00035         measload_.tracer(this);
00036         measload_.name("\"Measured Util.\"");
00037 }
00038 
00039 int Estimator::command(int argc, const char*const* argv)
00040 {
00041         Tcl& tcl = Tcl::instance();
00042         if (argc==2) {
00043                 if (strcmp(argv[1],"load-est") == 0) {
00044                         tcl.resultf("%.3f",double(avload_));
00045                         return(TCL_OK);
00046                 } else if (strcmp(argv[1],"link-utlzn") == 0) {
00047                         tcl.resultf("%.3f",meas_mod_->bitcnt()/period_);
00048                         return(TCL_OK);
00049                 }
00050         }
00051         if (argc == 3) {
00052                 if (strcmp(argv[1], "attach") == 0) {
00053                         int mode;
00054                         const char* id = argv[2];
00055                         tchan_ = Tcl_GetChannel(tcl.interp(), (char*)id, &mode);
00056                         if (tchan_ == 0) {
00057                                 tcl.resultf("Estimator: trace: can't attach %s for writing", id);
00058                                 return (TCL_ERROR);
00059                         }
00060                         return (TCL_OK);
00061                 }
00062                 if (strcmp(argv[1], "setbuf") == 0) {
00063                         /* some sub classes actually do something here */
00064                         return(TCL_OK);
00065                 }
00066         }
00067         return NsObject::command(argc,argv);
00068 }
00069 
00070 void Estimator::setmeasmod (MeasureMod *measmod)
00071 {
00072         meas_mod_=measmod;
00073 }
00074 
00075 void Estimator::start()
00076 {
00077         avload_=0;
00078         measload_ = 0;
00079         est_timer_.resched(period_);
00080 }
00081 
00082 void Estimator::stop()
00083 {
00084         est_timer_.cancel();
00085 }
00086 
00087 void Estimator::timeout(int)
00088 {
00089         estimate();
00090         est_timer_.resched(period_);
00091 }
00092 
00093 void Estimator_Timer::expire(Event* /*e*/) 
00094 {
00095         est_->timeout(0);
00096 }
00097 
00098 void Estimator::trace(TracedVar* v)
00099 {
00100         char wrk[500];
00101         double *p, newval;
00102 
00103         /* check for right variable */
00104         if (strcmp(v->name(), "\"Estimated Util.\"") == 0) {
00105                 p = &oavload_;
00106         }
00107         else if (strcmp(v->name(), "\"Measured Util.\"") == 0) {
00108                 p = &omeasload_;
00109         }
00110         else {
00111                 fprintf(stderr, "Estimator: unknown trace var %s\n", v->name());
00112                 return;
00113         }
00114 
00115         newval = double(*((TracedDouble*)v));
00116 
00117         if (tchan_) {
00118                 int n;
00119                 double t = Scheduler::instance().clock();
00120                 /* f -t 0.0 -s 1 -a SA -T v -n Num -v 0 -o 0 */
00121                 sprintf(wrk, "f -t %g -s %d -a %s:%d-%d -T v -n %s -v %g -o %g",
00122                         t, src_, actype_, src_, dst_, v->name(), newval, *p);
00123                 n = strlen(wrk);
00124                 wrk[n] = '\n';
00125                 wrk[n+1] = 0;
00126                 (void)Tcl_Write(tchan_, wrk, n+1);
00127                 
00128         }
00129 
00130         *p = newval;
00131 
00132         return;
00133 
00134 
00135 
00136 }
00137 
00138 void Estimator::setactype(const char* type)
00139 {
00140         actype_ = new char[strlen(type)+1];
00141         strcpy(actype_, type);
00142         return;
00143 }

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