1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "tensorflow/stream_executor/host/host_timer.h" 17 18 #include "tensorflow/stream_executor/platform/logging.h" 19 #include "tensorflow/stream_executor/stream.h" 20 #include "tensorflow/stream_executor/stream_executor_internal.h" 21 22 namespace perftools { 23 namespace gputools { 24 namespace host { 25 26 using std::chrono::duration_cast; 27 28 bool HostTimer::Start(Stream* stream) { 29 return stream->ThenDoHostCallback([this]() { this->StartNow(); }).ok(); 30 } 31 32 bool HostTimer::Stop(Stream* stream) { 33 return stream->ThenDoHostCallback([this]() { this->StopNow(); }).ok(); 34 } 35 36 uint64 HostTimer::Microseconds() const { 37 return duration_cast<std::chrono::microseconds>(duration_).count(); 38 } 39 40 uint64 HostTimer::Nanoseconds() const { 41 return duration_cast<std::chrono::nanoseconds>(duration_).count(); 42 } 43 44 void HostTimer::StartNow() { start_time_ = clock::now(); } 45 46 void HostTimer::StopNow() { duration_ = clock::now() - start_time_; } 47 48 } // namespace host 49 } // namespace gputools 50 } // namespace perftools 51