1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
20 ///\brief Some basic non-inline functions and static global data.
22 #include<lemon/bits/windows.h>
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
35 #include <sys/times.h>
44 void getWinProcTimes(double &rtime,
45 double &utime, double &stime,
46 double &cutime, double &cstime)
49 static const double ch = 4294967296.0e-7;
50 static const double cl = 1.0e-7;
53 GetSystemTimeAsFileTime(&system);
54 rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
56 FILETIME create, exit, kernel, user;
57 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
58 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
59 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
72 rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
75 double tck=sysconf(_SC_CLK_TCK);
77 utime=ts.tms_utime/tck;
78 stime=ts.tms_stime/tck;
79 cutime=ts.tms_cutime/tck;
80 cstime=ts.tms_cstime/tck;
84 std::string getWinFormattedDate()
86 std::ostringstream os;
90 #if defined(_MSC_VER) && (_MSC_VER < 1500)
91 LPWSTR buf1, buf2, buf3;
92 if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
93 L"ddd MMM dd", buf1, 11) &&
94 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
95 L"HH':'mm':'ss", buf2, 9) &&
96 GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
98 os << buf1 << ' ' << buf2 << ' ' << buf3;
101 char buf1[11], buf2[9], buf3[5];
102 if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
103 "ddd MMM dd", buf1, 11) &&
104 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
105 "HH':'mm':'ss", buf2, 9) &&
106 GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
108 os << buf1 << ' ' << buf2 << ' ' << buf3;
111 else os << "unknown";
114 gettimeofday(&tv, 0);
117 ctime_r(&tv.tv_sec,cbuf);
127 GetSystemTimeAsFileTime(&time);
128 return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
131 gettimeofday(&tv, 0);
132 return getpid() + tv.tv_sec + tv.tv_usec;