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

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

  1. Request Latency是什么
  2. Request Latency配置
  3. Request Latency实战
资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出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(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());
}

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程

Android Camera性能分析