| 1 | #cxx . . $ `<file>/src/include/thresholdsampler.hpp`/pragma once |
| 2 | #include <unistd.h> |
| 3 | |
| 4 | #include <random> |
| 5 | |
| 6 | /** |
| 7 | * @brief "triggers" samples periodically when |increments-decrements| > |
| 8 | * SAMPLE_INTERVAL |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #define PRINT_STATScxx . . $ `src/include/thresholdsampler.hpp:12:9`! 0 |
| 13 | |
| 14 | class ThresholdSamplercxx . . $ ThresholdSampler# { |
| 15 | public: |
| 16 | /** |
| 17 | * @brief Construct a new ThresholdSampler object |
| 18 | * |
| 19 | */ |
| 20 | ThresholdSamplercxx . . $ ThresholdSampler#ThresholdSampler(2c44cd906ae4e829).(uint64_tcxx . . $ uint64_t# SAMPLE_INTERVAL) |
| 21 | : _sampleIntervalcxx . . $ ThresholdSampler#_sampleInterval.(SAMPLE_INTERVAL), allocscxx . . $ ThresholdSampler#allocs.(0), freescxx . . $ ThresholdSampler#frees.(0) { |
| 22 | resetcxx . . $ ThresholdSampler#reset(49f6e7a06ebc5aa8).(); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @brief decrement by the sample amount, triggering an interval reset when we |
| 27 | * cross the threshold |
| 28 | * |
| 29 | * @param sample the amount to decrement the sample interval by |
| 30 | * @return bool true iff sampled |
| 31 | */ |
| 32 | inline bool decrementcxx . . $ ThresholdSampler#decrement(9031ac04415d63cc).(uint64_tcxx . . $ uint64_t# sample, void*, size_t& ret) { |
| 33 | _decrementscxx . . $ ThresholdSampler#_decrements. += sample; |
| 34 | if (unlikelycxx . . $ `src/include/common.hpp:8:9`!(_decrements >= _increments + _sampleInterval)) { |
| 35 | #if PRINT_STATScxx . . $ `src/include/thresholdsampler.hpp:12:9`! |
| 36 | printf_("[%d] DEALLOC DECREMENT: %lu, %lu -> %lu\n", getpid(), |
| 37 | _decrements, _increments, _decrements - _increments); |
| 38 | #endif |
| 39 | ret = _decrementscxx . . $ ThresholdSampler#_decrements. - _incrementscxx . . $ ThresholdSampler#_increments.; |
| 40 | resetcxx . . $ ThresholdSampler#reset(49f6e7a06ebc5aa8).(); |
| 41 | freescxx . . $ ThresholdSampler#frees. += ret; |
| 42 | return true; |
| 43 | } |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @brief increment by the sample amount, triggering an interval reset when we |
| 49 | * cross the threshold |
| 50 | * |
| 51 | * @param sample the amount to decrement the sample interval by |
| 52 | * @return bool true iff sampled |
| 53 | */ |
| 54 | inline bool incrementcxx . . $ ThresholdSampler#increment(9031ac04415d63cc).(uint64_tcxx . . $ uint64_t# sample, void*, size_t& ret) { |
| 55 | _incrementscxx . . $ ThresholdSampler#_increments. += sample; |
| 56 | if (unlikelycxx . . $ `src/include/common.hpp:8:9`!(_increments >= _decrements + _sampleInterval)) { |
| 57 | ret = _incrementscxx . . $ ThresholdSampler#_increments. - _decrementscxx . . $ ThresholdSampler#_decrements.; |
| 58 | #if PRINT_STATScxx . . $ `src/include/thresholdsampler.hpp:12:9`! |
| 59 | printf_("[%d] ALLOC INCREMENT: %lu, %lu -> %lu\n", getpid(), _decrements, |
| 60 | _increments, _increments - _decrements); |
| 61 | #endif |
| 62 | resetcxx . . $ ThresholdSampler#reset(49f6e7a06ebc5aa8).(); |
| 63 | allocscxx . . $ ThresholdSampler#allocs. += ret; |
| 64 | return true; |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | void resetcxx . . $ ThresholdSampler#reset(49f6e7a06ebc5aa8).() { |
| 71 | _incrementscxx . . $ ThresholdSampler#_increments. = 0; |
| 72 | _decrementscxx . . $ ThresholdSampler#_decrements. = 0; |
| 73 | #if PRINT_STATScxx . . $ `src/include/thresholdsampler.hpp:12:9`! |
| 74 | printf_("FOOTPRINT = %lu\n", allocs - frees); |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | const uint64_tcxx . . $ uint64_t# _sampleIntervalcxx . . $ ThresholdSampler#_sampleInterval.; /// the current sample interval |
| 79 | uint64_tcxx . . $ uint64_t# _incrementscxx . . $ ThresholdSampler#_increments.; /// the number of increments since the last sample |
| 80 | /// interval reset |
| 81 | uint64_tcxx . . $ uint64_t# _decrementscxx . . $ ThresholdSampler#_decrements.; /// the number of decrements since the last sample |
| 82 | /// interval reset |
| 83 | uint64_tcxx . . $ uint64_t# allocscxx . . $ ThresholdSampler#allocs.; |
| 84 | uint64_tcxx . . $ uint64_t# freescxx . . $ ThresholdSampler#frees.; |
| 85 | }; |