Source release 17.1.0
This commit is contained in:
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user