Source release 17.1.0

This commit is contained in:
John "Juce" Bruce
2022-07-07 17:14:31 -07:00
parent 8c17574083
commit 694cf6fb25
2233 changed files with 272026 additions and 223371 deletions

View File

@@ -1,21 +1,18 @@
// Copyright 2018 Google Inc. All Rights Reserved.
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the declarations for the EventMetric class and related
// types.
#ifndef WVCDM_METRICS_ATTRIBUTE_HANDLER_H_
#define WVCDM_METRICS_ATTRIBUTE_HANDLER_H_
#include <string>
#include "OEMCryptoCENC.h"
#include "field_tuples.h"
#include "log.h"
#include "pow2bucket.h"
#include "value_metric.h"
#include "wv_cdm_types.h"
#include "wv_metrics.pb.h"
namespace wvcdm {
namespace metrics {
// This method is used to set the value of a single proto field.
// Specializations handle setting each value.
template <int I, typename F>
@@ -47,7 +44,6 @@ class AttributeHandler {
return serialized_attributes;
}
};
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_ATTRIBUTE_HANDLER_H_

View File

@@ -1,23 +1,23 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the declarations for the Metric class and related
// types.
#ifndef WVCDM_METRICS_COUNTER_METRIC_H_
#define WVCDM_METRICS_COUNTER_METRIC_H_
#include <cstdarg>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "attribute_handler.h"
#include "field_tuples.h"
#include "wv_metrics.pb.h"
namespace wvcdm {
namespace metrics {
class CounterMetricTest;
// This base class provides the common defintion used by all templated
@@ -37,7 +37,7 @@ class BaseCounterMetric {
// Increment will look for an existing instance of the field names and
// add the new value to the existing value. If the instance does not exist,
// this method will create it.
void Increment(const std::string &counter_key, int64_t value);
void Increment(const std::string& counter_key, int64_t value);
private:
friend class CounterMetricTest;
@@ -99,14 +99,13 @@ class CounterMetric : public BaseCounterMetric {
void Increment(int64_t value, F1 field1 = util::Unused(),
F2 field2 = util::Unused(), F3 field3 = util::Unused(),
F4 field4 = util::Unused()) {
std::string key =
attribute_handler_.GetSerializedAttributes(field1, field2,
field3, field4);
std::string key = attribute_handler_.GetSerializedAttributes(
field1, field2, field3, field4);
BaseCounterMetric::Increment(key, value);
}
void ToProto(::google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>
*counters) const;
void ToProto(::google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>*
counters) const;
private:
friend class CounterMetricTest;
@@ -120,13 +119,12 @@ class CounterMetric : public BaseCounterMetric {
template <>
inline void CounterMetric<0, util::Unused, 0, util::Unused, 0, util::Unused, 0,
util::Unused>::
ToProto(::google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>
*counters) const {
ToProto(::google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>*
counters) const {
const std::map<std::string, int64_t>* values = GetValues();
for (std::map<std::string, int64_t>::const_iterator it = values->begin();
it != values->end(); it++) {
drm_metrics::CounterMetric *new_counter = counters->Add();
drm_metrics::CounterMetric* new_counter = counters->Add();
new_counter->set_count(it->second);
}
}
@@ -134,20 +132,18 @@ inline void CounterMetric<0, util::Unused, 0, util::Unused, 0, util::Unused, 0,
template <int I1, typename F1, int I2, typename F2, int I3, typename F3, int I4,
typename F4>
inline void CounterMetric<I1, F1, I2, F2, I3, F3, I4, F4>::ToProto(
::google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>
*counters) const {
::google::protobuf::RepeatedPtrField<drm_metrics::CounterMetric>* counters)
const {
const std::map<std::string, int64_t>* values = GetValues();
for (std::map<std::string, int64_t>::const_iterator it = values->begin();
it != values->end(); it++) {
drm_metrics::CounterMetric *new_counter = counters->Add();
drm_metrics::CounterMetric* new_counter = counters->Add();
if (!new_counter->mutable_attributes()->ParseFromString(it->first)) {
LOGE("Failed to parse the attributes from a string.");
}
new_counter->set_count(it->second);
}
}
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_COUNTER_METRIC_H_

View File

@@ -1,16 +1,17 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the definition of a Distribution class which computes
// the distribution values of a series of samples.
#ifndef WVCDM_METRICS_DISTRIBUTION_H_
#define WVCDM_METRICS_DISTRIBUTION_H_
#include <stdint.h>
#include <limits>
namespace wvcdm {
namespace metrics {
// The Distribution class holds statistics about a series of values that the
// client provides via the Record method. A caller will call Record once for
// each of the values in a series. The Distribution instance will calculate the
@@ -24,7 +25,7 @@ namespace metrics {
// dist.Count(); // Returns 2.
class Distribution {
public:
Distribution();
Distribution() {}
// Uses the provided sample value to update the computed statistics.
void Record(float value);
@@ -40,14 +41,12 @@ class Distribution {
}
private:
uint64_t count_;
float min_;
float max_;
float mean_;
double sum_squared_deviation_;
uint64_t count_ = 0;
float min_ = std::numeric_limits<float>::max();
float max_ = std::numeric_limits<float>::lowest();
float mean_ = 0.0f;
double sum_squared_deviation_ = 0.0;
};
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_DISTRIBUTION_H_

View File

@@ -1,26 +1,24 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the declarations for the EventMetric class and related
// types.
#ifndef WVCDM_METRICS_EVENT_METRIC_H_
#define WVCDM_METRICS_EVENT_METRIC_H_
#include <cstdarg>
#include <map>
#include <mutex>
#include <string>
#include <vector>
#include "OEMCryptoCENC.h"
#include "attribute_handler.h"
#include "distribution.h"
#include "field_tuples.h"
#include "log.h"
#include "pow2bucket.h"
#include "wv_metrics.pb.h"
namespace wvcdm {
namespace metrics {
class EventMetricTest;
// This base class provides the common defintion used by all templated
@@ -36,12 +34,12 @@ class BaseEventMetric {
// Record will look for an existing instance of the Distribution identified
// by the distribution_key string and update it. If the instance does
// not exist, this will create it.
void Record(const std::string &distribution_key, double value);
void Record(const std::string& distribution_key, double value);
// value_map_ contains a mapping from the string key (attribute name/values)
// to the distribution instance which holds the metric information
// (min, max, sum, etc.).
std::map<std::string, Distribution *> value_map_;
std::map<std::string, Distribution*> value_map_;
private:
friend class EventMetricTest;
@@ -90,34 +88,33 @@ template <int I1 = 0, typename F1 = util::Unused, int I2 = 0,
class EventMetric : public BaseEventMetric {
public:
// Create an EventMetric instance with no attribute breakdowns.
explicit EventMetric() : BaseEventMetric(){}
explicit EventMetric() : BaseEventMetric() {}
// Record will update the statistics of the EventMetric broken down by the
// given field values.
void Record(double value, F1 field1 = util::Unused(),
F2 field2 = util::Unused(), F3 field3 = util::Unused(),
F4 field4 = util::Unused()) {
std::string key =
attribute_handler_.GetSerializedAttributes(field1, field2,
field3, field4);
std::string key = attribute_handler_.GetSerializedAttributes(
field1, field2, field3, field4);
BaseEventMetric::Record(key, value);
}
const std::map<std::string, Distribution *>* GetDistributions() const {
const std::map<std::string, Distribution*>* GetDistributions() const {
return &value_map_;
};
void ToProto(
::google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>
*distributions_proto) const;
::google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>*
distributions_proto) const;
private:
friend class EventMetricTest;
AttributeHandler<I1, F1, I2, F2, I3, F3, I4, F4> attribute_handler_;
inline void SetDistributionValues(
const Distribution &distribution,
drm_metrics::DistributionMetric *metric_proto) const {
const Distribution& distribution,
drm_metrics::DistributionMetric* metric_proto) const {
metric_proto->set_mean(distribution.Mean());
metric_proto->set_operation_count(distribution.Count());
if (distribution.Count() > 1) {
@@ -138,13 +135,14 @@ template <>
inline void EventMetric<0, util::Unused, 0, util::Unused, 0, util::Unused, 0,
util::Unused>::
ToProto(
::google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>
*distributions_proto) const {
const std::map<std::string, Distribution *>* distributions
= GetDistributions();
for (std::map<std::string, Distribution *>::const_iterator it =
distributions->begin(); it != distributions->end(); it++) {
drm_metrics::DistributionMetric *new_metric = distributions_proto->Add();
::google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>*
distributions_proto) const {
const std::map<std::string, Distribution*>* distributions =
GetDistributions();
for (std::map<std::string, Distribution*>::const_iterator it =
distributions->begin();
it != distributions->end(); it++) {
drm_metrics::DistributionMetric* new_metric = distributions_proto->Add();
SetDistributionValues(*it->second, new_metric);
}
}
@@ -152,21 +150,20 @@ inline void EventMetric<0, util::Unused, 0, util::Unused, 0, util::Unused, 0,
template <int I1, typename F1, int I2, typename F2, int I3, typename F3, int I4,
typename F4>
inline void EventMetric<I1, F1, I2, F2, I3, F3, I4, F4>::ToProto(
::google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>
*distributions_proto) const {
const std::map<std::string, Distribution *>* distributions
= GetDistributions();
for (std::map<std::string, Distribution *>::const_iterator it =
distributions->begin(); it != distributions->end(); it++) {
drm_metrics::DistributionMetric *new_metric = distributions_proto->Add();
::google::protobuf::RepeatedPtrField<drm_metrics::DistributionMetric>*
distributions_proto) const {
const std::map<std::string, Distribution*>* distributions =
GetDistributions();
for (std::map<std::string, Distribution*>::const_iterator it =
distributions->begin();
it != distributions->end(); it++) {
drm_metrics::DistributionMetric* new_metric = distributions_proto->Add();
if (!new_metric->mutable_attributes()->ParseFromString(it->first)) {
LOGE("Failed to parse the attributes from a string.");
}
SetDistributionValues(*it->second, new_metric);
}
}
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_EVENT_METRIC_H_

View File

@@ -1,17 +1,16 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the helper classes and methods for using field tuples
// used by metrics classes to record variations of a single metric.
#ifndef WVCDM_METRICS_FIELD_TUPLES_H_
#define WVCDM_METRICS_FIELD_TUPLES_H_
#include <ostream>
#include <sstream>
namespace wvcdm {
namespace metrics {
namespace util {
// TODO(blueeyes): Change to use C++ 11 support for variadic template args.
// The C++ 03 pattern is no longer needed since we require C++11. b/68766426.
@@ -23,9 +22,7 @@ struct Unused {
return out;
}
};
} // namespace util
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_FIELD_TUPLES_H_

View File

@@ -1,15 +1,18 @@
// Copyright 2016 Google Inc. All Rights Reserved.
// Copyright 2016 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains definitions for metrics being collected throughout the
// CDM.
#ifndef WVCDM_METRICS_METRICS_GROUP_H_
#define WVCDM_METRICS_METRICS_GROUP_H_
#ifndef WVCDM_METRICS_METRICS_COLLECTIONS_H_
#define WVCDM_METRICS_METRICS_COLLECTIONS_H_
#include <stddef.h>
#include <stdint.h>
#include <mutex>
#include <ostream>
#include <string>
#include <vector>
#include "OEMCryptoCENC.h"
#include "counter_metric.h"
@@ -48,7 +51,7 @@
// sts);
#define M_TIME(CALL, GROUP, METRIC, ...) \
if (GROUP) { \
wvcdm::metrics::TimerMetric timer; \
wvcdm::metrics::Timer timer; \
timer.Start(); \
CALL; \
(GROUP)->METRIC.Record(timer.AsUs(), ##__VA_ARGS__); \
@@ -58,9 +61,7 @@
namespace wvcdm {
namespace metrics {
namespace {
// Short name definitions to ease AttributeHandler definitions.
// Internal namespace to help simplify declarations.
const int kErrorCodeFieldNumber =
@@ -73,8 +74,7 @@ const int kCdmSecurityLevelFieldNumber =
::drm_metrics::Attributes::kCdmSecurityLevelFieldNumber;
const int kSecurityLevelFieldNumber =
::drm_metrics::Attributes::kSecurityLevelFieldNumber;
const int kLengthFieldNumber =
::drm_metrics::Attributes::kLengthFieldNumber;
const int kLengthFieldNumber = ::drm_metrics::Attributes::kLengthFieldNumber;
const int kEncryptAlgorithmFieldNumber =
::drm_metrics::Attributes::kEncryptionAlgorithmFieldNumber;
const int kSigningAlgorithmFieldNumber =
@@ -89,8 +89,7 @@ const int kKeyRequestTypeFieldNumber =
::drm_metrics::Attributes::kKeyRequestTypeFieldNumber;
const int kLicenseTypeFieldNumber =
::drm_metrics::Attributes::kLicenseTypeFieldNumber;
} // anonymous namespace
} // namespace
// The maximum number of completed sessions that can be stored. More than this
// will cause some metrics to be discarded.
@@ -120,13 +119,14 @@ typedef enum OEMCryptoInitializationMode {
OEMCrypto_INITIALIZED_L3_SAVE_DEVICE_KEYS_FAILED = 18,
OEMCrypto_INITIALIZED_L3_READ_DEVICE_KEYS_FAILED = 19,
OEMCrypto_INITIALIZED_L3_VERIFY_DEVICE_KEYS_FAILED = 20,
OEMCrypto_INITIALIZED_USING_L1_WITH_PROVISIONING_4_0 = 21,
} OEMCryptoInitializationMode;
// This class contains metrics for Crypto Session and OEM Crypto.
class CryptoMetrics {
public:
void Serialize(drm_metrics::WvCdmMetrics::CryptoMetrics *crypto_metrics)
const;
void Serialize(
drm_metrics::WvCdmMetrics::CryptoMetrics* crypto_metrics) const;
/* CRYPTO SESSION */
// TODO(blueeyes): Convert this to crypto_session_default_security_level_.
@@ -156,7 +156,7 @@ class CryptoMetrics {
crypto_session_load_certificate_private_key_;
// This uses the requested security level.
EventMetric<kErrorCodeFieldNumber, CdmResponseType, kSecurityLevelFieldNumber,
SecurityLevel>
RequestedSecurityLevel>
crypto_session_open_;
ValueMetric<uint32_t> crypto_session_system_id_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
@@ -234,7 +234,7 @@ class CryptoMetrics {
ValueMetric<bool> oemcrypto_is_anti_rollback_hw_present_;
ValueMetric<bool> oemcrypto_is_keybox_valid_;
EventMetric<kOemCryptoResultFieldNumber, OEMCryptoResult>
oemcrypto_load_device_rsa_key_;
oemcrypto_load_device_drm_key_;
EventMetric<kOemCryptoResultFieldNumber, OEMCryptoResult>
oemcrypto_load_entitled_keys_;
EventMetric<kOemCryptoResultFieldNumber, OEMCryptoResult>
@@ -293,7 +293,13 @@ class CryptoMetrics {
oemcrypto_load_provisioning_;
ValueMetric<uint32_t> oemcrypto_minor_api_version_;
ValueMetric<uint32_t> oemcrypto_maximum_usage_table_header_size_;
};
EventMetric<kOemCryptoResultFieldNumber, OEMCryptoResult>
oemcrypto_generate_certificate_key_pair_;
EventMetric<kOemCryptoResultFieldNumber, OEMCryptoResult>
oemcrypto_install_oem_private_key_;
ValueMetric<int> oemcrypto_watermarking_support_;
ValueMetric<int> oemcrypto_production_readiness_;
}; // class CryptoMetrics
// This class contains session-scoped metrics. All properties and
// statistics related to operations within a single session are
@@ -304,12 +310,12 @@ class SessionMetrics {
// Sets the session id of the metrics group. This allows the session
// id to be captured and reported as part of the collection of metrics.
void SetSessionId(const CdmSessionId &session_id) {
void SetSessionId(const CdmSessionId& session_id) {
session_id_ = session_id;
}
// Returns the session id or an empty session id if it has not been set.
const CdmSessionId &GetSessionId() const { return session_id_; }
const CdmSessionId& GetSessionId() const { return session_id_; }
// Marks the metrics object as completed and ready for serialization.
void SetCompleted() { completed_ = true; }
@@ -320,16 +326,16 @@ class SessionMetrics {
// Returns a pointer to the crypto metrics belonging to the engine instance.
// This instance retains ownership of the object.
CryptoMetrics *GetCryptoMetrics() { return &crypto_metrics_; }
CryptoMetrics* GetCryptoMetrics() { return &crypto_metrics_; }
// Metrics collected at the session level.
ValueMetric<double> cdm_session_life_span_; // Milliseconds.
EventMetric<kErrorCodeFieldNumber, CdmResponseType> cdm_session_renew_key_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType,
kErrorDetailFieldNumber, int32_t>
CounterMetric<kErrorCodeFieldNumber, CdmResponseType, kErrorDetailFieldNumber,
int32_t>
cdm_session_restore_offline_session_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType,
kErrorDetailFieldNumber, int32_t>
CounterMetric<kErrorCodeFieldNumber, CdmResponseType, kErrorDetailFieldNumber,
int32_t>
cdm_session_restore_usage_session_;
EventMetric<kKeyRequestTypeFieldNumber, CdmKeyRequestType>
@@ -337,19 +343,21 @@ class SessionMetrics {
ValueMetric<std::string> oemcrypto_build_info_;
ValueMetric<std::string> license_sdk_version_;
ValueMetric<std::string> license_service_version_;
ValueMetric<std::string> playback_id_;
ValueMetric<int> drm_certificate_key_type_;
// Serialize the session metrics to the provided |metric_group|.
// |metric_group| is owned by the caller and must not be null.
void Serialize(drm_metrics::WvCdmMetrics::SessionMetrics *session_metrics)
const;
void Serialize(
drm_metrics::WvCdmMetrics::SessionMetrics* session_metrics) const;
private:
void SerializeSessionMetrics(
drm_metrics::WvCdmMetrics::SessionMetrics *session_metrics) const;
drm_metrics::WvCdmMetrics::SessionMetrics* session_metrics) const;
CdmSessionId session_id_;
bool completed_;
CryptoMetrics crypto_metrics_;
};
}; // class SessionMetrics
// This class contains metrics for the OEMCrypto Dynamic Adapter. They are
// separated from other metrics because they need to be encapsulated in a
@@ -373,8 +381,8 @@ class OemCryptoDynamicAdapterMetrics {
// Serialize the session metrics to the provided |metric_group|.
// |metric_group| is owned by the caller and must not be null.
void Serialize(drm_metrics::WvCdmMetrics::EngineMetrics *engine_metrics)
const;
void Serialize(
drm_metrics::WvCdmMetrics::EngineMetrics* engine_metrics) const;
// Clears the existing metric values.
void Clear();
@@ -388,14 +396,14 @@ class OemCryptoDynamicAdapterMetrics {
previous_oemcrypto_initialization_failure_;
ValueMetric<uint32_t> oemcrypto_l1_api_version_;
ValueMetric<uint32_t> oemcrypto_l1_min_api_version_;
};
}; // class OemCryptoDynamicAdapterMetrics
// This will fetch the singleton instance for dynamic adapter metrics.
// This method is safe only if we use C++ 11. In C++ 11, static function-local
// initialization is guaranteed to be threadsafe. We return the reference to
// avoid non-guaranteed destructor order problems. Effectively, the destructor
// is never run for the created instance.
OemCryptoDynamicAdapterMetrics &GetDynamicAdapterMetricsInstance();
OemCryptoDynamicAdapterMetrics& GetDynamicAdapterMetricsInstance();
// This class contains engine-scoped metrics. All properties and
// statistics related to operations within the engine, but outside
@@ -426,18 +434,19 @@ class EngineMetrics {
// Returns a pointer to the crypto metrics belonging to the engine instance.
// The CryptoMetrics instance is still owned by this object and will exist
// until this object is deleted.
CryptoMetrics *GetCryptoMetrics() { return &crypto_metrics_; }
CryptoMetrics* GetCryptoMetrics() { return &crypto_metrics_; }
// Serialize engine and session metrics into a serialized WvCdmMetrics
// instance and output that instance to the provided |engine_metrics|.
// |engine_metrics| is owned by the caller and must NOT be null.
void Serialize(drm_metrics::WvCdmMetrics *engine_metrics) const;
void Serialize(drm_metrics::WvCdmMetrics* engine_metrics) const;
void SetAppPackageName(const std::string &app_package_name);
void SetAppPackageName(const std::string& app_package_name);
// Metrics recorded at the engine level.
EventMetric<kErrorCodeFieldNumber, CdmResponseType,
kLicenseTypeFieldNumber, CdmLicenseType> cdm_engine_add_key_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType, kLicenseTypeFieldNumber,
CdmLicenseType>
cdm_engine_add_key_;
ValueMetric<std::string> cdm_engine_cdm_version_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType>
cdm_engine_close_session_;
@@ -447,15 +456,15 @@ class EngineMetrics {
cdm_engine_decrypt_;
CounterMetric<kErrorCodeBoolFieldNumber, bool>
cdm_engine_find_session_for_key_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType,
kLicenseTypeFieldNumber, CdmLicenseType>
EventMetric<kErrorCodeFieldNumber, CdmResponseType, kLicenseTypeFieldNumber,
CdmLicenseType>
cdm_engine_generate_key_request_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
cdm_engine_get_provisioning_request_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType>
cdm_engine_get_secure_stop_ids_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType,
kErrorDetailFieldNumber, int32_t>
EventMetric<kErrorCodeFieldNumber, CdmResponseType, kErrorDetailFieldNumber,
int32_t>
cdm_engine_get_usage_info_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
cdm_engine_handle_provisioning_response_;
@@ -486,15 +495,13 @@ class EngineMetrics {
std::vector<std::shared_ptr<metrics::SessionMetrics>>
completed_session_metrics_list_;
// This is used to populate the engine lifespan metric
metrics::TimerMetric life_span_internal_;
metrics::Timer life_span_internal_;
CryptoMetrics crypto_metrics_;
std::string app_package_name_;
void SerializeEngineMetrics(
drm_metrics::WvCdmMetrics::EngineMetrics *engine_metrics) const;
};
drm_metrics::WvCdmMetrics::EngineMetrics* engine_metrics) const;
}; // class EngineMetrics
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_METRICS_GROUP_H_
#endif // WVCDM_METRICS_METRICS_COLLECTIONS_H_

View File

@@ -1,13 +1,13 @@
// Copyright 2018 Google Inc. All Rights Reserved.
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the declaration of the Pow2Bucket class which
// is a convenient way to bucketize sampled values into powers of 2.
#ifndef WVCDM_METRICS_POW2BUCKET_H_
#define WVCDM_METRICS_POW2BUCKET_H_
namespace wvcdm {
namespace metrics {
// This class converts the size_t value into the highest power of two
// below the value. E.g. for 7, the value is 4. For 11, the value is 8.
// This class is intended to simplify the use of EventMetric Fields that may
@@ -17,12 +17,12 @@ class Pow2Bucket {
public:
explicit Pow2Bucket(size_t value) : value_(GetLowerBucket(value)) {}
Pow2Bucket(const Pow2Bucket &value) : value_(value.value_) {}
Pow2Bucket(const Pow2Bucket& value) : value_(value.value_) {}
size_t value() const { return value_; }
// Support for converting to string.
friend std::ostream &operator<<(std::ostream &os, const Pow2Bucket &log) {
friend std::ostream& operator<<(std::ostream& os, const Pow2Bucket& log) {
return os << log.value_;
}
@@ -43,8 +43,6 @@ class Pow2Bucket {
size_t value_;
};
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_POW2BUCKET_H_

View File

@@ -1,15 +1,15 @@
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
#ifndef WVCDM_METRICS_TIMER_METRIC_H_
#define WVCDM_METRICS_TIMER_METRIC_H_
#include <chrono>
namespace wvcdm {
namespace metrics {
class TimerMetric {
class Timer {
public:
// Constructs a new TimerMetric.
explicit TimerMetric() : is_started_(false) {}
Timer() {}
// Starts the clock running. If the clock was previously set, this resets it.
// IsStarted will return true after this call.
void Start();
@@ -24,11 +24,9 @@ class TimerMetric {
double AsUs() const;
private:
std::chrono::steady_clock clock_;
std::chrono::time_point<std::chrono::steady_clock> start_;
bool is_started_;
bool is_started_ = false;
};
} // namespace metrics
} // namespace wvcdm
#endif
#endif // WVCDM_METRICS_TIMER_METRIC_H_

View File

@@ -1,11 +1,13 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the declarations for the Metric class and related
// types.
#ifndef WVCDM_METRICS_VALUE_METRIC_H_
#define WVCDM_METRICS_VALUE_METRIC_H_
#include <stdint.h>
#include <mutex>
#include <string>
@@ -13,114 +15,103 @@
namespace wvcdm {
namespace metrics {
// Internal namespace for helper methods.
namespace impl {
namespace internal {
// Helper function for setting a value in the proto.
template <typename T>
void SetValue(drm_metrics::ValueMetric *value_proto, const T &value);
} // namespace impl
void SetValue(drm_metrics::ValueMetric* value_proto, const T& value);
} // namespace internal
// The ValueMetric class supports storing a single, overwritable value or an
// error code. This class can be serialized to a drm_metrics::ValueMetric proto.
// If an error or value was not provided, this metric will serialize to nullptr.
//
// Example Usage:
// Metric<string> cdm_version().Record("a.b.c.d");
// ValueMetric<string> cdm_version().Record("a.b.c.d");
// std::unique_ptr<drm_metrics::ValueMetric> mymetric(
// cdm_version.ToProto());
//
// Example Error Usage:
//
// Metric<string> cdm_version().SetError(error_code);
// ValueMetric<string> cdm_version().SetError(error_code);
// std::unique_ptr<drm_metrics::ValueMetric> mymetric(
// cdm_version.ToProto());
//
template <typename T>
class ValueMetric {
public:
// Constructs a metric with the given metric name.
explicit ValueMetric()
: error_code_(0), has_error_(false), has_value_(false) {}
ValueMetric() {}
// Record the value of the metric.
void Record(const T &value) {
std::unique_lock<std::mutex> lock(internal_lock_);
void Record(const T& value) {
std::unique_lock<std::mutex> lock(mutex_);
value_ = value;
has_value_ = true;
has_error_ = false;
state_ = kHasValue;
}
// Set the error code if an error was encountered.
void SetError(int error_code) {
std::unique_lock<std::mutex> lock(internal_lock_);
std::unique_lock<std::mutex> lock(mutex_);
error_code_ = error_code;
has_value_ = false;
has_error_ = true;
state_ = kHasError;
}
bool HasValue() const {
std::unique_lock<std::mutex> lock(internal_lock_);
return has_value_;
std::unique_lock<std::mutex> lock(mutex_);
return state_ == kHasValue;
}
const T &GetValue() const {
std::unique_lock<std::mutex> lock(internal_lock_);
const T& GetValue() const {
std::unique_lock<std::mutex> lock(mutex_);
return value_;
}
bool HasError() const {
std::unique_lock<std::mutex> lock(internal_lock_);
return has_error_;
std::unique_lock<std::mutex> lock(mutex_);
return state_ == kHasError;
}
int GetError() const {
std::unique_lock<std::mutex> lock(internal_lock_);
std::unique_lock<std::mutex> lock(mutex_);
return error_code_;
}
// Clears the indicators that the metric or error was set.
void Clear() {
std::unique_lock<std::mutex> lock(internal_lock_);
has_value_ = false;
has_error_ = false;
std::unique_lock<std::mutex> lock(mutex_);
state_ = kNone;
}
// Returns a new ValueMetric proto containing the metric value or the
// error code. If neither the error or value are set, it returns nullptr.
drm_metrics::ValueMetric *ToProto() const {
std::unique_lock<std::mutex> lock(internal_lock_);
if (has_error_) {
drm_metrics::ValueMetric *value_proto = new drm_metrics::ValueMetric;
value_proto->set_error_code(error_code_);
return value_proto;
} else if (has_value_) {
drm_metrics::ValueMetric *value_proto = new drm_metrics::ValueMetric;
impl::SetValue(value_proto, value_);
return value_proto;
drm_metrics::ValueMetric* ToProto() const {
std::unique_lock<std::mutex> lock(mutex_);
switch (state_) {
case kHasValue: {
drm_metrics::ValueMetric* value_proto = new drm_metrics::ValueMetric;
internal::SetValue(value_proto, value_);
return value_proto;
}
case kHasError: {
drm_metrics::ValueMetric* value_proto = new drm_metrics::ValueMetric;
value_proto->set_error_code(error_code_);
return value_proto;
}
case kNone:
default:
return nullptr;
}
return nullptr;
}
private:
enum ValueState { kNone, kHasValue, kHasError };
T value_;
int error_code_;
bool has_error_;
bool has_value_;
int error_code_ = 0;
ValueState state_ = kNone;
/*
* This locks the internal state of the value metric to ensure safety
* across multiple threads preventing the caller from worrying about
* locking.
*
* This field must be declared mutable because the lock must be takeable even
* in const methods.
*/
mutable std::mutex internal_lock_;
// This locks the internal state of the value metric to ensure safety
// across multiple threads preventing the caller from worrying about
// locking.
mutable std::mutex mutex_;
};
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_VALUE_METRIC_H_

View File

@@ -1,10 +1,59 @@
cc_library {
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
name: "libcdm_metrics_protos",
// Build host library for metrics_dump tool.
// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS. PLEASE
// CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE
// DEPENDING ON IT IN YOUR PROJECT. ***
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "vendor_widevine_license"
// to get the below license kinds:
// legacy_by_exception_only (by exception only)
default_applicable_licenses: ["vendor_widevine_license"],
}
cc_library_host_shared {
name: "libcdm_metrics_protos_full_host",
vendor: true,
include_dirs: ["external/protobuf/src"],
srcs: [
"wv_metrics.proto",
"wv_metrics.proto",
],
cflags: [
"-Wall",
"-Werror",
],
proto: {
export_proto_headers: true,
type: "full",
},
}
cc_library {
name: "libcdm_metrics_protos",
vendor: true,
srcs: [
"wv_metrics.proto",
],
cflags: [
@@ -16,5 +65,4 @@ cc_library {
export_proto_headers: true,
type: "full",
},
}

View File

@@ -1,113 +1,114 @@
// Copyright 2018 Google Inc. All Rights Reserved.
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains implementations for the AttributeHandler.
#include "attribute_handler.h"
#include "OEMCryptoCENC.h"
#include "field_tuples.h"
#include "pow2bucket.h"
#include "wv_cdm_types.h"
namespace wvcdm {
namespace metrics {
//
// Specializations for setting attribute fields.
//
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) {
RequestedSecurityLevel>(
const RequestedSecurityLevel& 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);
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,16 +1,15 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains implementations for the BaseCounterMetric, the base class
// for CounterMetric.
#include "counter_metric.h"
#include "wv_metrics.pb.h"
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_);
@@ -20,6 +19,5 @@ void BaseCounterMetric::Increment(const std::string &counter_key,
value_map_[counter_key] = value_map_[counter_key] + value;
}
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,31 +1,19 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the definitions for the Distribution class members.
#include "distribution.h"
#include <float.h>
namespace wvcdm {
namespace metrics {
Distribution::Distribution()
: count_(0ULL),
min_(FLT_MAX),
max_(-FLT_MAX),
mean_(0.0),
sum_squared_deviation_(0.0) {}
void Distribution::Record(float value) {
// Using method of provisional means.
float deviation = value - mean_;
mean_ = mean_ + (deviation / ++count_);
sum_squared_deviation_ =
sum_squared_deviation_ + (deviation * (value - mean_));
const float deviation = value - mean_;
mean_ += (deviation / ++count_);
sum_squared_deviation_ += (deviation * (value - mean_));
min_ = min_ < value ? min_ : value;
max_ = max_ > value ? max_ : value;
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,28 +1,23 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains implementations for the BaseEventMetric.
#include "event_metric.h"
using ::google::protobuf::RepeatedPtrField;
namespace wvcdm {
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();
value_map_[key] = distribution;
@@ -32,6 +27,5 @@ void BaseEventMetric::Record(const std::string &key, double value) {
distribution->Record(value);
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,5 +1,6 @@
// Copyright 2016 Google Inc. All Rights Reserved.
// Copyright 2016 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
#include "metrics_collections.h"
#include <algorithm>
@@ -7,32 +8,28 @@
#include "log.h"
#include "wv_metrics.pb.h"
namespace wvcdm {
namespace metrics {
using ::drm_metrics::Attributes;
using ::drm_metrics::WvCdmMetrics;
using ::google::protobuf::RepeatedPtrField;
using ::wvcdm::metrics::EventMetric;
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_;
}
};
} // namespace
} // anonymous namespace
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());
@@ -140,8 +137,8 @@ void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
oemcrypto_is_anti_rollback_hw_present_.ToProto());
crypto_metrics->set_allocated_oemcrypto_is_keybox_valid(
oemcrypto_is_keybox_valid_.ToProto());
oemcrypto_load_device_rsa_key_.ToProto(
crypto_metrics->mutable_oemcrypto_load_device_rsa_key_time_us());
oemcrypto_load_device_drm_key_.ToProto(
crypto_metrics->mutable_oemcrypto_load_device_drm_key_time_us());
oemcrypto_load_entitled_keys_.ToProto(
crypto_metrics->mutable_oemcrypto_load_entitled_keys_time_us());
oemcrypto_load_keys_.ToProto(
@@ -182,8 +179,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(
@@ -213,18 +209,22 @@ void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
oemcrypto_minor_api_version_.ToProto());
crypto_metrics->set_allocated_oemcrypto_maximum_usage_table_header_size(
oemcrypto_maximum_usage_table_header_size_.ToProto());
crypto_metrics->set_allocated_oemcrypto_watermarking_support(
oemcrypto_watermarking_support_.ToProto());
crypto_metrics->set_allocated_oemcrypto_production_readiness(
oemcrypto_production_readiness_.ToProto());
}
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()) {
@@ -246,6 +246,9 @@ void SessionMetrics::SerializeSessionMetrics(
license_sdk_version_.ToProto());
session_metrics->set_allocated_license_service_version(
license_service_version_.ToProto());
session_metrics->set_allocated_playback_id(playback_id_.ToProto());
session_metrics->set_allocated_drm_certificate_key_type(
drm_certificate_key_type_.ToProto());
}
OemCryptoDynamicAdapterMetrics::OemCryptoDynamicAdapterMetrics()
@@ -284,15 +287,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(
oemcrypto_initialization_mode_.ToProto());
level3_oemcrypto_initialization_error_.ToProto());
engine_metrics->set_allocated_oemcrypto_initialization_mode(
oemcrypto_initialization_mode_.ToProto());
engine_metrics->set_allocated_previous_oemcrypto_initialization_failure(
oemcrypto_initialization_mode_.ToProto());
previous_oemcrypto_initialization_failure_.ToProto());
engine_metrics->set_allocated_oemcrypto_l1_api_version(
oemcrypto_l1_api_version_.ToProto());
engine_metrics->set_allocated_oemcrypto_l1_min_api_version(
@@ -311,22 +314,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());
@@ -355,38 +356,36 @@ 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
// consolidated metric.
int excess_completed = completed_session_metrics_list_.size()
- kMaxCompletedSessions;
if (excess_completed > 0) {
if (completed_session_metrics_list_.size() > kMaxCompletedSessions) {
const size_t excess_completed =
completed_session_metrics_list_.size() - kMaxCompletedSessions;
completed_session_metrics_list_.erase(
completed_session_metrics_list_.begin(),
completed_session_metrics_list_.begin() + excess_completed);
}
}
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()) {
@@ -405,12 +404,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());
@@ -460,6 +459,5 @@ void EngineMetrics::SerializeEngineMetrics(
crypto_metrics_.Serialize(engine_metrics->mutable_crypto_metrics());
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,24 +1,30 @@
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
#include "timer_metric.h"
namespace wvcdm {
namespace metrics {
using ClockType = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<ClockType>;
void TimerMetric::Start() {
start_ = clock_.now();
void Timer::Start() {
start_ = ClockType::now();
is_started_ = true;
}
void TimerMetric::Clear() {
is_started_ = false;
void Timer::Clear() { is_started_ = false; }
double Timer::AsMs() const {
if (!is_started_) return 0.0;
const TimePoint end = ClockType::now();
return (end - start_) / std::chrono::milliseconds(1);
}
double TimerMetric::AsMs() const {
return (clock_.now() - start_) / std::chrono::milliseconds(1);
double Timer::AsUs() const {
if (!is_started_) return 0.0;
const TimePoint end = ClockType::now();
return (end - start_) / std::chrono::microseconds(1);
}
double TimerMetric::AsUs() const {
return (clock_.now() - start_) / std::chrono::microseconds(1);
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,115 +1,129 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains the specializations for helper methods for the
// ValueMetric class.
#include <stdint.h>
#include <string>
#include "value_metric.h"
#include <limits>
#include "OEMCryptoCENC.h"
#include "metrics_collections.h"
#include "wv_cdm_types.h"
namespace wvcdm {
namespace metrics {
namespace internal {
namespace {
// Max value of protobuf's int64 type.
constexpr uint64_t kMaxValueCmp =
static_cast<uint64_t>(std::numeric_limits<int64_t>::max());
constexpr int64_t kMaxValue = std::numeric_limits<int64_t>::max();
namespace impl{
template <typename T>
constexpr bool WillOverflow(T value) {
return static_cast<uint64_t>(value) > kMaxValueCmp;
}
// Prevents an overflow of very large numbers. If the value attempted to
// be assigned is greater than the maximum value supported by protobuf's
// int64 type, then the value is capped at the max.
template <typename T>
constexpr int64_t SafeAssign(T value) {
return WillOverflow(value) ? kMaxValue : static_cast<int64_t>(value);
}
} // namespace
template <>
void SetValue<int>(drm_metrics::ValueMetric *value_proto,
const int &value) {
value_proto->set_int_value(value);
void SetValue<int>(drm_metrics::ValueMetric* value_proto, const int& value) {
value_proto->set_int_value(static_cast<int64_t>(value));
}
template <>
void SetValue<long>(drm_metrics::ValueMetric *value_proto,
const long &value) {
value_proto->set_int_value(value);
void SetValue<long>(drm_metrics::ValueMetric* value_proto, const long& value) {
value_proto->set_int_value(static_cast<int64_t>(value));
}
template <>
void SetValue<long long>(drm_metrics::ValueMetric *value_proto,
const long long &value) {
value_proto->set_int_value(value);
void SetValue<long long>(drm_metrics::ValueMetric* value_proto,
const long long& value) {
value_proto->set_int_value(SafeAssign(value));
}
template <>
void SetValue<unsigned int>(drm_metrics::ValueMetric *value_proto,
const unsigned int &value) {
value_proto->set_int_value((int64_t)value);
void SetValue<unsigned int>(drm_metrics::ValueMetric* value_proto,
const unsigned int& value) {
value_proto->set_int_value(SafeAssign(value));
}
template <>
void SetValue<unsigned short>(drm_metrics::ValueMetric *value_proto,
const unsigned short &value) {
value_proto->set_int_value((int64_t)value);
void SetValue<unsigned short>(drm_metrics::ValueMetric* value_proto,
const unsigned short& value) {
value_proto->set_int_value(SafeAssign(value));
}
template <>
void SetValue<unsigned long>(drm_metrics::ValueMetric *value_proto,
const unsigned long &value) {
value_proto->set_int_value((int64_t)value);
void SetValue<unsigned long>(drm_metrics::ValueMetric* value_proto,
const unsigned long& value) {
value_proto->set_int_value(SafeAssign(value));
}
template <>
void SetValue<unsigned long long>(drm_metrics::ValueMetric *value_proto,
const unsigned long long &value) {
value_proto->set_int_value((int64_t)value);
void SetValue<unsigned long long>(drm_metrics::ValueMetric* value_proto,
const unsigned long long& value) {
value_proto->set_int_value(SafeAssign(value));
}
template <>
void SetValue<bool>(drm_metrics::ValueMetric *value_proto,
const bool &value) {
value_proto->set_int_value(value);
void SetValue<bool>(drm_metrics::ValueMetric* value_proto, const bool& value) {
value_proto->set_int_value(value ? 1 : 0);
}
template <>
void SetValue<OEMCrypto_HDCP_Capability>(
drm_metrics::ValueMetric *value_proto,
const OEMCrypto_HDCP_Capability &value) {
value_proto->set_int_value(value);
drm_metrics::ValueMetric* value_proto,
const OEMCrypto_HDCP_Capability& value) {
value_proto->set_int_value(static_cast<int64_t>(value));
}
template <>
void SetValue<OEMCrypto_ProvisioningMethod>(
drm_metrics::ValueMetric *value_proto,
const OEMCrypto_ProvisioningMethod &value) {
value_proto->set_int_value(value);
drm_metrics::ValueMetric* value_proto,
const OEMCrypto_ProvisioningMethod& value) {
value_proto->set_int_value(static_cast<int64_t>(value));
}
template <>
void SetValue<OEMCryptoInitializationMode>(
drm_metrics::ValueMetric *value_proto,
const OEMCryptoInitializationMode &value) {
value_proto->set_int_value(value);
drm_metrics::ValueMetric* value_proto,
const OEMCryptoInitializationMode& value) {
value_proto->set_int_value(static_cast<int64_t>(value));
}
template <>
void SetValue<CdmSecurityLevel>(drm_metrics::ValueMetric *value_proto,
const CdmSecurityLevel &value) {
value_proto->set_int_value(value);
void SetValue<CdmSecurityLevel>(drm_metrics::ValueMetric* value_proto,
const CdmSecurityLevel& value) {
value_proto->set_int_value(static_cast<int64_t>(value));
}
template <>
void SetValue<CdmUsageSupportType>(drm_metrics::ValueMetric *value_proto,
const CdmUsageSupportType &value) {
value_proto->set_int_value(value);
void SetValue<CdmUsageSupportType>(drm_metrics::ValueMetric* value_proto,
const CdmUsageSupportType& value) {
value_proto->set_int_value(static_cast<int64_t>(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);
}
} // namespace impl
} // namespace internal
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,4 +1,6 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains a proto definition for serialization of metrics data.
//
@@ -15,10 +17,7 @@ option optimize_for = LITE_RUNTIME;
// want to count all of the operations with a give error code.
message Attributes {
// Reserved for compatibility with logging proto.
// TODO(blueeyes): The reserved keyword is not supported in the older version
// of protoc in the CE CDM third_party directory. Uncomment the reserved
// line when we upgrade. b/67016366.
// reserved 8, 10 to 13;
reserved 8, 10 to 13;
// The error code. See CdmResponseType in wv_cdm_types.h
optional int32 error_code = 1;
@@ -93,7 +92,7 @@ message WvCdmMetrics {
// This contains metrics that were captured at the CryptoSession level. These
// include CryptoSession metrics and most OEMCrypto metrics.
// next id: 85
// next id: 87
message CryptoMetrics {
// Crypto Session Metrics.
optional ValueMetric crypto_session_security_level = 1;
@@ -155,7 +154,7 @@ message WvCdmMetrics {
repeated DistributionMetric oemcrypto_initialize_time_us = 38;
optional ValueMetric oemcrypto_is_anti_rollback_hw_present = 39;
optional ValueMetric oemcrypto_is_keybox_valid = 40;
repeated DistributionMetric oemcrypto_load_device_rsa_key_time_us = 41;
repeated DistributionMetric oemcrypto_load_device_drm_key_time_us = 41;
repeated DistributionMetric oemcrypto_load_entitled_keys_time_us = 42;
repeated DistributionMetric oemcrypto_load_keys_time_us = 43;
optional ValueMetric oemcrypto_max_hdcp_capability = 44;
@@ -182,8 +181,6 @@ message WvCdmMetrics {
optional ValueMetric oemcrypto_set_sandbox = 70;
repeated CounterMetric oemcrypto_set_decrypt_hash = 71;
optional ValueMetric oemcrypto_resource_rating_tier = 72;
// TODO(b/142684157): Remove this comment before closing bug.
// OemCrypto V16 metrics start at 77 (4 new metrics pending review).
repeated DistributionMetric
oemcrypto_prep_and_sign_license_request_time_us = 77;
repeated DistributionMetric
@@ -195,11 +192,13 @@ message WvCdmMetrics {
repeated DistributionMetric oemcrypto_load_provisioning_time_us = 82;
optional ValueMetric oemcrypto_minor_api_version = 83;
optional ValueMetric oemcrypto_maximum_usage_table_header_size = 84;
optional ValueMetric oemcrypto_watermarking_support = 85;
optional ValueMetric oemcrypto_production_readiness = 86;
}
// This contains metrics that were captured within a CdmSession. This contains
// nested CryptoMetrics that were captured in the context of the session.
// next id: 9
// next id: 13
message SessionMetrics {
optional ValueMetric session_id = 1;
optional CryptoMetrics crypto_metrics = 2;
@@ -211,6 +210,9 @@ message WvCdmMetrics {
optional ValueMetric oemcrypto_build_info = 8;
optional ValueMetric license_sdk_version = 9;
optional ValueMetric license_service_version = 10;
optional ValueMetric playback_id = 11;
// Value is enumerated based on the OEMCrypto document: RSA = 0, ECC = 1
optional ValueMetric drm_certificate_key_type = 12;
}
// These are metrics recorded at the Engine level. This includes CryptoSession

View File

@@ -1,19 +1,19 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Unit tests for CounterMetric
#include "counter_metric.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "string_conversions.h"
#include <gtest/gtest.h>
using drm_metrics::TestMetrics;
using testing::IsNull;
using testing::NotNull;
#include "pow2bucket.h"
#include "string_conversions.h"
#include "wv_cdm_types.h"
namespace wvcdm {
namespace metrics {
using drm_metrics::TestMetrics;
TEST(CounterMetricTest, NoFieldsEmpty) {
wvcdm::metrics::CounterMetric<> metric;
@@ -38,12 +38,13 @@ TEST(CounterMetricTest, NoFieldsSuccess) {
EXPECT_EQ(11, metric_proto.test_counters(0).count());
EXPECT_FALSE(metric_proto.test_counters(0).has_attributes())
<< std::string("Unexpected attributes value. Serialized metrics: ")
<< wvcdm::b2a_hex(serialized_metrics);
<< wvutil::b2a_hex(serialized_metrics);
}
TEST(CounterMetricTest, OneFieldSuccess) {
wvcdm::metrics::CounterMetric<drm_metrics::Attributes::kErrorCodeFieldNumber,
int> metric;
int>
metric;
metric.Increment(7);
metric.Increment(10, 7);
metric.Increment(13);
@@ -61,7 +62,8 @@ TEST(CounterMetricTest, OneFieldSuccess) {
TEST(CounterMetricTest, TwoFieldsSuccess) {
CounterMetric<drm_metrics::Attributes::kErrorCodeFieldNumber, int,
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket> metric;
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket>
metric;
metric.Increment(7, Pow2Bucket(23)); // Increment by one.
metric.Increment(2, 7, Pow2Bucket(33));
@@ -93,7 +95,7 @@ TEST(CounterMetricTest, ThreeFieldsSuccess) {
CounterMetric<drm_metrics::Attributes::kErrorCodeFieldNumber, int,
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket,
drm_metrics::Attributes::kErrorCodeBoolFieldNumber, bool>
metric;
metric;
metric.Increment(7, Pow2Bucket(13), true);
TestMetrics metric_proto;
@@ -110,7 +112,8 @@ TEST(CounterMetricTest, FourFieldsSuccess) {
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket,
drm_metrics::Attributes::kErrorCodeBoolFieldNumber, bool,
drm_metrics::Attributes::kSecurityLevelFieldNumber,
SecurityLevel> metric;
RequestedSecurityLevel>
metric;
metric.Increment(10LL, 7, Pow2Bucket(13), true, kLevel3);
TestMetrics metric_proto;
@@ -123,6 +126,5 @@ TEST(CounterMetricTest, FourFieldsSuccess) {
EXPECT_EQ(kLevel3,
metric_proto.test_counters(0).attributes().security_level());
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,16 +1,17 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Unit tests for Distribution.
#include <float.h>
#include "distribution.h"
#include "gtest/gtest.h"
#include <float.h>
#include <gtest/gtest.h>
namespace wvcdm {
namespace metrics {
TEST(DistributionTest, NoValuesRecorded) {
Distribution distribution;
EXPECT_EQ(FLT_MAX, distribution.Min());
@@ -41,7 +42,5 @@ TEST(DistributionTest, MultipleValuesRecorded) {
EXPECT_EQ(3u, distribution.Count());
EXPECT_NEAR(16.6667, distribution.Variance(), 0.0001);
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,23 +1,22 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Unit tests for EventMetric
#include "event_metric.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "string_conversions.h"
#include <gtest/gtest.h>
using drm_metrics::TestMetrics;
using testing::IsNull;
using testing::NotNull;
#include "string_conversions.h"
#include "wv_cdm_types.h"
namespace wvcdm {
namespace metrics {
using drm_metrics::TestMetrics;
class EventMetricTest : public ::testing::Test {
public:
void SetUp() {}
void SetUp() override {}
protected:
};
@@ -46,7 +45,7 @@ TEST_F(EventMetricTest, NoFieldsSuccess) {
EXPECT_EQ(2u, metric_proto.test_distributions(0).operation_count());
EXPECT_FALSE(metric_proto.test_distributions(0).has_attributes())
<< std::string("Unexpected attributes value. Serialized metrics: ")
<< wvcdm::b2a_hex(serialized_metrics);
<< wvutil::b2a_hex(serialized_metrics);
}
TEST_F(EventMetricTest, OneFieldSuccess) {
@@ -71,7 +70,8 @@ TEST_F(EventMetricTest, OneFieldSuccess) {
TEST_F(EventMetricTest, TwoFieldsSuccess) {
EventMetric<drm_metrics::Attributes::kErrorCodeFieldNumber, int,
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket> metric;
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket>
metric;
metric.Record(1, 7, Pow2Bucket(23));
metric.Record(2, 7, Pow2Bucket(33));
@@ -114,7 +114,8 @@ TEST_F(EventMetricTest, TwoFieldsSuccess) {
TEST_F(EventMetricTest, ThreeFieldsSuccess) {
EventMetric<drm_metrics::Attributes::kErrorCodeFieldNumber, int,
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket,
drm_metrics::Attributes::kErrorCodeBoolFieldNumber, bool> metric;
drm_metrics::Attributes::kErrorCodeBoolFieldNumber, bool>
metric;
metric.Record(10LL, 7, Pow2Bucket(13), false);
metric.Record(11LL, 8, Pow2Bucket(17), true);
@@ -127,14 +128,16 @@ TEST_F(EventMetricTest, ThreeFieldsSuccess) {
EXPECT_FALSE(metric_proto.test_distributions(0).has_variance());
EXPECT_EQ(7, metric_proto.test_distributions(0).attributes().error_code());
EXPECT_EQ(8u, metric_proto.test_distributions(0).attributes().length());
EXPECT_FALSE(metric_proto.test_distributions(0).attributes().error_code_bool());
EXPECT_FALSE(
metric_proto.test_distributions(0).attributes().error_code_bool());
EXPECT_EQ(1u, metric_proto.test_distributions(1).operation_count());
EXPECT_EQ(11LL, metric_proto.test_distributions(1).mean());
EXPECT_FALSE(metric_proto.test_distributions(1).has_variance());
EXPECT_EQ(8, metric_proto.test_distributions(1).attributes().error_code());
EXPECT_EQ(16u, metric_proto.test_distributions(1).attributes().length());
EXPECT_TRUE(metric_proto.test_distributions(1).attributes().error_code_bool());
EXPECT_TRUE(
metric_proto.test_distributions(1).attributes().error_code_bool());
}
TEST_F(EventMetricTest, FourFieldsSuccess) {
@@ -142,7 +145,8 @@ TEST_F(EventMetricTest, FourFieldsSuccess) {
drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket,
drm_metrics::Attributes::kErrorCodeBoolFieldNumber, bool,
drm_metrics::Attributes::kCdmSecurityLevelFieldNumber,
CdmSecurityLevel> metric;
CdmSecurityLevel>
metric;
metric.Record(10LL, 7, Pow2Bucket(13), true, kSecurityLevelL3);
@@ -155,7 +159,8 @@ TEST_F(EventMetricTest, FourFieldsSuccess) {
EXPECT_FALSE(metric_proto.test_distributions(0).has_variance());
EXPECT_EQ(7, metric_proto.test_distributions(0).attributes().error_code());
EXPECT_EQ(8u, metric_proto.test_distributions(0).attributes().length());
EXPECT_TRUE(metric_proto.test_distributions(0).attributes().error_code_bool());
EXPECT_TRUE(
metric_proto.test_distributions(0).attributes().error_code_bool());
EXPECT_EQ(
3u, metric_proto.test_distributions(0).attributes().cdm_security_level());
}
@@ -185,6 +190,5 @@ TEST_F(EventMetricTest, Pow2BucketTest) {
value << Pow2Bucket(0x7FFFFFFF);
EXPECT_EQ("1073741824", value.str());
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,29 +1,24 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Unit tests for the metrics collections,
// EngineMetrics, SessionMetrics and CrytpoMetrics.
#include "metrics_collections.h"
#include <sstream>
#include <gtest/gtest.h>
#include "gmock/gmock.h"
#include "google/protobuf/text_format.h"
#include "gtest/gtest.h"
#include "log.h"
#include "wv_cdm_types.h"
#include "wv_metrics.pb.h"
using drm_metrics::MetricsGroup;
using google::protobuf::TextFormat;
namespace wvcdm {
namespace metrics {
using drm_metrics::MetricsGroup;
// TODO(blueeyes): Improve this implementation by supporting full message
// API In CDM. That allows us to use MessageDifferencer.
class EngineMetricsTest : public ::testing::Test {
};
class EngineMetricsTest : public ::testing::Test {};
TEST_F(EngineMetricsTest, AllEngineMetrics) {
EngineMetrics engine_metrics;
@@ -45,7 +40,8 @@ TEST_F(EngineMetricsTest, AllEngineMetrics) {
engine_metrics.cdm_engine_release_usage_info_.Record(1.0, NO_ERROR);
engine_metrics.cdm_engine_remove_keys_.Record(1.0, NO_ERROR);
engine_metrics.cdm_engine_restore_key_.Record(1.0, NO_ERROR);
engine_metrics.cdm_engine_unprovision_.Record(1.0, NO_ERROR, kSecurityLevelL1);
engine_metrics.cdm_engine_unprovision_.Record(1.0, NO_ERROR,
kSecurityLevelL1);
drm_metrics::MetricsGroup actual_metrics;
engine_metrics.Serialize(&actual_metrics, true, false);
@@ -73,10 +69,9 @@ TEST_F(EngineMetricsTest, EngineAndCryptoMetrics) {
engine_metrics.cdm_engine_close_session_.Record(1.0, NO_ERROR);
CryptoMetrics* crypto_metrics = engine_metrics.GetCryptoMetrics();
crypto_metrics->crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics->crypto_session_get_device_unique_id_
.Record(4.0, false);
crypto_metrics->crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics->crypto_session_get_device_unique_id_.Record(4.0, false);
drm_metrics::MetricsGroup actual_metrics;
engine_metrics.Serialize(&actual_metrics, true, false);
@@ -124,8 +119,8 @@ TEST_F(EngineMetricsTest, EngineMetricsWithCompletedSessions) {
SessionMetrics* session_metrics_2 = engine_metrics.AddSession();
session_metrics_2->SetSessionId("session_id_2");
// Record a CryptoMetrics metric in the session.
session_metrics_2->GetCryptoMetrics()->crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
session_metrics_2->GetCryptoMetrics()->crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
session_metrics_2->SetSessionId("session_id_2");
// Mark only session 2 as completed.
session_metrics_2->SetCompleted();
@@ -144,9 +139,10 @@ TEST_F(EngineMetricsTest, EngineMetricsWithCompletedSessions) {
// Spot check some metrics.
EXPECT_EQ("/drm/widevine/cdm_engine/add_key/time/count{error:2}",
actual_metrics.metric(0).name());
EXPECT_EQ("/drm/widevine/crypto_session/load_certificate_private_key"
"/time/count{success:1}",
actual_metrics.metric(2).name());
EXPECT_EQ(
"/drm/widevine/crypto_session/load_certificate_private_key"
"/time/count{success:1}",
actual_metrics.metric(2).name());
EXPECT_EQ("/drm/widevine/cdm_session/session_id",
actual_metrics.metric_sub_group(0).metric(0).name());
EXPECT_EQ(
@@ -241,8 +237,7 @@ TEST_F(EngineMetricsTest, EngineMetricsRemoveSessions) {
ASSERT_EQ(0, actual_metrics.metric_sub_group_size());
}
class SessionMetricsTest : public ::testing::Test {
};
class SessionMetricsTest : public ::testing::Test {};
TEST_F(SessionMetricsTest, AllSessionMetrics) {
SessionMetrics session_metrics;
@@ -254,8 +249,8 @@ TEST_F(SessionMetricsTest, AllSessionMetrics) {
session_metrics.cdm_session_restore_usage_session_.Record(1.0, NO_ERROR);
// Record a CryptoMetrics metric in the session.
session_metrics.GetCryptoMetrics()->crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
session_metrics.GetCryptoMetrics()->crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
MetricsGroup actual_metrics;
session_metrics.Serialize(&actual_metrics);
@@ -271,9 +266,10 @@ TEST_F(SessionMetricsTest, AllSessionMetrics) {
EXPECT_EQ("/drm/widevine/cdm_session/renew_key/time/mean{error:0}",
actual_metrics.metric(4).name());
EXPECT_EQ(1.0, actual_metrics.metric(4).value().double_value());
EXPECT_EQ("/drm/widevine/crypto_session/generic_decrypt/time/count"
"{error:0&length:1024&encryption_algorithm:1}",
actual_metrics.metric(9).name());
EXPECT_EQ(
"/drm/widevine/crypto_session/generic_decrypt/time/count"
"{error:0&length:1024&encryption_algorithm:1}",
actual_metrics.metric(9).name());
}
TEST_F(SessionMetricsTest, EmptySessionMetrics) {
@@ -290,134 +286,126 @@ TEST_F(SessionMetricsTest, EmptySessionMetrics) {
EXPECT_EQ(0, actual_metrics.metric_sub_group_size());
}
class CryptoMetricsTest : public ::testing::Test {
};
class CryptoMetricsTest : public ::testing::Test {};
TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
CryptoMetrics crypto_metrics;
// Crypto session metrics.
crypto_metrics.crypto_session_delete_all_usage_reports_
.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_delete_multiple_usage_information_
.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_encrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_sign_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_generic_verify_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_delete_all_usage_reports_.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_delete_multiple_usage_information_.Record(
1.0, NO_ERROR);
crypto_metrics.crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_encrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_sign_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_generic_verify_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_get_device_unique_id_.Record(1.0, true);
crypto_metrics.crypto_session_get_security_level_
.Record(1.0, kSecurityLevelL1);
crypto_metrics.crypto_session_get_security_level_.Record(1.0,
kSecurityLevelL1);
crypto_metrics.crypto_session_get_system_id_.Record(1.0, true, 1234);
crypto_metrics.crypto_session_get_token_.Record(1.0, true);
crypto_metrics.crypto_session_life_span_.Record(1.0);
crypto_metrics.crypto_session_load_certificate_private_key_
.Record(1.0, true);
crypto_metrics.crypto_session_load_certificate_private_key_.Record(1.0, true);
crypto_metrics.crypto_session_open_.Record(1.0, NO_ERROR, kLevelDefault);
crypto_metrics.crypto_session_update_usage_information_
.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_update_usage_information_.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_usage_information_support_.Record(1.0, true);
// Oem crypto metrics.
crypto_metrics.oemcrypto_api_version_.Record(1.0, 123, kLevelDefault);
crypto_metrics.oemcrypto_close_session_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_copy_buffer_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED,
kLevelDefault, Pow2Bucket(1025));
crypto_metrics.oemcrypto_deactivate_usage_entry_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_decrypt_cenc_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_delete_usage_entry_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_delete_usage_table_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_derive_keys_from_session_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_force_delete_usage_entry_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_derived_keys_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_nonce_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_rsa_signature_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generate_signature_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_decrypt_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_encrypt_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_sign_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_verify_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_get_device_id_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_hdcp_capability_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_key_data_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED,
Pow2Bucket(1025), kLevelDefault);
crypto_metrics.oemcrypto_get_max_number_of_sessions_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_number_of_open_sessions_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_oem_public_certificate_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_close_session_.Record(1.0,
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_copy_buffer_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED,
kLevelDefault, Pow2Bucket(1025));
crypto_metrics.oemcrypto_deactivate_usage_entry_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_decrypt_cenc_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_delete_usage_entry_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_delete_usage_table_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_derive_keys_from_session_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_force_delete_usage_entry_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_derived_keys_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_nonce_.Record(1.0,
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_rsa_signature_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generate_signature_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_decrypt_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_encrypt_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_sign_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_verify_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_get_device_id_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_hdcp_capability_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_key_data_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025), kLevelDefault);
crypto_metrics.oemcrypto_get_max_number_of_sessions_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_number_of_open_sessions_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_get_oem_public_certificate_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_get_provisioning_method_
.Record(1.0, OEMCrypto_Keybox, kLevelDefault);
crypto_metrics.oemcrypto_get_provisioning_method_.Record(
1.0, OEMCrypto_Keybox, kLevelDefault);
crypto_metrics.oemcrypto_get_random_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_initialize_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_install_keybox_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_is_anti_rollback_hw_present_
.Record(1.0, true, kLevelDefault);
crypto_metrics.oemcrypto_get_random_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED,
Pow2Bucket(1025));
crypto_metrics.oemcrypto_initialize_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_install_keybox_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_is_anti_rollback_hw_present_.Record(1.0, true,
kLevelDefault);
crypto_metrics.oemcrypto_is_keybox_valid_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_load_device_rsa_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_is_keybox_valid_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_load_device_rsa_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_keys_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_test_keybox_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_test_rsa_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_open_session_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_refresh_keys_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_report_usage_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_30_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_security_level_
.Record(1.0, kSecurityLevelL2, kLevelDefault);
crypto_metrics.oemcrypto_security_patch_level_
.Record(1.0, 123, kLevelDefault);
crypto_metrics.oemcrypto_select_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_supports_usage_table_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_update_usage_table_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_wrap_keybox_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_test_keybox_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_test_rsa_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_open_session_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_refresh_keys_.Record(1.0,
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_report_usage_.Record(1.0,
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_30_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_security_level_.Record(1.0, kSecurityLevelL2,
kLevelDefault);
crypto_metrics.oemcrypto_security_patch_level_.Record(1.0, 123,
kLevelDefault);
crypto_metrics.oemcrypto_select_key_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_supports_usage_table_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, kLevelDefault);
crypto_metrics.oemcrypto_update_usage_table_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_wrap_keybox_.Record(1.0,
OEMCrypto_ERROR_INIT_FAILED);
// Internal OEMCrypto Metrics
crypto_metrics.oemcrypto_initialization_mode_
.Record(1.0, OEMCrypto_INITIALIZED_FORCING_L3);
crypto_metrics.oemcrypto_initialization_mode_.Record(
1.0, OEMCrypto_INITIALIZED_FORCING_L3);
crypto_metrics.oemcrypto_l1_api_version_.Record(1.0, 12, 123);
MetricsGroup actual_metrics;
@@ -440,6 +428,5 @@ TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
// No subgroups should exist.
EXPECT_EQ(0, actual_metrics.metric_sub_group_size());
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,35 +1,31 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Unit tests for the metrics collections,
// EngineMetrics, SessionMetrics and CryptoMetrics.
#include "metrics_collections.h"
#include <sstream>
#include <gtest/gtest.h>
#include "device_files.h"
#include "gmock/gmock.h"
#include "google/protobuf/text_format.h"
#include "gtest/gtest.h"
#include "log.h"
#include "string_conversions.h"
#include "wv_cdm_types.h"
#include "wv_metrics.pb.h"
namespace wvcdm {
namespace metrics {
using drm_metrics::WvCdmMetrics;
namespace {
const char kSessionId1[] = "session_id_1";
const char kSessionId2[] = "session_id_2";
} // anonymous namespace
namespace wvcdm {
namespace metrics {
} // namespace
// TODO(blueeyes): Improve this implementation by supporting full message
// API In CDM. That allows us to use MessageDifferencer.
class EngineMetricsTest : public ::testing::Test {
};
class EngineMetricsTest : public ::testing::Test {};
TEST_F(EngineMetricsTest, AllEngineMetrics) {
EngineMetrics engine_metrics;
@@ -78,16 +74,16 @@ TEST_F(EngineMetricsTest, AllEngineMetrics) {
EXPECT_GT(actual.engine_metrics().cdm_engine_decrypt_time_us_size(), 0);
EXPECT_GT(actual.engine_metrics().cdm_engine_find_session_for_key_size(), 0);
EXPECT_GT(
actual.engine_metrics()
.cdm_engine_generate_key_request_time_us_size(), 0);
EXPECT_GT(
actual.engine_metrics()
.cdm_engine_get_provisioning_request_time_us_size(), 0);
actual.engine_metrics().cdm_engine_generate_key_request_time_us_size(),
0);
EXPECT_GT(actual.engine_metrics()
.cdm_engine_get_provisioning_request_time_us_size(),
0);
EXPECT_GT(actual.engine_metrics().cdm_engine_get_usage_info_time_us_size(),
0);
EXPECT_GT(
actual.engine_metrics()
.cdm_engine_handle_provisioning_response_time_us_size(), 0);
EXPECT_GT(actual.engine_metrics()
.cdm_engine_handle_provisioning_response_time_us_size(),
0);
EXPECT_GT(actual.engine_metrics().cdm_engine_open_key_set_session_size(), 0);
EXPECT_GT(actual.engine_metrics().cdm_engine_open_session_size(), 0);
EXPECT_GT(actual.engine_metrics().cdm_engine_query_key_status_time_us_size(),
@@ -105,9 +101,9 @@ TEST_F(EngineMetricsTest, AllEngineMetrics) {
actual.engine_metrics().app_package_name().string_value());
EXPECT_EQ("test cdm version",
actual.engine_metrics().cdm_engine_cdm_version().string_value());
EXPECT_EQ(100,
actual.engine_metrics()
.cdm_engine_creation_time_millis().int_value());
EXPECT_EQ(
100,
actual.engine_metrics().cdm_engine_creation_time_millis().int_value());
}
TEST_F(EngineMetricsTest, EngineAndCryptoMetrics) {
@@ -120,8 +116,8 @@ TEST_F(EngineMetricsTest, EngineAndCryptoMetrics) {
CryptoMetrics* crypto_metrics = engine_metrics.GetCryptoMetrics();
crypto_metrics->crypto_session_get_device_unique_id_.Increment(NO_ERROR);
crypto_metrics->crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics->crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
WvCdmMetrics actual_metrics;
engine_metrics.Serialize(&actual_metrics);
@@ -133,29 +129,38 @@ TEST_F(EngineMetricsTest, EngineAndCryptoMetrics) {
ASSERT_EQ(1,
actual_metrics.engine_metrics().cdm_engine_add_key_time_us_size());
EXPECT_EQ(2, actual_metrics.engine_metrics()
.cdm_engine_add_key_time_us(0)
.attributes().error_code());
ASSERT_EQ(1,
actual_metrics.engine_metrics().cdm_engine_close_session_size());
.cdm_engine_add_key_time_us(0)
.attributes()
.error_code());
ASSERT_EQ(1, actual_metrics.engine_metrics().cdm_engine_close_session_size());
EXPECT_EQ(UNKNOWN_ERROR, actual_metrics.engine_metrics()
.cdm_engine_close_session(0)
.attributes().error_code());
ASSERT_EQ(1, actual_metrics.engine_metrics().crypto_metrics()
.crypto_session_get_device_unique_id_size());
EXPECT_EQ(1, actual_metrics.engine_metrics().crypto_metrics()
.crypto_session_get_device_unique_id(0)
.count());
EXPECT_EQ(NO_ERROR, actual_metrics.engine_metrics().crypto_metrics()
.crypto_session_get_device_unique_id(0)
.attributes().error_code());
ASSERT_EQ(1, actual_metrics.engine_metrics().crypto_metrics()
.crypto_session_generic_decrypt_time_us_size());
EXPECT_EQ(2.0, actual_metrics.engine_metrics().crypto_metrics()
.crypto_session_generic_decrypt_time_us(0)
.mean());
EXPECT_EQ(NO_ERROR, actual_metrics.engine_metrics().crypto_metrics()
.crypto_session_generic_decrypt_time_us(0)
.attributes().error_code());
.cdm_engine_close_session(0)
.attributes()
.error_code());
ASSERT_EQ(1, actual_metrics.engine_metrics()
.crypto_metrics()
.crypto_session_get_device_unique_id_size());
EXPECT_EQ(1, actual_metrics.engine_metrics()
.crypto_metrics()
.crypto_session_get_device_unique_id(0)
.count());
EXPECT_EQ(NO_ERROR, actual_metrics.engine_metrics()
.crypto_metrics()
.crypto_session_get_device_unique_id(0)
.attributes()
.error_code());
ASSERT_EQ(1, actual_metrics.engine_metrics()
.crypto_metrics()
.crypto_session_generic_decrypt_time_us_size());
EXPECT_EQ(2.0, actual_metrics.engine_metrics()
.crypto_metrics()
.crypto_session_generic_decrypt_time_us(0)
.mean());
EXPECT_EQ(NO_ERROR, actual_metrics.engine_metrics()
.crypto_metrics()
.crypto_session_generic_decrypt_time_us(0)
.attributes()
.error_code());
}
TEST_F(EngineMetricsTest, EmptyEngineMetrics) {
@@ -186,8 +191,8 @@ TEST_F(EngineMetricsTest, EngineMetricsWithSessions) {
engine_metrics.AddSession();
session_metrics_2->SetSessionId(kSessionId2);
// Record a CryptoMetrics metric in the session.
session_metrics_2->GetCryptoMetrics()->crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
session_metrics_2->GetCryptoMetrics()->crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
WvCdmMetrics actual_metrics;
engine_metrics.Serialize(&actual_metrics);
@@ -201,7 +206,8 @@ TEST_F(EngineMetricsTest, EngineMetricsWithSessions) {
actual_metrics.session_metrics(0).session_id().string_value());
EXPECT_EQ(kSessionId2,
actual_metrics.session_metrics(1).session_id().string_value());
EXPECT_EQ(1, actual_metrics.session_metrics(1).crypto_metrics()
EXPECT_EQ(1, actual_metrics.session_metrics(1)
.crypto_metrics()
.crypto_session_generic_decrypt_time_us_size());
}
@@ -259,8 +265,7 @@ TEST_F(EngineMetricsTest, EngineMetricsConsolidateSessionsNoSessions) {
ASSERT_EQ(0, actual_metrics.session_metrics_size());
}
class SessionMetricsTest : public ::testing::Test {
};
class SessionMetricsTest : public ::testing::Test {};
TEST_F(SessionMetricsTest, AllSessionMetrics) {
SessionMetrics session_metrics;
@@ -275,11 +280,13 @@ TEST_F(SessionMetricsTest, AllSessionMetrics) {
2.0, kKeyRequestTypeInitial);
session_metrics.oemcrypto_build_info_.Record("test build info");
session_metrics.license_sdk_version_.Record("test license sdk version");
session_metrics.license_service_version_.Record("test license service version");
session_metrics.license_service_version_.Record(
"test license service version");
session_metrics.drm_certificate_key_type_.Record(1);
// Record a CryptoMetrics metric in the session.
session_metrics.GetCryptoMetrics()->crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
session_metrics.GetCryptoMetrics()->crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
WvCdmMetrics::SessionMetrics actual;
session_metrics.Serialize(&actual);
@@ -297,6 +304,7 @@ TEST_F(SessionMetricsTest, AllSessionMetrics) {
actual.license_service_version().string_value().c_str());
EXPECT_GT(
actual.crypto_metrics().crypto_session_generic_decrypt_time_us_size(), 0);
EXPECT_EQ(1, actual.drm_certificate_key_type().int_value());
}
TEST_F(SessionMetricsTest, EmptySessionMetrics) {
@@ -313,32 +321,30 @@ TEST_F(SessionMetricsTest, EmptySessionMetrics) {
EXPECT_EQ(0, actual_metrics.cdm_session_restore_usage_session_size());
}
class CryptoMetricsTest : public ::testing::Test {
};
class CryptoMetricsTest : public ::testing::Test {};
TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
CryptoMetrics crypto_metrics;
// Crypto session metrics.
crypto_metrics.crypto_session_delete_all_usage_reports_.Increment(NO_ERROR);
crypto_metrics.crypto_session_delete_multiple_usage_information_
.Increment(NO_ERROR);
crypto_metrics.crypto_session_generic_decrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_encrypt_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_sign_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_generic_verify_
.Record(2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_delete_multiple_usage_information_.Increment(
NO_ERROR);
crypto_metrics.crypto_session_generic_decrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_encrypt_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kEncryptionAlgorithmAesCbc128);
crypto_metrics.crypto_session_generic_sign_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_generic_verify_.Record(
2.0, NO_ERROR, Pow2Bucket(1025), kSigningAlgorithmHmacSha256);
crypto_metrics.crypto_session_get_device_unique_id_.Increment(NO_ERROR);
crypto_metrics.crypto_session_get_token_.Increment(NO_ERROR);
crypto_metrics.crypto_session_life_span_.Record(1.0);
crypto_metrics.crypto_session_load_certificate_private_key_
.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_load_certificate_private_key_.Record(1.0,
NO_ERROR);
crypto_metrics.crypto_session_open_.Record(1.0, NO_ERROR, kLevelDefault);
crypto_metrics.crypto_session_update_usage_information_
.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_update_usage_information_.Record(1.0, NO_ERROR);
crypto_metrics.crypto_session_usage_information_support_.Record(true);
crypto_metrics.crypto_session_security_level_.Record(kSecurityLevelL2);
@@ -357,90 +363,89 @@ TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
// Oem crypto metrics.
crypto_metrics.oemcrypto_api_version_.Record(123);
crypto_metrics.oemcrypto_close_session_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_copy_buffer_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_deactivate_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_decrypt_cenc_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_delete_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_delete_usage_table_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_derive_keys_from_session_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_force_delete_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_derived_keys_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_nonce_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_rsa_signature_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generate_signature_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_decrypt_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_encrypt_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_sign_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_verify_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_get_device_id_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_get_key_data_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_close_session_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_copy_buffer_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED,
Pow2Bucket(1025));
crypto_metrics.oemcrypto_deactivate_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_decrypt_cenc_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_delete_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_delete_usage_table_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_derive_keys_from_session_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_force_delete_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_derived_keys_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_nonce_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_generate_rsa_signature_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generate_signature_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_decrypt_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_encrypt_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_sign_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_generic_verify_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_get_device_id_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_get_key_data_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED, Pow2Bucket(1025));
crypto_metrics.oemcrypto_max_number_of_sessions_.Record(7);
crypto_metrics.oemcrypto_number_of_open_sessions_.Record(5);
crypto_metrics.oemcrypto_get_oem_public_certificate_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_get_oem_public_certificate_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_provisioning_method_.Record(OEMCrypto_Keybox);
crypto_metrics.oemcrypto_get_random_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_initialize_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_get_random_.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_initialize_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_is_anti_rollback_hw_present_.Record(true);
crypto_metrics.oemcrypto_is_keybox_valid_.Record(true);
crypto_metrics.oemcrypto_load_device_rsa_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_device_drm_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_keys_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_refresh_keys_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_refresh_keys_.Record(1.0,
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_report_usage_.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_30_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_rewrap_device_rsa_key_30_.Record(
1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_security_patch_level_.Record(123);
crypto_metrics.oemcrypto_select_key_
.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_update_usage_table_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_create_usage_table_header_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_usage_table_header_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_shrink_usage_table_header_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_create_new_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_move_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_create_old_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_copy_old_usage_entry_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_select_key_.Record(1.0, OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_update_usage_table_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_create_usage_table_header_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_usage_table_header_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_shrink_usage_table_header_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_create_new_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_load_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_move_entry_.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_create_old_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_copy_old_usage_entry_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_set_sandbox_.Record("sandbox");
crypto_metrics.oemcrypto_set_decrypt_hash_
.Increment(OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_set_decrypt_hash_.Increment(
OEMCrypto_ERROR_INIT_FAILED);
crypto_metrics.oemcrypto_resource_rating_tier_.Record(123);
crypto_metrics.oemcrypto_minor_api_version_.Record(234);
crypto_metrics.oemcrypto_maximum_usage_table_header_size_.Record(321);
crypto_metrics.oemcrypto_watermarking_support_.Record(
OEMCrypto_WatermarkingAlwaysOn);
crypto_metrics.oemcrypto_production_readiness_.Record(OEMCrypto_SUCCESS);
WvCdmMetrics::CryptoMetrics actual;
crypto_metrics.Serialize(&actual);
@@ -509,7 +514,7 @@ TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
EXPECT_GT(actual.oemcrypto_initialize_time_us_size(), 0);
EXPECT_EQ(true, actual.oemcrypto_is_anti_rollback_hw_present().int_value());
EXPECT_EQ(true, actual.oemcrypto_is_keybox_valid().int_value());
EXPECT_GT(actual.oemcrypto_load_device_rsa_key_time_us_size(), 0);
EXPECT_GT(actual.oemcrypto_load_device_drm_key_time_us_size(), 0);
EXPECT_GT(actual.oemcrypto_load_keys_time_us_size(), 0);
EXPECT_GT(actual.oemcrypto_refresh_keys_time_us_size(), 0);
EXPECT_GT(actual.oemcrypto_report_usage_size(), 0);
@@ -532,7 +537,10 @@ TEST_F(CryptoMetricsTest, AllCryptoMetrics) {
EXPECT_EQ(234, actual.oemcrypto_minor_api_version().int_value());
EXPECT_EQ(321,
actual.oemcrypto_maximum_usage_table_header_size().int_value());
EXPECT_EQ(static_cast<int>(OEMCrypto_WatermarkingAlwaysOn),
actual.oemcrypto_watermarking_support().int_value());
EXPECT_EQ(static_cast<int>(OEMCrypto_SUCCESS),
actual.oemcrypto_production_readiness().int_value());
}
} // namespace metrics
} // namespace wvcdm

View File

@@ -1,19 +1,17 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// Unit tests for ValueMetric.
#include "value_metric.h"
#include <memory>
#include <string>
#include "value_metric.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "wv_metrics.pb.h"
#include <gtest/gtest.h>
namespace wvcdm {
namespace metrics {
TEST(ValueMetricTest, StringValue) {
ValueMetric<std::string> metric;
metric.Record("foo");
@@ -60,5 +58,31 @@ TEST(ValueMetricTest, SetError) {
ASSERT_FALSE(metric_proto->has_int_value());
}
TEST(ValueMetricTest, ValueOverflow) {
constexpr int64_t kMaxValue = std::numeric_limits<int64_t>::max();
constexpr uint64_t kMaxU64 = std::numeric_limits<uint64_t>::max();
constexpr size_t kMaxSizeT = std::numeric_limits<size_t>::max();
ValueMetric<uint64_t> metric_u64;
metric_u64.Record(kMaxU64);
// Runtime value should not be capped.
ASSERT_EQ(kMaxU64, metric_u64.GetValue());
std::unique_ptr<drm_metrics::ValueMetric> metric_proto(metric_u64.ToProto());
// Proto value should be capped.
ASSERT_EQ(kMaxValue, metric_proto->int_value());
ASSERT_FALSE(metric_proto->has_error_code());
ValueMetric<uint64_t> metric_z;
metric_z.Record(kMaxSizeT);
ASSERT_EQ(kMaxSizeT, metric_z.GetValue());
metric_proto.reset(metric_z.ToProto());
if (sizeof(int64_t) <= sizeof(size_t) &&
static_cast<size_t>(kMaxValue) <= kMaxSizeT) {
ASSERT_EQ(kMaxValue, metric_proto->int_value());
} else {
ASSERT_GT(kMaxValue, metric_proto->int_value());
}
}
} // namespace metrics
} // namespace wvcdm