From 80235403d2a80eee1c23dbe856d18194b1b93843 Mon Sep 17 00:00:00 2001 From: Yao Chen Date: Mon, 13 Nov 2017 20:42:25 -0800 Subject: [PATCH] statsd: parse the new format of stats log + Changed how we construct LogEvent, now it's based on the context from log_msg without making a copy of the list. + All stats logs now have the same event tag, the atom id is the first elem in the log. Test: statsd_test Change-Id: I4419380f2ee1c2b2155d427b9f2adb78883b337f --- .../src/external/CpuTimePerUidFreqPuller.cpp | 7 +- .../src/external/CpuTimePerUidPuller.cpp | 7 +- .../external/ResourcePowerManagerPuller.cpp | 31 +++---- cmds/statsd/src/logd/LogEvent.cpp | 91 +++++++++++++++---- cmds/statsd/src/logd/LogEvent.h | 37 ++++---- cmds/statsd/src/matchers/matcher_util.cpp | 6 +- cmds/statsd/tests/LogEntryMatcher_test.cpp | 55 +++++------ cmds/statsd/tests/UidMap_test.cpp | 14 ++- .../condition/SimpleConditionTracker_test.cpp | 7 +- .../metrics/CountMetricProducer_test.cpp | 6 +- .../metrics/EventMetricProducer_test.cpp | 6 +- .../metrics/ValueMetricProducer_test.cpp | 40 ++++---- tools/stats_log_api_gen/main.cpp | 10 +- 13 files changed, 171 insertions(+), 146 deletions(-) diff --git a/cmds/statsd/src/external/CpuTimePerUidFreqPuller.cpp b/cmds/statsd/src/external/CpuTimePerUidFreqPuller.cpp index e004d217a9664..e2745d21af3dd 100644 --- a/cmds/statsd/src/external/CpuTimePerUidFreqPuller.cpp +++ b/cmds/statsd/src/external/CpuTimePerUidFreqPuller.cpp @@ -71,10 +71,9 @@ bool CpuTimePerUidFreqPuller::Pull(const int tagId, vector> do { timeMs = std::stoull(pch); auto ptr = make_shared(android::util::CPU_TIME_PER_UID_FREQ_PULLED, timestamp); - auto elemList = ptr->GetAndroidLogEventList(); - *elemList << uid; - *elemList << idx; - *elemList << timeMs; + ptr->write(uid); + ptr->write(idx); + ptr->write(timeMs); ptr->init(); data->push_back(ptr); VLOG("uid %lld, freq idx %d, sys time %lld", (long long)uid, idx, (long long)timeMs); diff --git a/cmds/statsd/src/external/CpuTimePerUidPuller.cpp b/cmds/statsd/src/external/CpuTimePerUidPuller.cpp index b84b877a0ee94..e0572dca679d4 100644 --- a/cmds/statsd/src/external/CpuTimePerUidPuller.cpp +++ b/cmds/statsd/src/external/CpuTimePerUidPuller.cpp @@ -66,10 +66,9 @@ bool CpuTimePerUidPuller::Pull(const int tagId, vector>* da uint64_t sysTimeMs = std::stoull(pch); auto ptr = make_shared(android::util::CPU_TIME_PER_UID_PULLED, timestamp); - auto elemList = ptr->GetAndroidLogEventList(); - *elemList << uid; - *elemList << userTimeMs; - *elemList << sysTimeMs; + ptr->write(uid); + ptr->write(userTimeMs); + ptr->write(sysTimeMs); ptr->init(); data->push_back(ptr); VLOG("uid %lld, user time %lld, sys time %lld", (long long)uid, (long long)userTimeMs, (long long)sysTimeMs); diff --git a/cmds/statsd/src/external/ResourcePowerManagerPuller.cpp b/cmds/statsd/src/external/ResourcePowerManagerPuller.cpp index 319feef49b35b..3ee636dfcde5f 100644 --- a/cmds/statsd/src/external/ResourcePowerManagerPuller.cpp +++ b/cmds/statsd/src/external/ResourcePowerManagerPuller.cpp @@ -93,11 +93,10 @@ bool ResourcePowerManagerPuller::Pull(const int tagId, vector( android::util::POWER_STATE_PLATFORM_SLEEP_STATE_PULLED, timestamp); - auto elemList = statePtr->GetAndroidLogEventList(); - *elemList << state.name; - *elemList << state.residencyInMsecSinceBoot; - *elemList << state.totalTransitions; - *elemList << state.supportedOnlyInSuspend; + statePtr->write(state.name); + statePtr->write(state.residencyInMsecSinceBoot); + statePtr->write(state.totalTransitions); + statePtr->write(state.supportedOnlyInSuspend); statePtr->init(); data->push_back(statePtr); VLOG("powerstate: %s, %lld, %lld, %d", state.name.c_str(), @@ -106,11 +105,10 @@ bool ResourcePowerManagerPuller::Pull(const int tagId, vector(android::util::POWER_STATE_VOTER_PULLED, timestamp); - auto elemList = voterPtr->GetAndroidLogEventList(); - *elemList << state.name; - *elemList << voter.name; - *elemList << voter.totalTimeInMsecVotedForSinceBoot; - *elemList << voter.totalNumberOfTimesVotedSinceBoot; + voterPtr->write(state.name); + voterPtr->write(voter.name); + voterPtr->write(voter.totalTimeInMsecVotedForSinceBoot); + voterPtr->write(voter.totalNumberOfTimesVotedSinceBoot); voterPtr->init(); data->push_back(voterPtr); VLOG("powerstatevoter: %s, %s, %lld, %lld", state.name.c_str(), @@ -141,13 +139,12 @@ bool ResourcePowerManagerPuller::Pull(const int tagId, vector( android::util::POWER_STATE_SUBSYSTEM_SLEEP_STATE_PULLED, timestamp); - auto elemList = subsystemStatePtr->GetAndroidLogEventList(); - *elemList << subsystem.name; - *elemList << state.name; - *elemList << state.residencyInMsecSinceBoot; - *elemList << state.totalTransitions; - *elemList << state.lastEntryTimestampMs; - *elemList << state.supportedOnlyInSuspend; + subsystemStatePtr->write(subsystem.name); + subsystemStatePtr->write(state.name); + subsystemStatePtr->write(state.residencyInMsecSinceBoot); + subsystemStatePtr->write(state.totalTransitions); + subsystemStatePtr->write(state.lastEntryTimestampMs); + subsystemStatePtr->write(state.supportedOnlyInSuspend); subsystemStatePtr->init(); data->push_back(subsystemStatePtr); VLOG("subsystemstate: %s, %s, %lld, %lld, %lld", diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp index 913b906986c3d..80236703c89e5 100644 --- a/cmds/statsd/src/logd/LogEvent.cpp +++ b/cmds/statsd/src/logd/LogEvent.cpp @@ -29,21 +29,72 @@ using std::ostringstream; using std::string; using android::util::ProtoOutputStream; -// We need to keep a copy of the android_log_event_list owned by this instance so that the char* -// for strings is not cleared before we can read them. -LogEvent::LogEvent(log_msg& msg) : mList(msg) { - init(msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec, &mList); +LogEvent::LogEvent(log_msg& msg) { + android_log_context context = + create_android_log_parser(msg.msg() + sizeof(uint32_t), msg.len() - sizeof(uint32_t)); + mTimestampNs = msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec; + mContext = NULL; + init(context); } -LogEvent::LogEvent(int tag, uint64_t timestampNs) : mList(tag), mTimestampNs(timestampNs) { -} - -LogEvent::~LogEvent() { +LogEvent::LogEvent(int32_t tagId, uint64_t timestampNs) { + mTimestampNs = timestampNs; + mTagId = tagId; + mContext = create_android_logger(1937006964); // the event tag shared by all stats logs + if (mContext) { + android_log_write_int32(mContext, tagId); + } } void LogEvent::init() { - mList.convert_to_reader(); - init(mTimestampNs, &mList); + if (mContext) { + const char* buffer; + size_t len = android_log_write_list_buffer(mContext, &buffer); + // turns to reader mode + mContext = create_android_log_parser(buffer, len); + init(mContext); + } +} + +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(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; +} + +LogEvent::~LogEvent() { + if (mContext) { + android_log_destroy(&mContext); + } } /** @@ -51,22 +102,25 @@ void LogEvent::init() { * The goal is to do as little preprocessing as possible, because we read a tiny fraction * of the elements that are written to the log. */ -void LogEvent::init(int64_t timestampNs, android_log_event_list* reader) { - mTimestampNs = timestampNs; - mTagId = reader->tag(); - +void LogEvent::init(android_log_context context) { mElements.clear(); android_log_list_element elem; - // TODO: The log is actually structured inside one list. This is convenient // because we'll be able to use it to put the attribution (WorkSource) block first // without doing our own tagging scheme. Until that change is in, just drop the // list-related log elements and the order we get there is our index-keyed data // structure. + int i = 0; do { - elem = android_log_read_next(reader->context()); + elem = android_log_read_next(context); switch ((int)elem.type) { case EVENT_TYPE_INT: + // elem at [0] is EVENT_TYPE_LIST, [1] is the tag id. If we add WorkSource, it would + // be the list starting at [2]. + if (i == 1) { + mTagId = elem.data.int32; + break; + } case EVENT_TYPE_FLOAT: case EVENT_TYPE_STRING: case EVENT_TYPE_LONG: @@ -81,13 +135,10 @@ void LogEvent::init(int64_t timestampNs, android_log_event_list* reader) { default: break; } + i++; } while ((elem.type != EVENT_TYPE_UNKNOWN) && !elem.complete); } -android_log_event_list* LogEvent::GetAndroidLogEventList() { - return &mList; -} - int64_t LogEvent::GetLong(size_t key, status_t* err) const { if (key < 1 || (key - 1) >= mElements.size()) { *err = BAD_INDEX; diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h index 298494049628f..7e8a96b2114ef 100644 --- a/cmds/statsd/src/logd/LogEvent.h +++ b/cmds/statsd/src/logd/LogEvent.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -45,12 +46,9 @@ public: explicit LogEvent(log_msg& msg); /** - * Constructs a LogEvent with the specified tag and creates an android_log_event_list in write - * mode. Obtain this list with the getter. Make sure to call init() before attempting to read - * any of the values. This constructor is useful for unit-testing since we can't pass in an - * android_log_event_list since there is no copy constructor or assignment operator available. + * Constructs a LogEvent with synthetic data for testing. Must call init() before reading. */ - explicit LogEvent(int tag, uint64_t timestampNs); + explicit LogEvent(int32_t tagId, uint64_t timestampNs); ~LogEvent(); @@ -75,6 +73,17 @@ public: bool GetBool(size_t key, status_t* err) const; float GetFloat(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 string& value); + bool write(float value); + /** * Return a string representation of this event. */ @@ -90,13 +99,6 @@ public: */ KeyValuePair GetKeyValueProto(size_t key) const; - /** - * A pointer to the contained log_event_list. - * - * @return The android_log_event_list contained within. - */ - android_log_event_list* GetAndroidLogEventList(); - /** * Used with the constructor where tag is passed in. Converts the log_event_list to read mode * and prepares the list for reading. @@ -113,16 +115,11 @@ private: /** * Parses a log_msg into a LogEvent object. */ - void init(const log_msg& msg); - - /** - * Parses a log_msg into a LogEvent object. - */ - void init(int64_t timestampNs, android_log_event_list* reader); + void init(android_log_context context); vector mElements; - // Need a copy of the android_log_event_list so the strings are not cleared. - android_log_event_list mList; + + android_log_context mContext; uint64_t mTimestampNs; diff --git a/cmds/statsd/src/matchers/matcher_util.cpp b/cmds/statsd/src/matchers/matcher_util.cpp index 1c699e822420a..255165cee7ea2 100644 --- a/cmds/statsd/src/matchers/matcher_util.cpp +++ b/cmds/statsd/src/matchers/matcher_util.cpp @@ -165,15 +165,15 @@ bool matchesSimple(const SimpleLogEntryMatcher& simpleMatcher, const LogEvent& e matcherCase == KeyValueMatcher::ValueMatcherCase::kGtFloat) { // Float fields status_t err = NO_ERROR; - bool val = event.GetFloat(key, &err); + float val = event.GetFloat(key, &err); if (err == NO_ERROR) { if (matcherCase == KeyValueMatcher::ValueMatcherCase::kLtFloat) { - if (!(cur.lt_float() <= val)) { + if (!(val < cur.lt_float())) { allMatched = false; break; } } else if (matcherCase == KeyValueMatcher::ValueMatcherCase::kGtFloat) { - if (!(cur.gt_float() >= val)) { + if (!(val > cur.gt_float())) { allMatched = false; break; } diff --git a/cmds/statsd/tests/LogEntryMatcher_test.cpp b/cmds/statsd/tests/LogEntryMatcher_test.cpp index bb4930a9a342d..40c0e9d74c1d2 100644 --- a/cmds/statsd/tests/LogEntryMatcher_test.cpp +++ b/cmds/statsd/tests/LogEntryMatcher_test.cpp @@ -27,7 +27,7 @@ using namespace android::os::statsd; using std::unordered_map; using std::vector; -const int TAG_ID = 123; +const int32_t TAG_ID = 123; const int FIELD_ID_1 = 1; const int FIELD_ID_2 = 2; const int FIELD_ID_3 = 2; @@ -43,8 +43,6 @@ TEST(LogEntryMatcherTest, TestSimpleMatcher) { simpleMatcher->set_tag(TAG_ID); LogEvent event(TAG_ID, 0); - - // Convert to a LogEvent event.init(); // Test @@ -63,10 +61,8 @@ TEST(LogEntryMatcherTest, TestBoolMatcher) { // Set up the event LogEvent event(TAG_ID, 0); - auto list = event.GetAndroidLogEventList(); - *list << true; - *list << false; - + event.write(true); + event.write(false); // Convert to a LogEvent event.init(); @@ -99,9 +95,7 @@ TEST(LogEntryMatcherTest, TestStringMatcher) { // Set up the event LogEvent event(TAG_ID, 0); - auto list = event.GetAndroidLogEventList(); - *list << "some value"; - + event.write("some value"); // Convert to a LogEvent event.init(); @@ -121,9 +115,8 @@ TEST(LogEntryMatcherTest, TestMultiFieldsMatcher) { // Set up the event LogEvent event(TAG_ID, 0); - auto list = event.GetAndroidLogEventList(); - *list << 2; - *list << 3; + event.write(2); + event.write(3); // Convert to a LogEvent event.init(); @@ -153,9 +146,7 @@ TEST(LogEntryMatcherTest, TestIntComparisonMatcher) { // Set up the event LogEvent event(TAG_ID, 0); - auto list = event.GetAndroidLogEventList(); - *list << 11; - + event.write(11); event.init(); // Test @@ -201,8 +192,6 @@ TEST(LogEntryMatcherTest, TestIntComparisonMatcher) { EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); } -#if 0 - TEST(LogEntryMatcherTest, TestFloatComparisonMatcher) { // Set up the matcher LogEntryMatcher matcher; @@ -212,22 +201,28 @@ TEST(LogEntryMatcherTest, TestFloatComparisonMatcher) { auto keyValue = simpleMatcher->add_key_value_matcher(); keyValue->mutable_key_matcher()->set_key(FIELD_ID_1); - LogEvent event; - event.tagId = TAG_ID; - + LogEvent event1(TAG_ID, 0); keyValue->set_lt_float(10.0); - event.floatMap[FIELD_ID_1] = 10.1; - EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); - event.floatMap[FIELD_ID_1] = 9.9; - EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); + event1.write(10.1f); + event1.init(); + EXPECT_FALSE(matchesSimple(*simpleMatcher, event1)); + LogEvent event2(TAG_ID, 0); + event2.write(9.9f); + event2.init(); + EXPECT_TRUE(matchesSimple(*simpleMatcher, event2)); + + LogEvent event3(TAG_ID, 0); + event3.write(10.1f); + event3.init(); keyValue->set_gt_float(10.0); - event.floatMap[FIELD_ID_1] = 10.1; - EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); - event.floatMap[FIELD_ID_1] = 9.9; - EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); + EXPECT_TRUE(matchesSimple(*simpleMatcher, event3)); + + LogEvent event4(TAG_ID, 0); + event4.write(9.9f); + event4.init(); + EXPECT_FALSE(matchesSimple(*simpleMatcher, event4)); } -#endif // Helper for the composite matchers. void addSimpleMatcher(SimpleLogEntryMatcher* simpleMatcher, int tag, int key, int val) { diff --git a/cmds/statsd/tests/UidMap_test.cpp b/cmds/statsd/tests/UidMap_test.cpp index c64719ee0c85d..4c12b0397769e 100644 --- a/cmds/statsd/tests/UidMap_test.cpp +++ b/cmds/statsd/tests/UidMap_test.cpp @@ -36,10 +36,9 @@ TEST(UidMapTest, TestIsolatedUID) { sp m = new UidMap(); StatsLogProcessor p(m, nullptr); LogEvent addEvent(android::util::ISOLATED_UID_CHANGED, 1); - android_log_event_list* list = addEvent.GetAndroidLogEventList(); - *list << 100; // parent UID - *list << 101; // isolated UID - *list << 1; // Indicates creation. + addEvent.write(100); // parent UID + addEvent.write(101); // isolated UID + addEvent.write(1); // Indicates creation. addEvent.init(); EXPECT_EQ(101, m->getParentUidOrSelf(101)); @@ -48,10 +47,9 @@ TEST(UidMapTest, TestIsolatedUID) { EXPECT_EQ(100, m->getParentUidOrSelf(101)); LogEvent removeEvent(android::util::ISOLATED_UID_CHANGED, 1); - list = removeEvent.GetAndroidLogEventList(); - *list << 100; // parent UID - *list << 101; // isolated UID - *list << 0; // Indicates removal. + removeEvent.write(100); // parent UID + removeEvent.write(101); // isolated UID + removeEvent.write(0); // Indicates removal. removeEvent.init(); p.OnLogEvent(removeEvent); EXPECT_EQ(101, m->getParentUidOrSelf(101)); diff --git a/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp b/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp index 855e66615f8e3..80a0068690f72 100644 --- a/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp +++ b/cmds/statsd/tests/condition/SimpleConditionTracker_test.cpp @@ -46,10 +46,9 @@ SimpleCondition getWakeLockHeldCondition(bool countNesting, bool defaultFalse, } void makeWakeLockEvent(LogEvent* event, int uid, const string& wl, int acquire) { - auto list = event->GetAndroidLogEventList(); - *list << uid; // uid - *list << wl; - *list << acquire; + event->write(uid); // uid + event->write(wl); + event->write(acquire); event->init(); } diff --git a/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp b/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp index d07a84d4c3d8e..b7c9b406e0b92 100644 --- a/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/CountMetricProducer_test.cpp @@ -138,15 +138,13 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) { link->add_key_in_condition()->set_key(2); LogEvent event1(1, bucketStartTimeNs + 1); - auto list = event1.GetAndroidLogEventList(); - *list << "111"; // uid + event1.write("111"); // uid event1.init(); ConditionKey key1; key1["APP_IN_BACKGROUND_PER_UID"] = "2:111|"; LogEvent event2(1, bucketStartTimeNs + 10); - auto list2 = event2.GetAndroidLogEventList(); - *list2 << "222"; // uid + event2.write("222"); // uid event2.init(); ConditionKey key2; key2["APP_IN_BACKGROUND_PER_UID"] = "2:222|"; diff --git a/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp b/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp index 0971d2682d40b..18d177cb91732 100644 --- a/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/EventMetricProducer_test.cpp @@ -95,15 +95,13 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) { link->add_key_in_condition()->set_key(2); LogEvent event1(1, bucketStartTimeNs + 1); - auto list = event1.GetAndroidLogEventList(); - *list << "111"; // uid + event1.write("111"); // uid event1.init(); ConditionKey key1; key1["APP_IN_BACKGROUND_PER_UID"] = "2:111|"; LogEvent event2(1, bucketStartTimeNs + 10); - auto list2 = event2.GetAndroidLogEventList(); - *list2 << "222"; // uid + event2.write("222"); // uid event2.init(); ConditionKey key2; key2["APP_IN_BACKGROUND_PER_UID"] = "2:222|"; diff --git a/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp b/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp index 72b4194d533e8..cd647cb9c238a 100644 --- a/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp +++ b/cmds/statsd/tests/metrics/ValueMetricProducer_test.cpp @@ -64,9 +64,8 @@ TEST(ValueMetricProducerTest, TestNonDimensionalEvents) { vector> allData; allData.clear(); shared_ptr event = make_shared(tagId, bucketStartTimeNs + 1); - auto list = event->GetAndroidLogEventList(); - *list << 1; - *list << 11; + event->write(1); + event->write(11); event->init(); allData.push_back(event); @@ -89,9 +88,8 @@ TEST(ValueMetricProducerTest, TestNonDimensionalEvents) { allData.clear(); event = make_shared(tagId, bucket2StartTimeNs + 1); - list = event->GetAndroidLogEventList(); - *list << 1; - *list << 22; + event->write(1); + event->write(22); event->init(); allData.push_back(event); valueProducer.onDataPulled(allData); @@ -110,9 +108,8 @@ TEST(ValueMetricProducerTest, TestNonDimensionalEvents) { allData.clear(); event = make_shared(tagId, bucket3StartTimeNs + 1); - list = event->GetAndroidLogEventList(); - *list << 1; - *list << 33; + event->write(1); + event->write(33); event->init(); allData.push_back(event); valueProducer.onDataPulled(allData); @@ -159,9 +156,8 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) { int64_t bucket3StartTimeNs = bucketStartTimeNs + 2 * bucketSizeNs; data->clear(); shared_ptr event = make_shared(tagId, bucketStartTimeNs + 10); - auto list = event->GetAndroidLogEventList(); - *list << 1; - *list << 100; + event->write(1); + event->write(100); event->init(); data->push_back(event); return true; @@ -174,9 +170,8 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) { int64_t bucket3StartTimeNs = bucketStartTimeNs + 2 * bucketSizeNs; data->clear(); shared_ptr event = make_shared(tagId, bucket2StartTimeNs + 10); - auto list = event->GetAndroidLogEventList(); - *list << 1; - *list << 120; + event->write(1); + event->write(120); event->init(); data->push_back(event); return true; @@ -201,9 +196,8 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) { vector> allData; allData.clear(); shared_ptr event = make_shared(tagId, bucket2StartTimeNs + 1); - auto list = event->GetAndroidLogEventList(); - *list << 1; - *list << 110; + event->write(1); + event->write(110); event->init(); allData.push_back(event); valueProducer.onDataPulled(allData); @@ -253,14 +247,12 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) { bucketStartTimeNs, pullerManager); shared_ptr event1 = make_shared(tagId, bucketStartTimeNs + 10); - auto list = event1->GetAndroidLogEventList(); - *list << 1; - *list << 10; + event1->write(1); + event1->write(10); event1->init(); shared_ptr event2 = make_shared(tagId, bucketStartTimeNs + 10); - auto list2 = event2->GetAndroidLogEventList(); - *list2 << 1; - *list2 << 20; + event2->write(1); + event2->write(20); event2->init(); valueProducer.onMatchedLogEvent(1 /*log matcher index*/, *event1, false); // has one slice diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp index c54ab18717dd1..cca12947d26ec 100644 --- a/tools/stats_log_api_gen/main.cpp +++ b/tools/stats_log_api_gen/main.cpp @@ -107,6 +107,8 @@ write_stats_log_cpp(FILE* out, const Atoms& atoms) fprintf(out, "namespace android {\n"); fprintf(out, "namespace util {\n"); + fprintf(out, "// the single event tag id for all stats logs\n"); + fprintf(out, "const static int kStatsEventTag = 1937006964;\n"); // Print write methods fprintf(out, "\n"); @@ -115,7 +117,7 @@ write_stats_log_cpp(FILE* out, const Atoms& atoms) int argIndex; fprintf(out, "void\n"); - fprintf(out, "stats_write(int code"); + fprintf(out, "stats_write(int32_t code"); argIndex = 1; for (vector::const_iterator arg = signature->begin(); arg != signature->end(); arg++) { @@ -126,7 +128,8 @@ write_stats_log_cpp(FILE* out, const Atoms& atoms) fprintf(out, "{\n"); argIndex = 1; - fprintf(out, " android_log_event_list event(code);\n"); + fprintf(out, " android_log_event_list event(kStatsEventTag);\n"); + fprintf(out, " event << code;\n"); for (vector::const_iterator arg = signature->begin(); arg != signature->end(); arg++) { if (*arg == JAVA_TYPE_STRING) { @@ -204,8 +207,7 @@ write_stats_log_header(FILE* out, const Atoms& atoms) fprintf(out, "//\n"); for (set>::const_iterator signature = atoms.signatures.begin(); signature != atoms.signatures.end(); signature++) { - - fprintf(out, "void stats_write(int code"); + fprintf(out, "void stats_write(int32_t code "); int argIndex = 1; for (vector::const_iterator arg = signature->begin(); arg != signature->end(); arg++) {