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:
Alex Dale
2019-12-11 15:45:18 -08:00
parent 061b0e7caf
commit aa0d93bf36
6 changed files with 74 additions and 3 deletions

View File

@@ -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));
}
}
}