#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/segmentation_platform/internal/segmentation_ukm_helper.h"
#include "base/bit_cast.h"
#include "base/metrics/field_trial_params.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "components/segmentation_platform/internal/constants.h"
#include "components/segmentation_platform/internal/selection/segmentation_result_prefs.h"
#include "components/segmentation_platform/internal/stats.h"
#include "components/segmentation_platform/public/config.h"
#include "components/segmentation_platform/public/features.h"
#include "components/segmentation_platform/public/local_state_helper.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#define CALL_MEMBER_FN(obj, func) …
#define ARRAY_SIZE(x) …
SegmentationUkmHelper;
SegmentId;
Segmentation_ModelExecution;
namespace segmentation_platform {
namespace {
UkmMemberFn;
const UkmMemberFn kSegmentationUkmInputMethods[] = …;
const UkmMemberFn kSegmentationUkmPredictionResultMethods[] = …;
const UkmMemberFn kSegmentationUkmOutputMethods[] = …;
const int kDefaultModelExecutionSamplingRate = …;
int GetModelExecutionSamplingRate() { … }
void AddPredictionResultToUkmModelExecution(
ukm::builders::Segmentation_ModelExecution* model_execution,
const std::vector<float>& results) { … }
std::string GetDebugString(const ModelProvider::Request& input_tensor,
const ModelProvider::Response& outputs) { … }
}
SegmentationUkmHelper::SegmentationUkmHelper() { … }
SegmentationUkmHelper::~SegmentationUkmHelper() = default;
SegmentationUkmHelper* SegmentationUkmHelper::GetInstance() { … }
void SegmentationUkmHelper::Initialize() { … }
ukm::SourceId SegmentationUkmHelper::RecordModelExecutionResult(
SegmentId segment_id,
int64_t model_version,
const ModelProvider::Request& input_tensor,
const std::vector<float>& results) { … }
ukm::SourceId SegmentationUkmHelper::RecordTrainingData(
SegmentId segment_id,
int64_t model_version,
ukm::SourceId ukm_source_id,
const ModelProvider::Request& input_tensor,
const ModelProvider::Response& outputs,
const std::vector<int>& output_indexes,
std::optional<proto::PredictionResult> prediction_result,
std::optional<SelectedSegment> selected_segment) { … }
bool SegmentationUkmHelper::AddInputsToUkm(
ukm::builders::Segmentation_ModelExecution* ukm_builder,
SegmentId segment_id,
int64_t model_version,
const ModelProvider::Request& input_tensor) { … }
bool SegmentationUkmHelper::AddOutputsToUkm(
ukm::builders::Segmentation_ModelExecution* ukm_builder,
const ModelProvider::Response& outputs,
const std::vector<int>& output_indexes) { … }
bool SegmentationUkmHelper::IsUploadRequested(
const proto::SegmentInfo& segment_info) const { … }
int64_t SegmentationUkmHelper::FloatToInt64(float f) { … }
bool SegmentationUkmHelper::AllowedToUploadData(
base::TimeDelta signal_storage_length,
base::Clock* clock) { … }
}