第31讲 添加stream fps统计图和trace -凯发k8手机登录

本讲是android camera性能分析专题的第31讲,我们介绍添加stream fps统计图和trace,包括如下内容:

  1. 添加stream fps histogram
  2. 添加stream fps trace
资源 描述
在线课程
知识星球 星球名称:深入浅出android camera
星球id: 17296815
wechat 极客笔记圈

添加stream fps histogram

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

添加stream buffer interval histogram

添加stream fps trace

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

添加stream fps trace

代码修改点

diff --git a/android13/libcameraservice/device3/camera3outputstream.cpp b/android13/libcameraservice/device3/camera3outputstream.cpp
index 204947c..d7ab76c 100644
--- a/android13/libcameraservice/device3/camera3outputstream.cpp
    b/android13/libcameraservice/device3/camera3outputstream.cpp
@@ -73,6  73,7 @@ camera3outputstream::camera3outputstream(int id,
         mdequeuebufferlatency(kdequeuelatencybinsize),
 #ifdef deepinout
         mqueuebufferintervalhistogram(kqueuebufferintervalbinsize),
         mstreamfpshistogram(kfpsbinsize),
 #endif
         mipctransport(transport) {
@@ -109,6  110,7 @@ camera3outputstream::camera3outputstream(int id,
         mdequeuebufferlatency(kdequeuelatencybinsize),
 #ifdef deepinout
         mqueuebufferintervalhistogram(kqueuebufferintervalbinsize),
         mstreamfpshistogram(kfpsbinsize),
 #endif
         mipctransport(transport) {
@@ -152,6  154,7 @@ camera3outputstream::camera3outputstream(int id,
         mdequeuebufferlatency(kdequeuelatencybinsize),
 #ifdef deepinout
         mqueuebufferintervalhistogram(kqueuebufferintervalbinsize),
         mstreamfpshistogram(kfpsbinsize),
 #endif
         mipctransport(transport) {
     // deferred consumer only support preview surface format now.
@@ -203,6  206,7 @@ camera3outputstream::camera3outputstream(int id, camera_stream_type_t type,
         mdequeuebufferlatency(kdequeuelatencybinsize),
 #ifdef deepinout
         mqueuebufferintervalhistogram(kqueuebufferintervalbinsize),
         mstreamfpshistogram(kfpsbinsize),
 #endif
         mipctransport(transport) {
@@ -334,6  338,23 @@ status_t camera3outputstream::returnbufferlocked(
         atrace_async_end(tracelog, mid);
     }
     mlastqueuebuffertime = currentqueuebuffertime;
 
     // add for stream fps
     if (mlastsectimestamp == 0) {
         mlastsectimestamp = timestamp;
         mlastframecount = mframecount;
     }
     if ((timestamp - mlastsectimestamp) >= 1000 * 1000000) {
         int32_t curframecount = (int32_t) (mframecount - mlastframecount);
         nsecs_t timestampinterval = timestamp - mlastsectimestamp;
         char fpstracetag[48];
         snprintf(fpstracetag, sizeof(fpstracetag), "stream %d: fps\n", mid);
         float streamfps = 1000 / ((timestampinterval / 1000000) / curframecount);
         atrace_int(fpstracetag, (int32_t)streamfps);
         mlastsectimestamp = timestamp;
         mlastframecount = mframecount;
         mstreamfpshistogram.addfps(streamfps);
     }
 #endif
     return ok;
@@ -547,6  568,8 @@ void camera3outputstream::dump(int fd, const vector &args) const {
 #ifdef deepinout
     mqueuebufferintervalhistogram.dump(fd,
         "      queuebufferinterval histogram:");
     mstreamfpshistogram.dump(fd,
         "      stream fps histogram:");
 #endif
 }
@@ -1060,6  1083,15 @@ status_t camera3outputstream::disconnectlocked() {
     camera_stream::width,
     camera_stream::height);
     mqueuebufferintervalhistogram.reset();
 
     mstreamfpshistogram.logfps("camid(l:p):(%s:%s) stream %d-%s-%dx%d fps histogram",
     mlogicalcameraid.string(),
     getphysicalcameraid().string(),
     mid,
     mconsumername.string(),
     camera_stream::width,
     camera_stream::height);
     mstreamfpshistogram.reset();
 #endif
     mdequeuebufferlatency.reset();
     return ok;
diff --git a/android13/libcameraservice/device3/camera3outputstream.h b/android13/libcameraservice/device3/camera3outputstream.h
index 05831ec..65d8292 100644
--- a/android13/libcameraservice/device3/camera3outputstream.h
    b/android13/libcameraservice/device3/camera3outputstream.h
@@ -412,6  412,12 @@ class camera3outputstream :
     nsecs_t mlastqueuebuffertime = 0;
     static const int32_t kqueuebufferintervalbinsize = 35; // in ms
     cameralatencyhistogram mqueuebufferintervalhistogram;
 
     // add for stream fps
     nsecs_t mlastsectimestamp = 0;
     uint32_t mlastframecount;
     static const int32_t kfpsbinsize = 5; // in fps
     cameralatencyhistogram mstreamfpshistogram;
 #endif
     ipctransport mipctransport = ipctransport::invalid;
diff --git a/android13/libcameraservice/utils/latencyhistogram.cpp b/android13/libcameraservice/utils/latencyhistogram.cpp
index a48ada7..f289ce6 100644
--- a/android13/libcameraservice/utils/latencyhistogram.cpp
    b/android13/libcameraservice/utils/latencyhistogram.cpp
@@ -137,4  137,53 @@ void cameralatencyhistogram::formathistogramtext(
     linebincounts.append(" (%)");
 }
 #ifdef deepinout
 void cameralatencyhistogram::addfps(float fps) {
     int32_t binindex = floor(fps / mbinsizems) - 1;
 
     if (binindex < 0) {
         binindex = 0;
     } else if (binindex >= mbincount) {
         binindex = mbincount-1;
     }
 
     mbins[binindex]  ;
     mtotalcount  ;
 #ifdef deepinout
     mtotalfps  = fps;
     if (mmaxfps == 0 || mmaxfps < fps) {
         mmaxfps = fps;
     }
     if (mminfps ==0 || mminfps > fps) {
         mminfps = fps;
     }
 #endif
 }
 
 void cameralatencyhistogram::logfps(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:max:min(%.2f fps:%.2f fps:%.2f fps):",
     histogramname.string(),
     mtotalcount,
     mtotalfps / mtotalcount,
     mmaxfps,
     mminfps);
 
     va_end(args);
 
     string8 linebins, linebincounts;
     formathistogramtext(linebins, linebincounts);
 
     alogi("%s", linebins.c_str());
     alogi("%s", linebincounts.c_str());
 }
 #endif
 
 }; //namespace android
diff --git a/android13/libcameraservice/utils/latencyhistogram.h b/android13/libcameraservice/utils/latencyhistogram.h
index d0dcbf7..9ae7706 100644
--- a/android13/libcameraservice/utils/latencyhistogram.h
    b/android13/libcameraservice/utils/latencyhistogram.h
@@ -21,6  21,9 @@
 #include 
 #include 
 #ifdef deepinout
 #include 
 #endif
 namespace android {
@@ -34,6  37,10 @@ public:
     void dump(int fd, const char* name) const;
     void log(const char* format, ...);
 #ifdef deepinout
     void addfps(float fps);
     void logfps(const char* format, ...);
 #endif
 private:
     int32_t mbinsizems;
     int32_t mbincount;
@@ -42,6  49,9 @@ private:
     nsecs_t mtotoalduration;
     nsecs_t mmaxduration;
     nsecs_t mminduration;
     float mtotalfps;
     float mmaxfps;
     float mminfps;
 #endif
     uint64_t mtotalcount;

camera课程

python教程

java教程

web教程

数据库教程

图形图像教程

办公软件教程

linux教程

计算机教程

大数据教程

开发工具教程

android camera性能分析

网站地图