From 481fb67a595f23c5b7f5be84b06db9b84a41a42f Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Mon, 30 Sep 2013 14:39:28 -0700 Subject: Add RecordThread media.log and deferred deallocation This change allows a media.log buffer for RecordThread. Unlike playback threads which stick around forever, the RecordThread comes and goes for every capture session. This means that the media.log buffer for a RecordThread would disappear too, and so was useless. Now when a thread exits, it's associated media.log buffer is just marked for deferred deallocation. It is only actually freed when the memory is needed. Other changes: - Fix bug in unregistering comparison, it was comparing the wrong pointers - Increased size of log area so we can log for RecordThread also Change-Id: If45d4c03a793b86390a0112ec3acc5d41b2e3635 --- media/libnbaio/NBLog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'media/libnbaio/NBLog.cpp') diff --git a/media/libnbaio/NBLog.cpp b/media/libnbaio/NBLog.cpp index 045bf64..ba8d0b4 100644 --- a/media/libnbaio/NBLog.cpp +++ b/media/libnbaio/NBLog.cpp @@ -441,7 +441,7 @@ void NBLog::Reader::dump(int fd, size_t indent) bool NBLog::Reader::isIMemory(const sp& iMemory) const { - return iMemory.get() == mIMemory.get(); + return iMemory != 0 && mIMemory != 0 && iMemory->pointer() == mIMemory->pointer(); } } // namespace android -- cgit v1.1 From 4e01ef6b2f6d288b9aa83b5817adad02cecc429f Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Thu, 11 Jul 2013 14:29:59 -0700 Subject: Add private method NBLog::Reader::dumpLine() This allows us to abstract out fdprintf vs ALOGI so that callers don't need an 'if' at every location. Change-Id: I4c68185fc19f32caeaed93347e6b7d09b8d4c4d8 --- media/libnbaio/NBLog.cpp | 80 ++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 37 deletions(-) (limited to 'media/libnbaio/NBLog.cpp') diff --git a/media/libnbaio/NBLog.cpp b/media/libnbaio/NBLog.cpp index 190824d..895fd60 100644 --- a/media/libnbaio/NBLog.cpp +++ b/media/libnbaio/NBLog.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace android { @@ -337,25 +338,25 @@ void NBLog::Reader::dump(int fd, size_t indent) } i -= length + 3; } + mFd = fd; + mIndent = indent; + String8 timestamp, body; if (i > 0) { lost += i; - if (fd >= 0) { - fdprintf(fd, "%*swarning: lost %zu bytes worth of events\n", indent, "", lost); - } else { - ALOGI("%*swarning: lost %u bytes worth of events\n", indent, "", lost); - } + body.appendFormat("warning: lost %u bytes worth of events", lost); + // TODO timestamp empty here, only other choice to wait for the first timestamp event in the + // log to push it out. Consider keeping the timestamp/body between calls to readAt(). + dumpLine(timestamp, body); } size_t width = 1; while (maxSec >= 10) { ++width; maxSec /= 10; } - char prefix[32]; if (maxSec >= 0) { - snprintf(prefix, sizeof(prefix), "[%*s] ", width + 4, ""); - } else { - prefix[0] = '\0'; + timestamp.appendFormat("[%*s]", width + 4, ""); } + bool deferredTimestamp = false; while (i < avail) { event = (Event) copy[i]; length = copy[i + 1]; @@ -363,11 +364,8 @@ void NBLog::Reader::dump(int fd, size_t indent) size_t advance = length + 3; switch (event) { case EVENT_STRING: - if (fd >= 0) { - fdprintf(fd, "%*s%s%.*s\n", indent, "", prefix, length, (const char *) data); - } else { - ALOGI("%*s%s%.*s", indent, "", prefix, length, (const char *) data); - } break; + body.appendFormat("%.*s", length, (const char *) data); + break; case EVENT_TIMESTAMP: { // already checked that length == sizeof(struct timespec); memcpy(&ts, data, sizeof(struct timespec)); @@ -400,45 +398,53 @@ void NBLog::Reader::dump(int fd, size_t indent) prevNsec = tsNext.tv_nsec; } size_t n = (j - i) / (sizeof(struct timespec) + 3); + if (deferredTimestamp) { + dumpLine(timestamp, body); + deferredTimestamp = false; + } + timestamp.clear(); if (n >= kSquashTimestamp) { - if (fd >= 0) { - fdprintf(fd, "%*s[%d.%03d to .%.03d by .%.03d to .%.03d]\n", indent, "", - (int) ts.tv_sec, (int) (ts.tv_nsec / 1000000), - (int) ((ts.tv_nsec + deltaTotal) / 1000000), - (int) (deltaMin / 1000000), (int) (deltaMax / 1000000)); - } else { - ALOGI("%*s[%d.%03d to .%.03d by .%.03d to .%.03d]\n", indent, "", - (int) ts.tv_sec, (int) (ts.tv_nsec / 1000000), - (int) ((ts.tv_nsec + deltaTotal) / 1000000), - (int) (deltaMin / 1000000), (int) (deltaMax / 1000000)); - } + timestamp.appendFormat("[%d.%03d to .%.03d by .%.03d to .%.03d]", + (int) ts.tv_sec, (int) (ts.tv_nsec / 1000000), + (int) ((ts.tv_nsec + deltaTotal) / 1000000), + (int) (deltaMin / 1000000), (int) (deltaMax / 1000000)); i = j; advance = 0; break; } - if (fd >= 0) { - fdprintf(fd, "%*s[%d.%03d]\n", indent, "", (int) ts.tv_sec, - (int) (ts.tv_nsec / 1000000)); - } else { - ALOGI("%*s[%d.%03d]", indent, "", (int) ts.tv_sec, - (int) (ts.tv_nsec / 1000000)); - } + timestamp.appendFormat("[%d.%03d]", (int) ts.tv_sec, + (int) (ts.tv_nsec / 1000000)); + deferredTimestamp = true; } break; case EVENT_RESERVED: default: - if (fd >= 0) { - fdprintf(fd, "%*s%swarning: unknown event %d\n", indent, "", prefix, event); - } else { - ALOGI("%*s%swarning: unknown event %d", indent, "", prefix, event); - } + body.appendFormat("warning: unknown event %d", event); break; } i += advance; + + if (!body.isEmpty()) { + dumpLine(timestamp, body); + deferredTimestamp = false; + } + } + if (deferredTimestamp) { + dumpLine(timestamp, body); } // FIXME it would be more efficient to put a char mCopy[256] as a member variable of the dumper delete[] copy; } +void NBLog::Reader::dumpLine(const String8& timestamp, String8& body) +{ + if (mFd >= 0) { + fdprintf(mFd, "%.*s%s %s\n", mIndent, "", timestamp.string(), body.string()); + } else { + ALOGI("%.*s%s %s", mIndent, "", timestamp.string(), body.string()); + } + body.clear(); +} + bool NBLog::Reader::isIMemory(const sp& iMemory) const { return iMemory != 0 && mIMemory != 0 && iMemory->pointer() == mIMemory->pointer(); -- cgit v1.1 From c02c96161dde9d6ca7b408cf08fcf10bd8e61a54 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Tue, 15 Oct 2013 09:25:11 -0700 Subject: Fix bug with not reporting lost bytes Change-Id: I431d989dbd115b43822e9e48fd4c2b8e6322cfe3 --- media/libnbaio/NBLog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'media/libnbaio/NBLog.cpp') diff --git a/media/libnbaio/NBLog.cpp b/media/libnbaio/NBLog.cpp index 895fd60..96738a7 100644 --- a/media/libnbaio/NBLog.cpp +++ b/media/libnbaio/NBLog.cpp @@ -341,8 +341,8 @@ void NBLog::Reader::dump(int fd, size_t indent) mFd = fd; mIndent = indent; String8 timestamp, body; - if (i > 0) { - lost += i; + lost += i; + if (lost > 0) { body.appendFormat("warning: lost %u bytes worth of events", lost); // TODO timestamp empty here, only other choice to wait for the first timestamp event in the // log to push it out. Consider keeping the timestamp/body between calls to readAt(). -- cgit v1.1