本讲是Android Camera性能分析专题的第30讲,我们介绍统计每路stream的buffer时间间隔耗时,包括如下内容:
- 添加Stream Buffer Interval Histogram
- 添加Stream Buffer Interval Trace
资源 | 描述 |
---|---|
在线课程 | 极客笔记在线课程 |
知识星球 | 星球名称:深入浅出Android Camera 星球ID: 17296815 |
极客笔记圈 |
添加Stream Buffer Interval Histogram
代码见视频讲解,运行效果如下:
添加Stream Buffer Interval Trace
代码见视频讲解,运行效果如下:
代码修改点
diff --git a/Android13/libcameraservice/device3/Camera3OutputStream.cpp b/Android13/libcameraservice/device3/Camera3OutputStream.cpp
index 9ce1a7e..204947c 100644
--- a/Android13/libcameraservice/device3/Camera3OutputStream.cpp
+++ b/Android13/libcameraservice/device3/Camera3OutputStream.cpp
@@ -71,6 +71,9 @@ Camera3OutputStream::Camera3OutputStream(int id,
mDropBuffers(false),
mMirrorMode(mirrorMode),
mDequeueBufferLatency(kDequeueLatencyBinSize),
+#ifdef Deepinout
+ mQueueBufferIntervalHistogram(kQueueBufferIntervalBinSize),
+#endif
mIPCTransport(transport) {
if (mConsumer == NULL) {
@@ -104,6 +107,9 @@ Camera3OutputStream::Camera3OutputStream(int id,
mDropBuffers(false),
mMirrorMode(mirrorMode),
mDequeueBufferLatency(kDequeueLatencyBinSize),
+#ifdef Deepinout
+ mQueueBufferIntervalHistogram(kQueueBufferIntervalBinSize),
+#endif
mIPCTransport(transport) {
if (format != HAL_PIXEL_FORMAT_BLOB && format != HAL_PIXEL_FORMAT_RAW_OPAQUE) {
@@ -144,6 +150,9 @@ Camera3OutputStream::Camera3OutputStream(int id,
mDropBuffers(false),
mMirrorMode(mirrorMode),
mDequeueBufferLatency(kDequeueLatencyBinSize),
+#ifdef Deepinout
+ mQueueBufferIntervalHistogram(kQueueBufferIntervalBinSize),
+#endif
mIPCTransport(transport) {
// Deferred consumer only support preview surface format now.
if (format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
@@ -192,6 +201,9 @@ Camera3OutputStream::Camera3OutputStream(int id, camera_stream_type_t type,
mDropBuffers(false),
mMirrorMode(mirrorMode),
mDequeueBufferLatency(kDequeueLatencyBinSize),
+#ifdef Deepinout
+ mQueueBufferIntervalHistogram(kQueueBufferIntervalBinSize),
+#endif
mIPCTransport(transport) {
bool needsReleaseNotify = setId > CAMERA3_STREAM_SET_ID_INVALID;
@@ -312,6 +324,17 @@ status_t Camera3OutputStream::returnBufferLocked(
mLastTimestamp = timestamp;
mFrameCount++;
+#ifdef Deepinout
+ nsecs_t currentQueueBufferTime = systemTime(SYSTEM_TIME_MONOTONIC);
+ if (mLastQueueBufferTime > 0) {
+ mQueueBufferIntervalHistogram.add(mLastQueueBufferTime, currentQueueBufferTime);
+ char traceLog[48];
+ snprintf(traceLog, sizeof(traceLog), "queueBufferInterval-%d", mId);
+ ATRACE_ASYNC_BEGIN(traceLog, mId);
+ ATRACE_ASYNC_END(traceLog, mId);
+ }
+ mLastQueueBufferTime = currentQueueBufferTime;
+#endif
return OK;
}
@@ -521,6 +544,10 @@ void Camera3OutputStream::dump(int fd, const Vector &args) const {
mDequeueBufferLatency.dump(fd,
" DequeueBuffer latency histogram:");
+#ifdef Deepinout
+ mQueueBufferIntervalHistogram.dump(fd,
+ " QueueBufferInterval histogram:");
+#endif
}
status_t Camera3OutputStream::setTransform(int transform, bool mayChangeMirror) {
@@ -1025,6 +1052,14 @@ status_t Camera3OutputStream::disconnectLocked() {
mConsumerName.string(),
camera_stream::width,
camera_stream::height);
+ mQueueBufferIntervalHistogram.log("CamId(L:P):(%s:%s) Stream %d-%s-%dx%d queueBuffer interval histogram",
+ mLogicalCameraId.string(),
+ getPhysicalCameraId().string(),
+ mId,
+ mConsumerName.string(),
+ camera_stream::width,
+ camera_stream::height);
+ mQueueBufferIntervalHistogram.reset();
#endif
mDequeueBufferLatency.reset();
return OK;
diff --git a/Android13/libcameraservice/device3/Camera3OutputStream.h b/Android13/libcameraservice/device3/Camera3OutputStream.h
index e8065ce..05831ec 100644
--- a/Android13/libcameraservice/device3/Camera3OutputStream.h
+++ b/Android13/libcameraservice/device3/Camera3OutputStream.h
@@ -408,6 +408,11 @@ class Camera3OutputStream :
static const int32_t kDequeueLatencyBinSize = 5; // in ms
CameraLatencyHistogram mDequeueBufferLatency;
+#ifdef Deepinout
+ nsecs_t mLastQueueBufferTime = 0;
+ static const int32_t kQueueBufferIntervalBinSize = 35; // in ms
+ CameraLatencyHistogram mQueueBufferIntervalHistogram;
+#endif
IPCTransport mIPCTransport = IPCTransport::INVALID;
int mImageDumpMask = 0;