Support StatsD sending broadcasts.
StatsD will send a broadcast when we're 90% of the way to our
allocated memory limit for the configuration. If the memory usage
goes over the limit, we just lose all the data for this config.
Also modifies the adb shell commands to facilitate debugging of the
broadcasts.
Test: Manually tested on marlin-eng with custom gmscore code.
Change-Id: I517a15bd4c959aa221802f84a51f13141a725102
diff --git a/cmds/statsd/src/StatsLogProcessor.h b/cmds/statsd/src/StatsLogProcessor.h
index f38d715..2091774 100644
--- a/cmds/statsd/src/StatsLogProcessor.h
+++ b/cmds/statsd/src/StatsLogProcessor.h
@@ -33,7 +33,7 @@
class StatsLogProcessor : public ConfigListener {
public:
StatsLogProcessor(const sp<UidMap>& uidMap,
- const std::function<void(const vector<uint8_t>&)>& pushLog);
+ const std::function<void(const ConfigKey&)>& sendBroadcast);
virtual ~StatsLogProcessor();
virtual void OnLogEvent(const LogEvent& event);
@@ -41,15 +41,16 @@
void OnConfigUpdated(const ConfigKey& key, const StatsdConfig& config);
void OnConfigRemoved(const ConfigKey& key);
- vector<uint8_t> onDumpReport(const ConfigKey& key);
+ size_t GetMetricsSize(const ConfigKey& key);
- /* Request a flush through a binder call. */
- void flush();
+ void onDumpReport(const ConfigKey& key, vector<uint8_t>* outData);
private:
+ mutable mutex mBroadcastTimesMutex;
+
std::unordered_map<ConfigKey, std::unique_ptr<MetricsManager>> mMetricsManagers;
- std::unordered_map<ConfigKey, long> mLastFlushTimes;
+ std::unordered_map<ConfigKey, long> mLastBroadcastTimes;
sp<UidMap> mUidMap; // Reference to the UidMap to lookup app name and version for each uid.
@@ -60,17 +61,18 @@
*/
static const size_t kMaxSerializedBytes = 16 * 1024;
- /* Check if the buffer size exceeds the max buffer size when the new entry is added, and flush
- the logs to callback clients if true. */
+ /* Check if we should send a broadcast if approaching memory limits and if we're over, we
+ * actually delete the data. */
void flushIfNecessary(uint64_t timestampNs,
const ConfigKey& key,
const unique_ptr<MetricsManager>& metricsManager);
- std::function<void(const vector<uint8_t>&)> mPushLog;
+ // Function used to send a broadcast so that receiver for the config key can call getData
+ // to retrieve the stored data.
+ std::function<void(const ConfigKey& key)> mSendBroadcast;
- /* Minimum period between two flushes in nanoseconds. Currently set to 10
- * minutes. */
- static const unsigned long long kMinFlushPeriod = 600 * NS_PER_SEC;
+ /* Minimum period between two broadcasts in nanoseconds. Currently set to 60 seconds. */
+ static const unsigned long long kMinBroadcastPeriod = 60 * NS_PER_SEC;
};
} // namespace statsd