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

Commit 1e4368aa authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Comment out Statsd tests

Added todos to make them ues the new schema.

Bug: 145923087
Test: m -j && bit statsd_test:*
Change-Id: I0749760eb3123407b78b9ace9a93967bac727bf5
parent b55d7214
Loading
Loading
Loading
Loading
+49 −53
Original line number Diff line number Diff line
@@ -105,10 +105,6 @@ cc_defaults {
        "src/uid_data.proto",
    ],

    cflags: [
        "-DNEW_ENCODING_SCHEME",
    ],

    local_include_dirs: [
        "src",
    ],
@@ -316,55 +312,55 @@ cc_test {
// statsd micro benchmark
//#############################

cc_benchmark {
    name: "statsd_benchmark",
    defaults: ["statsd_defaults"],

    srcs: [
        // atom_field_options.proto needs field_options.proto, but that is
        // not included in libprotobuf-cpp-lite, so compile it here.
        ":libprotobuf-internal-protos",

        "benchmark/duration_metric_benchmark.cpp",
        "benchmark/filter_value_benchmark.cpp",
        "benchmark/get_dimensions_for_condition_benchmark.cpp",
        "benchmark/hello_world_benchmark.cpp",
        "benchmark/log_event_benchmark.cpp",
        "benchmark/main.cpp",
        "benchmark/metric_util.cpp",
        "benchmark/stats_write_benchmark.cpp",
        "src/atom_field_options.proto",
        "src/atoms.proto",
        "src/stats_log.proto",
    ],

    proto: {
        type: "lite",
        include_dirs: ["external/protobuf/src"],
    },

    cflags: [
        "-Wall",
        "-Werror",
        "-Wno-unused-parameter",
        "-Wno-unused-variable",
        "-Wno-unused-function",

        // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374
        "-Wno-varargs",
    ],

    static_libs: [
        "libplatformprotos",
    ],

    shared_libs: [
        "libgtest_prod",
        "libprotobuf-cpp-lite",
        "libstatslog",
        "libstatssocket",
    ],
}
//cc_benchmark {
//    name: "statsd_benchmark",
//    defaults: ["statsd_defaults"],
//
//    srcs: [
//        // atom_field_options.proto needs field_options.proto, but that is
//        // not included in libprotobuf-cpp-lite, so compile it here.
//        ":libprotobuf-internal-protos",
//
//        "benchmark/duration_metric_benchmark.cpp",
//        "benchmark/filter_value_benchmark.cpp",
//        "benchmark/get_dimensions_for_condition_benchmark.cpp",
//        "benchmark/hello_world_benchmark.cpp",
//        "benchmark/log_event_benchmark.cpp",
//        "benchmark/main.cpp",
//        "benchmark/metric_util.cpp",
//        "benchmark/stats_write_benchmark.cpp",
//        "src/atom_field_options.proto",
//        "src/atoms.proto",
//        "src/stats_log.proto",
//    ],
//
//    proto: {
//        type: "lite",
//        include_dirs: ["external/protobuf/src"],
//    },
//
//    cflags: [
//        "-Wall",
//        "-Werror",
//        "-Wno-unused-parameter",
//        "-Wno-unused-variable",
//        "-Wno-unused-function",
//
//        // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374
//        "-Wno-varargs",
//    ],
//
//    static_libs: [
//        "libplatformprotos",
//    ],
//
//    shared_libs: [
//        "libgtest_prod",
//        "libprotobuf-cpp-lite",
//        "libstatslog",
//        "libstatssocket",
//    ],
//}

// ====  java proto device library (for test only)  ==============================
java_library {
+0 −16
Original line number Diff line number Diff line
@@ -208,12 +208,8 @@ void StatsLogProcessor::onBinaryPushStateChangedEventLocked(LogEvent* event) {
    trainInfo.requiresLowLatencyMonitor =
            event->GetBool(5 /*requires low latency monitor field id*/, &err);
    trainInfo.status = int32_t(event->GetLong(6 /*state field id*/, &err));
#ifdef NEW_ENCODING_SCHEME
    std::vector<uint8_t> trainExperimentIdBytes =
            event->GetStorage(7 /*experiment ids field id*/, &err);
#else
    string trainExperimentIdString = event->GetString(7 /*experiment ids field id*/, &err);
#endif
    bool is_rollback = event->GetBool(10 /*is rollback field id*/, &err);

    if (err != NO_ERROR) {
@@ -221,12 +217,8 @@ void StatsLogProcessor::onBinaryPushStateChangedEventLocked(LogEvent* event) {
        return;
    }
    ExperimentIds trainExperimentIds;
#ifdef NEW_ENCODING_SCHEME
    if (!trainExperimentIds.ParseFromArray(trainExperimentIdBytes.data(),
                                           trainExperimentIdBytes.size())) {
#else
    if (!trainExperimentIds.ParseFromString(trainExperimentIdString)) {
#endif
        ALOGE("Failed to parse experimentids in binary push state changed.");
        return;
    }
@@ -241,11 +233,7 @@ void StatsLogProcessor::onBinaryPushStateChangedEventLocked(LogEvent* event) {
    int32_t userId = multiuser_get_user_id(uid);

    event->updateValue(2 /*train version field id*/, trainInfo.trainVersionCode, LONG);
#ifdef NEW_ENCODING_SCHEME
    event->updateValue(7 /*experiment ids field id*/, trainExperimentIdProto, STORAGE);
#else
    event->updateValue(7 /*experiment ids field id*/, trainExperimentIdProto, STRING);
#endif
    event->updateValue(8 /*user id field id*/, userId, INT);

    // If this event is a rollback event, then the following bits in the event
@@ -352,11 +340,7 @@ void StatsLogProcessor::onWatchdogRollbackOccurredLocked(LogEvent* event) {
    vector<uint8_t> experimentIdProto;
    writeExperimentIdsToProto(experimentIds, &experimentIdProto);

#ifdef NEW_ENCODING_SCHEME
    event->updateValue(6 /*experiment ids field id*/, experimentIdProto, STORAGE);
#else
    event->updateValue(6 /*experiment ids field id*/, experimentIdProto, STRING);
#endif
}

vector<int64_t> StatsLogProcessor::processWatchdogRollbackOccurred(const int32_t rollbackTypeIn,
+1 −2
Original line number Diff line number Diff line
@@ -69,8 +69,7 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) {
                        uint8_t* buf = reinterpret_cast<uint8_t*>(
                                const_cast<int8_t*>(parcel.buffer.data()));
                        shared_ptr<LogEvent> event = make_shared<LogEvent>(
                                buf, parcel.buffer.size(), /*uid=*/-1, /*pid=*/-1,
                                /*useNewSchema=*/true);
                                buf, parcel.buffer.size(), /*uid=*/-1, /*pid=*/-1);
                        sharedData->push_back(event);
                    }
                    *pullSuccess = success;
+0 −164
Original line number Diff line number Diff line
@@ -74,29 +74,7 @@ LogEvent::LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid)
      mLogUid(uid),
      mLogPid(pid)
{
#ifdef NEW_ENCODING_SCHEME
    initNew();
# else
    mContext = create_android_log_parser((char*)msg, len);
    init(mContext);
    if (mContext) android_log_destroy(&mContext); // set mContext to NULL
#endif
}

LogEvent::LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid, bool useNewSchema)
    : mBuf(msg),
      mRemainingLen(len),
      mLogdTimestampNs(time(nullptr)),
      mLogUid(uid),
      mLogPid(pid)
{
    if (useNewSchema) {
        initNew();
    } else {
        mContext = create_android_log_parser((char*)msg, len);
        init(mContext);
        if (mContext) android_log_destroy(&mContext);  // set mContext to NULL
    }
}

LogEvent::LogEvent(const LogEvent& event) {
@@ -225,22 +203,6 @@ LogEvent::LogEvent(int32_t tagId, int64_t timestampNs, int32_t uid) {
    }
}

void LogEvent::init() {
    if (mContext) {
        const char* buffer;
        size_t len = android_log_write_list_buffer(mContext, &buffer);
        // turns to reader mode
        android_log_context contextForRead = create_android_log_parser(buffer, len);
        if (contextForRead) {
            init(contextForRead);
            // destroy the context to save memory.
            // android_log_destroy will set mContext to NULL
            android_log_destroy(&contextForRead);
        }
        android_log_destroy(&mContext);
    }
}

LogEvent::~LogEvent() {
    if (mContext) {
        // This is for the case when LogEvent is created using the test interface
@@ -577,132 +539,6 @@ uint8_t LogEvent::getNumAnnotations(uint8_t typeInfo) {
    return (typeInfo >> 4) & 0x0F;
}

/**
 * The elements of each log event are stored as a vector of android_log_list_elements.
 * 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.
 *
 * The idea here is to read through the log items once, we get as much information we need for
 * matching as possible. Because this log will be matched against lots of matchers.
 */
void LogEvent::init(android_log_context context) {
    android_log_list_element elem;
    int i = 0;
    int depth = -1;
    int pos[] = {1, 1, 1};
    bool isKeyValuePairAtom = false;
    do {
        elem = android_log_read_next(context);
        switch ((int)elem.type) {
            case EVENT_TYPE_INT:
                // elem at [0] is EVENT_TYPE_LIST, [1] is the timestamp, [2] is tag id.
                if (i == 2) {
                    mTagId = elem.data.int32;
                    isKeyValuePairAtom = (mTagId == android::util::KEY_VALUE_PAIRS_ATOM);
                } else {
                    if (depth < 0 || depth > 2) {
                        return;
                    }

                    mValues.push_back(
                            FieldValue(Field(mTagId, pos, depth), Value((int32_t)elem.data.int32)));

                    pos[depth]++;
                }
                break;
            case EVENT_TYPE_FLOAT: {
                if (depth < 0 || depth > 2) {
                    ALOGE("Depth > 2. Not supported!");
                    return;
                }

                // Handles the oneof field in KeyValuePair atom.
                if (isKeyValuePairAtom && depth == 2) {
                    pos[depth] = 5;
                }

                mValues.push_back(FieldValue(Field(mTagId, pos, depth), Value(elem.data.float32)));

                pos[depth]++;

            } break;
            case EVENT_TYPE_STRING: {
                if (depth < 0 || depth > 2) {
                    ALOGE("Depth > 2. Not supported!");
                    return;
                }

                // Handles the oneof field in KeyValuePair atom.
                if (isKeyValuePairAtom && depth == 2) {
                    pos[depth] = 4;
                }
                mValues.push_back(FieldValue(Field(mTagId, pos, depth),
                                             Value(string(elem.data.string, elem.len))));

                pos[depth]++;

            } break;
            case EVENT_TYPE_LONG: {
                if (i == 1) {
                    mElapsedTimestampNs = elem.data.int64;
                } else {
                    if (depth < 0 || depth > 2) {
                        ALOGE("Depth > 2. Not supported!");
                        return;
                    }
                    // Handles the oneof field in KeyValuePair atom.
                    if (isKeyValuePairAtom && depth == 2) {
                        pos[depth] = 3;
                    }
                    mValues.push_back(
                            FieldValue(Field(mTagId, pos, depth), Value((int64_t)elem.data.int64)));

                    pos[depth]++;
                }
            } break;
            case EVENT_TYPE_LIST:
                depth++;
                if (depth > 2) {
                    ALOGE("Depth > 2. Not supported!");
                    return;
                }
                pos[depth] = 1;

                break;
            case EVENT_TYPE_LIST_STOP: {
                int prevDepth = depth;
                depth--;
                if (depth >= 0 && depth < 2) {
                    // Now go back to decorate the previous items that are last at prevDepth.
                    // So that we can later easily match them with Position=Last matchers.
                    pos[prevDepth]--;
                    int path = getEncodedField(pos, prevDepth, false);
                    for (auto it = mValues.rbegin(); it != mValues.rend(); ++it) {
                        if (it->mField.getDepth() >= prevDepth &&
                            it->mField.getPath(prevDepth) == path) {
                            it->mField.decorateLastPos(prevDepth);
                        } else {
                            // Safe to break, because the items are in DFS order.
                            break;
                        }
                    }
                    pos[depth]++;
                }
                break;
            }
            case EVENT_TYPE_UNKNOWN:
                break;
            default:
                break;
        }
        i++;
    } while ((elem.type != EVENT_TYPE_UNKNOWN) && !elem.complete);
    if (isKeyValuePairAtom && mValues.size() > 0) {
        mValues[0] = FieldValue(Field(android::util::KEY_VALUE_PAIRS_ATOM, getSimpleField(1)),
                                Value((int32_t)mLogUid));
    }
}

int64_t LogEvent::GetLong(size_t key, status_t* err) const {
    // TODO(b/110561208): encapsulate the magical operations in Field struct as static functions
    int field = getSimpleField(key);
+0 −16
Original line number Diff line number Diff line
@@ -70,11 +70,6 @@ public:
     */
    explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid);

    /**
     * Temp constructor to use for pulled atoms until we flip the socket schema.
     */
    explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid, bool useNewSchema);

    /**
     * Constructs a LogEvent with synthetic data for testing. Must call init() before reading.
     */
@@ -171,12 +166,6 @@ public:
     */
    void ToProto(android::util::ProtoOutputStream& out) const;

    /**
     * Used with the constructor where tag is passed in. Converts the log_event_list to read mode
     * and prepares the list for reading.
     */
    void init();

    /**
     * Set elapsed timestamp if the original timestamp is missing.
     */
@@ -304,11 +293,6 @@ private:
    uint8_t getTypeId(uint8_t typeInfo);
    uint8_t getNumAnnotations(uint8_t typeInfo);

    /**
     * Parses a log_msg into a LogEvent object.
     */
    void init(android_log_context context);

    // The items are naturally sorted in DFS order as we read them. this allows us to do fast
    // matching.
    std::vector<FieldValue> mValues;
Loading