proxygen
Counters.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-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 <string>
20 
21 #include <folly/Function.h>
22 #include <folly/Optional.h>
23 #include <folly/Range.h>
24 
25 namespace folly {
26 namespace io {
27 enum class CodecType;
28 } // namespace io
29 
35  COMPRESSIONS = 4,
36  DECOMPRESSIONS = 5,
39 };
40 
42  AVG = 0,
43  SUM = 1,
44 };
45 
61  folly::io::CodecType codecType,
62  folly::StringPiece codecName,
65  CompressionCounterType counterType);
66 
67 namespace detail {
68 
71  public:
74  folly::io::CodecType codecType,
75  folly::StringPiece codecName,
78  CompressionCounterType counterType) {
79  initialize_ = [=]() {
81  codecType, codecName, level, key, counterType);
82  };
83  DCHECK(!initialize_.hasAllocatedMemory());
84  }
85 
86  void operator+=(double sum) {
87  performLazyInit();
88  if (increment_) {
89  increment_(sum);
90  }
91  }
92 
93  void operator++() {
94  *this += 1.0;
95  }
96 
97  void operator++(int) {
98  *this += 1.0;
99  }
100 
102  performLazyInit();
103  return static_cast<bool>(increment_);
104  }
105 
106  private:
108  if (!initialized_) {
109  initialized_ = true;
110  increment_ = initialize_();
111  initialize_ = {};
112  }
113  }
114 
115  bool initialized_{false};
118 };
119 
120 } // namespace detail
121 } // namespace folly
CompressionCounterType
Definition: Counters.h:41
std::atomic< int64_t > sum(0)
void operator+=(double sum)
Definition: Counters.h:86
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
folly::Function< void(double)> increment_
Definition: Counters.h:117
FOLLY_ATTR_WEAK folly::Function< void(double)> makeCompressionCounterHandler(folly::io::CodecType, folly::StringPiece, folly::Optional< int >, CompressionCounterKey, CompressionCounterType)
Definition: Counters.cpp:21
CompressionCounterKey
Definition: Counters.h:30
Wrapper around the makeCompressionCounterHandler() extension point.
Definition: Counters.h:70
CompressionCounter(folly::io::CodecType codecType, folly::StringPiece codecName, folly::Optional< int > level, CompressionCounterKey key, CompressionCounterType counterType)
Definition: Counters.h:73