Author Topic: Code Profiler: Problem with gprof under WINDOWS  (Read 43662 times)

Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Code Profiler: Problem with gprof under WINDOWS
« on: June 09, 2008, 10:14:59 am »
I have some problem with gprof under WINDOWS
with C:B 5082.
I remember that it has worked in the past..
 
This is the wrong result of my test code under WINDOWS XP

Code
Each sample counts as 0.01 seconds.
no time accumulated

  %  cumulative  self              self    total         
time  seconds  seconds    calls  Ts/call  Ts/call  name   
  0.00      0.00    0.00      500    0.00    0.00  f(int)
  0.00      0.00    0.00      500    0.00    0.00  g(int)
.
.
.
granularity: each sample hit covers 0 byte(s) no time propagated



index % time    self  children    called     name

                0.00    0.00     500/500         _main [53]

[3]      0.0    0.00    0.00     500         f(int) [3]

-----------------------------------------------

                0.00    0.00     500/500         _main [53]

[4]      0.0    0.00    0.00     500         g(int) [4]

-----------------------------------------------



and this is the correct version under LINUX
where it works fine

Code
Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name   
 79.66      0.47     0.47      250     1.88     1.88  f(int)
 20.34      0.59     0.12      250     0.48     0.48  g(int)
.
,
,
granularity: each sample hit covers 4 byte(s) for 1.69% of 0.59 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.00    0.59                 main [1]
                0.47    0.00     250/250         f(int) [2]
                0.12    0.00     250/250         g(int) [3]
-----------------------------------------------
                0.47    0.00     250/250         main [1]
[2]     79.7    0.47    0.00     250         f(int) [2]
-----------------------------------------------
                0.12    0.00     250/250         main [1]
[3]     20.3    0.12    0.00     250         g(int) [3]
-----------------------------------------------

Here i put the test code
Code
#include <sys/time.h>

#define rdtscll(val) asm volatile("rdtsc" : "=A" (val))

struct timeval tv;
unsigned long long t;

void f (int n)
{
  int x, y, z = 0;

  for (x = 0; x < n; x++)
    for (y = 0; y < n; y++) {
      z += x * y;
      rdtscll (t);
    }
}

void g (int n)
{
  int x, y, z = 0;

  for (x = 0; x < n; x++)
    for (y = 0; y < n; y++) {
      z += x * y;
      gettimeofday (&tv, 0);
    }
}

int main (int argc, char *argv[])
{
  int n;

  for (n = 0; n < 500; n++) {
    if (n % 2)
      f (n);
    else
      g (n);
  }
  return 0;
}

Where is the problem?? I miss some library or what???

Any help is appreciated.

Thanks very much, Zak




Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #1 on: June 09, 2008, 01:07:55 pm »
Please don't post your problem multiple times. Your post may be locked for spamming. If noone answers to your query you need to wait.

Check that you compiled with -g option and linked against libgprof.a (hopefully I'm correct).
Be a part of the solution, not a part of the problem.

Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #2 on: June 09, 2008, 02:25:54 pm »
I'm sorry for multiple posting.

I compiled with -g -pg (when I compile without -g I get an error from Code Profiler).

Maybe the problem is libgprof.a, I have not it.

What can I do?


Tanks very much Biplab!

Best regards, Zak

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #3 on: June 09, 2008, 02:50:27 pm »
I compiled with -g -pg (when I compile without -g I get an error from Code Profiler).

Maybe the problem is libgprof.a, I have not it.

What can I do?

Run it once before launching the Code-profiler plugin.
Be a part of the solution, not a part of the problem.

Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #4 on: June 09, 2008, 03:09:32 pm »
Sorry, I'm going to explain better the problem.

I know how gprof works.

I must compile with -pg and -g.
I must run the program.
If the prograg exit with 0 code i can start plugin (or gprof directly)
and see the call graph.

Now, i have a code. I compile it with g++ under Linux (Ubuntu 8.4)
using Codeblocks IDE and the Code Profiler works fine.

When I compile with g++ under Windows Xp using the same versione of
Codeblocks, just those for Windows, and i run it...

I obtain all 0.00 time.

In the Windows version i don't need link with libgprof.a, there is a Profiler.dll file
in the directory C:\Programmi\Codeblocks\Share\Plugins.

I hope to be clear the problem.

However, Thanks very Much for your reply.

Best regards, Zak



Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #5 on: June 11, 2008, 09:44:08 am »


PLEASE,
        HELP ME!!

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #6 on: June 11, 2008, 11:20:03 am »
In the Windows version i don't need link with libgprof.a, there is a Profiler.dll file
in the directory C:\Programmi\Codeblocks\Share\Plugins.

What does profiler.dll (the C::B plugin) has to do with libgprof.a ?!?
You must link your app with libgprof.a if you want to profile it.
Be patient!
This bug will be fixed soon...

Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #7 on: June 11, 2008, 11:51:45 am »
Thanks very much for the reply.

Were is libgprof.a???



Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #8 on: June 11, 2008, 02:36:53 pm »
Thanks very much for the reply.

Were is libgprof.a???

See? You confused me too :)
It's libgmon.a.
Be patient!
This bug will be fixed soon...

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #9 on: June 11, 2008, 03:10:34 pm »
In the Windows version i don't need link with libgprof.a, there is a Profiler.dll file
in the directory C:\Programmi\Codeblocks\Share\Plugins.

What does profiler.dll (the C::B plugin) has to do with libgprof.a ?!?
You must link your app with libgprof.a if you want to profile it.
Thanks very much for the reply.

Were is libgprof.a???

See? You confused me too :)
It's libgmon.a.

Linking with libgmon.* should be done automagically.

It happens at least on my WinXP system at work, but the profiling does not work, or more exact, it works for me on linux, but not on WinXP (the calls are counted, but not the times).

@ zak:
libgmon.a is in <MinGW-root>/lib

Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #10 on: June 11, 2008, 03:24:26 pm »
Quote
See? You confused me too Smile
It's libgmon.a.
Sorry!!!

Quote
Linking with libgmon.* should be done automagically.

It happens at least on my WinXP system at work, but the profiling does not work, or more exact, it works for me on linux, but not on WinXP (the calls are counted, but not the times).

@ zak:
libgmon.a is in <MinGW-root>/lib

We have exactely the same problem!!
How you fixed it????

Best Regards.
« Last Edit: June 12, 2008, 12:23:01 pm by zak »

Offline zak

  • Multiple posting newcomer
  • *
  • Posts: 26
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #11 on: June 12, 2008, 05:12:51 pm »

Who was writed Code::Profiler???

Maybe he know what happened..


Best Regards.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #12 on: June 12, 2008, 06:21:08 pm »
It appears to be a problem in gprof. The output from gprof doesn't contain time output. Apply the following patch and note the output at Debug Log.

Code
Index: src/plugins/contrib/profiler/cbprofilerexec.cpp
===================================================================
--- src/plugins/contrib/profiler/cbprofilerexec.cpp (revision 5094)
+++ src/plugins/contrib/profiler/cbprofilerexec.cpp (working copy)
@@ -52,6 +52,7 @@
 
     wxString cmd;
     cmd << _T("gprof ") << param << _T(" \"") << exename << _T("\" \"") << dataname << _T("\"");
+    Manager::Get()->GetLogManager()->DebugLog(cmd);
 
     wxProgressDialog progress(_("C::B Profiler plugin"),_("Launching gprof. Please wait..."));
     int pid = wxExecute(cmd, gprof_output, gprof_errors);
@@ -157,8 +158,10 @@
     while ((begin < msg.GetCount())&&(msg[begin].Find(_T("index % time")) == -1))
     {
         ++begin;
+        Manager::Get()->GetLogManager()->DebugLog(msg[begin]);
     }
     ++begin;
+    Manager::Get()->GetLogManager()->DebugLog(msg[begin]);
 
     progress.Update((100*begin)/(msg.GetCount()-1),_("Parsing Call Graph information. Please wait..."));
 
« Last Edit: June 12, 2008, 06:23:28 pm by Biplab »
Be a part of the solution, not a part of the problem.

Offline irf610

  • Single posting newcomer
  • *
  • Posts: 4
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #13 on: June 12, 2008, 07:18:42 pm »
Hi,

Just ran into this problem. gprof 2.18.50 seem to have a problem. Just install gprof 2.17.50 and everything work fine.

You can find it in the Mingw GNU Bintuils release 2.17.50 at the following address :
http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=11290

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code Profiler: Problem with gprof under WINDOWS
« Reply #14 on: June 13, 2008, 08:58:14 am »
Just ran into this problem. gprof 2.18.50 seem to have a problem. Just install gprof 2.17.50 and everything work fine.
Confirmed. :?

O dear... I already had to go back to gdb 6.6 due to bugs, now even more up-to-date binutils seem to be buggy... Darn! :(
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ