#include "components/segmentation_platform/internal/stats.h"
#include <string_view>
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/thread_pool.h"
#include "components/segmentation_platform/internal/post_processor/post_processor.h"
#include "components/segmentation_platform/public/constants.h"
#include "components/segmentation_platform/public/proto/model_metadata.pb.h"
#include "components/segmentation_platform/public/proto/output_config.pb.h"
#include "components/segmentation_platform/public/proto/segmentation_platform.pb.h"
#include "components/segmentation_platform/public/proto/types.pb.h"
namespace segmentation_platform::stats {
namespace {
enum class AdaptiveToolbarButtonVariant { … };
proto::SegmentationModelMetadata::OutputDescription
GetOptimizationTargetOutputDescription(SegmentId segment_id) { … }
AdaptiveToolbarButtonVariant OptimizationTargetToAdaptiveToolbarButtonVariant(
SegmentId segment_id) { … }
BooleanSegmentSwitch GetBooleanSegmentSwitch(SegmentId new_selection,
SegmentId previous_selection) { … }
AdaptiveToolbarSegmentSwitch GetAdaptiveToolbarSegmentSwitch(
SegmentId new_selection,
SegmentId previous_selection) { … }
std::optional<std::string_view> ModelExecutionStatusToHistogramVariant(
ModelExecutionStatus status) { … }
std::string SignalTypeToHistogramVariant(proto::SignalType signal_type) { … }
float ZeroValueFraction(const std::vector<float>& tensor) { … }
std::string GetModelSourceAsString(proto::ModelSource model_source) { … }
}
void RecordModelUpdateTimeDifference(SegmentId segment_id,
int64_t model_update_time) { … }
void RecordSegmentSelectionComputed(
const Config& config,
SegmentId new_selection,
std::optional<SegmentId> previous_selection) { … }
void RecordClassificationResultComputed(
const Config& config,
const proto::PredictionResult& new_result) { … }
void RecordClassificationResultUpdated(
const Config& config,
const proto::PredictionResult* old_result,
const proto::PredictionResult& new_result) { … }
void RecordMaintenanceCleanupSignalSuccessCount(size_t count) { … }
void RecordMaintenanceCompactionResult(proto::SignalType signal_type,
bool success) { … }
void RecordMaintenanceSignalIdentifierCount(size_t count) { … }
void RecordModelDeliveryHasMetadata(SegmentId segment_id, bool has_metadata) { … }
void RecordModelDeliveryMetadataFeatureCount(SegmentId segment_id,
ModelSource model_source,
size_t count) { … }
void RecordModelDeliveryMetadataValidation(
SegmentId segment_id,
proto::ModelSource model_source,
bool processed,
metadata_utils::ValidationResult validation_result) { … }
void RecordModelDeliveryReceived(SegmentId segment_id,
proto::ModelSource model_source) { … }
void RecordModelDeliverySaveResult(SegmentId segment_id,
proto::ModelSource model_source,
bool success) { … }
void RecordModelDeliveryDeleteResult(SegmentId segment_id,
proto::ModelSource model_source,
bool success) { … }
void RecordModelDeliverySegmentIdMatches(SegmentId segment_id,
proto::ModelSource model_source,
bool matches) { … }
void RecordModelExecutionDurationFeatureProcessing(SegmentId segment_id,
base::TimeDelta duration) { … }
void RecordModelExecutionDurationModel(SegmentId segment_id,
bool success,
base::TimeDelta duration) { … }
void RecordModelExecutionDurationTotal(SegmentId segment_id,
ModelExecutionStatus status,
base::TimeDelta duration) { … }
void RecordClassificationRequestTotalDuration(const Config& config,
base::TimeDelta duration) { … }
void RecordOnDemandSegmentSelectionDuration(
const Config& config,
const SegmentSelectionResult& result,
base::TimeDelta duration) { … }
void RecordModelExecutionResult(
SegmentId segment_id,
float result,
proto::SegmentationModelMetadata::OutputDescription return_type) { … }
void RecordModelExecutionResult(SegmentId segment_id,
const ModelProvider::Response& result,
proto::OutputConfig output_config) { … }
void RecordModelExecutionSaveResult(SegmentId segment_id, bool success) { … }
void RecordModelExecutionStatus(SegmentId segment_id,
bool default_provider,
ModelExecutionStatus status) { … }
void RecordModelExecutionZeroValuePercent(SegmentId segment_id,
const std::vector<float>& tensor) { … }
void RecordSignalDatabaseGetSamplesDatabaseEntryCount(size_t count) { … }
void RecordSignalDatabaseGetSamplesResult(bool success) { … }
void RecordSignalDatabaseGetSamplesSampleCount(size_t count) { … }
void RecordSegmentInfoDatabaseUpdateEntriesResult(SegmentId segment_id,
bool success) { … }
void RecordSignalsListeningCount(
const std::set<uint64_t>& user_actions,
const std::set<std::pair<std::string, proto::SignalType>>& histograms) { … }
void RecordSegmentSelectionFailure(const Config& config,
SegmentationSelectionFailureReason reason) { … }
std::string FeatureProcessingErrorToString(FeatureProcessingError error) { … }
void RecordFeatureProcessingError(SegmentId segment_id,
FeatureProcessingError error) { … }
void RecordModelAvailability(SegmentId segment_id,
SegmentationModelAvailability availability) { … }
void RecordTooManyInputTensors(int tensor_size) { … }
std::string TrainingDataCollectionEventToErrorMsg(
TrainingDataCollectionEvent event) { … }
void RecordTrainingDataCollectionEvent(SegmentId segment_id,
TrainingDataCollectionEvent event) { … }
SegmentationSelectionFailureReason GetSuccessOrFailureReason(
SegmentResultProvider::ResultState result_state) { … }
BackgroundUmaRecorder& BackgroundUmaRecorder::GetInstance() { … }
BackgroundUmaRecorder::BackgroundUmaRecorder() = default;
BackgroundUmaRecorder::~BackgroundUmaRecorder() = default;
void BackgroundUmaRecorder::Initialize() { … }
void BackgroundUmaRecorder::InitializeForTesting(
scoped_refptr<base::SequencedTaskRunner> bg_task_runner) { … }
void BackgroundUmaRecorder::AddMetric(base::OnceClosure add_sample) { … }
void BackgroundUmaRecorder::FlushSamples() { … }
}