Commit d2cc7586 authored by chcunningham's avatar chcunningham Committed by Commit Bot

MediaCapabilities: make DB configurable via Finch.

Adds flags for configuring the size of the rolling window and the number
of days to keep stats before expiring.

Bug: 910404
Test: new unit tests
Change-Id: I8a88a81154c710a1cc9b029e2b8ef8af61d945e0
Reviewed-on: https://chromium-review.googlesource.com/c/1355996Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612479}
parent 2a3c852f
......@@ -10,11 +10,13 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequence_checker.h"
#include "base/task/post_task.h"
#include "base/time/default_clock.h"
#include "components/leveldb_proto/proto_database_impl.h"
#include "media/base/media_switches.h"
#include "media/capabilities/video_decode_stats.pb.h"
namespace media {
......@@ -27,8 +29,32 @@ namespace {
// See comments in components/leveldb_proto/leveldb_database.h
const char kDatabaseClientName[] = "VideoDecodeStatsDB";
const int kMaxFramesPerBufferDefault = 2500;
const int kMaxDaysToKeepStatsDefault = 30;
}; // namespace
const char VideoDecodeStatsDBImpl::kMaxFramesPerBufferParamName[] =
"db_frames_buffer_size";
const char VideoDecodeStatsDBImpl::kMaxDaysToKeepStatsParamName[] =
"db_days_to_keep_stats";
// static
int VideoDecodeStatsDBImpl::GetMaxFramesPerBuffer() {
return base::GetFieldTrialParamByFeatureAsDouble(
kMediaCapabilitiesWithParameters, kMaxFramesPerBufferParamName,
kMaxFramesPerBufferDefault);
}
// static
int VideoDecodeStatsDBImpl::GetMaxDaysToKeepStats() {
return base::GetFieldTrialParamByFeatureAsDouble(
kMediaCapabilitiesWithParameters, kMaxDaysToKeepStatsParamName,
kMaxDaysToKeepStatsDefault);
}
// static
std::unique_ptr<VideoDecodeStatsDBImpl> VideoDecodeStatsDBImpl::Create(
base::FilePath db_dir) {
......@@ -137,8 +163,11 @@ bool VideoDecodeStatsDBImpl::AreStatsExpired(
last_write_date = default_write_time_.ToJsTime();
}
const int kMaxDaysToKeepStats = GetMaxDaysToKeepStats();
DCHECK_GT(kMaxDaysToKeepStats, 0);
return wall_clock_->Now() - base::Time::FromJsTime(last_write_date) >
base::TimeDelta::FromDays(VideoDecodeStatsDBImpl::kMaxDaysToKeepStats);
base::TimeDelta::FromDays(kMaxDaysToKeepStats);
}
void VideoDecodeStatsDBImpl::WriteUpdatedEntry(
......@@ -170,6 +199,9 @@ void VideoDecodeStatsDBImpl::WriteUpdatedEntry(
uint64_t old_frames_dropped = stats_proto->frames_dropped();
uint64_t old_frames_power_efficient = stats_proto->frames_power_efficient();
const uint64_t kMaxFramesPerBuffer = GetMaxFramesPerBuffer();
DCHECK_GT(kMaxFramesPerBuffer, 0UL);
if (old_frames_decoded + new_entry.frames_decoded > kMaxFramesPerBuffer) {
// The |new_entry| is pushing out some or all of the old data. Achieve this
// by weighting the dropped and power efficiency stats by the ratio of the
......
......@@ -29,19 +29,8 @@ class DecodeStatsProto;
// construction. API callbacks will also occur on this sequence.
class MEDIA_EXPORT VideoDecodeStatsDBImpl : public VideoDecodeStatsDB {
public:
enum : int {
// Number chosen after manual review of metrics (accuracy, precision,
// recall).
// TODO(chcunningham): Run experiments with different values. Metrics
// suggest different platforms, even different stream properties (e.g.
// framerate) could benefit from customized thresholds. Machine learning
// would probably be best.
kMaxFramesPerBuffer = 2500,
// Number of days after which stats will be discarded if not updated. This
// avoids users getting stuck with a bad capability prediction that may have
// been due to one-off circumstances.
kMaxDaysToKeepStats = 30,
};
static const char kMaxFramesPerBufferParamName[];
static const char kMaxDaysToKeepStatsParamName[];
// Create an instance! |db_dir| specifies where to store LevelDB files to
// disk. LevelDB generates a handful of files, so its recommended to provide a
......@@ -74,6 +63,15 @@ class MEDIA_EXPORT VideoDecodeStatsDBImpl : public VideoDecodeStatsDB {
// after the proto update hits the chrome Stable channel (M71).
static constexpr char kDefaultWriteTime[] = "01-FEB-2019 12:00pm";
// Number of decoded frames to keep in the rolling "window" for a given entry
// in the database.
static int GetMaxFramesPerBuffer();
// Number of days after which stats will be discarded if not updated. This
// avoids users getting stuck with a bad capability prediction that may have
// been due to one-off circumstances.
static int GetMaxDaysToKeepStats();
// Called when the database has been initialized. Will immediately call
// |init_cb| to forward |success|.
void OnInit(InitializeCB init_cb, bool success);
......@@ -111,7 +109,7 @@ class MEDIA_EXPORT VideoDecodeStatsDBImpl : public VideoDecodeStatsDB {
void OnStatsCleared(base::OnceClosure clear_done_cb, bool success);
// Return true if:
// "now" - stats_proto.last_write_date > kMaxDaysToKeepStats
// "now" - stats_proto.last_write_date > GeMaxDaysToKeepStats()
bool AreStatsExpired(const DecodeStatsProto* const stats_proto);
void set_wall_clock_for_test(const base::Clock* tick_clock) {
......
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