alpar@511: /* -*- mode: C++; indent-tabs-mode: nil; -*- alpar@511: * alpar@511: * This file is a part of LEMON, a generic C++ optimization library. alpar@511: * alpar@956: * Copyright (C) 2003-2010 alpar@511: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@511: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@511: * alpar@511: * Permission to use, modify and distribute this software is granted alpar@511: * provided that this copyright notice appears in all copies. For alpar@511: * precise terms see the accompanying LICENSE file. alpar@511: * alpar@511: * This software is provided "AS IS" with no warranty of any kind, alpar@511: * express or implied, and with no claim as to its suitability for any alpar@511: * purpose. alpar@511: * alpar@511: */ alpar@511: alpar@511: ///\file alpar@511: ///\brief Some basic non-inline functions and static global data. alpar@511: alpar@511: #include alpar@511: alpar@511: #ifdef WIN32 alpar@511: #ifndef WIN32_LEAN_AND_MEAN alpar@511: #define WIN32_LEAN_AND_MEAN alpar@511: #endif alpar@511: #ifndef NOMINMAX alpar@511: #define NOMINMAX alpar@511: #endif tapolcai@513: #ifdef UNICODE tapolcai@513: #undef UNICODE tapolcai@513: #endif alpar@511: #include tapolcai@513: #ifdef LOCALE_INVARIANT tapolcai@513: #define MY_LOCALE LOCALE_INVARIANT tapolcai@513: #else tapolcai@513: #define MY_LOCALE LOCALE_NEUTRAL tapolcai@513: #endif alpar@511: #else alpar@511: #include alpar@511: #include alpar@1053: #ifndef WIN32 alpar@511: #include alpar@1053: #endif alpar@511: #include alpar@511: #endif alpar@511: alpar@511: #include alpar@511: #include alpar@511: alpar@511: namespace lemon { alpar@511: namespace bits { alpar@511: void getWinProcTimes(double &rtime, alpar@511: double &utime, double &stime, alpar@511: double &cutime, double &cstime) alpar@511: { alpar@511: #ifdef WIN32 alpar@511: static const double ch = 4294967296.0e-7; alpar@511: static const double cl = 1.0e-7; alpar@511: alpar@511: FILETIME system; alpar@511: GetSystemTimeAsFileTime(&system); alpar@511: rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; alpar@511: alpar@511: FILETIME create, exit, kernel, user; alpar@511: if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { alpar@511: utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; alpar@511: stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; alpar@511: cutime = 0; alpar@511: cstime = 0; alpar@511: } else { alpar@511: rtime = 0; alpar@511: utime = 0; alpar@511: stime = 0; alpar@511: cutime = 0; alpar@511: cstime = 0; alpar@511: } alpar@511: #else alpar@511: timeval tv; alpar@511: gettimeofday(&tv, 0); alpar@511: rtime=tv.tv_sec+double(tv.tv_usec)/1e6; alpar@511: alpar@511: tms ts; alpar@511: double tck=sysconf(_SC_CLK_TCK); alpar@511: times(&ts); alpar@511: utime=ts.tms_utime/tck; alpar@511: stime=ts.tms_stime/tck; alpar@511: cutime=ts.tms_cutime/tck; alpar@511: cstime=ts.tms_cstime/tck; alpar@511: #endif alpar@511: } alpar@511: alpar@511: std::string getWinFormattedDate() alpar@511: { alpar@511: std::ostringstream os; alpar@511: #ifdef WIN32 alpar@511: SYSTEMTIME time; alpar@511: GetSystemTime(&time); tapolcai@513: char buf1[11], buf2[9], buf3[5]; alpar@956: if (GetDateFormat(MY_LOCALE, 0, &time, tapolcai@513: ("ddd MMM dd"), buf1, 11) && tapolcai@513: GetTimeFormat(MY_LOCALE, 0, &time, tapolcai@513: ("HH':'mm':'ss"), buf2, 9) && tapolcai@513: GetDateFormat(MY_LOCALE, 0, &time, tapolcai@513: ("yyyy"), buf3, 5)) { alpar@511: os << buf1 << ' ' << buf2 << ' ' << buf3; alpar@511: } alpar@511: else os << "unknown"; alpar@511: #else alpar@511: timeval tv; alpar@511: gettimeofday(&tv, 0); alpar@511: alpar@511: char cbuf[26]; alpar@511: ctime_r(&tv.tv_sec,cbuf); alpar@511: os << cbuf; alpar@511: #endif alpar@511: return os.str(); alpar@511: } alpar@511: alpar@511: int getWinRndSeed() alpar@511: { alpar@511: #ifdef WIN32 alpar@511: FILETIME time; alpar@511: GetSystemTimeAsFileTime(&time); alpar@511: return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime; alpar@511: #else alpar@511: timeval tv; alpar@511: gettimeofday(&tv, 0); alpar@511: return getpid() + tv.tv_sec + tv.tv_usec; alpar@511: #endif alpar@511: } alpar@511: } alpar@511: }