diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-24 12:15:48 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-28 13:30:04 +0000 |
commit | b014812705fc80bff0a5c120dfcef88f349816dc (patch) | |
tree | 25a2e2d9fa285f1add86aa333389a839f81a39ae /chromium/components/assist_ranker | |
parent | 9f4560b1027ae06fdb497023cdcaf91b8511fa74 (diff) | |
download | qtwebengine-chromium-b014812705fc80bff0a5c120dfcef88f349816dc.tar.gz |
BASELINE: Update Chromium to 68.0.3440.125
Change-Id: I23f19369e01f688e496f5bf179abb521ad73874f
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/assist_ranker')
5 files changed, 116 insertions, 20 deletions
diff --git a/chromium/components/assist_ranker/OWNERS b/chromium/components/assist_ranker/OWNERS index 36ad72d71e6..8aee8cf06a5 100644 --- a/chromium/components/assist_ranker/OWNERS +++ b/chromium/components/assist_ranker/OWNERS @@ -1,3 +1,5 @@ +amoylan@chromium.org charleszhao@chromium.org hamelphi@chromium.org +jiameng@chromium.org rogerm@chromium.org diff --git a/chromium/components/assist_ranker/base_predictor.cc b/chromium/components/assist_ranker/base_predictor.cc index 28ccc264275..9060cd8de64 100644 --- a/chromium/components/assist_ranker/base_predictor.cc +++ b/chromium/components/assist_ranker/base_predictor.cc @@ -56,8 +56,7 @@ bool BasePredictor::IsReady() { void BasePredictor::LogFeatureToUkm(const std::string& feature_name, const Feature& feature, ukm::UkmEntryBuilder* ukm_builder) { - if (!ukm_builder) - return; + DCHECK(ukm_builder); if (!base::ContainsKey(*config_.feature_whitelist, feature_name)) { DVLOG(1) << "Feature not whitelisted: " << feature_name; @@ -72,7 +71,7 @@ void BasePredictor::LogFeatureToUkm(const std::string& feature_name, int64_t feature_int64_value = -1; FeatureToInt64(feature, &feature_int64_value); DVLOG(3) << "Logging: " << feature_name << ": " << feature_int64_value; - ukm_builder->AddMetric(feature_name.c_str(), feature_int64_value); + ukm_builder->SetMetric(feature_name, feature_int64_value); break; } case Feature::kStringList: { @@ -80,7 +79,7 @@ void BasePredictor::LogFeatureToUkm(const std::string& feature_name, int64_t feature_int64_value = -1; FeatureToInt64(feature, &feature_int64_value, i); DVLOG(3) << "Logging: " << feature_name << ": " << feature_int64_value; - ukm_builder->AddMetric(feature_name.c_str(), feature_int64_value); + ukm_builder->SetMetric(feature_name, feature_int64_value); } break; } @@ -105,16 +104,11 @@ void BasePredictor::LogExampleToUkm(const RankerExample& example, return; } - // Releasing the builder will trigger logging. - std::unique_ptr<ukm::UkmEntryBuilder> builder = - ukm::UkmRecorder::Get()->GetEntryBuilder(source_id, config_.logging_name); - if (builder) { - for (const auto& feature_kv : example.features()) { - LogFeatureToUkm(feature_kv.first, feature_kv.second, builder.get()); - } - } else { - DVLOG(0) << "Could not get UKM Entry Builder."; + ukm::UkmEntryBuilder builder(source_id, config_.logging_name); + for (const auto& feature_kv : example.features()) { + LogFeatureToUkm(feature_kv.first, feature_kv.second, &builder); } + builder.Record(ukm::UkmRecorder::Get()); } std::string BasePredictor::GetModelName() const { diff --git a/chromium/components/assist_ranker/base_predictor_unittest.cc b/chromium/components/assist_ranker/base_predictor_unittest.cc index 3ec770e99a4..aae82621b11 100644 --- a/chromium/components/assist_ranker/base_predictor_unittest.cc +++ b/chromium/components/assist_ranker/base_predictor_unittest.cc @@ -26,16 +26,19 @@ namespace { // Predictor config for testing. const char kTestModelName[] = "test_model"; -const char kTestLoggingName[] = "TestLoggingName"; +// This name needs to be an entry in ukm.xml +const char kTestLoggingName[] = "ContextualSearch"; const char kTestUmaPrefixName[] = "Test.Ranker"; const char kTestUrlParamName[] = "ranker-model-url"; const char kTestDefaultModelUrl[] = "https://foo.bar/model.bin"; -const char kBoolFeature[] = "bool_feature"; -const char kIntFeature[] = "int_feature"; -const char kFloatFeature[] = "float_feature"; -const char kStringFeature[] = "string_feature"; -const char kStringListFeature[] = "string_list_feature"; +// The whitelisted features must be metrics of kTestLoggingName in ukm.xml, +// though the types do not need to match. +const char kBoolFeature[] = "DidOptIn"; +const char kIntFeature[] = "DurationAfterScrollMs"; +const char kFloatFeature[] = "FontSize"; +const char kStringFeature[] = "IsEntity"; +const char kStringListFeature[] = "IsEntityEligible"; const char kFeatureNotWhitelisted[] = "not_whitelisted"; const char kTestNavigationUrl[] = "https://foo.com"; diff --git a/chromium/components/assist_ranker/fake_ranker_model_loader.cc b/chromium/components/assist_ranker/fake_ranker_model_loader.cc index b1804ce09c3..9097243c765 100644 --- a/chromium/components/assist_ranker/fake_ranker_model_loader.cc +++ b/chromium/components/assist_ranker/fake_ranker_model_loader.cc @@ -19,7 +19,7 @@ FakeRankerModelLoader::FakeRankerModelLoader( FakeRankerModelLoader::~FakeRankerModelLoader() {} void FakeRankerModelLoader::NotifyOfRankerActivity() { - if (validate_model_cb_.Run(*ranker_model_.get()) == RankerModelStatus::OK) { + if (validate_model_cb_.Run(*ranker_model_) == RankerModelStatus::OK) { on_model_available_cb_.Run(std::move(ranker_model_)); } } diff --git a/chromium/components/assist_ranker/print_example_preprocessor_config.py b/chromium/components/assist_ranker/print_example_preprocessor_config.py new file mode 100755 index 00000000000..5e35a0f1a6e --- /dev/null +++ b/chromium/components/assist_ranker/print_example_preprocessor_config.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python2 + +# Copyright 2018 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Dumps info from a ExamplePreprocessorConfig protobuf file. + +Prints feature names, types, and bucket values. +""" + +import os +import sys +import textwrap +from enum import Enum +from google.protobuf import text_format + +class FeatureType(Enum): + CATEGORICAL = 'categorical' + BUCKETED = 'bucketed' + SCALAR = 'scalar' + + +def ReadConfig(pb_file): + """Parses the protobuf containing the example preprocessor config.""" + import example_preprocessor_pb2 + config = example_preprocessor_pb2.ExamplePreprocessorConfig() + with open(pb_file) as pb: + config.ParseFromString(pb.read()) + return config + + +def PrintExamplePreprocessorConfig(pb_file): + """Prints the features listed the example preprocessor config.""" + config = ReadConfig(pb_file) + + features = set() + for feature_index in sorted(config.feature_indices): + # For string or string list feature types, remove the "_value" suffix to get + # the base name. + name_parts = feature_index.split('_') + base_name = name_parts[0] + # Skip additional values of the same base name. + if base_name in features: + continue + + features.add(base_name) + if len(name_parts) == 1: + feature_type = FeatureType.SCALAR + elif base_name in config.bucketizers: + feature_type = FeatureType.BUCKETED + else: + feature_type = FeatureType.CATEGORICAL + description = '* %s (%s)' % (base_name, feature_type.value) + + if feature_type == FeatureType.BUCKETED: + description += ':\n\t' + boundaries = config.bucketizers[base_name].boundaries + bucket_str = ', '.join(['%.1f' % bucket for bucket in boundaries]) + + # Indent description by a tab and wrap text. + max_len = 80 - 8 # Leave at least 8 columns for tab width. + description += ('\n\t').join(textwrap.wrap(bucket_str, max_len)) + print description + return 0 + + +def Main(args): + if len(args) != 2: + print 'Usage: %s <out_dir> <path/to/example_preprocessor_config.pb>' % ( + __file__) + return 1 + + out_dir = args[0] + if not os.path.isdir(out_dir): + print 'Could not find out directory: %s' % out_dir + return 1 + + pb_file = args[1] + if not os.path.isfile(pb_file): + print 'Protobuf file not found: %s' % pb_file + return 1 + + proto_dir = os.path.join(out_dir, 'pyproto/components/assist_ranker/proto') + if not os.path.isdir(proto_dir): + print 'Proto directory not found: %s' % proto_dir + print 'Build the "components/assist_ranker/proto" target' + print ' (usually built with chrome)' + return 1 + + # Allow importing the ExamplePreprocessorConfig proto definition. + sys.path.insert(0, proto_dir) + PrintExamplePreprocessorConfig(pb_file) + + +if __name__ == '__main__': + sys.exit(Main(sys.argv[1:])) |