#include "base/metrics/histogram.h"
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <atomic>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/dummy_histogram.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/metrics_hashes.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/metrics/persistent_memory_allocator.h"
#include "base/metrics/sample_vector.h"
#include "base/metrics/statistics_recorder.h"
#include "base/notreached.h"
#include "base/pickle.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/values.h"
#include "build/build_config.h"
namespace base {
namespace {
bool ReadHistogramArguments(PickleIterator* iter,
std::string* histogram_name,
int* flags,
int* declared_min,
int* declared_max,
size_t* bucket_count,
uint32_t* range_checksum) { … }
bool ValidateRangeChecksum(const HistogramBase& histogram,
uint32_t range_checksum) { … }
}
Count;
Sample;
class Histogram::Factory { … };
HistogramBase* Histogram::Factory::Build() { … }
HistogramBase* Histogram::FactoryGet(std::string_view name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryTimeGet(std::string_view name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryMicrosecondsTimeGet(std::string_view name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryGet(const std::string& name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryTimeGet(const std::string& name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryMicrosecondsTimeGet(const std::string& name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryGet(const char* name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryTimeGet(const char* name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryMicrosecondsTimeGet(const char* name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
std::unique_ptr<HistogramBase> Histogram::PersistentCreate(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta) { … }
void Histogram::InitializeBucketRanges(Sample minimum,
Sample maximum,
BucketRanges* ranges) { … }
const int Histogram::kCommonRaceBasedCountMismatch = …;
uint32_t Histogram::FindCorruption(const HistogramSamples& samples) const { … }
const BucketRanges* Histogram::bucket_ranges() const { … }
Sample Histogram::declared_min() const { … }
Sample Histogram::declared_max() const { … }
Sample Histogram::ranges(size_t i) const { … }
size_t Histogram::bucket_count() const { … }
bool Histogram::InspectConstructionArguments(std::string_view name,
Sample* minimum,
Sample* maximum,
size_t* bucket_count) { … }
uint64_t Histogram::name_hash() const { … }
HistogramType Histogram::GetHistogramType() const { … }
bool Histogram::HasConstructionArguments(Sample expected_minimum,
Sample expected_maximum,
size_t expected_bucket_count) const { … }
void Histogram::Add(int value) { … }
void Histogram::AddCount(int value, int count) { … }
std::unique_ptr<HistogramSamples> Histogram::SnapshotSamples() const { … }
std::unique_ptr<HistogramSamples> Histogram::SnapshotUnloggedSamples() const { … }
void Histogram::MarkSamplesAsLogged(const HistogramSamples& samples) { … }
std::unique_ptr<HistogramSamples> Histogram::SnapshotDelta() { … }
std::unique_ptr<HistogramSamples> Histogram::SnapshotFinalDelta() const { … }
void Histogram::AddSamples(const HistogramSamples& samples) { … }
bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { … }
base::Value::Dict Histogram::ToGraphDict() const { … }
void Histogram::SerializeInfoImpl(Pickle* pickle) const { … }
Histogram::Histogram(const char* name, const BucketRanges* ranges)
: … { … }
Histogram::Histogram(const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta)
: … { … }
Histogram::~Histogram() = default;
const std::string Histogram::GetAsciiBucketRange(size_t i) const { … }
HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) { … }
HistogramBase* Histogram::FactoryGetInternal(std::string_view name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryTimeGetInternal(std::string_view name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* Histogram::FactoryMicrosecondsTimeGetInternal(
std::string_view name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
std::unique_ptr<SampleVector> Histogram::SnapshotAllSamples() const { … }
std::unique_ptr<SampleVector> Histogram::SnapshotUnloggedSamplesImpl() const { … }
Value::Dict Histogram::GetParameters() const { … }
class LinearHistogram::Factory : public Histogram::Factory { … };
LinearHistogram::~LinearHistogram() = default;
HistogramBase* LinearHistogram::FactoryGet(std::string_view name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::FactoryTimeGet(std::string_view name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::FactoryGet(const std::string& name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::FactoryGet(const char* name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::FactoryTimeGet(const char* name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta) { … }
HistogramBase* LinearHistogram::FactoryGetWithRangeDescription(
std::string_view name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags,
const DescriptionPair descriptions[]) { … }
HistogramType LinearHistogram::GetHistogramType() const { … }
LinearHistogram::LinearHistogram(const char* name, const BucketRanges* ranges)
: … { … }
LinearHistogram::LinearHistogram(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta)
: … { … }
const std::string LinearHistogram::GetAsciiBucketRange(size_t i) const { … }
void LinearHistogram::InitializeBucketRanges(Sample minimum,
Sample maximum,
BucketRanges* ranges) { … }
HistogramBase* LinearHistogram::FactoryGetInternal(std::string_view name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::FactoryTimeGetInternal(std::string_view name,
TimeDelta minimum,
TimeDelta maximum,
size_t bucket_count,
int32_t flags) { … }
HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) { … }
ScaledLinearHistogram::ScaledLinearHistogram(std::string_view name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t scale,
int32_t flags)
: … { … }
ScaledLinearHistogram::ScaledLinearHistogram(const std::string& name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t scale,
int32_t flags)
: … { … }
ScaledLinearHistogram::ScaledLinearHistogram(const char* name,
Sample minimum,
Sample maximum,
size_t bucket_count,
int32_t scale,
int32_t flags)
: … { … }
ScaledLinearHistogram::~ScaledLinearHistogram() = default;
void ScaledLinearHistogram::AddScaledCount(Sample value, int64_t count) { … }
class BooleanHistogram::Factory : public Histogram::Factory { … };
HistogramBase* BooleanHistogram::FactoryGet(std::string_view name,
int32_t flags) { … }
HistogramBase* BooleanHistogram::FactoryGet(const std::string& name,
int32_t flags) { … }
HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) { … }
std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta) { … }
HistogramType BooleanHistogram::GetHistogramType() const { … }
HistogramBase* BooleanHistogram::FactoryGetInternal(std::string_view name,
int32_t flags) { … }
BooleanHistogram::BooleanHistogram(const char* name, const BucketRanges* ranges)
: … { … }
BooleanHistogram::BooleanHistogram(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta)
: … { … }
HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { … }
class CustomHistogram::Factory : public Histogram::Factory { … };
HistogramBase* CustomHistogram::FactoryGet(
std::string_view name,
const std::vector<Sample>& custom_ranges,
int32_t flags) { … }
HistogramBase* CustomHistogram::FactoryGet(
const std::string& name,
const std::vector<Sample>& custom_ranges,
int32_t flags) { … }
HistogramBase* CustomHistogram::FactoryGet(
const char* name,
const std::vector<Sample>& custom_ranges,
int32_t flags) { … }
std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta) { … }
HistogramType CustomHistogram::GetHistogramType() const { … }
std::vector<Sample> CustomHistogram::ArrayToCustomEnumRanges(
base::span<const Sample> values) { … }
CustomHistogram::CustomHistogram(const char* name, const BucketRanges* ranges)
: … { … }
CustomHistogram::CustomHistogram(
const char* name,
const BucketRanges* ranges,
const DelayedPersistentAllocation& counts,
const DelayedPersistentAllocation& logged_counts,
HistogramSamples::Metadata* meta,
HistogramSamples::Metadata* logged_meta)
: … { … }
void CustomHistogram::SerializeInfoImpl(Pickle* pickle) const { … }
HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { … }
HistogramBase* CustomHistogram::FactoryGetInternal(
std::string_view name,
const std::vector<Sample>& custom_ranges,
int32_t flags) { … }
bool CustomHistogram::ValidateCustomRanges(
const std::vector<Sample>& custom_ranges) { … }
namespace internal {
namespace {
constinit std::atomic<const std::atomic<TimeTicks>*> g_last_foreground_time_ref;
}
void SetSharedLastForegroundTimeForMetrics(
const std::atomic<TimeTicks>* last_foreground_time_ref) { … }
bool OverlapsBestEffortRange(TimeTicks sample_time, TimeDelta sample_interval) { … }
}
}