Home | History | Annotate | Download | only in host
      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 #ifndef TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_TIMER_H_
     17 #define TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_TIMER_H_
     18 
     19 #include <chrono>
     20 
     21 #include "tensorflow/stream_executor/stream_executor_internal.h"
     22 
     23 namespace perftools {
     24 namespace gputools {
     25 namespace host {
     26 
     27 class HostTimer : public internal::TimerInterface {
     28  public:
     29   HostTimer() {}
     30   ~HostTimer() override {}
     31 
     32   // Begins the timer at the present point in the stream.
     33   bool Start(Stream *stream);
     34 
     35   // Stops the timer at the present point in the stream.
     36   bool Stop(Stream *stream);
     37 
     38   // Returns the most recent value recorded for a start/stopcycle, in
     39   // microseconds.
     40   uint64 Microseconds() const override;
     41 
     42   // Returns the most recent value recorded for a start/stopcycle, in
     43   // nanoseconds.
     44   uint64 Nanoseconds() const override;
     45 
     46  private:
     47   using clock = std::chrono::high_resolution_clock;
     48 
     49   clock::time_point start_time_;
     50   clock::duration duration_;
     51 
     52   // Actually starts (rather than enqueues starting) the timer.
     53   void StartNow();
     54 
     55   // Actually stops (rather than enqueues stopping) the timer.
     56   void StopNow();
     57 };
     58 
     59 }  // namespace host
     60 }  // namespace gputools
     61 }  // namespace perftools
     62 
     63 #endif  // TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_TIMER_H_
     64