小编Ray*_*Ray的帖子

我已经设置了CPUPROFILE环境变量并链接了-lprofiler.为什么gperftools没有启动分析器?

根据gperftools文档,可以使用以下任何方法启动探查器:

  1. 将CPUPROFILE环境变量设置为将保存配置文件信息的文件名
  2. 执行上述操作,并设置CPUPROFILESIGNAL和发送适当的信号以启动或停止采样.
  3. 呼叫ProfilerStart(filename)和ProfileStop()从您的代码直接

所有这三种方法都需要libprofiler.so链接.

当我尝试这个时,第三种方法有效,但是当我只是设置时CPUPROFILE,没有生成分析信息.

不起作用:

$ cat foo.c
#include <stdio.h>

int main(void) {
    printf("Hello, world!\n");
}
$ gcc foo.c -std=c99 -lprofiler -g && CPUPROFILE=foo.prof ./a.out
Hello, world!
$ ls foo.prof
ls: cannot access foo.prof: No such file or directory
Run Code Online (Sandbox Code Playgroud)

工作:

$ cat bar.c
#include <stdio.h>
#include <gperftools/profiler.h>

int main(void) {
    ProfilerStart("bogus_filename");
    printf("Hello, world!\n");
    ProfilerStop();
}
$ gcc -std=c99 bar.c -lprofiler -g && CPUPROFILE=foo.prof ./a.out …
Run Code Online (Sandbox Code Playgroud)

c++ ld gperftools

2
推荐指数
1
解决办法
2024
查看次数

malloc和sizeof时出现分段错误

抱歉,如果我冒犯了任何人,但是我本周开始学习C,并且在编译此代码时遇到了段错误。我能否再请一双眼睛帮助我解决此错误?

void Space(void *empty, size_p s)
{
    empty = malloc(s);
}

int main()
{
    int *p = NULL;
    Space(p, sizeof(p));
    *p = 7;

    return;
}
Run Code Online (Sandbox Code Playgroud)

c segmentation-fault

0
推荐指数
1
解决办法
62
查看次数

if语句不适用于某些测试用例

该代码不适用于测试用例17 13 3 15。在我尝试过的其他测试案例中,它运行良好。

#include <stdio.h>
int max_of_four(int a,int b,int c,int d)
{
    int max;
    a=max;
    if(b>max)
    max=b;
    if(c>max)
    max=c;
    if(d>max)
    max=d;
    return max;
}

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int ans = max_of_four(a, b, c, d);
    printf("%d", ans);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
1
解决办法
60
查看次数

标签 统计

c ×2

c++ ×1

gperftools ×1

ld ×1

segmentation-fault ×1