xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

timer.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
3 //
4 // This file may be distributed under terms of the GPL
5 //
6 
7 #ifndef _TIMER_H_
8 #define _TIMER_H_
9 
10 //
11 // General purpose interval timer class
12 //
13 // Implemented using BSD derived function gettimeofday for greater resolution
14 //
15 // Author : Mike Romberg
16 
17 #include "timeval.h"
18 #include <sys/time.h>
19 #include <iostream>
20 
21 
22 class Timer {
23 public:
24  Timer( int start = 0 ) { if ( start ) Timer::start(); }
25  ~Timer( void ){}
26 
27  void start( void ) { gettimeofday( &starttime_, NULL ); }
28  void stop( void ) { gettimeofday( &stoptime_, NULL ); }
29 
30  // This one uses doubles as the return value, to avoid
31  // overflow/sign problems.
32  double report_usecs(void) const {
33  return (stoptime_.tv_sec - starttime_.tv_sec) * 1000000.0
34  + stoptime_.tv_usec - starttime_.tv_usec;
35  }
36 
37  std::ostream &printOn(std::ostream &os) const {
38  return os <<"Timer : ["
39  <<"starttime_ = " <<TimeVal(starttime_)
40  <<", stoptime_ = " <<TimeVal(stoptime_)
41  <<", duration = " <<report_usecs() <<" usecs]";
42  }
43 
44 protected:
45  struct timeval starttime_, stoptime_;
46 
47 private:
48 };
49 
50 inline std::ostream &operator<<(std::ostream &os, const Timer &t){
51  return t.printOn(os);
52 }
53 
54 #endif
Definition: timer.h:22
Timer(int start=0)
Definition: timer.h:24
double report_usecs(void) const
Definition: timer.h:32
void start(void)
Definition: timer.h:27
std::ostream & printOn(std::ostream &os) const
Definition: timer.h:37
void stop(void)
Definition: timer.h:28
struct timeval starttime_ stoptime_
Definition: timer.h:45
~Timer(void)
Definition: timer.h:25
std::ostream & operator<<(std::ostream &os, const Timer &t)
Definition: timer.h:50