第27讲 Request Latency - Android Camera性能分析

本讲是Android Camera性能分析专题的第27讲,我们介绍CameraServer Request Latency,包括如下内容:

  1. Request Latency是什么
  2. Request Latency配置
  3. Request Latency实战

视频在线观看:

加入知识星球与更多Camera同学交流
– 星球名称:深入浅出Android Camera
– 星球ID: 17296815
– Wechat: 极客笔记圈

Request Latency是什么

Request Latency用于衡量HAL执行processBatchCaptureRequests的耗时。

影响:

  • 如果该耗时太长,会拉低CaptureRequest的帧率,需要从HAL角度分析

Request Latency配置

Request Latency直方图配置

  • 分成10份(默认值), 间隔为40ms

  • static const int32_t kRequestLatencyBinSize = 40; // in ms

添加Sample的时机

  • 在每次调用HAL的processCaptureRequest接口时,会统计其耗时,然后作为一个Sample添加到CameraLatencyHistogram

Request Latency配置

Request Latency实战

  • 代码讲解
nsecs_t tRequestStart = systemTime(SYSTEM_TIME_MONOTONIC);
submitRequestSuccess = sendRequestsBatch();

nsecs_t tRequestEnd = systemTime(SYSTEM_TIME_MONOTONIC);
mRequestLatency.add(tRequestStart, tRequestEnd);
  • 实战演示:在CameraLatencyHistogram增加Samples总的平均耗时
void CameraLatencyHistogram::add(nsecs_t start, nsecs_t end) {
    nsecs_t duration = end - start;
    int32_t durationMs = static_cast<int32_t>(duration / 1000000LL);
    int32_t binIndex = durationMs / mBinSizeMs;

    if (binIndex < 0) {
        binIndex = 0;
    } else if (binIndex >= mBinCount) {
        binIndex = mBinCount-1;
    }

    mBins[binIndex]++;
    mTotalCount++;
    mTotoalDuration += duration;
}

打印Log时:

void CameraLatencyHistogram::log(const char* fmt, ...) {
    if (mTotalCount == 0) {
        return;
    }

    va_list args;
    va_start(args, fmt);
    String8 histogramName = String8::formatV(fmt, args);
    ALOGI("%s (%" PRId64 ") samples, avg(%.2f ms):", histogramName.string(), mTotalCount, (float)(mTotoalDuration/1e6) / mTotalCount);
    va_end(args);

    String8 lineBins, lineBinCounts;
    formatHistogramText(lineBins, lineBinCounts);

    ALOGI("%s", lineBins.c_str());
    ALOGI("%s", lineBinCounts.c_str());
}

赞(1)
未经允许不得转载:极客笔记 » 第27讲 Request Latency

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址