Included metrics for LRU replacement.
[ Merge of http://go/wvgerrit/88016 ] In the event of an LRU replacement event on AddKey, we gather some metrics on what the state of the usage table is and some info on the the entry that was removed. Metrics collected: - How many usage info (streaming license) in the table - How many offline licenses in the table - What type of entry was evicted from the table - How stale (time since last use) was the evicted entry This also enables unit tests for marshalling the metrics into proto message on Android unit test. Bug: 135046978 Test: Android and Linux unit tests Change-Id: If8e562ae6f98270a0e6c5aa4251127ce9b79a8b0
This commit is contained in:
@@ -55,6 +55,7 @@ WV_TEST_TARGETS="base64_test \
|
||||
libwvdrmmediacrypto_test \
|
||||
license_keys_unittest \
|
||||
license_unittest \
|
||||
metrics_collections_unittest \
|
||||
oemcrypto_test \
|
||||
policy_engine_constraints_unittest \
|
||||
policy_engine_unittest \
|
||||
|
||||
@@ -280,10 +280,32 @@ CdmResponseType UsageTableHeader::AddEntry(
|
||||
return status;
|
||||
}
|
||||
|
||||
// Variables for metrics.
|
||||
const size_t usage_info_count =
|
||||
std::count_if(usage_entry_info_.cbegin(), usage_entry_info_.cend(),
|
||||
[](const CdmUsageEntryInfo& usage_entry) {
|
||||
return usage_entry.storage_type == kStorageUsageInfo;
|
||||
});
|
||||
const size_t license_count =
|
||||
std::count_if(usage_entry_info_.cbegin(), usage_entry_info_.cend(),
|
||||
[](const CdmUsageEntryInfo& usage_entry) {
|
||||
return usage_entry.storage_type == kStorageLicense;
|
||||
});
|
||||
int64_t staleness_of_removed;
|
||||
CdmUsageEntryStorageType storage_type_of_removed;
|
||||
const int64_t current_time = GetCurrentTime();
|
||||
|
||||
for (size_t i = 0; i < removal_candidates.size() &&
|
||||
status == INSUFFICIENT_CRYPTO_RESOURCES_3;
|
||||
++i) {
|
||||
const uint32_t entry_number_to_delete = removal_candidates[i];
|
||||
// Calculate metric values.
|
||||
staleness_of_removed =
|
||||
current_time -
|
||||
usage_entry_info_[entry_number_to_delete].last_use_time;
|
||||
storage_type_of_removed =
|
||||
usage_entry_info_[entry_number_to_delete].storage_type;
|
||||
|
||||
if (DeleteEntry(entry_number_to_delete, file_handle_.get(), metrics) ==
|
||||
NO_ERROR) {
|
||||
// If the entry was deleted, it is still possible for the create new
|
||||
@@ -297,6 +319,18 @@ CdmResponseType UsageTableHeader::AddEntry(
|
||||
}
|
||||
}
|
||||
status = crypto_session->CreateUsageEntry(usage_entry_number);
|
||||
|
||||
// Record metrics on success.
|
||||
if (status == NO_ERROR) {
|
||||
metrics->usage_table_header_lru_usage_info_count_.Record(
|
||||
usage_info_count);
|
||||
metrics->usage_table_header_lru_offline_license_count_.Record(
|
||||
license_count);
|
||||
metrics->usage_table_header_lru_evicted_entry_staleness_.Record(
|
||||
staleness_of_removed);
|
||||
metrics->usage_table_header_lru_evicted_entry_type_.Record(
|
||||
static_cast<int>(storage_type_of_removed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,11 @@ class CryptoMetrics {
|
||||
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
|
||||
usage_table_header_update_entry_;
|
||||
ValueMetric<size_t> usage_table_header_initial_size_;
|
||||
/* UsageTableHeader - LRU */
|
||||
ValueMetric<size_t> usage_table_header_lru_usage_info_count_;
|
||||
ValueMetric<size_t> usage_table_header_lru_offline_license_count_;
|
||||
ValueMetric<int64_t> usage_table_header_lru_evicted_entry_staleness_;
|
||||
ValueMetric<int> usage_table_header_lru_evicted_entry_type_;
|
||||
/* OEMCRYPTO */
|
||||
ValueMetric<uint32_t> oemcrypto_api_version_;
|
||||
CounterMetric<kOemCryptoResultFieldNumber, OEMCryptoResult>
|
||||
|
||||
@@ -83,7 +83,6 @@ message ValueMetric {
|
||||
optional string string_value = 4;
|
||||
}
|
||||
|
||||
|
||||
// This message contains the specific metrics captured by DrmMetrics. It is
|
||||
// used for serializing and logging metrics.
|
||||
// next id: 3.
|
||||
@@ -94,7 +93,7 @@ message WvCdmMetrics {
|
||||
|
||||
// This contains metrics that were captured at the CryptoSession level. These
|
||||
// include CryptoSession metrics and most OEMCrypto metrics.
|
||||
// next id: 73
|
||||
// next id: 77
|
||||
message CryptoMetrics {
|
||||
// Crypto Session Metrics.
|
||||
optional ValueMetric crypto_session_security_level = 1;
|
||||
@@ -119,6 +118,13 @@ message WvCdmMetrics {
|
||||
repeated CounterMetric usage_table_header_delete_entry = 60;
|
||||
repeated DistributionMetric usage_table_header_update_entry_time_us = 56;
|
||||
repeated CounterMetric usage_table_header_load_entry = 61;
|
||||
// Usage Table LRU Metrics
|
||||
optional ValueMetric usage_table_header_lru_usage_info_count = 73;
|
||||
optional ValueMetric usage_table_header_lru_offline_license_count = 74;
|
||||
optional ValueMetric usage_table_header_lru_evicted_entry_staleness_s = 75;
|
||||
// |usage_table_header_lru_evicted_entry_type| refers to the enumeration
|
||||
// CdmUsageEntryStorageType in wv_cdm_types.h.
|
||||
optional ValueMetric usage_table_header_lru_evicted_entry_type = 76;
|
||||
|
||||
// OemCrypto metrics.
|
||||
optional ValueMetric oemcrypto_api_version = 16;
|
||||
|
||||
@@ -79,6 +79,16 @@ void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
|
||||
crypto_metrics->mutable_usage_table_header_load_entry());
|
||||
crypto_metrics->set_allocated_usage_table_header_initial_size(
|
||||
usage_table_header_initial_size_.ToProto());
|
||||
/* USAGE TABLE HEADER - LRU */
|
||||
crypto_metrics->set_allocated_usage_table_header_lru_usage_info_count(
|
||||
usage_table_header_lru_usage_info_count_.ToProto());
|
||||
crypto_metrics->set_allocated_usage_table_header_lru_offline_license_count(
|
||||
usage_table_header_lru_offline_license_count_.ToProto());
|
||||
crypto_metrics
|
||||
->set_allocated_usage_table_header_lru_evicted_entry_staleness_s(
|
||||
usage_table_header_lru_evicted_entry_staleness_.ToProto());
|
||||
crypto_metrics->set_allocated_usage_table_header_lru_evicted_entry_type(
|
||||
usage_table_header_lru_evicted_entry_type_.ToProto());
|
||||
|
||||
/* OEMCRYPTO */
|
||||
crypto_metrics->set_allocated_oemcrypto_api_version(
|
||||
|
||||
@@ -348,6 +348,12 @@ TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
|
||||
crypto_metrics.usage_table_header_delete_entry_.Increment(UNKNOWN_ERROR);
|
||||
crypto_metrics.usage_table_header_update_entry_.Record(2.0, UNKNOWN_ERROR);
|
||||
crypto_metrics.usage_table_header_load_entry_.Increment(UNKNOWN_ERROR);
|
||||
// Usage table LRU metrics.
|
||||
crypto_metrics.usage_table_header_lru_usage_info_count_.Record(150);
|
||||
crypto_metrics.usage_table_header_lru_offline_license_count_.Record(50);
|
||||
crypto_metrics.usage_table_header_lru_evicted_entry_staleness_.Record(259200);
|
||||
crypto_metrics.usage_table_header_lru_evicted_entry_type_.Record(
|
||||
kStorageUsageInfo);
|
||||
|
||||
// Oem crypto metrics.
|
||||
crypto_metrics.oemcrypto_api_version_.Record(123);
|
||||
@@ -462,6 +468,15 @@ TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
|
||||
EXPECT_GT(actual.usage_table_header_delete_entry_size(), 0);
|
||||
EXPECT_GT(actual.usage_table_header_update_entry_time_us_size(), 0);
|
||||
EXPECT_GT(actual.usage_table_header_load_entry_size(), 0);
|
||||
// Usage table LRU metrics.
|
||||
EXPECT_EQ(150, actual.usage_table_header_lru_usage_info_count().int_value());
|
||||
EXPECT_EQ(50,
|
||||
actual.usage_table_header_lru_offline_license_count().int_value());
|
||||
EXPECT_EQ(
|
||||
259200,
|
||||
actual.usage_table_header_lru_evicted_entry_staleness_s().int_value());
|
||||
EXPECT_EQ(kStorageUsageInfo,
|
||||
actual.usage_table_header_lru_evicted_entry_type().int_value());
|
||||
|
||||
// Oem crypto metrics.
|
||||
EXPECT_EQ(123, actual.oemcrypto_api_version().int_value());
|
||||
|
||||
Reference in New Issue
Block a user