Merge "Clean up unused LogEvent constructors" into rvc-dev
diff --git a/cmds/statsd/benchmark/metric_util.cpp b/cmds/statsd/benchmark/metric_util.cpp
index 4bce89f..482d66f 100644
--- a/cmds/statsd/benchmark/metric_util.cpp
+++ b/cmds/statsd/benchmark/metric_util.cpp
@@ -370,13 +370,6 @@
return processor;
}
-AttributionNodeInternal CreateAttribution(const int& uid, const string& tag) {
- AttributionNodeInternal attribution;
- attribution.set_uid(uid);
- attribution.set_tag(tag);
- return attribution;
-}
-
void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events) {
std::sort(events->begin(), events->end(),
[](const std::unique_ptr<LogEvent>& a, const std::unique_ptr<LogEvent>& b) {
diff --git a/cmds/statsd/benchmark/metric_util.h b/cmds/statsd/benchmark/metric_util.h
index 6199fa9..c5fcf7c 100644
--- a/cmds/statsd/benchmark/metric_util.h
+++ b/cmds/statsd/benchmark/metric_util.h
@@ -120,9 +120,6 @@
const vector<string>& attributionTags,
const string& name);
-// Helper function to create an AttributionNodeInternal proto.
-AttributionNodeInternal CreateAttribution(const int& uid, const string& tag);
-
// Create a statsd log event processor upon the start time in seconds, config and key.
sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
const ConfigKey& key);
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index a6ae389..0ec11f9 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -81,74 +81,6 @@
mLogPid(pid) {
}
-LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs) {
- mLogdTimestampNs = wallClockTimestampNs;
- mElapsedTimestampNs = elapsedTimestampNs;
- mTagId = tagId;
- mLogUid = 0;
- mContext = create_android_logger(1937006964); // the event tag shared by all stats logs
- if (mContext) {
- android_log_write_int64(mContext, elapsedTimestampNs);
- android_log_write_int32(mContext, tagId);
- }
-}
-
-LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
- int32_t uid,
- const std::map<int32_t, int32_t>& int_map,
- const std::map<int32_t, int64_t>& long_map,
- const std::map<int32_t, std::string>& string_map,
- const std::map<int32_t, float>& float_map) {
- mLogdTimestampNs = wallClockTimestampNs;
- mElapsedTimestampNs = elapsedTimestampNs;
- mTagId = util::KEY_VALUE_PAIRS_ATOM;
- mLogUid = uid;
-
- int pos[] = {1, 1, 1};
-
- mValues.push_back(FieldValue(Field(mTagId, pos, 0 /* depth */), Value(uid)));
- pos[0]++;
- for (const auto&itr : int_map) {
- pos[2] = 1;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.first)));
- pos[2] = 2;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.second)));
- mValues.back().mField.decorateLastPos(2);
- pos[1]++;
- }
-
- for (const auto&itr : long_map) {
- pos[2] = 1;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.first)));
- pos[2] = 3;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.second)));
- mValues.back().mField.decorateLastPos(2);
- pos[1]++;
- }
-
- for (const auto&itr : string_map) {
- pos[2] = 1;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.first)));
- pos[2] = 4;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.second)));
- mValues.back().mField.decorateLastPos(2);
- pos[1]++;
- }
-
- for (const auto&itr : float_map) {
- pos[2] = 1;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.first)));
- pos[2] = 5;
- mValues.push_back(FieldValue(Field(mTagId, pos, 2 /* depth */), Value(itr.second)));
- mValues.back().mField.decorateLastPos(2);
- pos[1]++;
- }
- if (!mValues.empty()) {
- mValues.back().mField.decorateLastPos(1);
- mValues.at(mValues.size() - 2).mField.decorateLastPos(1);
- }
-}
-
LogEvent::LogEvent(const string& trainName, int64_t trainVersionCode, bool requiresStaging,
bool rollbackEnabled, bool requiresLowLatencyMonitor, int32_t state,
const std::vector<uint8_t>& experimentIds, int32_t userId) {
@@ -184,17 +116,6 @@
mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), Value(trainInfo.status)));
}
-LogEvent::LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid) {
- mLogdTimestampNs = timestampNs;
- mTagId = tagId;
- mLogUid = uid;
- mContext = create_android_logger(1937006964); // the event tag shared by all stats logs
- if (mContext) {
- android_log_write_int64(mContext, timestampNs);
- android_log_write_int32(mContext, tagId);
- }
-}
-
LogEvent::~LogEvent() {
if (mContext) {
// This is for the case when LogEvent is created using the test interface
@@ -203,154 +124,6 @@
}
}
-bool LogEvent::write(int32_t value) {
- if (mContext) {
- return android_log_write_int32(mContext, value) >= 0;
- }
- return false;
-}
-
-bool LogEvent::write(uint32_t value) {
- if (mContext) {
- return android_log_write_int32(mContext, value) >= 0;
- }
- return false;
-}
-
-bool LogEvent::write(int64_t value) {
- if (mContext) {
- return android_log_write_int64(mContext, value) >= 0;
- }
- return false;
-}
-
-bool LogEvent::write(uint64_t value) {
- if (mContext) {
- return android_log_write_int64(mContext, value) >= 0;
- }
- return false;
-}
-
-bool LogEvent::write(const string& value) {
- if (mContext) {
- return android_log_write_string8_len(mContext, value.c_str(), value.length()) >= 0;
- }
- return false;
-}
-
-bool LogEvent::write(float value) {
- if (mContext) {
- return android_log_write_float32(mContext, value) >= 0;
- }
- return false;
-}
-
-bool LogEvent::writeBytes(const string& value) {
- /* if (mContext) {
- return android_log_write_char_array(mContext, value.c_str(), value.length()) >= 0;
- }*/
- return false;
-}
-
-bool LogEvent::writeKeyValuePairs(int32_t uid,
- const std::map<int32_t, int32_t>& int_map,
- const std::map<int32_t, int64_t>& long_map,
- const std::map<int32_t, std::string>& string_map,
- const std::map<int32_t, float>& float_map) {
- if (mContext) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- write(uid);
- for (const auto& itr : int_map) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- write(itr.first);
- write(itr.second);
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- }
-
- for (const auto& itr : long_map) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- write(itr.first);
- write(itr.second);
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- }
-
- for (const auto& itr : string_map) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- write(itr.first);
- write(itr.second.c_str());
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- }
-
- for (const auto& itr : float_map) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- write(itr.first);
- write(itr.second);
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- }
-
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- return true;
- }
- return false;
-}
-
-bool LogEvent::write(const std::vector<AttributionNodeInternal>& nodes) {
- if (mContext) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- for (size_t i = 0; i < nodes.size(); ++i) {
- if (!write(nodes[i])) {
- return false;
- }
- }
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- return true;
- }
- return false;
-}
-
-bool LogEvent::write(const AttributionNodeInternal& node) {
- if (mContext) {
- if (android_log_write_list_begin(mContext) < 0) {
- return false;
- }
- if (android_log_write_int32(mContext, node.uid()) < 0) {
- return false;
- }
- if (android_log_write_string8(mContext, node.tag().c_str()) < 0) {
- return false;
- }
- if (android_log_write_list_end(mContext) < 0) {
- return false;
- }
- return true;
- }
- return false;
-}
-
void LogEvent::parseInt32(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
int32_t value = readNextValue<int32_t>();
addToValues(pos, depth, value, last);
diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h
index 0a89be4..6c6aab1 100644
--- a/cmds/statsd/src/logd/LogEvent.h
+++ b/cmds/statsd/src/logd/LogEvent.h
@@ -28,27 +28,6 @@
namespace os {
namespace statsd {
-struct AttributionNodeInternal {
- void set_uid(int32_t id) {
- mUid = id;
- }
-
- void set_tag(const std::string& value) {
- mTag = value;
- }
-
- int32_t uid() const {
- return mUid;
- }
-
- const std::string& tag() const {
- return mTag;
- }
-
- int32_t mUid;
- std::string mTag;
-};
-
struct InstallTrainInfo {
int64_t trainVersionCode;
std::string trainName;
@@ -83,28 +62,6 @@
*/
bool parseBuffer(uint8_t* buf, size_t len);
- // TODO(b/149590301): delete unused functions below once LogEvent uses the
- // new socket schema within test code. Really we would like the only entry
- // points into LogEvent to be the above constructor and parseBuffer functions.
-
- /**
- * Constructs a LogEvent with synthetic data for testing. Must call init() before reading.
- */
- explicit LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs);
-
- // For testing. The timestamp is used as both elapsed real time and logd timestamp.
- explicit LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid);
-
- /**
- * Constructs a KeyValuePairsAtom LogEvent from value maps.
- */
- explicit LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
- int32_t uid,
- const std::map<int32_t, int32_t>& int_map,
- const std::map<int32_t, int64_t>& long_map,
- const std::map<int32_t, std::string>& string_map,
- const std::map<int32_t, float>& float_map);
-
// Constructs a BinaryPushStateChanged LogEvent from API call.
explicit LogEvent(const std::string& trainName, int64_t trainVersionCode, bool requiresStaging,
bool rollbackEnabled, bool requiresLowLatencyMonitor, int32_t state,
@@ -152,25 +109,6 @@
std::vector<uint8_t> GetStorage(size_t key, status_t* err) const;
/**
- * Write test data to the LogEvent. This can only be used when the LogEvent is constructed
- * using LogEvent(tagId, timestampNs). You need to call init() before you can read from it.
- */
- bool write(uint32_t value);
- bool write(int32_t value);
- bool write(uint64_t value);
- bool write(int64_t value);
- bool write(const std::string& value);
- bool write(float value);
- bool write(const std::vector<AttributionNodeInternal>& nodes);
- bool write(const AttributionNodeInternal& node);
- bool writeBytes(const std::string& value);
- bool writeKeyValuePairs(int32_t uid,
- const std::map<int32_t, int32_t>& int_map,
- const std::map<int32_t, int64_t>& long_map,
- const std::map<int32_t, std::string>& string_map,
- const std::map<int32_t, float>& float_map);
-
- /**
* Return a string representation of this event.
*/
std::string ToString() const;
diff --git a/cmds/statsd/tests/statsd_test_util.cpp b/cmds/statsd/tests/statsd_test_util.cpp
index 2f81c2d..7d765d3 100644
--- a/cmds/statsd/tests/statsd_test_util.cpp
+++ b/cmds/statsd/tests/statsd_test_util.cpp
@@ -1060,13 +1060,6 @@
return processor;
}
-AttributionNodeInternal CreateAttribution(const int& uid, const string& tag) {
- AttributionNodeInternal attribution;
- attribution.set_uid(uid);
- attribution.set_tag(tag);
- return attribution;
-}
-
void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events) {
std::sort(events->begin(), events->end(),
[](const std::unique_ptr<LogEvent>& a, const std::unique_ptr<LogEvent>& b) {
diff --git a/cmds/statsd/tests/statsd_test_util.h b/cmds/statsd/tests/statsd_test_util.h
index 715ba2b..f24705a 100644
--- a/cmds/statsd/tests/statsd_test_util.h
+++ b/cmds/statsd/tests/statsd_test_util.h
@@ -291,9 +291,6 @@
const bool usingAlertWindow,
const OverlayStateChanged::State state);
-// Helper function to create an AttributionNodeInternal proto.
-AttributionNodeInternal CreateAttribution(const int& uid, const string& tag);
-
// Create a statsd log event processor upon the start time in seconds, config and key.
sp<StatsLogProcessor> CreateStatsLogProcessor(const int64_t timeBaseNs, const int64_t currentTimeNs,
const StatsdConfig& config, const ConfigKey& key,