Merge "Clean up unused LogEvent constructors" into rvc-dev

This commit is contained in:
Christine Tsai
2020-04-03 21:03:57 +00:00
committed by Android (Google) Code Review
6 changed files with 0 additions and 309 deletions

View File

@@ -370,13 +370,6 @@ sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const Stat
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) {

View File

@@ -120,9 +120,6 @@ std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs,
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);

View File

@@ -81,74 +81,6 @@ LogEvent::LogEvent(int32_t uid, int32_t pid)
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 @@ LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
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 @@ LogEvent::~LogEvent() {
}
}
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);

View File

@@ -28,27 +28,6 @@ namespace android {
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 @@ public:
*/
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,
@@ -151,25 +108,6 @@ public:
float GetFloat(size_t key, status_t* err) const;
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.
*/

View File

@@ -1060,13 +1060,6 @@ sp<StatsLogProcessor> CreateStatsLogProcessor(const int64_t timeBaseNs, const in
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) {

View File

@@ -291,9 +291,6 @@ std::unique_ptr<LogEvent> CreateOverlayStateChangedEvent(int64_t timestampNs, co
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,