Move assign patch out
[hiphop-php.git] / hphp / runtime / base / perf-warning-inl.h
blob2e5b08701510b863091d5a971a488f3e1b4fb4c3
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2016 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/runtime-option.h"
19 #include <folly/Random.h>
21 namespace HPHP {
23 template<typename F>
24 void logPerfWarningImpl(folly::StringPiece event, int64_t priority,
25 int64_t rate, F fillCols) {
26 auto const effectiveRate = rate * RuntimeOption::EvalPerfWarningSampleRate;
27 if (effectiveRate > std::numeric_limits<uint32_t>::max()) return;
28 if (!StructuredLog::coinflip(effectiveRate)) return;
30 StructuredLogEntry cols;
31 fillCols(cols);
32 cols.setStr("event_name", event);
33 cols.setInt("priority", priority);
34 StructuredLog::log("hhvm_perf_warning", cols);
37 template<typename F>
38 void logPerfWarning(folly::StringPiece event, F fillCols) {
39 logPerfWarningImpl(event, 1, kDefaultPerfWarningRate, fillCols);
41 template<typename F>
42 void logPerfWarning(folly::StringPiece event, int64_t rate, F fillCols) {
43 logPerfWarningImpl(event, 1, rate, fillCols);
46 template<typename F>
47 void logLowPriPerfWarning(folly::StringPiece event, F fillCols) {
48 logPerfWarningImpl(event, 0, kDefaultPerfWarningRate, fillCols);
50 template<typename F>
51 void logLowPriPerfWarning(folly::StringPiece event, int64_t rate, F fillCols) {
52 logPerfWarningImpl(event, 0, rate, fillCols);
55 template<typename AHM>
56 void checkAHMSubMaps(const AHM& map, folly::StringPiece mapName,
57 std::atomic<bool>& done) {
58 if (LIKELY(map.numSubMaps() == 1) ||
59 done.load(std::memory_order_acquire) ||
60 done.exchange(true, std::memory_order_acq_rel)) {
61 return;
64 logAHMSubMapWarning(mapName);