proxygen
TimeUtil.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <chrono>
19 #include <iosfwd>
20 
22 
23 namespace folly {
24 
34 class TimePoint {
35  public:
36  explicit TimePoint(bool set = true) : tid_(0) {
37  if (set) {
38  reset();
39  }
40  }
41 
42  void reset();
43 
44  bool isUnset() const {
45  return (
46  timeStart_.time_since_epoch().count() == 0 &&
47  timeEnd_.time_since_epoch().count() == 0 && timeWaiting_.count() == 0);
48  }
49 
50  std::chrono::steady_clock::time_point getTime() const {
51  return timeStart_;
52  }
53 
54  std::chrono::steady_clock::time_point getTimeStart() const {
55  return timeStart_;
56  }
57 
58  std::chrono::steady_clock::time_point getTimeEnd() const {
59  return timeStart_;
60  }
61 
62  std::chrono::nanoseconds getTimeWaiting() const {
63  return timeWaiting_;
64  }
65 
66  pid_t getTid() const {
67  return tid_;
68  }
69 
70  private:
71  std::chrono::steady_clock::time_point timeStart_;
72  std::chrono::steady_clock::time_point timeEnd_;
73  std::chrono::nanoseconds timeWaiting_{0};
74  pid_t tid_;
75 };
76 
77 std::ostream& operator<<(std::ostream& os, const TimePoint& timePoint);
78 
79 bool checkTimeout(
80  const TimePoint& start,
81  const TimePoint& end,
82  std::chrono::nanoseconds expected,
83  bool allowSmaller,
84  std::chrono::nanoseconds tolerance = std::chrono::milliseconds(5));
85 } // namespace folly
std::chrono::steady_clock::time_point timeEnd_
Definition: TimeUtil.h:72
std::chrono::steady_clock::time_point getTime() const
Definition: TimeUtil.h:50
std::chrono::nanoseconds getTimeWaiting() const
Definition: TimeUtil.h:62
TimePoint(bool set=true)
Definition: TimeUtil.h:36
bool checkTimeout(const TimePoint &start, const TimePoint &end, nanoseconds expected, bool allowSmaller, nanoseconds tolerance)
Definition: TimeUtil.cpp:241
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::chrono::nanoseconds timeWaiting_
Definition: TimeUtil.h:73
std::chrono::steady_clock::time_point timeStart_
Definition: TimeUtil.h:71
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
pid_t getTid() const
Definition: TimeUtil.h:66
std::chrono::steady_clock::time_point getTimeStart() const
Definition: TimeUtil.h:54
auto start
bool isUnset() const
Definition: TimeUtil.h:44
std::chrono::steady_clock::time_point getTimeEnd() const
Definition: TimeUtil.h:58
std::ostream & operator<<(std::ostream &out, dynamic const &d)
Definition: dynamic-inl.h:1158