diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/glean/bindings/private/Numerator.h | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/glean/bindings/private/Numerator.h')
-rw-r--r-- | toolkit/components/glean/bindings/private/Numerator.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/toolkit/components/glean/bindings/private/Numerator.h b/toolkit/components/glean/bindings/private/Numerator.h new file mode 100644 index 0000000000..66b7eef295 --- /dev/null +++ b/toolkit/components/glean/bindings/private/Numerator.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_glean_GleanNumerator_h +#define mozilla_glean_GleanNumerator_h + +#include "mozilla/Maybe.h" +#include "mozilla/Result.h" +#include "nsIGleanMetrics.h" +#include "nsString.h" + +namespace mozilla::glean { + +namespace impl { + +// Actually a RateMetric, but one whose denominator is a CounterMetric external +// to the RateMetric. +class NumeratorMetric { + public: + constexpr explicit NumeratorMetric(uint32_t aId) : mId(aId) {} + + /* + * Increases the numerator by `amount`. + * + * @param aAmount The amount to increase by. Should be positive. + */ + void AddToNumerator(int32_t aAmount = 1) const; + + /** + * **Test-only API** + * + * Gets the currently stored value as a pair of integers. + * + * This function will attempt to await the last parent-process task (if any) + * writing to the the metric's storage engine before returning a value. + * This function will not wait for data from child processes. + * + * This doesn't clear the stored value. + * Parent process only. Panics in child processes. + * + * @param aPingName The (optional) name of the ping to retrieve the metric + * for. Defaults to the first value in `send_in_pings`. + * + * @return value of the stored metric, or Nothing() if there is no value. + */ + Result<Maybe<std::pair<int32_t, int32_t>>, nsCString> TestGetValue( + const nsACString& aPingName = nsCString()) const; + + private: + const uint32_t mId; +}; +} // namespace impl + +class GleanNumerator final : public nsIGleanNumerator { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIGLEANNUMERATOR + + explicit GleanNumerator(uint32_t id) : mNumerator(id){}; + + private: + virtual ~GleanNumerator() = default; + + const impl::NumeratorMetric mNumerator; +}; + +} // namespace mozilla::glean + +#endif /* mozilla_glean_GleanNumerator_h */ |