timing.C

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 // $Id: timing.C,v 1.26 2007/05/30 19:20:36 legendre Exp $
00032 
00033 #include "common/h/Timer.h"
00034 #include "common/h/timing.h"
00035 #include "common/h/Time.h"
00036 
00037 /* time retrieval function definitions */
00038 
00039 timeStamp getCurrentTime() {
00040   return timeStamp(getRawTime1970(), timeUnit::us(), timeBase::b1970());
00041 }
00042 
00043 #if !defined(os_windows)
00044 
00045 // returns us since 1970
00046 int64_t getRawTime1970() {
00047   struct timeval tv;
00048   if (-1 == gettimeofday(&tv, NULL)) {
00049     perror("getCurrentTime gettimeofday()");
00050     return 0;
00051   }
00052   int64_t result = tv.tv_sec;
00053   result *= 1000000;
00054   result += tv.tv_usec;
00055   return result;
00056 }
00057 #endif
00058 
00059 
00060 // Shows the time until the auxillary fraction conversion algorithm
00061 // will be used in order to get around internal rollover 
00062 // (see util/src/Time.C).  Auxiliary algorithm requires an additional
00063 // 64bit integer div, mult, modulas, addition.  Conversion efficiency
00064 // to this degree most likely isn't relevant.
00065 //
00066 //         Timing statistics for a 1999 MHz machine
00067 // fract numer    MHz precision     time until aux alg   time err/year
00068 //    1000        1 MHz             7.6 weeks            2.2 hrs
00069 //   10000        100,000 Hz        5.3 days             13 minutes
00070 //  100000         10,000 Hz        12 hrs               1.3 minutes   *
00071 // 1000000          1,000 Hz        1.2 hrs              8 seconds
00072 //
00073 //         Timing statistics for a  199 MHz machine
00074 // fract numer    MHz precision     time until aux alg   time err/year
00075 //    1000        1 MHz             7.6 weeks            22 hrs
00076 //   10000        100,000 Hz        5.3 days             2.2 hrs
00077 //  100000         10,000 Hz        12 hrs               13 minutes    *
00078 // 1000000          1,000 Hz        1.2 hrs              1.3 minutes
00079 //
00080 // * currently using
00081 // 10,000 Hz precision, 12 hrs time until aux alg, seems like a good compromise
00082 
00083 // access only through getCyclesPerSecond()
00084 timeUnit *pCyclesPerSecond = NULL;
00085 
00086 void initCyclesPerSecond() {
00087   double cpsHz = calcCyclesPerSecondOS();
00088   double cpsTTHz = cpsHz / 10000.0;
00089   // round it
00090   cpsTTHz = cpsTTHz + .5;
00091   int64_t tenThousHz = static_cast<int64_t>(cpsTTHz);
00092   // in case of multiple calls
00093   if(pCyclesPerSecond != NULL) delete pCyclesPerSecond;
00094   pCyclesPerSecond = new timeUnit(fraction(100000, tenThousHz));
00095 }
00096 
00097 timeUnit getCyclesPerSecond() {
00098   if(pCyclesPerSecond == NULL) { 
00099     cerr << "getCyclesPerSecond(): cycles per second hasn't been initialized\n";
00100     assert(0);
00101   }
00102   return (*pCyclesPerSecond);
00103 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1