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

Timer.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1.1.1 $
00022 // $Date: 2000/09/15 08:23:30 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/utility/Timer.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/utility/Timer.C
00027 //
00028 // Written: fmk 
00029 // Created: Mar 1997
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for Timer.
00033 // Timer is a stopwatch.
00034 //
00035 // What: "@(#) Timer.h, revA"
00036 
00037 
00038 
00039 #include<Timer.h>
00040 #include <bool.h>
00041 
00042 #ifdef NOW
00043 extern "C" int getrusage(int who, struct rusage *rusage);
00044 #endif
00045 
00046 #ifndef CLK_TCK
00047 #define CLK_TCK _sysconf(3)
00048 #endif
00049 
00050 Timer::Timer() 
00051 {
00052 #ifdef _WIN32
00053     // fill in later
00054 #else    
00055     r1us = &r1usage;
00056     r2us = &r2usage;
00057 #endif
00058 }
00059 
00060 Timer::~Timer()
00061 { 
00062 
00063 }
00064 
00065 void 
00066 Timer::start(void)
00067 {
00068 #ifdef _WIN32
00069     // fill in later
00070 #else        
00071     t1 = times(&tmsstart);
00072     getrusage(0,r1us);
00073 #endif
00074 }
00075 
00076 void 
00077 Timer::pause(void)
00078 {
00079 #ifdef _WIN32
00080     // fill in later
00081 #else        
00082     t2 = times(&tmsend);
00083     getrusage(0,r2us);    
00084 #endif
00085 } 
00086 
00087 
00088 double
00089 Timer::getReal(void) const
00090 {
00091 #ifdef _WIN32
00092     // fill in later
00093     return 0.0;
00094 #else        
00095     long clktck = CLK_TCK;    
00096     double Real = (t2-t1)/(double) clktck;
00097     return Real;
00098 #endif
00099 }    
00100 
00101 double
00102 Timer::getCPU(void) const
00103 {
00104 #ifdef _WIN32
00105     // fill in later
00106     return 0.0;
00107 #else        
00108     long clktck = CLK_TCK;
00109     double CPU  = (tmsend.tms_utime - tmsstart.tms_utime)/(double) clktck;    
00110     return CPU;
00111 #endif    
00112 }    
00113 
00114 int
00115 Timer::getNumPageFaults(void) const
00116 {
00117 #ifdef _WIN32
00118     // fill in later
00119     return 0;
00120 #else        
00121     int r2yes = r2us->ru_majflt;
00122     int r1yes = r1us->ru_majflt;
00123     return r2yes-r1yes;
00124 #endif
00125 }    
00126 
00127 
00128 
00129 void 
00130 Timer::Print(ostream &s) const
00131 {
00132 #ifdef _WIN32
00133     // fill in later
00134 #else        
00135     long clktck = CLK_TCK;
00136     double Real = (t2-t1)/(double) clktck;
00137     double CPU  = (tmsend.tms_utime - tmsstart.tms_utime)/(double) clktck;
00138     double System  = (tmsend.tms_stime - tmsstart.tms_stime)/(double) clktck;
00139     s << endl;
00140     s << "TIME(sec) Real: " << Real << "  CPU: " << CPU;
00141     s << "   System: " << System << endl;
00142 
00143     int r2no = r2us->ru_minflt;
00144     int r2yes = r2us->ru_majflt;
00145     int r1no = r1us->ru_minflt;
00146     int r1yes = r1us->ru_majflt;
00147     int r1page = r1no + r1yes;
00148     int r2page = r2no + r2yes;
00149     
00150     s << "PAGE FAULTS: " << r2page-r1page << " (NO i/o: ";
00151     s << r2no-r1no << " YES i/o " << r2yes-r1yes << ") ";
00152 
00153     r2no = r2us->ru_nivcsw;
00154     r2yes = r2us->ru_nvcsw;
00155     r1no = r1us->ru_nivcsw;
00156     r1yes = r1us->ru_nvcsw;
00157     r1page = r1no + r1yes;
00158     r2page = r2no + r2yes;
00159 
00160     s << "CONTEXT SWITCHES " << r2page-r1page << " (Invol: ";
00161     s << r2no-r1no << " Voluntary " << r2yes-r1yes << ") ";
00162 
00163     r2no = r2us->ru_nswap;
00164     r1no = r1us->ru_nswap;
00165     r2yes = r2us->ru_maxrss;
00166     
00167     s << "Swapped: " << r2no-r1no << " Max Res Set Size: " << r2yes << endl;
00168     s << endl;
00169 #endif    
00170 }    
00171 
00172 ostream &operator<<(ostream &s, const Timer &E)
00173 {
00174     E.Print(s);
00175     return s;
00176 }
00177 
00178 
Copyright Contact Us