time_tracker.h

00001 /*
00002  *  Copyright (C) 2005 M.J. Zaki <zaki@cs.rpi.edu> Rensselaer Polytechnic Institute
00003  *  Written by parimi@cs.rpi.edu
00004  *  Updated by chaojv@cs.rpi.edu, alhasan@cs.rpi.edu, salems@cs.rpi.edu
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 #ifndef _TT_H
00021 #define _TT_H
00022 
00023 #include <sys/time.h>
00024 #include <unistd.h>
00025 
00026 #define microsec 1000000.0
00027 
00032 class time_tracker {
00033  private:
00034   struct timeval start_time;
00035   struct timeval stop_time;
00036   bool  running;
00037   double curr_time;
00038  public:
00039   time_tracker() {
00040     running=false;
00041     curr_time=0;
00042   }
00043 
00045   void start() {
00046     gettimeofday(&start_time, (struct timezone *)0);
00047     running=true;
00048   }
00049 
00051   void stop() {
00052     double st, en;
00053     if (!running) return;
00054     else {
00055       gettimeofday(&stop_time, (struct timezone *)0);
00056       st = start_time.tv_sec + (start_time.tv_usec/microsec);
00057       en = stop_time.tv_sec + (stop_time.tv_usec/microsec);
00058       running=false;
00059       curr_time+=en-st;
00060     }
00061   }
00062 
00063   double print() const
00064   { return curr_time; }
00065 };
00066 
00067 #endif

Generated on Wed Jul 26 14:01:08 2006 for DMTL by  doxygen 1.4.7