源码分析 | 使用 gcov 和 lcov 测试 PostgreSQL 代码覆盖率

Logisim新手避坑指南:从2选1到8选1,手把手教你搞定头歌实训的多路选择器作业 本文为Logisim新手提供从2选1到8选1多路选择器的详细设计指南,特别针对头歌实训平台的作业要求。内容涵盖基础搭建、级联技巧、架构优化及实战应用,帮助读者避开常见错误,掌握数字逻辑设计的核心要点。 阅读详情

本文首发于 2016-03-30 15:34:34

引言

通常我们评判一个 test case 好坏的标准之一是代码的覆盖率,一个好的 test case 应该覆盖到所有的代码。

那么问题来了,我们怎么知道这个 test case 有没有覆盖到所有的代码呢?

以 PostgreSQL 为例,我们看看如何检测 C 语言程序的代码覆盖率。

C 代码覆盖率测试,需要用到 gcc 的配套工具gcov,还有一个可视化工具lcov。

1. 安装依赖

首先需要安装依赖 gcov 和 lcov 。

gcov 在 gcc 包中已经包含了,lcov 是 ltp 的一个 gcov 扩展插件,用来产生HTML报告。

sudo apt install lcov

2. 编译、安装 PG

2.1. 编译选项介绍

首先介绍一下 PostgreSQL 的编译选项 --enable-coverage:

--enable-coverage       build with coverage testing instrumentation

这个编译项对应gcc的两个参数:-fprofile-arcs 和 -ftest-coverage。

# enable code coverage if --enable-coverage
if test "$enable_coverage" = yes; then
  if test "$GCC" = yes; then
    CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
  else
    as_fn_error $? "--enable-coverage is supported only when using GCC" "$LINENO" 5
  fi
fi

通过man gcc查看这两个参数的含义:

-fprofile-arcs
           Add code so that program flow arcs are instrumented.  During execution the program records how many times each branch and call is executed and how many times it is taken or returns.  When
           the compiled program exits it saves this data to a file called auxname.gcda for each source file.  The data may be used for profile-directed optimizations (-fbranch-probabilities), or for
           test coverage analysis (-ftest-coverage).  Each object file's auxname is generated from the name of the output file, if explicitly specified and it is not the final executable, otherwise
           it is the basename of the source file.  In both cases any suffix is removed (e.g. foo.gcda for input file dir/foo.c, or dir/foo.gcda for output file specified as -o dir/foo.o).

--coverage
           This option is used to compile and link code instrumented for coverage analysis.  The option is a synonym for -fprofile-arcs -ftest-coverage (when compiling) and -lgcov (when linking).
           See the documentation for those options for more details.

           *   Compile the source files with -fprofile-arcs plus optimization and code generation options.  For test coverage analysis, use the additional -ftest-coverage option.  You do not need to
               profile every source file in a program.

           *   Link your object files with -lgcov or -fprofile-arcs (the latter implies the former).

           *   Run the program on a representative workload to generate the arc profile information.  This may be repeated any number of times.  You can run concurrent instances of your program, and
               provided that the file system supports locking, the data files will be correctly updated.  Also "fork" calls are detected and correctly handled (double counting will not happen).

           *   For profile-directed optimizations, compile the source files again with the same optimization and code generation options plus -fbranch-probabilities.

           *   For test coverage analysis, use gcov to produce human readable information from the .gcno and .gcda files.  Refer to the gcov documentation for further information.

           With -fprofile-arcs, for each function of your program GCC creates a program flow graph, then finds a spanning tree for the graph.  Only arcs that are not on the spanning tree have to be
           instrumented: the compiler adds code to count the number of times that these arcs are executed.  When an arc is the only exit or only entrance to a block, the instrumentation code can be
           added to the block; otherwise, a new basic block must be created to hold the instrumentation code.

-ftest-coverage
           Produce a notes file that the gcov code-coverage utility can use to show program coverage.  Each source file's note file is called auxname.gcno.  Refer to the -fprofile-arcs option above
           for a description of auxname and instructions on how to generate test coverage data.  Coverage data matches the source files more closely if you do not optimize.

-fprofile-arcs:

-fprofile-arcs 用于产生 .c 文件对应的 .gcda 文件,.gcda 文件可以被用于 profile 驱动的优化,或者结合 gcov 来做代码覆盖分析。

编译时尽量不要使用 -O 优化,这样代码覆盖数据 .gcda 才能尽可能和代码接近。

当代码被调用时,.gcda 文件中对应的计数器会被修改,记录代码被调用的次数。

-ftest-coverage:

-ftest-coverage 这个选项用于产生 .c 文件的 .gcno 文件。这个文件生成后不会被修改。结合 .gcda,可以分析测试代码覆盖率。

2.2. 编译安装

./configure --prefix=/opt/pgsql9.4.4 --with-pgport=1921 --with-perl --with-python --with-tcl --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety --enable-debug --enable-dtrace --enable-coverage

gmake world && gmake install-world

安装好后,我们会发现在源码目录中多了一些.gcda和.gcno的文件,每个.c文件都会对应这两个文件:

postgres@wslu-> ll
total 1.3M
-rw-r--r-- 1 postgres postgres  22K Jun 10 03:29 gistbuildbuffers.c
-rw------- 1 postgres postgres 1.6K Sep  7 14:42 gistbuildbuffers.gcda
-rw-r--r-- 1 postgres postgres  15K Sep  7 14:38 gistbuildbuffers.gcno
-rw-r--r-- 1 postgres postgres  70K Sep  7 14:38 gistbuildbuffers.o
-rw-r--r-- 1 postgres postgres  37K Jun 10 03:29 gistbuild.c
-rw------- 1 postgres postgres 2.2K Sep  7 14:42 gistbuild.gcda
-rw-r--r-- 1 postgres postgres  20K Sep  7 14:38 gistbuild.gcno
-rw-r--r-- 1 postgres postgres  92K Sep  7 14:38 gistbuild.o
-rw-r--r-- 1 postgres postgres  43K Jun 10 03:29 gist.c
-rw------- 1 postgres postgres 3.1K Sep  7 14:42 gist.gcda
-rw-r--r-- 1 postgres postgres  29K Sep  7 14:38 gist.gcno
-rw-r--r-- 1 postgres postgres  16K Jun 10 03:29 gistget.c
-rw------- 1 postgres postgres 1.3K Sep  7 14:42 gistget.gcda
-rw-r--r-- 1 postgres postgres  13K Sep  7 14:38 gistget.gcno
-rw-r--r-- 1 postgres postgres  74K Sep  7 14:38 gistget.o
-rw-r--r-- 1 postgres postgres 101K Sep  7 14:38 gist.o
-rw-r--r-- 1 postgres postgres  39K Jun 10 03:29 gistproc.c
-rw------- 1 postgres postgres 3.1K Sep  7 14:42 gistproc.gcda
-rw-r--r-- 1 postgres postgres  31K Sep  7 14:38 gistproc.gcno
-rw-r--r-- 1 postgres postgres  79K Sep  7 14:38 gistproc.o
-rw-r--r-- 1 postgres postgres 9.1K Jun 10 03:29 gistscan.c
-rw------- 1 postgres postgres  848 Sep  7 14:42 gistscan.gcda
-rw-r--r-- 1 postgres postgres 6.7K Sep  7 14:38 gistscan.gcno
-rw-r--r-- 1 postgres postgres  60K Sep  7 14:38 gistscan.o
-rw-r--r-- 1 postgres postgres  24K Jun 10 03:29 gistsplit.c
-rw------- 1 postgres postgres 1.5K Sep  7 14:42 gistsplit.gcda
-rw-r--r-- 1 postgres postgres  15K Sep  7 14:38 gistsplit.gcno
-rw-r--r-- 1 postgres postgres  68K Sep  7 14:38 gistsplit.o
-rw-r--r-- 1 postgres postgres  21K Jun 10 03:29 gistutil.c
-rw------- 1 postgres postgres 2.2K Sep  7 14:42 gistutil.gcda
-rw-r--r-- 1 postgres postgres  20K Sep  7 14:38 gistutil.gcno
-rw-r--r-- 1 postgres postgres  84K Sep  7 14:38 gistutil.o
-rw-r--r-- 1 postgres postgres 7.1K Jun 10 03:29 gistvacuum.c
-rw------- 1 postgres postgres  784 Sep  7 14:42 gistvacuum.gcda
-rw-r--r-- 1 postgres postgres 7.3K Sep  7 14:38 gistvacuum.gcno
-rw-r--r-- 1 postgres postgres  56K Sep  7 14:38 gistvacuum.o
-rw-r--r-- 1 postgres postgres  14K Jun 10 03:29 gistxlog.c
-rw------- 1 postgres postgres 1.2K Sep  7 14:42 gistxlog.gcda
-rw-r--r-- 1 postgres postgres  12K Sep  7 14:38 gistxlog.gcno
-rw-r--r-- 1 postgres postgres  50K Sep  7 14:38 gistxlog.o
-rw-r--r-- 1 postgres postgres  538 Jun 10 03:29 Makefile
-rw-r--r-- 1 postgres postgres  357 Sep  7 14:38 objfiles.txt
-rw-r--r-- 1 postgres postgres  20K Jun 10 03:29 README

postgres@wslu-> pwd
/opt/soft_bak/postgresql-9.4.4/src/backend/access/gist

注意事项:

源码文件目录的权限需要改为数据库启动用户的权限,否则无法修改 .gcda 的值,也就无法获取代码被调用的次数了。

root@wslu-> chown -R postgres:postgres /opt/soft_bak/postgresql-9.4.4

接下来我们看看文件的变化,以 dbsize.c 中的两个获取 pg_database_size 的 C 函数为例:

postgres@wslu-> ls -la|grep dbsize
-rw-r--r--  1 postgres postgres  19342 Jun 10 03:29 dbsize.c
-rw-------  1 postgres postgres   2664 Sep  7 15:01 dbsize.gcda
-rw-r--r--  1 postgres postgres  23272 Sep  7 14:38 dbsize.gcno
-rw-r--r--  1 postgres postgres  89624 Sep  7 14:38 dbsize.o

调用一次:

postgres@wslu-> psql
psql (9.4.4)
Type "help" for help.
postgres=# select pg_database_size(oid) from pg_database;
 pg_database_size 
------------------
          6898180
          6889988
         24742560
          6898180
          6898180
          6898180
(6 rows)
postgres=# \q

再次查看:

postgres@wslu-> ls -la|grep dbsize
-rw-r--r--  1 postgres postgres  19342 Jun 10 03:29 dbsize.c
-rw-------  1 postgres postgres   2664 Sep  7 15:12 dbsize.gcda
-rw-r--r--  1 postgres postgres  23272 Sep  7 14:38 dbsize.gcno
-rw-r--r--  1 postgres postgres  89624 Sep  7 14:38 dbsize.o

dbsize.gcda 文件的修改时间发送了变化,说明刚才我们调用pg_database_size(oid) 时,调用了 dbsize.c 中的代码。对应的行计数器会发生变化。

3. 生成 HTML 报告

$ mkdir html
$ cd html

$ lcov --directory /opt/soft_bak/postgresql-9.4.4 --capture --output-file ./app.info
# 如果你不需要所有的代码,修改以上目录即可,譬如只看 contrib 下面的代码覆盖率。

$ genhtml ./app.info 
postgres@wslu-> ll
total 3.7M
drwxrwxr-x 12 postgres postgres 4.0K Sep  7 15:02 access
-rw-rw-r--  1 postgres postgres  141 Sep  7 15:02 amber.png
-rw-rw-r--  1 postgres postgres 3.4M Sep  7 15:02 app.info
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 bootstrap
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 catalog
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 commands
-rw-rw-r--  1 postgres postgres  141 Sep  7 15:02 emerald.png
drwxrwxr-x  2 postgres postgres  12K Sep  7 15:02 executor
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 foreign
-rw-rw-r--  1 postgres postgres 9.7K Sep  7 15:02 gcov.css
-rw-rw-r--  1 postgres postgres  167 Sep  7 15:02 glass.png
-rw-rw-r--  1 postgres postgres  57K Sep  7 15:02 index.html
-rw-rw-r--  1 postgres postgres  57K Sep  7 15:02 index-sort-f.html
-rw-rw-r--  1 postgres postgres  57K Sep  7 15:02 index-sort-l.html
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 lib
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 libpq
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 main
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 nodes
drwxrwxr-x  3 postgres postgres 4.0K Sep  7 15:02 opt
drwxrwxr-x  7 postgres postgres 4.0K Sep  7 15:02 optimizer
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 parser
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 port
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 postmaster
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 regex
drwxrwxr-x  3 postgres postgres 4.0K Sep  7 15:02 replication
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 rewrite
-rw-rw-r--  1 postgres postgres  141 Sep  7 15:02 ruby.png
drwxrwxr-x  3 postgres postgres 4.0K Sep  7 15:02 snowball
-rw-rw-r--  1 postgres postgres  141 Sep  7 15:02 snow.png
drwxrwxr-x 10 postgres postgres 4.0K Sep  7 15:02 storage
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 tcop
drwxrwxr-x  2 postgres postgres 4.0K Sep  7 15:02 tsearch
-rw-rw-r--  1 postgres postgres  117 Sep  7 15:02 updown.png
drwxrwxr-x  3 postgres postgres 4.0K Sep  7 15:02 usr
drwxrwxr-x 14 postgres postgres 4.0K Sep  7 15:02 utils

4. 查看报告

浏览器中打开 index.html 即可查看。

后记

PostgreSQL 其实已经在 Makefile 提供了生成代码覆盖 HTML 的 target 。

[root@wslu postgresql-9.4.4]# make coverage-html

产生的html目录如下:

[root@wslu postgresql-9.4.4]# cd coverage
[root@wslu coverage]# ll
total 224
-rw-r--r--  1 root root   141 Sep  7 19:17 amber.png
-rw-r--r--  1 root root   141 Sep  7 19:17 emerald.png
-rw-r--r--  1 root root  9893 Sep  7 19:17 gcov.css
-rw-r--r--  1 root root   167 Sep  7 19:17 glass.png
-rw-r--r--  1 root root 58737 Sep  7 19:18 index.html
-rw-r--r--  1 root root 58730 Sep  7 19:18 index-sort-f.html
-rw-r--r--  1 root root 58730 Sep  7 19:18 index-sort-l.html
-rw-r--r--  1 root root   141 Sep  7 19:17 ruby.png
-rw-r--r--  1 root root   141 Sep  7 19:17 snow.png
drwxr-xr-x 11 root root  4096 Sep  7 19:18 src
-rw-r--r--  1 root root   117 Sep  7 19:17 updown.png
drwxr-xr-x  3 root root  4096 Sep  7 19:18 usr

每次对代码改动后,执行完 make check 或其他回归测试手段后,就可以执行 make coverage-html 了。

参考链接

  1. Magus Test Archive
  2. lcov
  3. lcov readme
  4. GitHub - linux-test-project/ltp: Linux Test Project http://linux-test-project.github.io/
  5. Gcov (Using the GNU Compiler Collection (GCC))
  6. CodeCoverage - PostgreSQL wiki
  7. PostgreSQL: Documentation: devel: 33.5. Test Coverage Examination

欢迎关注我的微信公众号【数据库内核】:分享主流开源数据库和存储引擎相关技术。

标题网址
GitHubhttps://dbkernel.github.io
知乎https://www.zhihu.com/people/…
思否(SegmentFault)https://segmentfault.com/u/db…
掘金https://juejin.im/user/5e9d3e…
开源中国(oschina)https://my.oschina.net/dbkernel
博客园(cnblogs)https://www.cnblogs.com/dbkernel
C++智能物流调度系统:从单元测试到性能优化的全链路工程实践 在软件工程领域,性能优化与系统稳定性是衡量工业级软件成熟度的关键指标。其核心原理在于通过系统性的测试与调优,确保软件在高并发、高负载场景下仍能保持高效、可靠的运行。这对于处理海量实时数据的系统,如智能调度、推荐引擎等,具有极高的技术价值。在实际应用中,开发者常面临内存泄漏、锁竞争、算法效率等挑战。本文以智能物流调度系统为具体场景,深入探讨了如何运用分层测试策略、性能压测工具(如Apache JMeter)、内存分析技术(如tcmalloc/pprof)以及算法优化等手段,系统性地解决这些问题,实现系统从“能 阅读详情

相关推荐

HFSS微带贴片天线设计:从仿真到工程化流程的实战指南

天线设计是射频与微波工程领域的核心技术,其本质在于通过特定结构控制电磁场的谐振与辐射。理解电磁场原理是设计的基础,而仿真软件如HFSS则是将物理概念转化为精确数学模型并进行求解的关键工具。在工程实践中,仿真不仅是验证设计的手段,更是实现性能优化和问题排查的核心环节。通过建立参数化模型、设置正确的边界条件和激励端口,工程师可以系统性地分析S参数、辐射方向图等关键指标,从而优化天线性能。这种工程化设计流程对于微带贴片天线、阵列天线乃至更复杂的滤波器等无源器件开发都具有重要价值,能够显著提升设计效率和可靠性,帮助

weixin_34038293的博客 399

想让你的接口自动化测试更加有效? 这个统计方法必须掌握

接口自动化测试是现代软件开发中不可或缺的一环,它能够帮助开发团队自动化执行测试用例,以快速而准确地发现并修复软件缺陷。而覆盖率统计则是在测试执行完成后,帮助测试团队了解哪些代码路径被覆盖了,哪些未被覆盖的技术手段,下面我将介绍一下接口自动化测试覆盖率的统计方法。

HSS919的博客 1058

C++高性能微服务架构:高并发设计与异步优化实战指南

微服务架构通过将复杂系统拆分为独立、可独立部署的服务,提升了系统的可维护性和可扩展性。其核心原理在于服务间的松耦合与通信,通常采用RPC或消息队列等技术实现。这种架构的技术价值在于能够支撑高并发、低延迟的业务场景,例如金融交易、实时游戏和物联网平台。在追求极致性能的应用中,对硬件资源的精准掌控和零开销抽象变得至关重要。C++语言凭借其手动内存管理、编译期优化和直接操作系统底层API的能力,成为构建这类高性能微服务的理想选择。本文聚焦于利用现代C++(C++17/20)实现高并发微服务,深入探讨进程间通信(I

weixin_34195142的博客 340

PostgreSQL C代码覆盖率测试(gcov, lcov)

通常我们评判一个test case好坏的标准之一是代码的覆盖率,一个好的test case应该覆盖到所有的代码。 那么问题来了,我们怎么知道这个test case有没有覆盖到所有的代码呢? 以C代码为例,我们看看如何检测代码覆盖率。其他语言自然有其他语言的代码覆盖测试工具,例如plpgsql: http://blog.163.com/digoal@126/blog/static/

postgrechina的博客 944

PostgreSQL的学习心得和知识总结(三十四)|PostgreSQL数据库中的代码覆盖工具(gcov、lcov)的使用及代码覆盖率测试(coverage)

目录结构 注:提前言明 本文借鉴了以下博主、书籍或网站的内容,其列表如下: 1、参考书籍:《PostgreSQL数据库内核分析》 2、参考书籍:《数据库事务处理的艺术:事务管理与并发控制》 3、PostgreSQL数据库仓库链接,点击前往 4、参考书籍:《PostgreSQL中文手册》 5、gcov代码覆盖率测试-原理和实践总结,点击前往 6、LCOV - the LTP GCOV extension 官方文档,点击前往 1、本文内容全部来源于开源社区 GitHub和以上博主的贡献,本文也免费开源(.

孤傲小二~阿沐的博客 2360

lcov版本1.9代码覆盖率工具的安装与应用

本文还有配套的精品资源,点击获取 简介:lcov是一个专注于C/C++程序代码覆盖率的开源工具,其最新版本为1.9。它通过编译时的GCC覆盖率选项生成的信息文件,帮助开发者评估测试套件对源代码的覆盖程度。工具包括geninfo核心组件用于生成覆盖率数据和lcov用于生成可视化的HTML报告。这个压缩包包含了所有必需的文件和目录结构,支持在Linux/Unix系统上通过标准安...

weixin_31800911的博客 1801

PostgreSQL 10.1 手册_部分 III. 服务器管理_第 32 章 回归测试_32.5. 测试覆盖检查

32.5.测试覆盖检查 PostgreSQL 源代码可以使用覆盖测试指令编译,因此可以检查哪些部分的代码被回归测试或任何其他测试套件所覆盖。当前使用 GCC 编译时支持该特性,并且需要gcov和lcov程序。 一个典型的工作流程看起来是: ./configure --enable-coverage ... OTHER OPTIONS ... mak...

weixin_34358092的博客 128

lcov的源代码,可以生称html文件

lcov,可以将gcov生成的测试结果转换为html

数据库PostrageSQL-测试覆盖检查

33.5. 测试覆盖检查 PostgreSQL 源代码可以使用覆盖测试指令编译,因此可以检查哪些部分的代码被回归测试或任何其他测试套件所覆盖。当前使用 GCC 编译时支持该特性,并且需要gcov和lcov程序。一个典型的工作流程看起来是: ./configure --enable-coverage ... OTHER OPTIONS ... make make check # 或其他测试套件 make coverage-html 然后将你的 HTML 浏览器指向coverage/index.html。ma

逍遥云恋 698

lcov-1.10.tar.gz

lcov,配合gcov可以进行图形化的代码覆盖率查看

Linux之SUSE系统SAP-HANA经常系统内存不足使得SAP应用不能使用解决方案

问题描述 Linux内存使用量超过阈值,使得sap应用程序无可用内存,最终导致程序崩溃。 问题原因 自己查阅了一些资料,也基于zabbix的可用内存和实际不太一样入手去找原因发现问题出现于Cached的值过大,导致系统没有可以再分配的内存空间。Cached只要用来缓存文件的,经常读写的文件会被缓存到Cached中,可以增加读写效率,该功能是Linux系统内核提供的,而SAP-HANA的日志文件很大...

liuxiangyang_的博客 6712

构建智能CI/CD测试流水线:大模型驱动C++项目高效测试

持续集成与持续交付(CI/CD)是现代软件工程的核心实践,通过自动化构建、测试和部署流程,显著提升开发效率。其核心原理在于将代码变更快速集成到主干,并通过自动化测试保障质量。传统CI/CD流水线虽实现了自动化,但在面对大型项目时,往往因执行全量测试而效率低下,无法智能应对代码变更。结合大语言模型(LLM)的语义理解能力,可以构建智能测试流水线,实现测试集的动态选择与失败智能诊断。这项技术的价值在于将测试从成本中心转变为驱动效率的质量引擎,尤其适用于C++等系统级语言项目,这些项目通常编译时间长、测试环境复杂

chouxuyi9789的博客 458

5分钟搞定!用FunASR在本地快速部署达摩院Paraformer语音识别模型

本文提供了一份快速部署指南,教你如何在5分钟内利用FunASR工具包在本地电脑上启动达摩院Paraformer语音识别模型。Paraformer作为一款非自回归端到端模型,以其推理速度快、识别精度高的特点,结合FunASR的一键式模型加载和统一API,让开发者能轻松构建本地语音识别系统,极大降低了前沿AI技术的应用门槛。

q9w8e7r6t5的博客 608

ProxySQL 测试流水线深度解析:从 TAP 单元测试到多平台 CI/CD 与第三方集成验证

ProxySQL 是一个面向 MySQL 与 PostgreSQL 的高性能代理(proxy),其代码质量保障依赖一套多层次、可自动化的测试基础设施。本文以仓库文档 [TEST-PIPELINE.md](https://link.gitcode.com/i/081c0cb99142be89a9ef23e070686220) 为骨架,结合真实源码与 CI 工作流,系统讲解 ProxySQL 的 TA

gitblog_00753的博客 458

Qt 6.5实战:用QMediaPlayer搞定RTSP监控流播放(附LAV Filters解码器避坑指南)

本文详细介绍了如何在Qt 6.5中使用QMediaPlayer实现低延迟RTSP监控流播放,并提供了LAV Filters解码器的配置避坑指南。通过优化缓冲策略和硬件加速设置,显著提升视频流的播放性能和稳定性,适用于工业视觉检测和安防监控等实时场景。

weixin_33712987的博客 402

硬件级Dalvik字节码粒度无痕HOOK及VMP取址码定位分析

2.通过硬件读写断点的输出信息 可知pc寄存器就是art解释器的取码地址 直接硬件执行断点在这个pc 即可直接trace所有的smali执行流 通杀所有机型系统。本文即将探讨的是 如何在硬件级别实现dalvik bytecode粒度的无痕拦截技术 并实现鼠标点击一键hook 指哪儿打哪儿 感受 button power 的强大魅力!4.由于硬件断点是同步的 断下后可随时硬件dump下这一瞬间的app内存映像 写入unicorn的内存模拟执行。解释器在解释执行前必会读取内存中的bytecode。

2503_90751789的博客 1086

如何为AgentTorch做贡献?开发者环境搭建与第一个PR完整指南

想为 **AgentTorch**——这个专为大规模群体模型(Large Population Models, LPM)打造的开源 Python 仿真框架——提交你的第一个 PR,却不知道从哪里下手?本文就是一份从零到合并的开发者环境搭建指南:你会在 10 分钟内配好虚拟环境,看懂项目结构,跑通全部单元测试,并按规范的 commit 格式推送代码、创建第一个 Pull Request。 [![A

gitblog_00509的博客 716

解锁RK1126与SC132GS摄像头适配密码:技术与代码全解析

本文详细介绍了瑞芯微RK1126芯片与SC132GS摄像头的适配方法。首先分析了RK1126的四核Cortex-A7处理器、Mali-T860 GPU等硬件特性,以及SC132GS的130万像素、全局快门等技术参数。重点阐述了基于MIPI CSI接口的硬件连接原理和基于V4L2框架的软件驱动设计,并提供了完整的初始化、数据采集和图像处理代码实现。针对常见连接和图像质量问题给出了解决方案,展现了该组合在智能安防、工业检测等领域的应用潜力,为开发者提供了实用的技术参考。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 1507

C++ 知识点清单_Blog导航

三次握手(建立连接)、四次挥手(断开连接)、滑动窗口(流量控制)、拥塞控制(慢启动 / 拥塞避免 / 快重传 / 快恢复)、超时重传、粘包 / 拆包问题(解决方案:固定长度 / 分隔符 / 长度字段)。IPv4/IPv6、IP 地址分类(A/B/C 类)、子网划分(子网掩码)、路由协议(RIP/OSPF/BGP)、ARP(地址解析协议)、ICMP(互联网控制报文协议,ping/tracert)。先来先服务(FCFS)、短作业优先(SJF)、时间片轮转(RR)、优先级调度、多级反馈队列。

我的博客主要是用来给我自己复习的,主要是上传一些知识点,小型的项目和功能模块,如果有什么问题或错误麻烦联系我! 827

弱网、高热、只有 32MB 内存:恶劣环境下嵌入式 SoC 音视频开发的“不死”法则

永远不要假设。你申请一个 1920 宽的图像,硬件为了对齐(比如 16 字节对齐或 256 字节对齐),实际分配的一行可能有 1936 甚至是 2048 字节。那个多出来的部分叫Padding。如果你写代码时用来计算数据量,或者用Width来做指针偏移:恭喜你,你的画面会像被风吹歪的百叶窗一样,产生斜切畸变。永远使用VB_CONF结构体里返回的u32Stride字段。这是区分新手和老手的试金石。第六章 ISP 调优(Tuning)实战:为什么你调出的画面像个“鬼片”?

大模型大数据攻城狮的专栏 1773

24年电赛H题 | 想要小车走直线,正在调角度环,但不知道怎么把角度偏航角偏差转化成电机速度输出?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1320

gcov源码,供学习使用。

摘自http://www.opensource.apple.com/source/gcc/gcc-5484/gcc/gcov.c 1 /* Gcov.c: prepend line execution counts and branch probabilities to a 2 source file. 3 Copyright (C) 1990, 199

Kernel Main的专栏 1565

【目标检测】基于yolov5的道路坑洼检测(附代码和数据集)

基于yolov5的道路坑洼检测(附代码和数据集)

学无止境、积少成多、厚积薄发 4625

覆盖率测试工具gcov的前端工具_LCOV_简介

1、Gcov是进行代码运行的覆盖率统计的工具,它随着gcc的发布一起发布的,它的使用也很简单,需要在编译和链接的时候加上-fprofile-arcs -ftest-coverage生成二进制文件,gcov主要使用.gcno和.gcda两个文件,.gcno是由-ftest-coverage产生的,它包含了重建基本块图和相应的块的源码的行号的信息。.gcda是由加了-fprofile-arcs编译参数

宋宝华 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

使用gtest和lcov测试代码覆盖率

使用gtest和lcov测试代码覆盖率

lansebingxuan的专栏 5822

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

上一篇: 源码分析 | PostgreSQL 回归测试详解
下一篇: 问题定位 | PostgreSQL 报错 requested WAL segment has already been removed
dbkernel
博客等级 码龄4年 60粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值