第29讲 优化camera latencyhistogram -凯发k8旗舰厅

本讲是android camera性能分析专题的第29讲,我们来优化camera latencyhistogram,包括如下内容:

  1. 直方图统计时添加平均值、最大值、最小值、camera id
  2. 为stream直方图添加size和name
资源 描述
在线课程
知识星球 星球名称:深入浅出android camera
星球id: 17296815
wechat 极客笔记圈

直方图统计时添加平均值、最大值、最小值、camera id

代码见视频讲解,运行结果如下:

直方图统计时添加平均值、最大值、最小值、camera id

为stream直方图添加size和name

代码见视频讲解,运行结果如下:

为stream直方图添加size和name

代码修改点

diff --git a/services/camera/libcameraservice/android.bp b/services/camera/libcameraservice/android.bp
index 981c569..dc02162 100644
--- a/services/camera/libcameraservice/android.bp
    b/services/camera/libcameraservice/android.bp
@@ -196,6  196,7 @@ cc_library_shared {
         "-wextra",
         "-werror",
         "-wno-ignored-qualifiers",
         "-ddeepinout",
     ],
 }
diff --git a/services/camera/libcameraservice/api2/cameradeviceclient.cpp b/services/camera/libcameraservice/api2/cameradeviceclient.cpp
index 5e91501..554e267 100644
--- a/services/camera/libcameraservice/api2/cameradeviceclient.cpp
    b/services/camera/libcameraservice/api2/cameradeviceclient.cpp
@@ -958,12  958,14 @@ binder::status cameradeviceclient::createstream(
                 static_cast(outputconfiguration.getrotation()),
                 &streamid, physicalcameraid, streaminfo.sensorpixelmodesused, &surfaceids,
                 outputconfiguration.getsurfacesetid(), isshared, ismultiresolution);
 
         if (err == ok) {
             mutex::autolock l(mcompositelock);
             mcompositestreammap.add(iinterface::asbinder(surfaces[0]->getigraphicbufferproducer()),
                     compositestream);
         }
     } else {
 
         err = mdevice->createstream(surfaces, deferredconsumer, streaminfo.width,
                 streaminfo.height, streaminfo.format, streaminfo.dataspace,
                 static_cast(outputconfiguration.getrotation()),
diff --git a/services/camera/libcameraservice/device3/camera3device.cpp b/services/camera/libcameraservice/device3/camera3device.cpp
index 7c2f34f..e4361ac 100644
--- a/services/camera/libcameraservice/device3/camera3device.cpp
    b/services/camera/libcameraservice/device3/camera3device.cpp
@@ -1139,6  1139,9 @@ status_t camera3device::createstream(const std::vector>& consumers,
                 ismultiresolution, dynamicrangeprofile, streamusecase, mdevicetimebaseisrealtime,
                 timestampbase, mirrormode);
     }
 #ifdef deepinout
         newstream->mlogicalcameraid = mid;
 #endif
     size_t consumercount = consumers.size();
     for (size_t i = 0; i < consumercount; i  ) {
diff --git a/services/camera/libcameraservice/device3/camera3outputstream.cpp b/services/camera/libcameraservice/device3/camera3outputstream.cpp
index 1e20ee0..204947c 100644
--- a/services/camera/libcameraservice/device3/camera3outputstream.cpp
    b/services/camera/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) {
@@ -1015,8  1042,25 @@ status_t camera3outputstream::disconnectlocked() {
     mstate = (mstate == state_in_reconfig) ? state_in_config
                                            : state_constructed;
-
 #ifndef deepinout
     mdequeuebufferlatency.log("stream %d dequeuebuffer latency histogram", mid);
 #else
     mdequeuebufferlatency.log("camid(l:p):(%s:%s) stream %d-%s-%dx%d dequeuebuffer latency histogram",
     mlogicalcameraid.string(),
     getphysicalcameraid().string(),
     mid,
     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/services/camera/libcameraservice/device3/camera3outputstream.h b/services/camera/libcameraservice/device3/camera3outputstream.h
index e8065ce..05831ec 100644
--- a/services/camera/libcameraservice/device3/camera3outputstream.h
    b/services/camera/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;
diff --git a/services/camera/libcameraservice/device3/camera3stream.h b/services/camera/libcameraservice/device3/camera3stream.h
index d429e6c..f7784bd 100644
--- a/services/camera/libcameraservice/device3/camera3stream.h
    b/services/camera/libcameraservice/device3/camera3stream.h
@@ -469,6  469,10 @@ class camera3stream :
     void firebufferrequestforframenumber(uint64_t framenumber,
             const camerametadata& settings) override;
 #ifdef deepinout
     string8 mlogicalcameraid;
 #endif
 
   protected:
     const int mid;
     /**
diff --git a/services/camera/libcameraservice/utils/latencyhistogram.cpp b/services/camera/libcameraservice/utils/latencyhistogram.cpp
index e2bdc43..a48ada7 100644
--- a/services/camera/libcameraservice/utils/latencyhistogram.cpp
    b/services/camera/libcameraservice/utils/latencyhistogram.cpp
@@ -27,7  27,14 @@ cameralatencyhistogram::cameralatencyhistogram(int32_t binsizems, int32_t bincou
         mbinsizems(binsizems),
         mbincount(bincount),
         mbins(bincount),
 #ifndef deepinout
         mtotalcount(0) {
 #else
         mtotoalduration(0),
         mmaxduration(0),
         mminduration(0),
         mtotalcount(0) {
 #endif
 }
 void cameralatencyhistogram::add(nsecs_t start, nsecs_t end) {
@@ -43,6  50,15 @@ void cameralatencyhistogram::add(nsecs_t start, nsecs_t end) {
     mbins[binindex]  ;
     mtotalcount  ;
 #ifdef deepinout
     mtotoalduration  = duration;
     if (mmaxduration == 0 || mmaxduration < duration) {
         mmaxduration = duration;
     }
     if (mminduration ==0 || mminduration > duration) {
         mminduration = duration;
     }
 #endif
 }
 void cameralatencyhistogram::reset() {
@@ -56,7  72,16 @@ void cameralatencyhistogram::dump(int fd, const char* name) const {
     }
     string8 lines;
 #ifndef deepinout
     lines.appendformat("%s (%" prid64 ") samples\n", name, mtotalcount);
 #else
     lines.appendformat("%s (%" prid64 ") samples , avg:max:min(%.2f ms:%.2f ms:%.2f):\n",
         name,
         mtotalcount,
         (float)(mtotoalduration / 1e6) / mtotalcount,
         (float)(mmaxduration / 1e6),
         (float)(mminduration / 1e6));
 #endif
     string8 linebins, linebincounts;
     formathistogramtext(linebins, linebincounts);
@@ -77,7  102,16 @@ void cameralatencyhistogram::log(const char* fmt, ...) {
     va_list args;
     va_start(args, fmt);
     string8 histogramname = string8::formatv(fmt, args);
 #ifndef deepinout
     alogi("%s (%" prid64 ") samples:", histogramname.string(), mtotalcount);
 #else
     alogi("%s (%" prid64 ") samples, avg:max:min(%.2f ms:%.2f ms:%.2f):",
     histogramname.string(),
     mtotalcount,
     (float)(mtotoalduration / 1e6) / mtotalcount,
     (float)(mmaxduration / 1e6),
     (float)(mminduration / 1e6));
 #endif
     va_end(args);
     string8 linebins, linebincounts;
diff --git a/services/camera/libcameraservice/utils/latencyhistogram.h b/services/camera/libcameraservice/utils/latencyhistogram.h
index bfd9b1b..d0dcbf7 100644
--- a/services/camera/libcameraservice/utils/latencyhistogram.h
    b/services/camera/libcameraservice/utils/latencyhistogram.h
@@ -38,6  38,11 @@ private:
     int32_t mbinsizems;
     int32_t mbincount;
     std::vector mbins;
 #ifdef deepinout
     nsecs_t mtotoalduration;
     nsecs_t mmaxduration;
     nsecs_t mminduration;
 #endif
     uint64_t mtotalcount;
     void formathistogramtext(string8& linebins, string8& linebincounts) const;

camera课程

python教程

java教程

web教程

数据库教程

图形图像教程

办公软件教程

linux教程

计算机教程

大数据教程

开发工具教程

android camera性能分析

网站地图