Ran clang-format on the metrics directory.
[ Merge of http://go/wvgerrit/137809 ] Bug: 204946540 Test: Metric unit tests Change-Id: Ibd68db73ea9ee64664d33c2cb8e8bb7c56674c27
This commit is contained in:
@@ -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,12 +132,12 @@ 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.");
|
||||
}
|
||||
|
||||
@@ -36,12 +36,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 +90,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 +137,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,13 +152,14 @@ 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.");
|
||||
}
|
||||
|
||||
@@ -73,8 +73,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 =
|
||||
@@ -125,8 +124,8 @@ typedef enum 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_.
|
||||
@@ -304,12 +303,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 +319,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>
|
||||
@@ -342,12 +341,12 @@ class SessionMetrics {
|
||||
|
||||
// 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_;
|
||||
@@ -375,8 +374,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();
|
||||
@@ -397,7 +396,7 @@ class OemCryptoDynamicAdapterMetrics {
|
||||
// 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
|
||||
@@ -428,18 +427,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_;
|
||||
@@ -449,15 +449,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_;
|
||||
@@ -493,7 +493,7 @@ class EngineMetrics {
|
||||
std::string app_package_name_;
|
||||
|
||||
void SerializeEngineMetrics(
|
||||
drm_metrics::WvCdmMetrics::EngineMetrics *engine_metrics) const;
|
||||
drm_metrics::WvCdmMetrics::EngineMetrics* engine_metrics) const;
|
||||
};
|
||||
|
||||
} // namespace metrics
|
||||
|
||||
@@ -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_;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace impl {
|
||||
|
||||
// Helper function for setting a value in the proto.
|
||||
template <typename T>
|
||||
void SetValue(drm_metrics::ValueMetric *value_proto, const T &value);
|
||||
void SetValue(drm_metrics::ValueMetric* value_proto, const T& value);
|
||||
|
||||
} // namespace impl
|
||||
|
||||
@@ -46,7 +46,7 @@ class ValueMetric {
|
||||
: error_code_(0), has_error_(false), has_value_(false) {}
|
||||
|
||||
// Record the value of the metric.
|
||||
void Record(const T &value) {
|
||||
void Record(const T& value) {
|
||||
std::unique_lock<std::mutex> lock(internal_lock_);
|
||||
value_ = value;
|
||||
has_value_ = true;
|
||||
@@ -65,7 +65,7 @@ class ValueMetric {
|
||||
std::unique_lock<std::mutex> lock(internal_lock_);
|
||||
return has_value_;
|
||||
}
|
||||
const T &GetValue() const {
|
||||
const T& GetValue() const {
|
||||
std::unique_lock<std::mutex> lock(internal_lock_);
|
||||
return value_;
|
||||
}
|
||||
@@ -88,14 +88,14 @@ 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 {
|
||||
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;
|
||||
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;
|
||||
drm_metrics::ValueMetric* value_proto = new drm_metrics::ValueMetric;
|
||||
impl::SetValue(value_proto, value_);
|
||||
return value_proto;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user