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

Commit d5c35621 authored by Yangster-mac's avatar Yangster-mac
Browse files

Timestamp Truncating whitelist.

Test: manually tested.
Change-Id: I46da375b6c0773ffc611bc06fff12cb4f9a7fc18
parent 15235cd5
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -129,12 +129,23 @@ void EventMetricProducer::onMatchedLogEventInternalLocked(

    long long wrapperToken =
            mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);

    long long eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
    const bool truncateTimestamp =
        android::util::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) ==
        android::util::kNotTruncatingTimestampAtomWhiteList.end();
    if (truncateTimestamp) {
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
            (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs()));
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
            (long long)truncateTimestampNsToFiveMinutes(getWallClockNs()));
    } else {
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
            (long long)event.GetElapsedTimestampNs());
    long long eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
    event.ToProto(*mProto);
        mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
            (long long)getWallClockNs());
    }
    event.ToProto(*mProto);
    mProto->end(eventToken);
    mProto->end(wrapperToken);
}
+6 −2
Original line number Diff line number Diff line
@@ -173,11 +173,15 @@ void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
                    writeFieldValueTreeToStream(mTagId, *(atom.mFields), protoOutput);
                }
                protoOutput->end(atomsToken);

                for (const auto& atom : bucket.mGaugeAtoms) {
                    const bool truncateTimestamp =
                        android::util::kNotTruncatingTimestampAtomWhiteList.find(mTagId) ==
                        android::util::kNotTruncatingTimestampAtomWhiteList.end();
                    int64_t timestampNs =  truncateTimestamp ?
                        truncateTimestampNsToFiveMinutes(atom.mTimestamps) : atom.mTimestamps;
                    protoOutput->write(
                        FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
                        (long long)atom.mTimestamps);
                        (long long)timestampNs);
                }
            }
            protoOutput->end(bucketInfoToken);
+4 −0
Original line number Diff line number Diff line
@@ -290,6 +290,10 @@ int64_t getWallClockMillis() {
    return time(nullptr) * MS_PER_SEC;
}

int64_t truncateTimestampNsToFiveMinutes(int64_t timestampNs) {
    return timestampNs / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60);
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ bool parseProtoOutputStream(util::ProtoOutputStream& protoOutput, T* message) {
    return message->ParseFromArray(pbBytes.c_str(), pbBytes.size());
}

// Returns the truncated timestamp.
int64_t truncateTimestampNsToFiveMinutes(int64_t timestampNs);

}  // namespace statsd
}  // namespace os
}  // namespace android
+12 −0
Original line number Diff line number Diff line
@@ -365,6 +365,18 @@ write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributio
    fprintf(out, "};\n");
    fprintf(out, "\n");

    std::set<string> kFuzzingAtomNames = { "mobile_radio_power_state_changed" };
    fprintf(out, "const static std::set<int> kNotTruncatingTimestampAtomWhiteList = {\n");
    for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
        atom != atoms.decls.end(); atom++) {
        if (kFuzzingAtomNames.find(atom->name) == kFuzzingAtomNames.end()) {
            string constant = make_constant_name(atom->name);
            fprintf(out, " %s,\n", constant.c_str());
        }
    }
    fprintf(out, "};\n");
    fprintf(out, "\n");

    fprintf(out, "const static std::set<int> kAtomsWithUidField = {\n");
    for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
        atom != atoms.decls.end(); atom++) {