Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f9ca14b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use new socket schema within TestSlicedCondition" into rvc-dev

parents 21e618d9 dfd63d45
Loading
Loading
Loading
Loading
+2 −4
Original line number Original line Diff line number Diff line
@@ -66,10 +66,8 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) {
                {
                {
                    lock_guard<mutex> lk(*cv_mutex);
                    lock_guard<mutex> lk(*cv_mutex);
                    for (const StatsEventParcel& parcel: output) {
                    for (const StatsEventParcel& parcel: output) {
                        uint8_t* buf = reinterpret_cast<uint8_t*>(
                        shared_ptr<LogEvent> event = make_shared<LogEvent>(/*uid=*/-1, /*pid=*/-1);
                                const_cast<int8_t*>(parcel.buffer.data()));
                        event->parseBuffer((uint8_t*)parcel.buffer.data(), parcel.buffer.size());
                        shared_ptr<LogEvent> event = make_shared<LogEvent>(
                                buf, parcel.buffer.size(), /*uid=*/-1, /*pid=*/-1);
                        sharedData->push_back(event);
                        sharedData->push_back(event);
                    }
                    }
                    *pullSuccess = success;
                    *pullSuccess = success;
+11 −16
Original line number Original line Diff line number Diff line
@@ -65,18 +65,6 @@ using std::vector;
#define ATTRIBUTION_CHAIN_TYPE 0x09
#define ATTRIBUTION_CHAIN_TYPE 0x09
#define ERROR_TYPE 0x0F
#define ERROR_TYPE 0x0F


// Msg is expected to begin at the start of the serialized atom -- it should not
// include the android_log_header_t or the StatsEventTag.
LogEvent::LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid)
    : mBuf(msg),
      mRemainingLen(len),
      mLogdTimestampNs(time(nullptr)),
      mLogUid(uid),
      mLogPid(pid)
{
    initNew();
}

LogEvent::LogEvent(const LogEvent& event) {
LogEvent::LogEvent(const LogEvent& event) {
    mTagId = event.mTagId;
    mTagId = event.mTagId;
    mLogUid = event.mLogUid;
    mLogUid = event.mLogUid;
@@ -86,6 +74,12 @@ LogEvent::LogEvent(const LogEvent& event) {
    mValues = event.mValues;
    mValues = event.mValues;
}
}


LogEvent::LogEvent(int32_t uid, int32_t pid)
    : mLogdTimestampNs(time(nullptr)),
      mLogUid(uid),
      mLogPid(pid) {
}

LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs) {
LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs) {
    mLogdTimestampNs = wallClockTimestampNs;
    mLogdTimestampNs = wallClockTimestampNs;
    mElapsedTimestampNs = elapsedTimestampNs;
    mElapsedTimestampNs = elapsedTimestampNs;
@@ -189,9 +183,6 @@ LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), Value(trainInfo.status)));
    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)), Value(trainInfo.status)));
}
}


LogEvent::LogEvent(int32_t tagId, int64_t timestampNs) : LogEvent(tagId, timestampNs, timestampNs) {
}

LogEvent::LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid) {
LogEvent::LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid) {
    mLogdTimestampNs = timestampNs;
    mLogdTimestampNs = timestampNs;
    mTagId = tagId;
    mTagId = tagId;
@@ -467,7 +458,10 @@ void LogEvent::parseAttributionChain(int32_t* pos, int32_t depth, bool* last) {


// This parsing logic is tied to the encoding scheme used in StatsEvent.java and
// This parsing logic is tied to the encoding scheme used in StatsEvent.java and
// stats_event.c
// stats_event.c
void LogEvent::initNew() {
bool LogEvent::parseBuffer(uint8_t* buf, size_t len) {
    mBuf = buf;
    mRemainingLen = (uint32_t)len;

    int32_t pos[] = {1, 1, 1};
    int32_t pos[] = {1, 1, 1};
    bool last[] = {false, false, false};
    bool last[] = {false, false, false};


@@ -529,6 +523,7 @@ void LogEvent::initNew() {


    if (mRemainingLen != 0) mValid = false;
    if (mRemainingLen != 0) mValid = false;
    mBuf = nullptr;
    mBuf = nullptr;
    return mValid;
}
}


uint8_t LogEvent::getTypeId(uint8_t typeInfo) {
uint8_t LogEvent::getTypeId(uint8_t typeInfo) {
+27 −22
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@


#include <android/util/ProtoOutputStream.h>
#include <android/util/ProtoOutputStream.h>
#include <private/android_logger.h>
#include <private/android_logger.h>
#include <stats_event.h>


#include <string>
#include <string>
#include <vector>
#include <vector>
@@ -61,23 +60,38 @@ struct InstallTrainInfo {
};
};


/**
/**
 * Wrapper for the log_msg structure.
 * This class decodes the structured, serialized encoding of an atom into a
 * vector of FieldValues.
 */
 */
class LogEvent {
class LogEvent {
public:
public:
    /**
    /**
     * Read a LogEvent from the socket
     * \param uid user id of the logging caller
     * \param pid process id of the logging caller
     */
     */
    explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid);
    explicit LogEvent(int32_t uid, int32_t pid);

    /**
     * Parses the atomId, timestamp, and vector of values from a buffer
     * containing the StatsEvent/AStatsEvent encoding of an atom.
     *
     * \param buf a buffer that begins at the start of the serialized atom (it
     * should not include the android_log_header_t or the StatsEventTag)
     * \param len size of the buffer
     *
     * \return success of the initialization
     */
    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.
     * Constructs a LogEvent with synthetic data for testing. Must call init() before reading.
     */
     */
    explicit LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs);
    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);

    // For testing. The timestamp is used as both elapsed real time and logd timestamp.
    // 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);
    explicit LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid);


@@ -192,10 +206,6 @@ public:
        return &mValues;
        return &mValues;
    }
    }


    bool isValid() {
          return mValid;
    }

    inline LogEvent makeCopy() {
    inline LogEvent makeCopy() {
        return LogEvent(*this);
        return LogEvent(*this);
    }
    }
@@ -222,12 +232,6 @@ private:
     */
     */
    LogEvent(const LogEvent&);
    LogEvent(const LogEvent&);



    /**
     * Parsing function for new encoding scheme.
     */
    void initNew();

    void parseInt32(int32_t* pos, int32_t depth, bool* last);
    void parseInt32(int32_t* pos, int32_t depth, bool* last);
    void parseInt64(int32_t* pos, int32_t depth, bool* last);
    void parseInt64(int32_t* pos, int32_t depth, bool* last);
    void parseString(int32_t* pos, int32_t depth, bool* last);
    void parseString(int32_t* pos, int32_t depth, bool* last);
@@ -238,13 +242,14 @@ private:
    void parseAttributionChain(int32_t* pos, int32_t depth, bool* last);
    void parseAttributionChain(int32_t* pos, int32_t depth, bool* last);


    /**
    /**
     * mBuf is a pointer to the current location in the buffer being parsed.
     * The below three variables are only valid during the execution of
     * Because the buffer lives  on the StatsSocketListener stack, this pointer
     * parseBuffer. There are no guarantees about the state of these variables
     * is only valid during the LogEvent constructor. It will be set to null at
     * before/after.
     * the end of initNew.
     *
     * TODO (b/150312423): These shouldn't be member variables. We should pass
     * them around as parameters.
     */
     */
    uint8_t* mBuf;
    uint8_t* mBuf;

    uint32_t mRemainingLen; // number of valid bytes left in the buffer being parsed
    uint32_t mRemainingLen; // number of valid bytes left in the buffer being parsed
    bool mValid = true; // stores whether the event we received from the socket is valid
    bool mValid = true; // stores whether the event we received from the socket is valid


+4 −1
Original line number Original line Diff line number Diff line
@@ -126,7 +126,10 @@ bool StatsSocketListener::onDataAvailable(SocketClient* cli) {
    uint32_t pid = cred->pid;
    uint32_t pid = cred->pid;


    int64_t oldestTimestamp;
    int64_t oldestTimestamp;
    if (!mQueue->push(std::make_unique<LogEvent>(msg, len, uid, pid), &oldestTimestamp)) {
    std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(uid, pid);
    logEvent->parseBuffer(msg, len);

    if (!mQueue->push(std::move(logEvent), &oldestTimestamp)) {
        StatsdStats::getInstance().noteEventQueueOverflow(oldestTimestamp);
        StatsdStats::getInstance().noteEventQueueOverflow(oldestTimestamp);
    }
    }


+15 −10
Original line number Original line Diff line number Diff line
@@ -54,8 +54,9 @@ TEST(LogEventTest, TestPrimitiveParsing) {
    size_t size;
    size_t size;
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);


    LogEvent logEvent(buf, size, /*uid=*/ 1000, /*pid=*/ 1001);
    LogEvent logEvent(/*uid=*/1000, /*pid=*/1001);
    EXPECT_TRUE(logEvent.isValid());
    EXPECT_TRUE(logEvent.parseBuffer(buf, size));

    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1001, logEvent.GetPid());
    EXPECT_EQ(1001, logEvent.GetPid());
@@ -102,8 +103,9 @@ TEST(LogEventTest, TestStringAndByteArrayParsing) {
    size_t size;
    size_t size;
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);


    LogEvent logEvent(buf, size, /*uid=*/ 1000, /*pid=*/ 1001);
    LogEvent logEvent(/*uid=*/ 1000, /*pid=*/ 1001);
    EXPECT_TRUE(logEvent.isValid());
    EXPECT_TRUE(logEvent.parseBuffer(buf, size));

    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1001, logEvent.GetPid());
    EXPECT_EQ(1001, logEvent.GetPid());
@@ -137,8 +139,9 @@ TEST(LogEventTest, TestEmptyString) {
    size_t size;
    size_t size;
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);


    LogEvent logEvent(buf, size, /*uid=*/ 1000, /*pid=*/ 1001);
    LogEvent logEvent(/*uid=*/ 1000, /*pid=*/ 1001);
    EXPECT_TRUE(logEvent.isValid());
    EXPECT_TRUE(logEvent.parseBuffer(buf, size));

    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1001, logEvent.GetPid());
    EXPECT_EQ(1001, logEvent.GetPid());
@@ -165,8 +168,9 @@ TEST(LogEventTest, TestByteArrayWithNullCharacter) {
    size_t size;
    size_t size;
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);


    LogEvent logEvent(buf, size, /*uid=*/ 1000, /*pid=*/ 1001);
    LogEvent logEvent(/*uid=*/ 1000, /*pid=*/ 1001);
    EXPECT_TRUE(logEvent.isValid());
    EXPECT_TRUE(logEvent.parseBuffer(buf, size));

    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1001, logEvent.GetPid());
    EXPECT_EQ(1001, logEvent.GetPid());
@@ -200,8 +204,9 @@ TEST(LogEventTest, TestAttributionChain) {
    size_t size;
    size_t size;
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);
    uint8_t* buf = AStatsEvent_getBuffer(event, &size);


    LogEvent logEvent(buf, size, /*uid=*/ 1000, /*pid=*/ 1001);
    LogEvent logEvent(/*uid=*/ 1000, /*pid=*/ 1001);
    EXPECT_TRUE(logEvent.isValid());
    EXPECT_TRUE(logEvent.parseBuffer(buf, size));

    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(100, logEvent.GetTagId());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1000, logEvent.GetUid());
    EXPECT_EQ(1001, logEvent.GetPid());
    EXPECT_EQ(1001, logEvent.GetPid());
Loading