Ran clang-format on the metrics directory.

[ Merge of http://go/wvgerrit/137809 ]

Bug: 204946540
Test: Metric unit tests
Change-Id: Ibd68db73ea9ee64664d33c2cb8e8bb7c56674c27
This commit is contained in:
Alex Dale
2021-11-03 17:24:34 -07:00
parent 2046fc05fa
commit 21a021e800
16 changed files with 431 additions and 441 deletions

View File

@@ -15,97 +15,95 @@ namespace metrics {
//
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeFieldNumber,
CdmResponseType>(const CdmResponseType &cdm_error,
drm_metrics::Attributes *attributes) {
CdmResponseType>(const CdmResponseType& cdm_error,
drm_metrics::Attributes* attributes) {
attributes->set_error_code(cdm_error);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kCdmSecurityLevelFieldNumber,
CdmSecurityLevel>(
const CdmSecurityLevel &cdm_security_level,
drm_metrics::Attributes *attributes) {
const CdmSecurityLevel& cdm_security_level,
drm_metrics::Attributes* attributes) {
attributes->set_cdm_security_level(cdm_security_level);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kSecurityLevelFieldNumber,
SecurityLevel>(const SecurityLevel &security_level,
drm_metrics::Attributes *attributes) {
SecurityLevel>(const SecurityLevel& security_level,
drm_metrics::Attributes* attributes) {
attributes->set_security_level(security_level);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeBoolFieldNumber,
bool>(const bool &cdm_error,
drm_metrics::Attributes *attributes) {
bool>(const bool& cdm_error,
drm_metrics::Attributes* attributes) {
attributes->set_error_code_bool(cdm_error);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kOemCryptoResultFieldNumber,
OEMCryptoResult>(
const OEMCryptoResult &oem_crypto_result,
drm_metrics::Attributes *attributes) {
const OEMCryptoResult& oem_crypto_result,
drm_metrics::Attributes* attributes) {
attributes->set_oem_crypto_result(oem_crypto_result);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket>(
const Pow2Bucket &pow2, drm_metrics::Attributes *attributes) {
const Pow2Bucket& pow2, drm_metrics::Attributes* attributes) {
attributes->set_length(pow2.value());
}
template <>
void SetAttributeField<drm_metrics::Attributes::kEncryptionAlgorithmFieldNumber,
CdmEncryptionAlgorithm>(
const CdmEncryptionAlgorithm &encryption_algorithm,
drm_metrics::Attributes *attributes) {
const CdmEncryptionAlgorithm& encryption_algorithm,
drm_metrics::Attributes* attributes) {
attributes->set_encryption_algorithm(encryption_algorithm);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kSigningAlgorithmFieldNumber,
CdmSigningAlgorithm>(
const CdmSigningAlgorithm &signing_algorithm,
drm_metrics::Attributes *attributes) {
const CdmSigningAlgorithm& signing_algorithm,
drm_metrics::Attributes* attributes) {
attributes->set_signing_algorithm(signing_algorithm);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kKeyRequestTypeFieldNumber,
CdmKeyRequestType>(
const CdmKeyRequestType &key_request_type,
drm_metrics::Attributes *attributes) {
const CdmKeyRequestType& key_request_type,
drm_metrics::Attributes* attributes) {
attributes->set_key_request_type(key_request_type);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kLicenseTypeFieldNumber,
CdmLicenseType>(
const CdmLicenseType &license_type,
drm_metrics::Attributes *attributes) {
CdmLicenseType>(const CdmLicenseType& license_type,
drm_metrics::Attributes* attributes) {
attributes->set_license_type(license_type);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorDetailFieldNumber,
int32_t>(
const int32_t &error_detail,
drm_metrics::Attributes *attributes) {
int32_t>(const int32_t& error_detail,
drm_metrics::Attributes* attributes) {
attributes->set_error_detail(error_detail);
}
template <>
void SetAttributeField<0, util::Unused>(const util::Unused &,
drm_metrics::Attributes *) {
void SetAttributeField<0, util::Unused>(const util::Unused&,
drm_metrics::Attributes*) {
// Intentionally empty.
}
// Specializations only used by tests.
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeFieldNumber, int>(
const int &cdm_error, drm_metrics::Attributes *attributes) {
const int& cdm_error, drm_metrics::Attributes* attributes) {
attributes->set_error_code(cdm_error);
}

View File

@@ -10,7 +10,7 @@
namespace wvcdm {
namespace metrics {
void BaseCounterMetric::Increment(const std::string &counter_key,
void BaseCounterMetric::Increment(const std::string& counter_key,
int64_t value) {
std::unique_lock<std::mutex> lock(internal_lock_);

View File

@@ -12,16 +12,16 @@ namespace metrics {
BaseEventMetric::~BaseEventMetric() {
std::unique_lock<std::mutex> lock(internal_lock_);
for (std::map<std::string, Distribution *>::iterator it = value_map_.begin();
for (std::map<std::string, Distribution*>::iterator it = value_map_.begin();
it != value_map_.end(); it++) {
delete it->second;
}
}
void BaseEventMetric::Record(const std::string &key, double value) {
void BaseEventMetric::Record(const std::string& key, double value) {
std::unique_lock<std::mutex> lock(internal_lock_);
Distribution *distribution;
Distribution* distribution;
if (value_map_.find(key) == value_map_.end()) {
distribution = new Distribution();

View File

@@ -16,12 +16,12 @@ namespace {
// Helper struct for comparing session ids.
struct CompareSessionIds {
const std::string &target_;
const std::string& target_;
CompareSessionIds(const wvcdm::CdmSessionId &target) : target_(target){};
CompareSessionIds(const wvcdm::CdmSessionId& target) : target_(target){};
bool operator()(const std::shared_ptr<wvcdm::metrics::SessionMetrics> metrics)
const {
bool operator()(
const std::shared_ptr<wvcdm::metrics::SessionMetrics> metrics) const {
return metrics->GetSessionId() == target_;
}
};
@@ -31,8 +31,8 @@ struct CompareSessionIds {
namespace wvcdm {
namespace metrics {
void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
const {
void CryptoMetrics::Serialize(
WvCdmMetrics::CryptoMetrics* crypto_metrics) const {
/* CRYPTO SESSION */
crypto_metrics->set_allocated_crypto_session_security_level(
crypto_session_security_level_.ToProto());
@@ -182,8 +182,7 @@ void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
crypto_metrics->mutable_oemcrypto_create_new_usage_entry());
oemcrypto_load_usage_entry_.ToProto(
crypto_metrics->mutable_oemcrypto_load_usage_entry());
oemcrypto_move_entry_.ToProto(
crypto_metrics->mutable_oemcrypto_move_entry());
oemcrypto_move_entry_.ToProto(crypto_metrics->mutable_oemcrypto_move_entry());
oemcrypto_create_old_usage_entry_.ToProto(
crypto_metrics->mutable_oemcrypto_create_old_usage_entry());
oemcrypto_copy_old_usage_entry_.ToProto(
@@ -217,14 +216,14 @@ void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
SessionMetrics::SessionMetrics() : session_id_(""), completed_(false) {}
void SessionMetrics::Serialize(WvCdmMetrics::SessionMetrics *session_metrics)
const {
void SessionMetrics::Serialize(
WvCdmMetrics::SessionMetrics* session_metrics) const {
SerializeSessionMetrics(session_metrics);
crypto_metrics_.Serialize(session_metrics->mutable_crypto_metrics());
}
void SessionMetrics::SerializeSessionMetrics(
WvCdmMetrics::SessionMetrics *session_metrics) const {
WvCdmMetrics::SessionMetrics* session_metrics) const {
// If the session id was set, add it to the metrics. It's possible that
// it's not set in some circumstances such as when provisioning is needed.
if (!session_id_.empty()) {
@@ -287,15 +286,15 @@ void OemCryptoDynamicAdapterMetrics::SetL1MinApiVersion(uint32_t version) {
}
void OemCryptoDynamicAdapterMetrics::Serialize(
WvCdmMetrics::EngineMetrics *engine_metrics) const {
WvCdmMetrics::EngineMetrics* engine_metrics) const {
std::unique_lock<std::mutex> lock(adapter_lock_);
engine_metrics->set_allocated_level3_oemcrypto_initialization_error(
level3_oemcrypto_initialization_error_.ToProto());
oemcrypto_initialization_mode_.ToProto());
engine_metrics->set_allocated_oemcrypto_initialization_mode(
oemcrypto_initialization_mode_.ToProto());
engine_metrics->set_allocated_previous_oemcrypto_initialization_failure(
previous_oemcrypto_initialization_failure_.ToProto());
oemcrypto_initialization_mode_.ToProto());
engine_metrics->set_allocated_oemcrypto_l1_api_version(
oemcrypto_l1_api_version_.ToProto());
engine_metrics->set_allocated_oemcrypto_l1_min_api_version(
@@ -314,22 +313,20 @@ void OemCryptoDynamicAdapterMetrics::Clear() {
// This method returns a reference. This means that the destructor is never
// executed for the returned object.
OemCryptoDynamicAdapterMetrics &GetDynamicAdapterMetricsInstance() {
OemCryptoDynamicAdapterMetrics& GetDynamicAdapterMetricsInstance() {
// This is safe in C++ 11 since the initialization is guaranteed to run
// only once regardless of multi-threaded access.
static OemCryptoDynamicAdapterMetrics *adapter_metrics =
static OemCryptoDynamicAdapterMetrics* adapter_metrics =
new OemCryptoDynamicAdapterMetrics();
return *adapter_metrics;
}
EngineMetrics::EngineMetrics() {
life_span_internal_.Start();
}
EngineMetrics::EngineMetrics() { life_span_internal_.Start(); }
EngineMetrics::~EngineMetrics() {
std::unique_lock<std::mutex> lock(session_metrics_lock_);
if (!active_session_metrics_list_.empty()
|| !completed_session_metrics_list_.empty()) {
if (!active_session_metrics_list_.empty() ||
!completed_session_metrics_list_.empty()) {
LOGV("Session counts: active = %zu, completed = %zu.",
active_session_metrics_list_.size(),
completed_session_metrics_list_.size());
@@ -358,19 +355,17 @@ void EngineMetrics::RemoveSession(wvcdm::CdmSessionId session_id) {
void EngineMetrics::ConsolidateSessions() {
auto completed_filter =
[] (const std::shared_ptr<SessionMetrics>& session_metrics) {
[](const std::shared_ptr<SessionMetrics>& session_metrics) {
return session_metrics->IsCompleted();
};
std::unique_lock<std::mutex> lock(session_metrics_lock_);
std::copy_if(active_session_metrics_list_.begin(),
active_session_metrics_list_.end(),
std::back_inserter(completed_session_metrics_list_),
completed_filter);
std::copy_if(
active_session_metrics_list_.begin(), active_session_metrics_list_.end(),
std::back_inserter(completed_session_metrics_list_), completed_filter);
active_session_metrics_list_.erase(
std::remove_if(active_session_metrics_list_.begin(),
active_session_metrics_list_.end(),
completed_filter),
active_session_metrics_list_.end(), completed_filter),
active_session_metrics_list_.end());
// TODO(b/118664842): Add support to merge older metrics into one
@@ -384,12 +379,12 @@ void EngineMetrics::ConsolidateSessions() {
}
}
void EngineMetrics::Serialize(WvCdmMetrics *wv_metrics) const {
void EngineMetrics::Serialize(WvCdmMetrics* wv_metrics) const {
std::unique_lock<std::mutex> lock(session_metrics_lock_);
WvCdmMetrics::EngineMetrics *engine_metrics =
WvCdmMetrics::EngineMetrics* engine_metrics =
wv_metrics->mutable_engine_metrics();
// Serialize the most recent metrics from the OemCyrpto dynamic adapter.
OemCryptoDynamicAdapterMetrics &adapter_metrics =
OemCryptoDynamicAdapterMetrics& adapter_metrics =
GetDynamicAdapterMetricsInstance();
adapter_metrics.Serialize(engine_metrics);
if (!app_package_name_.empty()) {
@@ -408,12 +403,12 @@ void EngineMetrics::Serialize(WvCdmMetrics *wv_metrics) const {
}
}
void EngineMetrics::SetAppPackageName(const std::string &app_package_name) {
void EngineMetrics::SetAppPackageName(const std::string& app_package_name) {
app_package_name_ = app_package_name;
}
void EngineMetrics::SerializeEngineMetrics(
WvCdmMetrics::EngineMetrics *engine_metrics) const {
WvCdmMetrics::EngineMetrics* engine_metrics) const {
// Set the engine lifespan at the time of serialization.
engine_metrics->mutable_cdm_engine_life_span_ms()->set_int_value(
life_span_internal_.AsMs());

View File

@@ -8,16 +8,14 @@ void TimerMetric::Start() {
is_started_ = true;
}
void TimerMetric::Clear() {
is_started_ = false;
}
void TimerMetric::Clear() { is_started_ = false; }
double TimerMetric::AsMs() const {
return (clock_.now() - start_) / std::chrono::milliseconds(1);
return (clock_.now() - start_) / std::chrono::milliseconds(1);
}
double TimerMetric::AsUs() const {
return (clock_.now() - start_) / std::chrono::microseconds(1);
return (clock_.now() - start_) / std::chrono::microseconds(1);
}
} // namespace metrics

View File

@@ -15,98 +15,95 @@
namespace wvcdm {
namespace metrics {
namespace impl{
namespace impl {
template <>
void SetValue<int>(drm_metrics::ValueMetric *value_proto,
const int &value) {
void SetValue<int>(drm_metrics::ValueMetric* value_proto, const int& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<long>(drm_metrics::ValueMetric *value_proto,
const long &value) {
void SetValue<long>(drm_metrics::ValueMetric* value_proto, const long& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<long long>(drm_metrics::ValueMetric *value_proto,
const long long &value) {
void SetValue<long long>(drm_metrics::ValueMetric* value_proto,
const long long& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<unsigned int>(drm_metrics::ValueMetric *value_proto,
const unsigned int &value) {
void SetValue<unsigned int>(drm_metrics::ValueMetric* value_proto,
const unsigned int& value) {
value_proto->set_int_value((int64_t)value);
}
template <>
void SetValue<unsigned short>(drm_metrics::ValueMetric *value_proto,
const unsigned short &value) {
void SetValue<unsigned short>(drm_metrics::ValueMetric* value_proto,
const unsigned short& value) {
value_proto->set_int_value((int64_t)value);
}
template <>
void SetValue<unsigned long>(drm_metrics::ValueMetric *value_proto,
const unsigned long &value) {
void SetValue<unsigned long>(drm_metrics::ValueMetric* value_proto,
const unsigned long& value) {
value_proto->set_int_value((int64_t)value);
}
template <>
void SetValue<unsigned long long>(drm_metrics::ValueMetric *value_proto,
const unsigned long long &value) {
void SetValue<unsigned long long>(drm_metrics::ValueMetric* value_proto,
const unsigned long long& value) {
value_proto->set_int_value((int64_t)value);
}
template <>
void SetValue<bool>(drm_metrics::ValueMetric *value_proto,
const bool &value) {
void SetValue<bool>(drm_metrics::ValueMetric* value_proto, const bool& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<OEMCrypto_HDCP_Capability>(
drm_metrics::ValueMetric *value_proto,
const OEMCrypto_HDCP_Capability &value) {
drm_metrics::ValueMetric* value_proto,
const OEMCrypto_HDCP_Capability& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<OEMCrypto_ProvisioningMethod>(
drm_metrics::ValueMetric *value_proto,
const OEMCrypto_ProvisioningMethod &value) {
drm_metrics::ValueMetric* value_proto,
const OEMCrypto_ProvisioningMethod& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<OEMCryptoInitializationMode>(
drm_metrics::ValueMetric *value_proto,
const OEMCryptoInitializationMode &value) {
drm_metrics::ValueMetric* value_proto,
const OEMCryptoInitializationMode& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<CdmSecurityLevel>(drm_metrics::ValueMetric *value_proto,
const CdmSecurityLevel &value) {
void SetValue<CdmSecurityLevel>(drm_metrics::ValueMetric* value_proto,
const CdmSecurityLevel& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<CdmUsageSupportType>(drm_metrics::ValueMetric *value_proto,
const CdmUsageSupportType &value) {
void SetValue<CdmUsageSupportType>(drm_metrics::ValueMetric* value_proto,
const CdmUsageSupportType& value) {
value_proto->set_int_value(value);
}
template <>
void SetValue<double>(drm_metrics::ValueMetric *value_proto,
const double &value) {
void SetValue<double>(drm_metrics::ValueMetric* value_proto,
const double& value) {
value_proto->set_double_value(value);
}
template <>
void SetValue<std::string>(drm_metrics::ValueMetric *value_proto,
const std::string &value) {
void SetValue<std::string>(drm_metrics::ValueMetric* value_proto,
const std::string& value) {
value_proto->set_string_value(value);
}