Thread: gprof in Linux

  1. #1
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138

    gprof in Linux

    Hi,

    I want to profile a multi source project via gprof. I was able to do it but there are issues here:

    The number of calls is not shown in output. Like:

    Code:
    %   cumulative   self              self     total           
     time   seconds   seconds    calls  Ts/call  Ts/call  name
    
      0.16     18.02     0.03                             ____strtod_l_internal
    I want to profile a single code file among all sources. How to ?

  2. #2
    Registered User
    Join Date
    May 2023
    Posts
    1
    1. Compile the source code file with the "-pg" compiler option to include profiling information in the executable. For example, if your source code file is "myfile.c", you can compile it as follows:
      gcc -pg -c myfile.c
    2. Link the profiling information with the rest of the project by specifying the "-pg" option during linking. For example:
      gcc -pg myfile.o other_source_files.o -o myprogram
    3. Run the executable to generate the profiling data:
      ./myprogram

    4. Analyze the profiling data using gprof, specifying the name of the object file (not the executable) that you want to profile. For example:
      gprof myfile.o gmon.out
      This should give you the profiling information for just the code in "myfile.c". Additionally, you may need to use the "-l" option to get gprof to display the number of calls, like this:
      gprof -1 myfile.o gmon.out
    Last edited by AldenDemuth; 05-03-2023 at 03:34 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to use gprof
    By mattholm in forum C Programming
    Replies: 5
    Last Post: 12-13-2011, 03:58 PM
  2. Profiling other than gprof
    By Kempelen in forum C Programming
    Replies: 1
    Last Post: 06-02-2011, 11:13 AM
  3. Question about Gprof
    By PetrolMan in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2009, 10:18 AM
  4. Gprof under windows
    By Kempelen in forum C Programming
    Replies: 7
    Last Post: 05-23-2008, 05:49 PM
  5. Profiling with GPROF
    By RoshanX in forum C Programming
    Replies: 2
    Last Post: 03-30-2007, 02:38 PM

Tags for this Thread