proxygen
GLog.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-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 
17 #pragma once
18 
19 #include <atomic>
20 #include <chrono>
21 
22 #include <glog/logging.h>
23 
24 #ifndef FB_LOG_EVERY_MS
25 
36 #define FB_LOG_EVERY_MS(severity, milli_interval) \
37  for (decltype(milli_interval) FB_LEM_once = 1, \
38  FB_LEM_interval = (milli_interval); \
39  FB_LEM_once;) \
40  for (::std::chrono::milliseconds::rep FB_LEM_prev, \
41  FB_LEM_now = FB_LEM_interval <= 0 \
42  ? 0 \
43  : ::std::chrono::duration_cast<::std::chrono::milliseconds>( \
44  ::std::chrono::system_clock::now().time_since_epoch()) \
45  .count(); \
46  FB_LEM_once;) \
47  for (static ::std::atomic<::std::chrono::milliseconds::rep> FB_LEM_hist; \
48  FB_LEM_once; \
49  FB_LEM_once = 0) \
50  if (FB_LEM_interval > 0 && \
51  (FB_LEM_now - \
52  (FB_LEM_prev = \
53  FB_LEM_hist.load(std::memory_order_acquire)) < \
54  FB_LEM_interval || \
55  !FB_LEM_hist.compare_exchange_strong(FB_LEM_prev, FB_LEM_now))) { \
56  } else \
57  LOG(severity)
58 
59 #endif