Source release 15.0.0

This commit is contained in:
John W. Bruce
2019-02-28 16:25:30 -08:00
parent f51edaba5a
commit 66628486b5
2672 changed files with 260431 additions and 762489 deletions

View File

@@ -8,12 +8,12 @@
#include <cstdarg>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "attribute_handler.h"
#include "field_tuples.h"
#include "lock.h"
namespace wvcdm {
namespace metrics {
@@ -51,7 +51,7 @@ class BaseCounterMetric {
* across multiple threads preventing the caller from worrying about
* locking.
*/
Lock internal_lock_;
std::mutex internal_lock_;
};
// The CounterMetric class is used to track a counter such as the number of

View File

@@ -7,17 +7,16 @@
#include <cstdarg>
#include <map>
#include <mutex>
#include <string>
#include <vector>
#include "OEMCryptoCENC.h"
#include "attribute_handler.h"
#include "distribution.h"
#include "lock.h"
#include "log.h"
#include "metrics.pb.h"
#include "pow2bucket.h"
#include "shared_ptr.h"
namespace wvcdm {
namespace metrics {
@@ -51,7 +50,7 @@ class BaseEventMetric {
* This locks the internal state of the event metric to ensure safety across
* multiple threads preventing the caller from worrying about locking.
*/
Lock internal_lock_;
std::mutex internal_lock_;
};
// The EventMetric class is used to capture statistics about an event such as

View File

@@ -8,6 +8,7 @@
#include <stddef.h>
#include <stdint.h>
#include <mutex>
#include <ostream>
#include "OEMCryptoCENC.h"
@@ -66,6 +67,8 @@ const int kErrorCodeFieldNumber =
::drm_metrics::Attributes::kErrorCodeFieldNumber;
const int kErrorCodeBoolFieldNumber =
::drm_metrics::Attributes::kErrorCodeBoolFieldNumber;
const int kErrorDetailFieldNumber =
::drm_metrics::Attributes::kErrorDetailFieldNumber;
const int kCdmSecurityLevelFieldNumber =
::drm_metrics::Attributes::kCdmSecurityLevelFieldNumber;
const int kSecurityLevelFieldNumber =
@@ -84,9 +87,15 @@ const int kEventTypeFieldNumber =
::drm_metrics::Attributes::kEventTypeFieldNumber;
const int kKeyRequestTypeFieldNumber =
::drm_metrics::Attributes::kKeyRequestTypeFieldNumber;
const int kLicenseTypeFieldNumber =
::drm_metrics::Attributes::kLicenseTypeFieldNumber;
} // anonymous namespace
// The maximum number of completed sessions that can be stored. More than this
// will cause some metrics to be discarded.
const int kMaxCompletedSessions = 40;
// This enum defines the conditions encountered during OEMCrypto Initialization
// in oemcrypto_adapter_dynamic.
typedef enum OEMCryptoInitializationMode {
@@ -106,10 +115,13 @@ typedef enum OEMCryptoInitializationMode {
OEMCrypto_INITIALIZED_USING_L1_INSTALLED_KEYBOX = 13,
OEMCrypto_INITIALIZED_USING_L3_INVALID_L1 = 14,
OEMCrypto_INITIALIZED_USING_L1_WITH_PROVISIONING_3_0 = 15,
OEMCrypto_INITIALIZED_L3_INITIALIZATION_FAILED = 16
OEMCrypto_INITIALIZED_L3_INITIALIZATION_FAILED = 16,
OEMCrypto_INITIALIZED_L3_RNG_FAILED = 17,
OEMCrypto_INITIALIZED_L3_SAVE_DEVICE_KEYS_FAILED = 18,
OEMCrypto_INITIALIZED_L3_READ_DEVICE_KEYS_FAILED = 19,
OEMCrypto_INITIALIZED_L3_VERIFY_DEVICE_KEYS_FAILED = 20,
} OEMCryptoInitializationMode;
// This class contains metrics for Crypto Session and OEM Crypto.
class CryptoMetrics {
public:
@@ -135,11 +147,12 @@ class CryptoMetrics {
EventMetric<kErrorCodeFieldNumber, CdmResponseType, kLengthFieldNumber,
Pow2Bucket, kSigningAlgorithmFieldNumber, CdmSigningAlgorithm>
crypto_session_generic_verify_;
CounterMetric<kErrorCodeBoolFieldNumber, bool>
CounterMetric<kErrorCodeFieldNumber, CdmResponseType>
crypto_session_get_device_unique_id_;
CounterMetric<kErrorCodeBoolFieldNumber, bool> crypto_session_get_token_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType>
crypto_session_get_token_;
ValueMetric<double> crypto_session_life_span_;
EventMetric<kErrorCodeBoolFieldNumber, bool>
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
crypto_session_load_certificate_private_key_;
// This uses the requested security level.
EventMetric<kErrorCodeFieldNumber, CdmResponseType, kSecurityLevelFieldNumber,
@@ -265,13 +278,16 @@ class SessionMetrics {
// Metrics collected at the session level.
ValueMetric<double> cdm_session_life_span_; // Milliseconds.
EventMetric<kErrorCodeFieldNumber, CdmResponseType> cdm_session_renew_key_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType>
CounterMetric<kErrorCodeFieldNumber, CdmResponseType,
kErrorDetailFieldNumber, int32_t>
cdm_session_restore_offline_session_;
CounterMetric<kErrorCodeFieldNumber, CdmResponseType>
CounterMetric<kErrorCodeFieldNumber, CdmResponseType,
kErrorDetailFieldNumber, int32_t>
cdm_session_restore_usage_session_;
EventMetric<kKeyRequestTypeFieldNumber, CdmKeyRequestType>
cdm_session_license_request_latency_ms_;
ValueMetric<std::string> oemcrypto_build_info_;
// Serialize the session metrics to the provided |metric_group|.
// |metric_group| is owned by the caller and must not be null.
@@ -301,6 +317,8 @@ class OemCryptoDynamicAdapterMetrics {
// Set methods for OEMCrypto metrics.
void SetInitializationMode(OEMCryptoInitializationMode mode);
void SetLevel3InitializationError(OEMCryptoInitializationMode mode);
void SetPreviousInitializationFailure(OEMCryptoInitializationMode mode);
void SetL1ApiVersion(uint32_t version);
void SetL1MinApiVersion(uint32_t version);
@@ -313,8 +331,12 @@ class OemCryptoDynamicAdapterMetrics {
void Clear();
private:
mutable Lock adapter_lock_;
mutable std::mutex adapter_lock_;
ValueMetric<OEMCryptoInitializationMode>
level3_oemcrypto_initialization_error_;
ValueMetric<OEMCryptoInitializationMode> oemcrypto_initialization_mode_;
ValueMetric<OEMCryptoInitializationMode>
previous_oemcrypto_initialization_failure_;
ValueMetric<uint32_t> oemcrypto_l1_api_version_;
ValueMetric<uint32_t> oemcrypto_l1_min_api_version_;
};
@@ -335,36 +357,38 @@ class EngineMetrics {
~EngineMetrics();
// Add a new SessionMetrics instance and return a pointer to the caller.
// The new SessionMetrics instance is owned by this EngineMetrics instance
// and will exist until RemoveSession is called or this object is deleted.
SessionMetrics *AddSession();
// A shared_ptr is used since it's possible that the SessionMetrics instance
// may be in use after the EngineMetrics instance is closed. The EngineMetrics
// instance will hold a shared_ptr reference to the SessionMetrics instance
// until RemoveSession is called, the EngineMetrics instance is deleted, or
// the SessionMetrics instance is marked as completed and ConsolidateSessions
// removes it.
std::shared_ptr<SessionMetrics> AddSession();
// Removes the metrics object for the given session id. This should only
// be called when the SessionMetrics instance is no longer in use.
void RemoveSession(CdmSessionId session_id);
// Looks for session metrics that have been marked as completed. These metrics
// may be merged or discarded if there are too many completed session metric
// instances.
void ConsolidateSessions();
// 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_; }
// Serialize engine and session metrics into a serialized MetricsGroup
// instance and output that instance to the provided |metric_group|.
// |metric_group| is owned by the caller and must NOT be null.
// |completed_only| indicates that this call should only publish
// SessionMetrics instances that are marked as completed.
// |clear_sessions| indicates that this call should clear sessions metrics
// for those sessions that were serialized. This allows atomic
// serialization and closing of session-level metrics.
// void Serialize(drm_metrics::MetricsGroup* metric_group, bool
// completed_only,
// bool clear_serialized_sessions);
// 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 SetAppPackageName(const std::string &app_package_name);
// Metrics recorded at the engine level.
EventMetric<kErrorCodeFieldNumber, CdmResponseType> 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_;
@@ -374,13 +398,15 @@ class EngineMetrics {
cdm_engine_decrypt_;
CounterMetric<kErrorCodeBoolFieldNumber, bool>
cdm_engine_find_session_for_key_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
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>
EventMetric<kErrorCodeFieldNumber, CdmResponseType,
kErrorDetailFieldNumber, int32_t>
cdm_engine_get_usage_info_;
EventMetric<kErrorCodeFieldNumber, CdmResponseType>
cdm_engine_handle_provisioning_response_;
@@ -405,8 +431,11 @@ class EngineMetrics {
cdm_engine_unprovision_;
private:
mutable Lock session_metrics_lock_;
std::vector<metrics::SessionMetrics *> session_metrics_list_;
mutable std::mutex session_metrics_lock_;
std::vector<std::shared_ptr<metrics::SessionMetrics>>
active_session_metrics_list_;
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_;
CryptoMetrics crypto_metrics_;

View File

@@ -1,19 +1,20 @@
#ifndef WVCDM_METRICS_TIMER_METRIC_H_
#define WVCDM_METRICS_TIMER_METRIC_H_
#include <stdint.h>
#include <chrono>
namespace wvcdm {
namespace metrics {
class TimerMetric {
public:
// Constructs a new TimerMetric.
explicit TimerMetric() : is_started_(false) {}
// Starts the clock running. If the clock was previously set, this resets it.
// IsStarted will return true after this call.
void Start();
// Returns whether or not the timer has started.
bool IsStarted() const { return is_started_; };
bool IsStarted() const { return is_started_; }
// Stops the clock and clears the current value. IsStarted will return false
// after this call.
void Clear();
@@ -23,10 +24,9 @@ class TimerMetric {
double AsUs() const;
private:
double sec_;
double usec_;
std::chrono::steady_clock clock_;
std::chrono::time_point<std::chrono::steady_clock> start_;
bool is_started_;
};
} // namespace metrics

View File

@@ -6,6 +6,7 @@
#define WVCDM_METRICS_VALUE_METRIC_H_
#include <stdint.h>
#include <mutex>
#include <string>
#include "metrics.pb.h"
@@ -46,6 +47,7 @@ class ValueMetric {
// Record the value of the metric.
void Record(const T &value) {
std::unique_lock<std::mutex> lock(internal_lock_);
value_ = value;
has_value_ = true;
has_error_ = false;
@@ -53,19 +55,33 @@ class ValueMetric {
// Set the error code if an error was encountered.
void SetError(int error_code) {
std::unique_lock<std::mutex> lock(internal_lock_);
error_code_ = error_code;
has_value_ = false;
has_error_ = true;
}
bool HasValue() const { return has_value_; }
const T &GetValue() const { return value_; }
bool HasValue() const {
std::unique_lock<std::mutex> lock(internal_lock_);
return has_value_;
}
const T &GetValue() const {
std::unique_lock<std::mutex> lock(internal_lock_);
return value_;
}
bool HasError() const { return has_error_; }
int GetError() const { return error_code_; }
bool HasError() const {
std::unique_lock<std::mutex> lock(internal_lock_);
return has_error_;
}
int GetError() const {
std::unique_lock<std::mutex> lock(internal_lock_);
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;
}
@@ -73,6 +89,7 @@ class ValueMetric {
// 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_);
@@ -91,6 +108,16 @@ class ValueMetric {
int error_code_;
bool has_error_;
bool has_value_;
/*
* 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_;
};
} // namespace metrics