Loading media/libnbaio/NBLog.cpp +44 −43 Original line number Original line Diff line number Diff line Loading @@ -96,11 +96,11 @@ NBLog::EntryIterator NBLog::FormatEntry::args() const { return it; return it; } } timespec NBLog::FormatEntry::timestamp() const { int64_t NBLog::FormatEntry::timestamp() const { auto it = begin(); auto it = begin(); // skip start fmt // skip start fmt ++it; ++it; return it.payload<timespec>(); return it.payload<int64_t>(); } } NBLog::log_hash_t NBLog::FormatEntry::hash() const { NBLog::log_hash_t NBLog::FormatEntry::hash() const { Loading Loading @@ -222,7 +222,7 @@ bool NBLog::EntryIterator::hasConsistentLength() const { // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- timespec NBLog::HistogramEntry::timestamp() const { int64_t NBLog::HistogramEntry::timestamp() const { return EntryIterator(mEntry).payload<HistTsEntry>().ts; return EntryIterator(mEntry).payload<HistTsEntry>().ts; } } Loading Loading @@ -370,13 +370,15 @@ void NBLog::Writer::logTimestamp() if (!mEnabled) { if (!mEnabled) { return; return; } } struct timespec ts; int64_t ts = get_monotonic_ns(); if (!clock_gettime(CLOCK_MONOTONIC, &ts)) { if (ts > 0) { log(EVENT_TIMESTAMP, &ts, sizeof(ts)); log(EVENT_TIMESTAMP, &ts, sizeof(ts)); } else { ALOGE("Failed to get timestamp"); } } } } void NBLog::Writer::logTimestamp(const struct timespec &ts) void NBLog::Writer::logTimestamp(const int64_t ts) { { if (!mEnabled) { if (!mEnabled) { return; return; Loading Loading @@ -444,11 +446,11 @@ void NBLog::Writer::logHistTS(log_hash_t hash) } } HistTsEntry data; HistTsEntry data; data.hash = hash; data.hash = hash; int error = clock_gettime(CLOCK_MONOTONIC, &data.ts); data.ts = get_monotonic_ns(); if (error == 0) { if (data.ts > 0) { log(EVENT_HISTOGRAM_ENTRY_TS, &data, sizeof(data)); log(EVENT_HISTOGRAM_ENTRY_TS, &data, sizeof(data)); } else { } else { ALOGE("Failed to get timestamp: error %d", error); ALOGE("Failed to get timestamp"); } } } } Loading @@ -459,11 +461,11 @@ void NBLog::Writer::logHistFlush(log_hash_t hash) } } HistTsEntry data; HistTsEntry data; data.hash = hash; data.hash = hash; int error = clock_gettime(CLOCK_MONOTONIC, &data.ts); data.ts = get_monotonic_ns(); if (error == 0) { if (data.ts > 0) { log(EVENT_HISTOGRAM_FLUSH, &data, sizeof(data)); log(EVENT_HISTOGRAM_FLUSH, &data, sizeof(data)); } else { } else { ALOGE("Failed to get timestamp: error %d", error); ALOGE("Failed to get timestamp"); } } } } Loading @@ -488,7 +490,7 @@ void NBLog::Writer::logVFormat(const char *fmt, log_hash_t hash, va_list argp) int i; int i; double f; double f; char* s; char* s; struct timespec t; int64_t t; Writer::logTimestamp(); Writer::logTimestamp(); Writer::logHash(hash); Writer::logHash(hash); for (const char *p = fmt; *p != '\0'; p++) { for (const char *p = fmt; *p != '\0'; p++) { Loading @@ -503,7 +505,7 @@ void NBLog::Writer::logVFormat(const char *fmt, log_hash_t hash, va_list argp) break; break; case 't': // timestamp case 't': // timestamp t = va_arg(argp, struct timespec); t = va_arg(argp, int64_t); Writer::logTimestamp(t); Writer::logTimestamp(t); break; break; Loading Loading @@ -631,7 +633,7 @@ void NBLog::LockedWriter::logTimestamp() Writer::logTimestamp(); Writer::logTimestamp(); } } void NBLog::LockedWriter::logTimestamp(const struct timespec &ts) void NBLog::LockedWriter::logTimestamp(const int64_t ts) { { Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock); Writer::logTimestamp(ts); Writer::logTimestamp(ts); Loading Loading @@ -798,8 +800,8 @@ std::unique_ptr<NBLog::Reader::Snapshot> NBLog::Reader::getSnapshot() } } int deltaMs(timespec *t1, timespec *t2) { inline static int deltaMs(int64_t t1, int64_t t2) { return (t2->tv_sec - t1->tv_sec) * 1000 + t2->tv_nsec / 1000000 - t1->tv_nsec / 1000000; return (t2 - t1) / (1000 * 1000); } } void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapshot) void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapshot) Loading Loading @@ -847,7 +849,7 @@ void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapsho bool deferredTimestamp = false; bool deferredTimestamp = false; #endif #endif std::map<std::pair<log_hash_t, int>, std::vector<int>> hists; std::map<std::pair<log_hash_t, int>, std::vector<int>> hists; std::map<std::pair<log_hash_t, int>, timespec*> lastTSs; std::map<std::pair<log_hash_t, int>, int64_t*> lastTSs; for (auto entry = snapshot.begin(); entry != snapshot.end();) { for (auto entry = snapshot.begin(); entry != snapshot.end();) { switch (entry->type) { switch (entry->type) { Loading Loading @@ -928,13 +930,13 @@ void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapsho memcpy(&hash, &(data->hash), sizeof(hash)); memcpy(&hash, &(data->hash), sizeof(hash)); const std::pair<log_hash_t, int> key(hash, data->author); const std::pair<log_hash_t, int> key(hash, data->author); if (lastTSs[key] != nullptr) { if (lastTSs[key] != nullptr) { timespec ts1; int64_t ts1; memcpy(&ts1, lastTSs[key], sizeof(timespec)); memcpy(&ts1, lastTSs[key], sizeof(ts1)); timespec ts2; int64_t ts2; memcpy(&ts2, &data->ts, sizeof(timespec)); memcpy(&ts2, &data->ts, sizeof(ts2)); // TODO might want to filter excessively high outliers, which are usually caused // TODO might want to filter excessively high outliers, which are usually caused // by the thread being inactive. // by the thread being inactive. hists[key].push_back(deltaMs(&ts1, &ts2)); hists[key].push_back(deltaMs(ts1, ts2)); } } lastTSs[key] = &(data->ts); lastTSs[key] = &(data->ts); ++entry; ++entry; Loading Loading @@ -995,10 +997,10 @@ bool NBLog::Reader::isIMemory(const sp<IMemory>& iMemory) const } } void NBLog::appendTimestamp(String8 *body, const void *data) { void NBLog::appendTimestamp(String8 *body, const void *data) { struct timespec ts; int64_t ts; memcpy(&ts, data, sizeof(struct timespec)); memcpy(&ts, data, sizeof(ts)); body->appendFormat("[%d.%03d]", (int) ts.tv_sec, body->appendFormat("[%d.%03d]", (int) (ts / (1000 * 1000 * 1000)), (int) (ts.tv_nsec / 1000000)); (int) ((ts / (1000 * 1000)) % 1000)); } } void NBLog::appendInt(String8 *body, const void *data) { void NBLog::appendInt(String8 *body, const void *data) { Loading @@ -1018,31 +1020,31 @@ void NBLog::appendPID(String8 *body, const void* data, size_t length) { body->appendFormat("<PID: %d, name: %.*s>", id, (int) (length - sizeof(pid_t)), name); body->appendFormat("<PID: %d, name: %.*s>", id, (int) (length - sizeof(pid_t)), name); } } String8 NBLog::bufferHexDump(const uint8_t *buffer, size_t size) String8 NBLog::bufferDump(const uint8_t *buffer, size_t size) { { String8 str; String8 str; str.append("[ "); str.append("[ "); for(size_t i = 0; i < size; i++) for(size_t i = 0; i < size; i++) { { str.appendFormat("%02x ", buffer[i]); str.appendFormat("%d ", buffer[i]); } } str.append("]"); str.append("]"); return str; return str; } } String8 NBLog::bufferHexDump(const EntryIterator &it) String8 NBLog::bufferDump(const EntryIterator &it) { { return bufferHexDump(it, it->length + Entry::kOverhead); return bufferDump(it, it->length + Entry::kOverhead); } } NBLog::EntryIterator NBLog::Reader::handleFormat(const FormatEntry &fmtEntry, NBLog::EntryIterator NBLog::Reader::handleFormat(const FormatEntry &fmtEntry, String8 *timestamp, String8 *timestamp, String8 *body) { String8 *body) { // log timestamp // log timestamp struct timespec ts = fmtEntry.timestamp(); int64_t ts = fmtEntry.timestamp(); timestamp->clear(); timestamp->clear(); timestamp->appendFormat("[%d.%03d]", (int) ts.tv_sec, timestamp->appendFormat("[%d.%03d]", (int) (ts / (1000 * 1000 * 1000)), (int) (ts.tv_nsec / 1000000)); (int) ((ts / (1000 * 1000)) % 1000)); // log unique hash // log unique hash log_hash_t hash = fmtEntry.hash(); log_hash_t hash = fmtEntry.hash(); Loading Loading @@ -1214,19 +1216,18 @@ void NBLog::Merger::addReader(const NBLog::NamedReader &reader) { // composed by a timestamp and the index of the snapshot where the timestamp came from // composed by a timestamp and the index of the snapshot where the timestamp came from struct MergeItem struct MergeItem { { struct timespec ts; int64_t ts; int index; int index; MergeItem(struct timespec ts, int index): ts(ts), index(index) {} MergeItem(int64_t ts, int index): ts(ts), index(index) {} }; }; // operators needed for priority queue in merge // operators needed for priority queue in merge bool operator>(const struct timespec &t1, const struct timespec &t2) { // bool operator>(const int64_t &t1, const int64_t &t2) { return t1.tv_sec > t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec); // return t1.tv_sec > t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec); } // } bool operator>(const struct MergeItem &i1, const struct MergeItem &i2) { bool operator>(const struct MergeItem &i1, const struct MergeItem &i2) { return i1.ts > i2.ts || return i1.ts > i2.ts || (i1.ts == i2.ts && i1.index > i2.index); (i1.ts.tv_sec == i2.ts.tv_sec && i1.ts.tv_nsec == i2.ts.tv_nsec && i1.index > i2.index); } } // Merge registered readers, sorted by timestamp // Merge registered readers, sorted by timestamp Loading @@ -1245,7 +1246,7 @@ void NBLog::Merger::merge() { for (int i = 0; i < nLogs; ++i) for (int i = 0; i < nLogs; ++i) { { if (offsets[i] != snapshots[i]->end()) { if (offsets[i] != snapshots[i]->end()) { timespec ts = AbstractEntry::buildEntry(offsets[i])->timestamp(); int64_t ts = AbstractEntry::buildEntry(offsets[i])->timestamp(); timestamps.emplace(ts, i); timestamps.emplace(ts, i); } } } } Loading @@ -1259,7 +1260,7 @@ void NBLog::Merger::merge() { // update data structures // update data structures timestamps.pop(); timestamps.pop(); if (offsets[index] != snapshots[index]->end()) { if (offsets[index] != snapshots[index]->end()) { timespec ts = AbstractEntry::buildEntry(offsets[index])->timestamp(); int64_t ts = AbstractEntry::buildEntry(offsets[index])->timestamp(); timestamps.emplace(ts, index); timestamps.emplace(ts, index); } } } } Loading media/libnbaio/include/NBLog.h +18 −11 Original line number Original line Diff line number Diff line Loading @@ -136,7 +136,7 @@ public: // get format entry timestamp // get format entry timestamp // TODO consider changing to uint64_t // TODO consider changing to uint64_t virtual timespec timestamp() const = 0; virtual int64_t timestamp() const = 0; // get format entry's unique id // get format entry's unique id virtual log_hash_t hash() const = 0; virtual log_hash_t hash() const = 0; Loading Loading @@ -172,7 +172,7 @@ public: EntryIterator args() const; EntryIterator args() const; // get format entry timestamp // get format entry timestamp virtual timespec timestamp() const override; virtual int64_t timestamp() const override; // get format entry's unique id // get format entry's unique id virtual log_hash_t hash() const override; virtual log_hash_t hash() const override; Loading @@ -194,7 +194,7 @@ public: explicit HistogramEntry(const uint8_t *ptr) : AbstractEntry(ptr) { explicit HistogramEntry(const uint8_t *ptr) : AbstractEntry(ptr) { } } virtual timespec timestamp() const override; virtual int64_t timestamp() const override; virtual log_hash_t hash() const override; virtual log_hash_t hash() const override; Loading Loading @@ -231,12 +231,12 @@ public: struct HistTsEntry { struct HistTsEntry { log_hash_t hash; log_hash_t hash; timespec ts; int64_t ts; }; //TODO __attribute__((packed)); }; //TODO __attribute__((packed)); struct HistTsEntryWithAuthor { struct HistTsEntryWithAuthor { log_hash_t hash; log_hash_t hash; timespec ts; int64_t ts; int author; int author; }; //TODO __attribute__((packed)); }; //TODO __attribute__((packed)); Loading @@ -261,8 +261,8 @@ struct HistIntEntry { static void appendPID(String8 *body, const void *data, size_t length); static void appendPID(String8 *body, const void *data, size_t length); static void appendTimestamp(String8 *body, const void *data); static void appendTimestamp(String8 *body, const void *data); static size_t fmtEntryLength(const uint8_t *data); static size_t fmtEntryLength(const uint8_t *data); static String8 bufferHexDump(const uint8_t *buffer, size_t size); static String8 bufferDump(const uint8_t *buffer, size_t size); static String8 bufferHexDump(const EntryIterator &it); static String8 bufferDump(const EntryIterator &it); public: public: // Located in shared memory, must be POD. // Located in shared memory, must be POD. Loading Loading @@ -323,7 +323,7 @@ public: virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logvf(const char *fmt, va_list ap); virtual void logvf(const char *fmt, va_list ap); virtual void logTimestamp(); virtual void logTimestamp(); virtual void logTimestamp(const struct timespec &ts); virtual void logTimestamp(const int64_t ts); virtual void logInteger(const int x); virtual void logInteger(const int x); virtual void logFloat(const float x); virtual void logFloat(const float x); virtual void logPID(); virtual void logPID(); Loading Loading @@ -375,7 +375,7 @@ public: virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logvf(const char *fmt, va_list ap); virtual void logvf(const char *fmt, va_list ap); virtual void logTimestamp(); virtual void logTimestamp(); virtual void logTimestamp(const struct timespec &ts); virtual void logTimestamp(const int64_t ts); virtual void logInteger(const int x); virtual void logInteger(const int x); virtual void logFloat(const float x); virtual void logFloat(const float x); virtual void logPID(); virtual void logPID(); Loading Loading @@ -509,8 +509,6 @@ private: Shared * const mShared; Shared * const mShared; std::unique_ptr<audio_utils_fifo> mFifo; std::unique_ptr<audio_utils_fifo> mFifo; std::unique_ptr<audio_utils_fifo_writer> mFifoWriter; std::unique_ptr<audio_utils_fifo_writer> mFifoWriter; static struct timespec getTimestamp(const uint8_t *data); }; }; class MergeReader : public Reader { class MergeReader : public Reader { Loading Loading @@ -562,6 +560,15 @@ private: }; // class NBLog }; // class NBLog // TODO put somewhere else static inline int64_t get_monotonic_ns() { timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { return (uint64_t) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec; } return 0; // should not happen. } } // namespace android } // namespace android #endif // ANDROID_MEDIA_NBLOG_H #endif // ANDROID_MEDIA_NBLOG_H Loading
media/libnbaio/NBLog.cpp +44 −43 Original line number Original line Diff line number Diff line Loading @@ -96,11 +96,11 @@ NBLog::EntryIterator NBLog::FormatEntry::args() const { return it; return it; } } timespec NBLog::FormatEntry::timestamp() const { int64_t NBLog::FormatEntry::timestamp() const { auto it = begin(); auto it = begin(); // skip start fmt // skip start fmt ++it; ++it; return it.payload<timespec>(); return it.payload<int64_t>(); } } NBLog::log_hash_t NBLog::FormatEntry::hash() const { NBLog::log_hash_t NBLog::FormatEntry::hash() const { Loading Loading @@ -222,7 +222,7 @@ bool NBLog::EntryIterator::hasConsistentLength() const { // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- timespec NBLog::HistogramEntry::timestamp() const { int64_t NBLog::HistogramEntry::timestamp() const { return EntryIterator(mEntry).payload<HistTsEntry>().ts; return EntryIterator(mEntry).payload<HistTsEntry>().ts; } } Loading Loading @@ -370,13 +370,15 @@ void NBLog::Writer::logTimestamp() if (!mEnabled) { if (!mEnabled) { return; return; } } struct timespec ts; int64_t ts = get_monotonic_ns(); if (!clock_gettime(CLOCK_MONOTONIC, &ts)) { if (ts > 0) { log(EVENT_TIMESTAMP, &ts, sizeof(ts)); log(EVENT_TIMESTAMP, &ts, sizeof(ts)); } else { ALOGE("Failed to get timestamp"); } } } } void NBLog::Writer::logTimestamp(const struct timespec &ts) void NBLog::Writer::logTimestamp(const int64_t ts) { { if (!mEnabled) { if (!mEnabled) { return; return; Loading Loading @@ -444,11 +446,11 @@ void NBLog::Writer::logHistTS(log_hash_t hash) } } HistTsEntry data; HistTsEntry data; data.hash = hash; data.hash = hash; int error = clock_gettime(CLOCK_MONOTONIC, &data.ts); data.ts = get_monotonic_ns(); if (error == 0) { if (data.ts > 0) { log(EVENT_HISTOGRAM_ENTRY_TS, &data, sizeof(data)); log(EVENT_HISTOGRAM_ENTRY_TS, &data, sizeof(data)); } else { } else { ALOGE("Failed to get timestamp: error %d", error); ALOGE("Failed to get timestamp"); } } } } Loading @@ -459,11 +461,11 @@ void NBLog::Writer::logHistFlush(log_hash_t hash) } } HistTsEntry data; HistTsEntry data; data.hash = hash; data.hash = hash; int error = clock_gettime(CLOCK_MONOTONIC, &data.ts); data.ts = get_monotonic_ns(); if (error == 0) { if (data.ts > 0) { log(EVENT_HISTOGRAM_FLUSH, &data, sizeof(data)); log(EVENT_HISTOGRAM_FLUSH, &data, sizeof(data)); } else { } else { ALOGE("Failed to get timestamp: error %d", error); ALOGE("Failed to get timestamp"); } } } } Loading @@ -488,7 +490,7 @@ void NBLog::Writer::logVFormat(const char *fmt, log_hash_t hash, va_list argp) int i; int i; double f; double f; char* s; char* s; struct timespec t; int64_t t; Writer::logTimestamp(); Writer::logTimestamp(); Writer::logHash(hash); Writer::logHash(hash); for (const char *p = fmt; *p != '\0'; p++) { for (const char *p = fmt; *p != '\0'; p++) { Loading @@ -503,7 +505,7 @@ void NBLog::Writer::logVFormat(const char *fmt, log_hash_t hash, va_list argp) break; break; case 't': // timestamp case 't': // timestamp t = va_arg(argp, struct timespec); t = va_arg(argp, int64_t); Writer::logTimestamp(t); Writer::logTimestamp(t); break; break; Loading Loading @@ -631,7 +633,7 @@ void NBLog::LockedWriter::logTimestamp() Writer::logTimestamp(); Writer::logTimestamp(); } } void NBLog::LockedWriter::logTimestamp(const struct timespec &ts) void NBLog::LockedWriter::logTimestamp(const int64_t ts) { { Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock); Writer::logTimestamp(ts); Writer::logTimestamp(ts); Loading Loading @@ -798,8 +800,8 @@ std::unique_ptr<NBLog::Reader::Snapshot> NBLog::Reader::getSnapshot() } } int deltaMs(timespec *t1, timespec *t2) { inline static int deltaMs(int64_t t1, int64_t t2) { return (t2->tv_sec - t1->tv_sec) * 1000 + t2->tv_nsec / 1000000 - t1->tv_nsec / 1000000; return (t2 - t1) / (1000 * 1000); } } void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapshot) void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapshot) Loading Loading @@ -847,7 +849,7 @@ void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapsho bool deferredTimestamp = false; bool deferredTimestamp = false; #endif #endif std::map<std::pair<log_hash_t, int>, std::vector<int>> hists; std::map<std::pair<log_hash_t, int>, std::vector<int>> hists; std::map<std::pair<log_hash_t, int>, timespec*> lastTSs; std::map<std::pair<log_hash_t, int>, int64_t*> lastTSs; for (auto entry = snapshot.begin(); entry != snapshot.end();) { for (auto entry = snapshot.begin(); entry != snapshot.end();) { switch (entry->type) { switch (entry->type) { Loading Loading @@ -928,13 +930,13 @@ void NBLog::Reader::dump(int fd, size_t indent, NBLog::Reader::Snapshot &snapsho memcpy(&hash, &(data->hash), sizeof(hash)); memcpy(&hash, &(data->hash), sizeof(hash)); const std::pair<log_hash_t, int> key(hash, data->author); const std::pair<log_hash_t, int> key(hash, data->author); if (lastTSs[key] != nullptr) { if (lastTSs[key] != nullptr) { timespec ts1; int64_t ts1; memcpy(&ts1, lastTSs[key], sizeof(timespec)); memcpy(&ts1, lastTSs[key], sizeof(ts1)); timespec ts2; int64_t ts2; memcpy(&ts2, &data->ts, sizeof(timespec)); memcpy(&ts2, &data->ts, sizeof(ts2)); // TODO might want to filter excessively high outliers, which are usually caused // TODO might want to filter excessively high outliers, which are usually caused // by the thread being inactive. // by the thread being inactive. hists[key].push_back(deltaMs(&ts1, &ts2)); hists[key].push_back(deltaMs(ts1, ts2)); } } lastTSs[key] = &(data->ts); lastTSs[key] = &(data->ts); ++entry; ++entry; Loading Loading @@ -995,10 +997,10 @@ bool NBLog::Reader::isIMemory(const sp<IMemory>& iMemory) const } } void NBLog::appendTimestamp(String8 *body, const void *data) { void NBLog::appendTimestamp(String8 *body, const void *data) { struct timespec ts; int64_t ts; memcpy(&ts, data, sizeof(struct timespec)); memcpy(&ts, data, sizeof(ts)); body->appendFormat("[%d.%03d]", (int) ts.tv_sec, body->appendFormat("[%d.%03d]", (int) (ts / (1000 * 1000 * 1000)), (int) (ts.tv_nsec / 1000000)); (int) ((ts / (1000 * 1000)) % 1000)); } } void NBLog::appendInt(String8 *body, const void *data) { void NBLog::appendInt(String8 *body, const void *data) { Loading @@ -1018,31 +1020,31 @@ void NBLog::appendPID(String8 *body, const void* data, size_t length) { body->appendFormat("<PID: %d, name: %.*s>", id, (int) (length - sizeof(pid_t)), name); body->appendFormat("<PID: %d, name: %.*s>", id, (int) (length - sizeof(pid_t)), name); } } String8 NBLog::bufferHexDump(const uint8_t *buffer, size_t size) String8 NBLog::bufferDump(const uint8_t *buffer, size_t size) { { String8 str; String8 str; str.append("[ "); str.append("[ "); for(size_t i = 0; i < size; i++) for(size_t i = 0; i < size; i++) { { str.appendFormat("%02x ", buffer[i]); str.appendFormat("%d ", buffer[i]); } } str.append("]"); str.append("]"); return str; return str; } } String8 NBLog::bufferHexDump(const EntryIterator &it) String8 NBLog::bufferDump(const EntryIterator &it) { { return bufferHexDump(it, it->length + Entry::kOverhead); return bufferDump(it, it->length + Entry::kOverhead); } } NBLog::EntryIterator NBLog::Reader::handleFormat(const FormatEntry &fmtEntry, NBLog::EntryIterator NBLog::Reader::handleFormat(const FormatEntry &fmtEntry, String8 *timestamp, String8 *timestamp, String8 *body) { String8 *body) { // log timestamp // log timestamp struct timespec ts = fmtEntry.timestamp(); int64_t ts = fmtEntry.timestamp(); timestamp->clear(); timestamp->clear(); timestamp->appendFormat("[%d.%03d]", (int) ts.tv_sec, timestamp->appendFormat("[%d.%03d]", (int) (ts / (1000 * 1000 * 1000)), (int) (ts.tv_nsec / 1000000)); (int) ((ts / (1000 * 1000)) % 1000)); // log unique hash // log unique hash log_hash_t hash = fmtEntry.hash(); log_hash_t hash = fmtEntry.hash(); Loading Loading @@ -1214,19 +1216,18 @@ void NBLog::Merger::addReader(const NBLog::NamedReader &reader) { // composed by a timestamp and the index of the snapshot where the timestamp came from // composed by a timestamp and the index of the snapshot where the timestamp came from struct MergeItem struct MergeItem { { struct timespec ts; int64_t ts; int index; int index; MergeItem(struct timespec ts, int index): ts(ts), index(index) {} MergeItem(int64_t ts, int index): ts(ts), index(index) {} }; }; // operators needed for priority queue in merge // operators needed for priority queue in merge bool operator>(const struct timespec &t1, const struct timespec &t2) { // bool operator>(const int64_t &t1, const int64_t &t2) { return t1.tv_sec > t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec); // return t1.tv_sec > t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec); } // } bool operator>(const struct MergeItem &i1, const struct MergeItem &i2) { bool operator>(const struct MergeItem &i1, const struct MergeItem &i2) { return i1.ts > i2.ts || return i1.ts > i2.ts || (i1.ts == i2.ts && i1.index > i2.index); (i1.ts.tv_sec == i2.ts.tv_sec && i1.ts.tv_nsec == i2.ts.tv_nsec && i1.index > i2.index); } } // Merge registered readers, sorted by timestamp // Merge registered readers, sorted by timestamp Loading @@ -1245,7 +1246,7 @@ void NBLog::Merger::merge() { for (int i = 0; i < nLogs; ++i) for (int i = 0; i < nLogs; ++i) { { if (offsets[i] != snapshots[i]->end()) { if (offsets[i] != snapshots[i]->end()) { timespec ts = AbstractEntry::buildEntry(offsets[i])->timestamp(); int64_t ts = AbstractEntry::buildEntry(offsets[i])->timestamp(); timestamps.emplace(ts, i); timestamps.emplace(ts, i); } } } } Loading @@ -1259,7 +1260,7 @@ void NBLog::Merger::merge() { // update data structures // update data structures timestamps.pop(); timestamps.pop(); if (offsets[index] != snapshots[index]->end()) { if (offsets[index] != snapshots[index]->end()) { timespec ts = AbstractEntry::buildEntry(offsets[index])->timestamp(); int64_t ts = AbstractEntry::buildEntry(offsets[index])->timestamp(); timestamps.emplace(ts, index); timestamps.emplace(ts, index); } } } } Loading
media/libnbaio/include/NBLog.h +18 −11 Original line number Original line Diff line number Diff line Loading @@ -136,7 +136,7 @@ public: // get format entry timestamp // get format entry timestamp // TODO consider changing to uint64_t // TODO consider changing to uint64_t virtual timespec timestamp() const = 0; virtual int64_t timestamp() const = 0; // get format entry's unique id // get format entry's unique id virtual log_hash_t hash() const = 0; virtual log_hash_t hash() const = 0; Loading Loading @@ -172,7 +172,7 @@ public: EntryIterator args() const; EntryIterator args() const; // get format entry timestamp // get format entry timestamp virtual timespec timestamp() const override; virtual int64_t timestamp() const override; // get format entry's unique id // get format entry's unique id virtual log_hash_t hash() const override; virtual log_hash_t hash() const override; Loading @@ -194,7 +194,7 @@ public: explicit HistogramEntry(const uint8_t *ptr) : AbstractEntry(ptr) { explicit HistogramEntry(const uint8_t *ptr) : AbstractEntry(ptr) { } } virtual timespec timestamp() const override; virtual int64_t timestamp() const override; virtual log_hash_t hash() const override; virtual log_hash_t hash() const override; Loading Loading @@ -231,12 +231,12 @@ public: struct HistTsEntry { struct HistTsEntry { log_hash_t hash; log_hash_t hash; timespec ts; int64_t ts; }; //TODO __attribute__((packed)); }; //TODO __attribute__((packed)); struct HistTsEntryWithAuthor { struct HistTsEntryWithAuthor { log_hash_t hash; log_hash_t hash; timespec ts; int64_t ts; int author; int author; }; //TODO __attribute__((packed)); }; //TODO __attribute__((packed)); Loading @@ -261,8 +261,8 @@ struct HistIntEntry { static void appendPID(String8 *body, const void *data, size_t length); static void appendPID(String8 *body, const void *data, size_t length); static void appendTimestamp(String8 *body, const void *data); static void appendTimestamp(String8 *body, const void *data); static size_t fmtEntryLength(const uint8_t *data); static size_t fmtEntryLength(const uint8_t *data); static String8 bufferHexDump(const uint8_t *buffer, size_t size); static String8 bufferDump(const uint8_t *buffer, size_t size); static String8 bufferHexDump(const EntryIterator &it); static String8 bufferDump(const EntryIterator &it); public: public: // Located in shared memory, must be POD. // Located in shared memory, must be POD. Loading Loading @@ -323,7 +323,7 @@ public: virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logvf(const char *fmt, va_list ap); virtual void logvf(const char *fmt, va_list ap); virtual void logTimestamp(); virtual void logTimestamp(); virtual void logTimestamp(const struct timespec &ts); virtual void logTimestamp(const int64_t ts); virtual void logInteger(const int x); virtual void logInteger(const int x); virtual void logFloat(const float x); virtual void logFloat(const float x); virtual void logPID(); virtual void logPID(); Loading Loading @@ -375,7 +375,7 @@ public: virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logf(const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); virtual void logvf(const char *fmt, va_list ap); virtual void logvf(const char *fmt, va_list ap); virtual void logTimestamp(); virtual void logTimestamp(); virtual void logTimestamp(const struct timespec &ts); virtual void logTimestamp(const int64_t ts); virtual void logInteger(const int x); virtual void logInteger(const int x); virtual void logFloat(const float x); virtual void logFloat(const float x); virtual void logPID(); virtual void logPID(); Loading Loading @@ -509,8 +509,6 @@ private: Shared * const mShared; Shared * const mShared; std::unique_ptr<audio_utils_fifo> mFifo; std::unique_ptr<audio_utils_fifo> mFifo; std::unique_ptr<audio_utils_fifo_writer> mFifoWriter; std::unique_ptr<audio_utils_fifo_writer> mFifoWriter; static struct timespec getTimestamp(const uint8_t *data); }; }; class MergeReader : public Reader { class MergeReader : public Reader { Loading Loading @@ -562,6 +560,15 @@ private: }; // class NBLog }; // class NBLog // TODO put somewhere else static inline int64_t get_monotonic_ns() { timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { return (uint64_t) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec; } return 0; // should not happen. } } // namespace android } // namespace android #endif // ANDROID_MEDIA_NBLOG_H #endif // ANDROID_MEDIA_NBLOG_H