Commit 836ab12f authored by Jia's avatar Jia Committed by Commit Bot

[Power ML] Change the logging order of consecutive events.

When the screen dim is deferred, its associated event will be logged along with
the next event (where screen dim doesn't get deferred). Previously we log the
latest event first and then log the earlier event associated with deferred dim.
Now we change the order to log earlier event first.

Bug: 862461
Change-Id: Ib29ebf60814ce266e6d271a0a4b7a52e6b5b36f3
Reviewed-on: https://chromium-review.googlesource.com/1170158
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarMichael Martis <martis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582070}
parent 8ce7d2ab
......@@ -484,26 +484,30 @@ void UserActivityManager::MaybeLogEvent(
*activity_event.mutable_model_prediction() = model_prediction_.value();
}
// Log to metrics.
ukm_logger_->LogActivity(activity_event);
LogMetricsToUMA(activity_event);
// If there's an earlier idle event that has not received its own event, log
// it here too.
// it here too. Note, we log the earlier event before the current event.
if (previous_idle_event_data_) {
if (event->has_log_duration_sec()) {
event->set_log_duration_sec(
event->log_duration_sec() +
UserActivityEvent previous_activity_event = activity_event;
UserActivityEvent::Event* previous_event =
previous_activity_event.mutable_event();
if (previous_event->has_log_duration_sec()) {
previous_event->set_log_duration_sec(
previous_event->log_duration_sec() +
previous_idle_event_data_->dim_imminent_signal_interval.InSeconds());
}
*activity_event.mutable_features() = previous_idle_event_data_->features;
*activity_event.mutable_model_prediction() =
*previous_activity_event.mutable_features() =
previous_idle_event_data_->features;
*previous_activity_event.mutable_model_prediction() =
previous_idle_event_data_->model_prediction;
ukm_logger_->LogActivity(activity_event);
LogMetricsToUMA(activity_event);
ukm_logger_->LogActivity(previous_activity_event);
LogMetricsToUMA(previous_activity_event);
}
// Log to metrics.
ukm_logger_->LogActivity(activity_event);
LogMetricsToUMA(activity_event);
// Update the counters for next event logging.
if (type == UserActivityEvent::Event::REACTIVATE) {
previous_negative_actions_count_++;
......
......@@ -1046,7 +1046,7 @@ TEST_F(UserActivityManagerTest, TwoScreenDimImminentWithoutEventInBetween) {
const std::vector<UserActivityEvent>& events = delegate_.events();
ASSERT_EQ(2U, events.size());
// The first event logged is the current one.
// The current event logged is after the earlier idle event.
UserActivityEvent::Event expected_event1;
expected_event1.set_type(UserActivityEvent::Event::TIMEOUT);
expected_event1.set_reason(UserActivityEvent::Event::IDLE_SLEEP);
......@@ -1054,7 +1054,7 @@ TEST_F(UserActivityManagerTest, TwoScreenDimImminentWithoutEventInBetween) {
expected_event1.set_screen_dim_occurred(false);
expected_event1.set_screen_off_occurred(false);
expected_event1.set_screen_lock_occurred(false);
EqualEvent(expected_event1, events[0].event());
EqualEvent(expected_event1, events[1].event());
UserActivityEvent::ModelPrediction expected_prediction1;
expected_prediction1.set_decision_threshold(50);
......@@ -1062,12 +1062,11 @@ TEST_F(UserActivityManagerTest, TwoScreenDimImminentWithoutEventInBetween) {
expected_prediction1.set_model_applied(false);
expected_prediction1.set_response(UserActivityEvent::ModelPrediction::NO_DIM);
EqualModelPrediction(expected_prediction1, events[0].model_prediction());
EqualModelPrediction(expected_prediction1, events[1].model_prediction());
// The earlier idle event is logged afterwards.
UserActivityEvent::Event expected_event2 = expected_event1;
expected_event2.set_log_duration_sec(30);
EqualEvent(expected_event2, events[1].event());
EqualEvent(expected_event2, events[0].event());
UserActivityEvent::ModelPrediction expected_prediction2;
expected_prediction2.set_decision_threshold(50);
......@@ -1075,7 +1074,7 @@ TEST_F(UserActivityManagerTest, TwoScreenDimImminentWithoutEventInBetween) {
expected_prediction2.set_model_applied(true);
expected_prediction2.set_response(UserActivityEvent::ModelPrediction::NO_DIM);
EqualModelPrediction(expected_prediction2, events[1].model_prediction());
EqualModelPrediction(expected_prediction2, events[0].model_prediction());
}
TEST_F(UserActivityManagerTest, ModelError) {
......
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