Skip to content

Commit

Permalink
[Power ML] UserActivityManager calls SmartDimModel for prediction.
Browse files Browse the repository at this point in the history
Once an idle event is received, UserActivityManager will call a smart dim model
to predict whether the upcoming dim should be deferred.

The smart dim model currently does nothing. It will be implemented to make
prediction in a later cl. The purpose of this cl is to set up the structure,
specifically how various classes work together.

This cl also contains the following changes:
1. All data that are used in prediction and logging now live in UserActivityEvent.
- This makes prediction and logging simpler as all data are now in one place.

2. Add additional metrics to log
(i). Model prediction data.
(ii). Previous positive and negative actions count.
- They were derived data from other logged data. They are used as prediction features,
and we log them directly now to avoid training-serving skew.

3. Stop logging several tab-related metrics logged, this will significantly reduce data logged.
- Also only log one active tab in the focused/topmost browser that's visible.

4. Add a flag to disable/enable prediction.
- It's disabled by default but will be set in experiments later.

Bug: 862461
Change-Id: I7770efdfb5f15679fc4b49f8bf892292e7a347fc
Reviewed-on: https://chromium-review.googlesource.com/1132828
Reviewed-by: Dan Erat <[email protected]>
Reviewed-by: Steven Holte <[email protected]>
Commit-Queue: Jia Meng <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#576808}(cherry picked from commit 7332829)
Reviewed-on: https://chromium-review.googlesource.com/1147620
Reviewed-by: Jia Meng <[email protected]>
Cr-Commit-Position: refs/branch-heads/3497@{#31}
Cr-Branched-From: 271eaf5-refs/heads/master@{#576753}
  • Loading branch information
jm318 committed Jul 23, 2018
1 parent 5c5ba8b commit 0c4405c
Show file tree
Hide file tree
Showing 17 changed files with 858 additions and 336 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,9 @@ source_set("chromeos") {
"power/ml/real_boot_clock.h",
"power/ml/recent_events_counter.cc",
"power/ml/recent_events_counter.h",
"power/ml/smart_dim_model.h",
"power/ml/smart_dim_model_impl.cc",
"power/ml/smart_dim_model_impl.h",
"power/ml/user_activity_controller.cc",
"power/ml/user_activity_controller.h",
"power/ml/user_activity_manager.cc",
Expand Down
36 changes: 36 additions & 0 deletions chrome/browser/chromeos/power/ml/smart_dim_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.

#ifndef CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_MODEL_H_
#define CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_MODEL_H_

#include "chrome/browser/chromeos/power/ml/user_activity_event.pb.h"

namespace chromeos {
namespace power {
namespace ml {

// Interface to indicate whether an upcoming screen dim should go ahead based on
// whether user will remain inactive if screen is dimmed now.
class SmartDimModel {
public:
virtual ~SmartDimModel() = default;

// Returns whether an upcoming dim should go ahead based on input |features|.
// If |inactive_probability_out| and |threshold_out| are non-null, also
// returns model confidence (probability that user will remain inactive if
// screen is dimmed now) and threshold: if probability >= threshold then model
// will return true for this function. Both |inactive_probability_out| and
// |threshold_out| are expected to be in the range of [0, 1.0] so that they
// can be logged as model results.
virtual bool ShouldDim(const UserActivityEvent::Features& features,
float* inactive_probability_out,
float* threshold_out) = 0;
};

} // namespace ml
} // namespace power
} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_MODEL_H_
31 changes: 31 additions & 0 deletions chrome/browser/chromeos/power/ml/smart_dim_model_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.

#include "chrome/browser/chromeos/power/ml/smart_dim_model_impl.h"

namespace chromeos {
namespace power {
namespace ml {

SmartDimModelImpl::SmartDimModelImpl() = default;

SmartDimModelImpl::~SmartDimModelImpl() = default;

// TODO(jiameng): add impl.
bool SmartDimModelImpl::ShouldDim(const UserActivityEvent::Features& features,
float* inactive_probability_out,
float* threshold_out) {
// Let dim go ahead before we have a model implementation in place.
if (inactive_probability_out) {
*inactive_probability_out = 1.0;
}
if (threshold_out) {
*threshold_out = 0.0;
}
return true;
}

} // namespace ml
} // namespace power
} // namespace chromeos
35 changes: 35 additions & 0 deletions chrome/browser/chromeos/power/ml/smart_dim_model_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

#ifndef CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_MODEL_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_MODEL_IMPL_H_

#include "base/macros.h"
#include "chrome/browser/chromeos/power/ml/smart_dim_model.h"

namespace chromeos {
namespace power {
namespace ml {

// Real implementation of SmartDimModel that predicts whether an upcoming screen
// dim should go ahead based on user activity/inactivity following dim.
class SmartDimModelImpl : public SmartDimModel {
public:
SmartDimModelImpl();
~SmartDimModelImpl() override;

// chromeos::power::ml::SmartDimModel overrides:
bool ShouldDim(const UserActivityEvent::Features& features,
float* inactive_probability_out,
float* threshold_out) override;

private:
DISALLOW_COPY_AND_ASSIGN(SmartDimModelImpl);
};

} // namespace ml
} // namespace power
} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_POWER_ML_SMART_DIM_MODEL_IMPL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ UserActivityController::UserActivityController() {
&user_activity_ukm_logger_, idle_event_notifier_.get(), detector,
power_manager_client, session_manager,
mojo::MakeRequest(&video_observer_user_logger),
chromeos::ChromeUserManager::Get());
chromeos::ChromeUserManager::Get(), &smart_dim_model_);
aura::Env::GetInstance()
->context_factory_private()
->GetHostFrameSinkManager()
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/power/ml/user_activity_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>

#include "chrome/browser/chromeos/power/ml/idle_event_notifier.h"
#include "chrome/browser/chromeos/power/ml/smart_dim_model_impl.h"
#include "chrome/browser/chromeos/power/ml/user_activity_manager.h"
#include "chrome/browser/chromeos/power/ml/user_activity_ukm_logger_impl.h"

Expand All @@ -27,6 +28,7 @@ class UserActivityController {
std::unique_ptr<IdleEventNotifier> idle_event_notifier_;
UserActivityUkmLoggerImpl user_activity_ukm_logger_;
std::unique_ptr<UserActivityManager> user_activity_manager_;
SmartDimModelImpl smart_dim_model_;

DISALLOW_COPY_AND_ASSIGN(UserActivityController);
};
Expand Down
29 changes: 28 additions & 1 deletion chrome/browser/chromeos/power/ml/user_activity_event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,36 @@ message UserActivityEvent {
optional bool screen_dimmed_initially = 22;
optional bool screen_off_initially = 23;
optional bool screen_locked_initially = 24;
} // next id = 25

// Properties associated with the active tab of the visible focused/topmost
// browser. Unset if there's no such tab.
optional int32 engagement_score = 25;
optional bool has_form_entry = 26;
optional int64 source_id = 27;
// A valid URL could still have empty domain.
optional string tab_domain = 28;

// Number of times user reactivated and thus undimmed the screen before
// system was suspended.
optional int32 previous_negative_actions_count = 29;
// Number of times user remained idle after dim until system was suspended
// or closed.
optional int32 previous_positive_actions_count = 30;
} // next id = 31

message ModelPrediction {
// If |inactivity_score| < |decision_threshold| then dim will be deferred.
optional int32 decision_threshold = 1;
// How likely user will remain inactive if screen is dimmed.
optional int32 inactivity_score = 2;
// Whether model decision (regardless if dim is to be deferred) is
// taken by powerd.
optional bool model_applied = 3;
}

optional ModelParams params = 1;
optional Event event = 2;
optional Features features = 3;
// Unset if model prediction is disabled in an experiment.
optional ModelPrediction model_prediction = 4;
}
Loading

0 comments on commit 0c4405c

Please sign in to comment.