PCMTimer.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00025 //
00026 // Inner includes
00027 //
00028 
00029 #include "../include/PCMTimer.h"
00030 
00031 #include "../include/PCMStringConverter.h"
00032 
00033 namespace ParCompMark
00034 {
00035 
00036   //
00037   // Class constants
00038   //
00039 
00040   const Real Timer::EPSILONDELAY = 0.000001;
00041 
00042   //
00043   // Class variables
00044   //
00045 
00046   Real Timer::mTimeCorrection = 0.0;
00047   Real Timer::mStartTime = 0.0;
00048 
00049   //
00050   // Class methods
00051   //
00052 
00053    std::string Timer::getTimeString(const bool & microseconds, const bool & seconds,
00054                                    const bool & minutes, const bool & hours,
00055                                    const Real & correction)
00056   {
00057         return getTimeDateString(microseconds, seconds, minutes, hours, false, false, false, correction);
00058   }
00059 
00060  /*----------------------------------------------------------------------*/
00061 
00062   std::string Timer::getDateString(const bool & days, const bool & months, const bool & years,
00063                                   const Real & correction)
00064   {
00065         return getTimeDateString(false, false, false, false, days, months, years, correction);
00066   }
00067 
00068  /*----------------------------------------------------------------------*/
00069 
00070   std::string Timer::getTimeDateString(const bool & microseconds, const bool & seconds,
00071                                          const bool & minutes, const bool & hours, const bool & days,
00072                                          const bool & months, const bool & years,
00073                                          const Real & correction)
00074   {
00075         time_t tloc;
00076         struct tm result;
00077 
00078         // Get time in seconds
00079         time(&tloc);
00080 
00081         // Get time in microseconds
00082         Real tloc_ms = getSystemTime();
00083 
00084         // Correct time
00085         tloc += (time_t) correction;
00086         tloc_ms += correction - floor(correction);
00087 
00088         localtime_r(&tloc, &result);
00089 
00090         return (hours ? StringConverter::toString(result.tm_hour) : "") + (minutes ? ":" +
00091                                                                          StringConverter::toString(result.
00092                                                                                                   tm_min) : "") +
00093          (seconds ? ":" + StringConverter::toString(result.tm_min) : "") + (microseconds ? "." +
00094                                                                            StringConverter::
00095 									   toString((tloc_ms -
00096                                                                                          tloc) * 1000000) : "") +
00097          (years ? " " + StringConverter::toString(result.tm_year + 1900) : "") + (months ? "-" +
00098                                                                                   StringConverter::toString(result.
00099                                                                                                            tm_mon +
00100                                                                                                            1) : "")
00101          + (days ? "-" + StringConverter::toString(result.tm_mday) : "");
00102   }
00103 
00104  /*----------------------------------------------------------------------*/
00105 
00106 }