Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决win32 X64下的gettimeofday非常缓慢的问题 #51

Merged
merged 7 commits into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions docs/quick_start_win32_vs2015.md
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的标题应该为 #####


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