小编Mal*_*lin的帖子

gprof产生空输出

我正在运行Ubuntu 16.10并尝试使用gprof配置程序.我用标志编译,-pg程序是单线程的.实际的编译命令是:

g++ -I. -std=c++11 -Wall -Wextra -O3 -pg -fPIC -Wno-unused-parameter -c -o build/obj/performance/stencil_application.o test/performance/stencil_application.cpp
g++ -I. -std=c++11 -Wall -Wextra -O3 -pg -Wno-unused-parameter build/obj/performance/stencil_application.o -o build/test/performance/stencil_application
Run Code Online (Sandbox Code Playgroud)

运行时程序需要几秒钟才能完成,并生成一个名为gmon.out的文件.但是,当我运行时gprof ./build/test/performance/stencil_application,我得到的输出不包含数字.我只得到表格标题和不同字段的解释,如下所示:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for …
Run Code Online (Sandbox Code Playgroud)

ubuntu profiling gprof

22
推荐指数
1
解决办法
5017
查看次数

为什么在类中不允许使用函数模板特化?

在找到关于stackoverflow的许多问题的答案之后,我现在遇到了一个我无法找到答案的问题,我希望有人愿意帮助我!

我的问题是我想在C++中对一个类中的函数进行明确的模板化.我的编译器(g ++)和C++标准(§14.7.3)中的一个看起来告诉我,这个特化必须在声明类的命名空间中完成.我明白这意味着我不能把专业化放在课堂里,但是我没有看到这个限制的重点!有没有人知道是否有充分的理由不让专业在课堂上进行?

我知道有一些解决方法,例如将函数放在结构体中,但我想理解为什么语言有这种设计.如果有充分的理由不在课堂上允许专门的功能,我想在尝试解决它之前我应该​​知道它.

提前致谢!


为了让我的问题更加精确:以下是一些测试示例中的代码,说明了我想要做的事情:

#include <cstdio>

namespace MalinTester {

template <size_t DIMENSIONALITY>
class SpecializationTest {
public:
    SpecializationTest() {
        privateVariable = 5;
    };
    virtual ~SpecializationTest() {};

    void execute() {
        execute<DIMENSIONALITY>();
    };

private:
    int privateVariable;
    template <size_t currentDim>
    static void execute() {
        printf("This is the general case. Current dim is %d. The private variable is %d.\n", currentDim, privateVariable);
        execute<currentDim-1>();
    }

    template <>
    static void execute<0>() {
        printf("This is the base case. Current dim is 0.\n");
    }

};
Run Code Online (Sandbox Code Playgroud)

这是不可能的; g ++说: …

c++ templates explicit class specialization

11
推荐指数
1
解决办法
6940
查看次数

标签 统计

c++ ×1

class ×1

explicit ×1

gprof ×1

profiling ×1

specialization ×1

templates ×1

ubuntu ×1