00001 /** 00002 \file Robots/LoBot/util/LoTime.C 00003 \brief Time related functions. 00004 */ 00005 00006 // //////////////////////////////////////////////////////////////////// // 00007 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00008 // by the University of Southern California (USC) and the iLab at USC. // 00009 // See http://iLab.usc.edu for information about this project. // 00010 // //////////////////////////////////////////////////////////////////// // 00011 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00012 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00013 // in Visual Environments, and Applications'' by Christof Koch and // 00014 // Laurent Itti, California Institute of Technology, 2001 (patent // 00015 // pending; application number 09/912,225 filed July 23, 2001; see // 00016 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00017 // //////////////////////////////////////////////////////////////////// // 00018 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00019 // // 00020 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00021 // redistribute it and/or modify it under the terms of the GNU General // 00022 // Public License as published by the Free Software Foundation; either // 00023 // version 2 of the License, or (at your option) any later version. // 00024 // // 00025 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00026 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00027 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00028 // PURPOSE. See the GNU General Public License for more details. // 00029 // // 00030 // You should have received a copy of the GNU General Public License // 00031 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00032 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00033 // Boston, MA 02111-1307 USA. // 00034 // //////////////////////////////////////////////////////////////////// // 00035 // 00036 // Primary maintainer for this file: mviswana usc edu 00037 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/util/LoTime.C $ 00038 // $Id: LoTime.C 13838 2010-08-27 20:42:20Z mviswana $ 00039 // 00040 00041 //------------------------------ HEADERS -------------------------------- 00042 00043 // lobot headers 00044 #include "Robots/LoBot/util/LoTime.H" 00045 00046 // Standard C headers 00047 #include <time.h> 00048 00049 // Standard Unix headers 00050 #include <sys/time.h> 00051 00052 //----------------------------- NAMESPACE ------------------------------- 00053 00054 namespace lobot { 00055 00056 //---------------------- TIME RELATED FUNCTIONS ------------------------- 00057 00058 // Current time as number of milliseconds since Unix epoch 00059 long long current_time() 00060 { 00061 struct timeval T ; 00062 if (gettimeofday(&T, 0) == -1) // error getting current time 00063 return 0 ; 00064 return (static_cast<long long>(T.tv_sec) * 1000000L 00065 + static_cast<long long>(T.tv_usec))/1000L ; 00066 } 00067 00068 // Uniform start-up time-stamp string for log files, directory names, etc. 00069 // 00070 // WARNING: NOT THREAD SAFE! 00071 const char* startup_timestamp_str() 00072 { 00073 static char app_start_time[20] ; 00074 if (app_start_time[0] == '\0') 00075 { 00076 time_t t = time(0) ; 00077 struct tm now ; 00078 strftime(app_start_time, sizeof(app_start_time), 00079 "%Y%m%d-%H%M%S", localtime_r(&t, &now)) ; 00080 } 00081 return app_start_time ; 00082 } 00083 00084 //----------------------------------------------------------------------- 00085 00086 } // end of namespace encapsulating this file's definitions 00087 00088 /* So things look consistent in everyone's emacs... */ 00089 /* Local Variables: */ 00090 /* indent-tabs-mode: nil */ 00091 /* End: */