log_histogram_snapshot.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/generic/vector.h>
  4. #include <cmath>
  5. namespace NMonitoring {
  6. constexpr ui32 LOG_HIST_MAX_BUCKETS = 100;
  7. class TLogHistogramSnapshot: public TAtomicRefCount<TLogHistogramSnapshot> {
  8. public:
  9. TLogHistogramSnapshot(double base, ui64 zerosCount, int startPower, TVector<double> buckets)
  10. : Base_(base)
  11. , ZerosCount_(zerosCount)
  12. , StartPower_(startPower)
  13. , Buckets_(std::move(buckets)) {
  14. }
  15. /**
  16. * @return buckets count.
  17. */
  18. ui32 Count() const noexcept {
  19. return Buckets_.size();
  20. }
  21. /**
  22. * @return upper bound for the bucket with particular index.
  23. */
  24. double UpperBound(int index) const noexcept {
  25. return std::pow(Base_, StartPower_ + index);
  26. }
  27. /**
  28. * @return value stored in the bucket with particular index.
  29. */
  30. double Bucket(ui32 index) const noexcept {
  31. return Buckets_[index];
  32. }
  33. /**
  34. * @return nonpositive values count
  35. */
  36. ui64 ZerosCount() const noexcept {
  37. return ZerosCount_;
  38. }
  39. double Base() const noexcept {
  40. return Base_;
  41. }
  42. int StartPower() const noexcept {
  43. return StartPower_;
  44. }
  45. ui64 MemorySizeBytes() const noexcept {
  46. return sizeof(*this) + Buckets_.capacity() * sizeof(double);
  47. }
  48. private:
  49. double Base_;
  50. ui64 ZerosCount_;
  51. int StartPower_;
  52. TVector<double> Buckets_;
  53. };
  54. using TLogHistogramSnapshotPtr = TIntrusivePtr<TLogHistogramSnapshot>;
  55. }
  56. std::ostream& operator<<(std::ostream& os, const NMonitoring::TLogHistogramSnapshot& hist);