-pg标志不生成gmon.out文件

时间:2017-02-21 03:23:15

标签: c++ gprof codelite

我使用-pg标志编译和链接我的cpp程序,运行程序,并检查我的目录gmon.out。我找不到任何东西。

我正在运行Ubuntu 16.04 LTS,这是一个完全默认的codelite项目。唯一的事情是我将-pg标志添加到c ++编译选项和链接选项中。

我已经阅读了所有其他线程,询问同样的问题。我相信我的问题不同。

这是我的makefile:

##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased      
##
## Release
ProjectName            :=trying_reproducible_gprof_error
ConfigurationName      :=Release
WorkspacePath          :=/home/taylor/Documents/ssmworkspace
ProjectPath            :=/home/taylor/Documents/ssmworkspace/trying_reproducible_gprof_error
IntermediateDirectory  :=./Release
OutDir                 := $(IntermediateDirectory)
CurrentFileName        :=
CurrentFilePath        :=
CurrentFileFullPath    :=
User                   :=taylor
Date                   :=20/02/17
CodeLitePath           :=/home/taylor/.codelite
LinkerName             :=/usr/bin/g++
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
ObjectSuffix           :=.o
DependSuffix           :=.o.d
PreprocessSuffix       :=.i
DebugSwitch            :=-g 
IncludeSwitch          :=-I
LibrarySwitch          :=-l
OutputSwitch           :=-o 
LibraryPathSwitch      :=-L
PreprocessorSwitch     :=-D
SourceSwitch           :=-c 
OutputFile             :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors          :=$(PreprocessorSwitch)NDEBUG 
ObjectSwitch           :=-o 
ArchiveOutputSwitch    := 
PreprocessOnlySwitch   :=-E
ObjectsFileList        :="trying_reproducible_gprof_error.txt"
PCHCompileFlags        :=
MakeDirCommand         :=mkdir -p
LinkOptions            :=  -pg
IncludePath            :=  $(IncludeSwitch). $(IncludeSwitch). 
IncludePCH             := 
RcIncludePath          := 
Libs                   := 
ArLibs                 :=  
LibPath                := $(LibraryPathSwitch). 

##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR       := /usr/bin/ar rcu
CXX      := /usr/bin/g++
CC       := /usr/bin/gcc
CXXFLAGS :=  -pg -O2 -Wall $(Preprocessors)
CFLAGS   :=  -O2 -Wall $(Preprocessors)
ASFLAGS  := 
AS       := /usr/bin/as


##
## User defined environment variables
##
CodeLiteDir:=/usr/share/codelite
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) 



Objects=$(Objects0) 

##
## Main Build Targets 
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)

$(OutputFile): $(IntermediateDirectory)/.d $(Objects) 
    @$(MakeDirCommand) $(@D)
    @echo "" > $(IntermediateDirectory)/.d
    @echo $(Objects0)  > $(ObjectsFileList)
    $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList)     $(LibPath) $(Libs) $(LinkOptions)

MakeIntermediateDirs:
    @test -d ./Release || $(MakeDirCommand) ./Release


$(IntermediateDirectory)/.d:
    @test -d ./Release || $(MakeDirCommand) ./Release

PreBuild:


##
## Objects
##
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp         $(IntermediateDirectory)/main.cpp$(DependSuffix)
    $(CXX) $(IncludePCH) $(SourceSwitch) "/home/taylor/Documents/ssmworkspace/trying_reproducible_gprof_error/main.cpp" $(CXXFLAGS)     $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
    @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP     -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix)     -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM main.cpp

$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch)     $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) main.cpp


-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
    $(RM) -r ./Release/

这是项目中唯一的文件,main.cpp

#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello world\n");
    return 0; 
}

编辑:

我将main.cpp更改为以下内容,现在可以正常运行:

#include <iostream>

void printLol(){
    std::cout << "lol........\n";
}

int main(int argc, char **argv)
{
    std::cout << "hello world\n";
    for(int i = 0; i < 10; ++i)
        printLol();

    return 0;
}

我需要至少一个非主要功能,或gprof不喜欢stdio.h。如果他们愿意,任何人都可以解释一下。

1 个答案:

答案 0 :(得分:0)

Gprof是一个基于抽样的分析器,你的第一个示例应用程序执行太小,无法由Gprof注册。

尝试在应用程序中添加一些sleep(1)调用并再次尝试。