2024年10月30日 第26讲 DequeueBuffer Latency 极客笔记
本讲是Android Camera性能分析专题的第26讲,我们介绍DequeueBuffer Latency,包括如下内容:
资源 | 描述 |
---|---|
在线课程 | 极客笔记在线课程 |
知识星球 | 星球名称:深入浅出Android Camera 星球ID: 17296815 |
极客笔记圈 |
DequeueBuffer Latency 用于衡量/记录从BufferQueue里面获取Buffer的耗时。
影响:
每一个Camera3OutputStream都会统计DequeueBuffer Latency。
DequeueBuffer:
DequeueBuffer Latency直方图配置
static const int32_t kDequeueLatencyBinSize = 5; // in ms
添加Sample的时机
nsecs_t dequeueStart = systemTime(SYSTEM_TIME_MONOTONIC);
size_t batchSize = mBatchSize.load();
if (batchSize == 1) {
sp anw = consumer;
res = anw->dequeueBuffer(anw.get(), anb, fenceFd);
} else {
std::unique_lock batchLock(mBatchLock);
res = OK;
if (mBatchedBuffers.size() == 0) {
if (remainingBuffers == 0) {
ALOGE("%s: cannot get buffer while all buffers are handed out", __FUNCTION__);
return INVALID_OPERATION;
}
if (batchSize > remainingBuffers) {
batchSize = remainingBuffers;
}
batchLock.unlock();
// Refill batched buffers
std::vector batchedBuffers;
batchedBuffers.resize(batchSize);
res = consumer->dequeueBuffers(&batchedBuffers);
batchLock.lock();
if (res != OK) {
ALOGE("%s: batch dequeueBuffers call failed! %s (%d)",
__FUNCTION__, strerror(-res), res);
} else {
mBatchedBuffers = std::move(batchedBuffers);
}
}
if (res == OK) {
// Dispatch batch buffers
*anb = mBatchedBuffers.back().buffer;
*fenceFd = mBatchedBuffers.back().fenceFd;
mBatchedBuffers.pop_back();
}
}
nsecs_t dequeueEnd = systemTime(SYSTEM_TIME_MONOTONIC);
mDequeueBufferLatency.add(dequeueStart, dequeueEnd);
本文链接:http://so.lmcjl.com/news/16551/