运行时转储gcov数据

阅读:
使用gcov生成增量覆盖率报告
https://blog.csdn.net/Ls4034/article/details/72911389
转自:https://stackoverflow.com/questions/14977285/dumping-gcov-data-at-runtime

待检测程序的main函数加入该函数:

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void __gcov_flush();

static void catch_function(int signal) {
   __gcov_flush();
}

int main(void) {
    if (signal(SIGINT, catch_function) == SIG_ERR) {
        fputs("An error occurred while setting a signal handler.\n", stderr);
        return EXIT_FAILURE;
    }
    while(1);
}

比如:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <signal.h>


void __gcov_flush();

static void catch_function(int signal) {
   __gcov_flush();
}
int main(int argc, char *argv[])
{   
   if (signal(SIGINT, catch_function) == SIG_ERR) {
        fputs("An error occurred while setting a signal handler.\n", stderr);
        return EXIT_FAILURE;
    }
    if (argc >=2) {
        printf("=====argc>=2\n");
    }
    printf("helloworld begin\n");

    if (argc <2){
        printf("=====argc<2\n");
    }

    while(1){

        printf("this is the server body");
        sleep(5);
	//break;
    }
    return 0;
}

当在被检测程序的运行界面按ctrl+C按钮,即生成一个.gcda文件。
该文件为追加:
https://stackoverflow.com/questions/15612077/is-there-anyway-to-merge-two-gcov-files-into-one
若需要最新的,需要删除该文件。




附录:

kill命令的使用

先用ps查找进程,然后用kill杀掉:

ps -ef | grep vim

root 19255 19224 1 05:49 pts/1 00:00:00 vim install.py
root 19257 18618 0 05:49 pts/0 00:00:00 grep vim

kill 19255
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值