diff options
author | Viacheslav Kovalevskyi <vkovalevskyi@google.com> | 2017-01-20 18:13:43 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-01-20 18:26:48 -0800 |
commit | 6e492242317c6940f0d7fd8948b14c9d38245cbc (patch) | |
tree | 0939075b2255ee9d460f46305f7cb38854532d0e /tensorflow/core/platform/windows | |
parent | 44042c876019d0e869fe75b93375de816304b9dc (diff) |
LogMesssage now includes a timestamp as beginning of a message.
Before:
I tensorflow/core/kernels/logging_ops.cc:79] [3]
I tensorflow/core/kernels/logging_ops.cc:79] [4]
After:
2016-11-15 21:01:25: I tensorflow/core/kernels/logging_ops.cc:79] [3]
2016-11-15 21:01:25: I tensorflow/core/kernels/logging_ops.cc:79] [4]
Fix for #2076
Change: 145150413
Diffstat (limited to 'tensorflow/core/platform/windows')
-rw-r--r-- | tensorflow/core/platform/windows/env.cc | 29 | ||||
-rw-r--r-- | tensorflow/core/platform/windows/env_time.cc | 82 |
2 files changed, 82 insertions, 29 deletions
diff --git a/tensorflow/core/platform/windows/env.cc b/tensorflow/core/platform/windows/env.cc index 904d06e2a9..b8e1c91616 100644 --- a/tensorflow/core/platform/windows/env.cc +++ b/tensorflow/core/platform/windows/env.cc @@ -75,35 +75,6 @@ class WindowsEnv : public Env { return PathMatchSpec(path.c_str(), pattern.c_str()) == TRUE; } - uint64 NowMicros() override { - if (GetSystemTimePreciseAsFileTime_ != NULL) { - // GetSystemTimePreciseAsFileTime function is only available in latest - // versions of Windows, so we need to check for its existence here. - // All std::chrono clocks on Windows proved to return - // values that may repeat, which is not good enough for some uses. - constexpr int64_t kUnixEpochStartTicks = 116444736000000000i64; - constexpr int64_t kFtToMicroSec = 10; - - // This interface needs to return system time and not - // just any microseconds because it is often used as an argument - // to TimedWait() on condition variable - FILETIME system_time; - GetSystemTimePreciseAsFileTime_(&system_time); - - LARGE_INTEGER li; - li.LowPart = system_time.dwLowDateTime; - li.HighPart = system_time.dwHighDateTime; - // Subtract unix epoch start - li.QuadPart -= kUnixEpochStartTicks; - // Convert to microsecs - li.QuadPart /= kFtToMicroSec; - return li.QuadPart; - } - using namespace std::chrono; - return duration_cast<microseconds>( - system_clock::now().time_since_epoch()).count(); - } - void SleepForMicroseconds(int64 micros) override { Sleep(micros / 1000); } Thread* StartThread(const ThreadOptions& thread_options, const string& name, diff --git a/tensorflow/core/platform/windows/env_time.cc b/tensorflow/core/platform/windows/env_time.cc new file mode 100644 index 0000000000..765dbc8504 --- /dev/null +++ b/tensorflow/core/platform/windows/env_time.cc @@ -0,0 +1,82 @@ +/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/core/platform/env_time.h" + +#include <time.h> + +namespace tensorflow { + +namespace { + +class WindowsEnvTime : public EnvTime { + public: + WindowsEnvTime() : GetSystemTimePreciseAsFileTime_(NULL) { + // GetSystemTimePreciseAsFileTime function is only available in the latest + // versions of Windows. For that reason, we try to look it up in + // kernel32.dll at runtime and use an alternative option if the function + // is not available. + HMODULE module = GetModuleHandle("kernel32.dll"); + if (module != NULL) { + auto func = (FnGetSystemTimePreciseAsFileTime)GetProcAddress( + module, "GetSystemTimePreciseAsFileTime"); + GetSystemTimePreciseAsFileTime_ = func; + } + } + + uint64 NowMicros() override { + if (GetSystemTimePreciseAsFileTime_ != NULL) { + // GetSystemTimePreciseAsFileTime function is only available in latest + // versions of Windows, so we need to check for its existence here. + // All std::chrono clocks on Windows proved to return + // values that may repeat, which is not good enough for some uses. + constexpr int64_t kUnixEpochStartTicks = 116444736000000000i64; + constexpr int64_t kFtToMicroSec = 10; + + // This interface needs to return system time and not + // just any microseconds because it is often used as an argument + // to TimedWait() on condition variable + FILETIME system_time; + GetSystemTimePreciseAsFileTime_(&system_time); + + LARGE_INTEGER li; + li.LowPart = system_time.dwLowDateTime; + li.HighPart = system_time.dwHighDateTime; + // Subtract unix epoch start + li.QuadPart -= kUnixEpochStartTicks; + // Convert to microsecs + li.QuadPart /= kFtToMicroSec; + return li.QuadPart; + } + using namespace std::chrono; + return duration_cast<microseconds>(system_clock::now().time_since_epoch()) + .count(); + } + + void SleepForMicroseconds(int64 micros) override { Sleep(micros / 1000); } + + private: + typedef VOID(WINAPI* FnGetSystemTimePreciseAsFileTime)(LPFILETIME); + FnGetSystemTimePreciseAsFileTime GetSystemTimePreciseAsFileTime_; +}; + +} // namespace + +EnvTime* EnvTime::Default() { + static EnvTime* default_time_env = new WindowsEnvTime; + return default_time_env; +} + +} // namespace tensorflow |