Skip to content

Commit

Permalink
Merge pull request #51 from yuangu/master
Browse files Browse the repository at this point in the history
Fix win32 X64 gettimeofday performance problem and modify the documents.
  • Loading branch information
zieckey authored Jul 4, 2017
2 parents b52673e + 29e6bc2 commit 35f3935
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ Prerequisites:

- Visual Studio 2015 Update 3 or
- Visual Studio 2017
- CMake 3.8.0 or higher (note: downloaded automatically if not found)
- CMake 3.8.0 (note: downloaded automatically if not found, but version must be 3.8.x)
- git.exe available in your path. You can download and install it from [https://git-for-windows.github.io/]
- vcpkg. You can download and install it from [https://github.com/Microsoft/vcpkg]. Commits c5daa93506b616d253e257488ecc385271238e2a tests OK. Following [https://github.com/Microsoft/vcpkg#quick-start](https://github.com/Microsoft/vcpkg#quick-start) to install [vcpkg]. This document assumes that [vcpkg] is installed at `d:\git\vcpkg`.

#### Install dependent libraries by using vcpkg

Use [vcpkg] to install libevent,glog,gtest,gflags.

##### for win_x32:

D:\git\vcpkg>vcpkg install gflags
D:\git\vcpkg>vcpkg install glog
D:\git\vcpkg>vcpkg install openssl
D:\git\vcpkg>vcpkg install libevent-2.x

##### for win_x64:

D:\git\vcpkg>vcpkg install gflags:x64-windows
D:\git\vcpkg>vcpkg install glog:x64-windows
D:\git\vcpkg>vcpkg install openssl:x64-windows
D:\git\vcpkg>vcpkg install libevent-2.x:x64-windows


#### Download the source code of evpp

$ git clone https://github.com/Qihoo360/evpp
Expand All @@ -36,9 +47,16 @@ Using the default vs solution file:

Or, we can use CMake to compile the whole projects on WIDNOWS command line console (This does not work on unix shell):

##### for win_x32:
D:\360.git\evpp>md build
D:\360.git\evpp>cd build
D:\360.git\evpp\build>cmake -DCMAKE_TOOLCHAIN_FILE=your_vcpkg_path/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 14 2015" ..
D:\360.git\evpp\build>start safe-evpp.sln

##### for win_x64:
D:\360.git\evpp>md build
D:\360.git\evpp>cd build
D:\360.git\evpp\build>cmake -DCMAKE_TOOLCHAIN_FILE=D:/git/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 14 2015" ..
D:\360.git\evpp\build>cmake -DCMAKE_TOOLCHAIN_FILE=your_vcpkg_path/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 14 2015 Win64" ..
D:\360.git\evpp\build>start safe-evpp.sln

#### Run the unit tests
Expand All @@ -61,3 +79,7 @@ That will install [evpp] in your local machine. And then, you can use [evpp] in
[https://git-for-windows.github.io/]:https://git-for-windows.github.io/






39 changes: 25 additions & 14 deletions evpp/gettimeofday.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@
#ifndef H_GETTIMEOFDAY
#define H_GETTIMEOFDAY
inline int gettimeofday(struct timeval* tp, void* tzp) {
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm.tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = (long)clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
uint64_t intervals;
FILETIME ft;

GetSystemTimeAsFileTime(&ft);

/*
* A file time is a 64-bit value that represents the number
* of 100-nanosecond intervals that have elapsed since
* January 1, 1601 12:00 A.M. UTC.
*
* Between January 1, 1970 (Epoch) and January 1, 1601 there were
* 134744 days,
* 11644473600 seconds or
* 11644473600,000,000,0 100-nanosecond intervals.
*
* See also MSKB Q167296.
*/

intervals = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
intervals -= 116444736000000000;

tp->tv_sec = (long)(intervals / 10000000);
tp->tv_usec = (long)((intervals % 10000000) / 10);


return (0);
}
#endif // end of H_GETTIMEOFDAY
Expand Down

0 comments on commit 35f3935

Please sign in to comment.