Commit 26a7e2c5 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Notification scheduler: Add metrics for background task.

This CL adds a few metrics to track the behavior of background tasks
for notification scheduling system.

TBR=nikunjb@chromium.org

Bug: 963298
Change-Id: Ic6107269db6eb5fbd70bef2836a18336daef55be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762954Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690796}
parent fa000df4
......@@ -21,6 +21,7 @@
#include "chrome/browser/notifications/scheduler/internal/notification_scheduler_context.h"
#include "chrome/browser/notifications/scheduler/internal/scheduled_notification_manager.h"
#include "chrome/browser/notifications/scheduler/internal/scheduler_utils.h"
#include "chrome/browser/notifications/scheduler/internal/stats.h"
#include "chrome/browser/notifications/scheduler/public/display_agent.h"
#include "chrome/browser/notifications/scheduler/public/notification_background_task_scheduler.h"
#include "chrome/browser/notifications/scheduler/public/notification_params.h"
......@@ -171,6 +172,8 @@ class NotificationSchedulerImpl : public NotificationScheduler,
// NotificationBackgroundTaskScheduler::Handler implementation.
void OnStartTask(SchedulerTaskTime task_time,
TaskFinishedCallback callback) override {
stats::LogBackgroundTaskEvent(stats::BackgroundTaskEvent::kStart);
task_start_time_ = task_time;
// Updates the impression data to compute daily notification shown budget.
......@@ -182,10 +185,12 @@ class NotificationSchedulerImpl : public NotificationScheduler,
// Schedule the next background task based on scheduled notifications.
ScheduleBackgroundTask();
stats::LogBackgroundTaskEvent(stats::BackgroundTaskEvent::kFinish);
std::move(callback).Run(false /*need_reschedule*/);
}
void OnStopTask(SchedulerTaskTime task_time) override {
stats::LogBackgroundTaskEvent(stats::BackgroundTaskEvent::kStopByOS);
task_start_time_ = task_time;
ScheduleBackgroundTask();
}
......@@ -258,6 +263,7 @@ class NotificationSchedulerImpl : public NotificationScheduler,
for (const auto& guid : results) {
context_->notification_manager()->DisplayNotification(guid);
}
stats::LogBackgroundTaskNotificationShown(results.size());
}
void ScheduleBackgroundTask() {
......
......@@ -35,6 +35,24 @@ void LogUserAction(const UserActionData& action_data) {
base::UmaHistogramEnumeration(name, action_data.action_type);
}
void LogBackgroundTaskEvent(BackgroundTaskEvent event) {
UMA_HISTOGRAM_ENUMERATION("Notifications.Scheduler.BackgroundTask.Event",
event);
if (event == BackgroundTaskEvent::kStart) {
base::Time::Exploded explode;
base::Time::Now().LocalExplode(&explode);
UMA_HISTOGRAM_EXACT_LINEAR("Notifications.Scheduler.BackgroundTask.Start",
explode.hour, 24);
}
}
void LogBackgroundTaskNotificationShown(int shown_count) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Notifications.Scheduler.BackgroundTask.NotificationShown", shown_count,
0, 10, 11);
}
void LogImpressionDbInit(bool success, int entry_count) {
UMA_HISTOGRAM_BOOLEAN("Notifications.Scheduler.ImpressionDb.InitResult",
success);
......
......@@ -10,6 +10,19 @@
namespace notifications {
namespace stats {
// Events to track behavior of the background task used by notification
// scheduling system. Used in histograms, don't reuse or delete values. Needs to
// match NotificationSchedulerBackgroundTaskEvent in enums.xml.
enum class BackgroundTaskEvent {
// Background task starts.
kStart = 0,
// Background task finishes and stopped gracefully.
kFinish = 1,
// The background task is stopped by the OS without finishing the its job.
kStopByOS = 2,
kMaxValue = kStopByOS
};
// Used to log events in impression tracker. Don't reuse or delete values. Needs
// to match NotificationSchedulerImpressionEvent in enums.xml.
enum class ImpressionEvent {
......@@ -26,6 +39,13 @@ enum class ImpressionEvent {
// scheduling system.
void LogUserAction(const UserActionData& user_action_data);
// Logs events to track the behavior of the background task used by notification
// scheduling system.
void LogBackgroundTaskEvent(BackgroundTaskEvent event);
// Logs the number of notification shown in the current background task.
void LogBackgroundTaskNotificationShown(int shown_count);
// Logs the initialization result for impression database.
void LogImpressionDbInit(bool success, int entry_count);
......
......@@ -43438,6 +43438,12 @@ Called by update_net_trust_anchors.py.-->
<int value="5" label="Chrome process launch failed"/>
</enum>
<enum name="NotificationSchedulerBackgroundTaskEvent">
<int value="0" label="Start"/>
<int value="1" label="Finish"/>
<int value="2" label="Stop by OS"/>
</enum>
<enum name="NotificationSchedulerImpressionEvent">
<int value="0" label="New suppression"/>
<int value="1" label="Suppression released"/>
......@@ -86856,6 +86856,35 @@ uploading your change for review.
</summary>
</histogram>
<histogram name="Notifications.Scheduler.BackgroundTask.Event"
enum="NotificationSchedulerBackgroundTaskEvent" expires_after="2020-08-01">
<owner>xingliu@chromium.org</owner>
<owner>hesen@chromium.org</owner>
<summary>
Records the various events when running the background task in notification
scheduling system.
</summary>
</histogram>
<histogram name="Notifications.Scheduler.BackgroundTask.NotificationShown"
units="notifications" expires_after="2020-08-01">
<owner>xingliu@chromium.org</owner>
<owner>hesen@chromium.org</owner>
<summary>
Records the number of notifications shown in each background task run.
</summary>
</histogram>
<histogram name="Notifications.Scheduler.BackgroundTask.Start" units="hours"
expires_after="2020-08-01">
<owner>xingliu@chromium.org</owner>
<owner>hesen@chromium.org</owner>
<summary>
Records the hour (0-23) when the notification scheduler background task
starts.
</summary>
</histogram>
<histogram name="Notifications.Scheduler.Impression.Count" units="records"
expires_after="2020-08-01">
<!-- Name completed by histogram_suffixes name="NotificationSchedulerClientType" -->
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