Commit 49d310f6 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[NTP][RQ] Add metrics for extraction of repeatable queries

Fixed: 1147136
Change-Id: Ic6ce9384eda8f59d4fbb223cbf2decb2e0ea668b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527857
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826165}
parent 855f0969
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram_functions.h"
#include "base/scoped_observer.h"
#include "base/stl_util.h"
#include "base/values.h"
......@@ -70,6 +71,12 @@ bool JsonToRepeatableQueriesData(const base::Value& root_value,
}
} // namespace
// static
const char RepeatableQueriesService::kExtractedCountHistogram[] =
"NewTabPage.RepeatableQueries.ExtractedCount";
const char RepeatableQueriesService::kExtractionDurationHistogram[] =
"NewTabPage.RepeatableQueries.ExtractionDuration";
class RepeatableQueriesService::SigninObserver
: public signin::IdentityManager::Observer {
public:
......@@ -353,6 +360,7 @@ void RepeatableQueriesService::GetRepeatableQueriesFromURLDatabase() {
if (!url_db)
return;
const base::TimeTicks db_query_time = base::TimeTicks::Now();
auto results = url_db->GetMostRecentNormalizedKeywordSearchTerms(
template_url_service_->GetDefaultSearchProvider()->id(),
ntp_features::GetLocalHistoryRepeatableQueriesAgeThreshold());
......@@ -380,6 +388,10 @@ void RepeatableQueriesService::GetRepeatableQueriesFromURLDatabase() {
break;
}
base::UmaHistogramTimes(kExtractionDurationHistogram,
base::TimeTicks::Now() - db_query_time);
base::UmaHistogramCounts10000(kExtractedCountHistogram, results.size());
NotifyObservers();
}
......
......@@ -73,6 +73,10 @@ class RepeatableQueriesService : public KeyedService {
RepeatableQueriesService(const RepeatableQueriesService&) = delete;
RepeatableQueriesService& operator=(const RepeatableQueriesService&) = delete;
// Histograms recorded by this class.
static const char kExtractedCountHistogram[];
static const char kExtractionDurationHistogram[];
// KeyedService:
void Shutdown() override;
......
......@@ -12,6 +12,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/optional.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/test_bookmark_client.h"
......@@ -429,6 +430,8 @@ TEST_F(RepeatableQueriesServiceTest, SignedIn_DefaultSearchProviderChanged) {
}
TEST_F(RepeatableQueriesServiceTest, SignedIn_SigninStatusChanged) {
base::HistogramTester histogram_tester;
SignIn();
test_url_loader_factory()->AddResponse(service()->GetRequestURL().spec(),
GoodServerResponse());
......@@ -470,6 +473,13 @@ TEST_F(RepeatableQueriesServiceTest, SignedIn_SigninStatusChanged) {
{base::ASCIIToUTF16("less recent local query"),
GetQueryDestinationURL("less recent local query"), ""}};
EXPECT_EQ(expected_local_queries, service()->repeatable_queries());
histogram_tester.ExpectTotalCount(
RepeatableQueriesService::kExtractionDurationHistogram, 1);
histogram_tester.ExpectTotalCount(
RepeatableQueriesService::kExtractedCountHistogram, 1);
histogram_tester.ExpectUniqueSample(
RepeatableQueriesService::kExtractedCountHistogram, 2, 1);
}
TEST_F(RepeatableQueriesServiceTest, SignedIn_Deletion) {
......
......@@ -1062,6 +1062,30 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="NewTabPage.RepeatableQueries.ExtractedCount" units="count"
expires_after="M90">
<owner>mahmadi@chromium.org</owner>
<owner>chrome-desktop-ntp@google.com</owner>
<summary>
The number of normalized search queries extracted from the in-memory URL DB
and examined (e.g., sorted) to produce repeatable query suggestions for
signed-out users. Triggered every time a signed-out user opens a new tab
when the repeatable queries are enabled.
</summary>
</histogram>
<histogram name="NewTabPage.RepeatableQueries.ExtractionDuration" units="ms"
expires_after="M90">
<owner>mahmadi@chromium.org</owner>
<owner>chrome-desktop-ntp@google.com</owner>
<summary>
The length of time it takes to extract normalized search queries from the
in-memory URL DB and examine (e.g., sort) them to produce repeatable query
suggestions for signed-out users. Triggered every time a signed-out user
opens a new tab when the repeatable queries are enabled.
</summary>
</histogram>
<histogram name="NewTabPage.RequestThrottler.PerDay" units="requests"
expires_after="2021-07-01">
<owner>freedjm@chromium.org</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment