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 #ifdef LOCALE_INVARIANT
36 #define MY_LOCALE LOCALE_INVARIANT
38 #define MY_LOCALE LOCALE_NEUTRAL
43 #include <sys/times.h>
52 void getWinProcTimes(double &rtime,
53 double &utime, double &stime,
54 double &cutime, double &cstime)
57 static const double ch = 4294967296.0e-7;
58 static const double cl = 1.0e-7;
61 GetSystemTimeAsFileTime(&system);
62 rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
64 FILETIME create, exit, kernel, user;
65 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
66 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
67 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
80 rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
83 double tck=sysconf(_SC_CLK_TCK);
85 utime=ts.tms_utime/tck;
86 stime=ts.tms_stime/tck;
87 cutime=ts.tms_cutime/tck;
88 cstime=ts.tms_cstime/tck;
92 std::string getWinFormattedDate()
94 std::ostringstream os;
98 char buf1[11], buf2[9], buf3[5];
99 if (GetDateFormat(MY_LOCALE, 0, &time,
100 ("ddd MMM dd"), buf1, 11) &&
101 GetTimeFormat(MY_LOCALE, 0, &time,
102 ("HH':'mm':'ss"), buf2, 9) &&
103 GetDateFormat(MY_LOCALE, 0, &time,
104 ("yyyy"), buf3, 5)) {
105 os << buf1 << ' ' << buf2 << ' ' << buf3;
107 else os << "unknown";
110 gettimeofday(&tv, 0);
113 ctime_r(&tv.tv_sec,cbuf);
123 GetSystemTimeAsFileTime(&time);
124 return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
127 gettimeofday(&tv, 0);
128 return getpid() + tv.tv_sec + tv.tv_usec;