Add session metric pruning.

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

Add support to drop closed metrics in order to save space for
long-running applications (and CdmEngine instances). The code now keeps
only a limited number of metrics collections after the session is closed.
As a session (and its metrics session) is closed, the oldest, closed metrics
session is dropped. This means those metrics will not be reported nor
accessible in the client.

Bug: http://b/118664842

Test: CDM Unit tests. Android Unit Test. Ran GPLay Manually.
Change-Id: I27d6e61a8fe4148ad1ef2a433c8e5f4cdd84cc72
This commit is contained in:
Adam Stone
2019-01-15 18:21:47 -08:00
parent 92e123d8ea
commit 700ee5160a
5 changed files with 270 additions and 284 deletions

View File

@@ -90,6 +90,10 @@ const int 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 {
@@ -356,22 +360,19 @@ class EngineMetrics {
// 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);
@@ -421,7 +422,10 @@ class EngineMetrics {
private:
mutable std::mutex session_metrics_lock_;
std::vector<metrics::SessionMetrics *> session_metrics_list_;
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_;