SF: Add continuous transaction tracing
Add the ability to capture all incoming transactions into a ring
buffer. Capture transactions as the come in through the binder
thread. On the main thread push committed transactions to the
tracing thread which will then add to the buffer and purge
older entries as the buffer gets filled.
Also introduce a new flag to enable transaction tracing (disabled
by default).
Test: presubmit
Bug: 200284593
Change-Id: I90dd0fa4f89f68cfc7b7922ecd0bba4adab8d7a4
diff --git a/services/surfaceflinger/Tracing/RingBuffer.h b/services/surfaceflinger/Tracing/RingBuffer.h
index d0fb3f2..63a2786 100644
--- a/services/surfaceflinger/Tracing/RingBuffer.h
+++ b/services/surfaceflinger/Tracing/RingBuffer.h
@@ -21,8 +21,9 @@
#include <log/log.h>
#include <utils/Errors.h>
-#include <utils/SystemClock.h>
+#include <utils/Timers.h>
#include <utils/Trace.h>
+#include <chrono>
#include <queue>
namespace android {
@@ -57,9 +58,7 @@
status_t writeToFile(FileProto& fileProto, std::string filename) {
ATRACE_CALL();
std::string output;
- flush(fileProto);
- reset(mSizeInBytes);
- if (!fileProto.SerializeToString(&output)) {
+ if (!writeToString(fileProto, &output)) {
ALOGE("Could not serialize proto.");
return UNKNOWN_ERROR;
}
@@ -73,6 +72,13 @@
return NO_ERROR;
}
+ bool writeToString(FileProto& fileProto, std::string* outString) {
+ ATRACE_CALL();
+ flush(fileProto);
+ reset(mSizeInBytes);
+ return fileProto.SerializeToString(outString);
+ }
+
std::vector<EntryProto> emplace(EntryProto&& proto) {
std::vector<EntryProto> replacedEntries;
size_t protoSize = static_cast<size_t>(proto.ByteSize());
@@ -99,8 +105,8 @@
const int64_t durationCount = duration.count();
base::StringAppendF(&result,
" number of entries: %zu (%.2fMB / %.2fMB) duration: %" PRIi64 "ms\n",
- frameCount(), float(used()) / 1024.f * 1024.f,
- float(size()) / 1024.f * 1024.f, durationCount);
+ frameCount(), float(used()) / (1024.f * 1024.f),
+ float(size()) / (1024.f * 1024.f), durationCount);
}
private: