Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: zak on June 09, 2008, 10:14:59 am

Title: Code Profiler: Problem with gprof under WINDOWS
Post by: zak 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



Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: Biplab 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).
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak 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
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: Biplab 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.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak 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


Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak on June 11, 2008, 09:44:08 am


PLEASE,
        HELP ME!!
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: mandrav 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.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak on June 11, 2008, 11:51:45 am
Thanks very much for the reply.

Were is libgprof.a???


Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: mandrav 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.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: Jenna 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
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak 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.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak on June 12, 2008, 05:12:51 pm

Who was writed Code::Profiler???

Maybe he know what happened..


Best Regards.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: Biplab 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..."));
 
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: irf610 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
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: MortenMacFly 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! :(
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak on June 13, 2008, 10:05:16 am


Thanks very much to all!!!

I am going to fix it..  ehmm... to try..

Best Regards.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: zak on June 13, 2008, 10:41:25 am


IT WORKS!!!!


THANKS TO ALL!!!!!!!!!!!
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: Steven 'lazalong' on September 09, 2008, 07:20:09 am
Seems I have the same problem but this 2.17.50 workaround doesn't work for me.

gprof works in command line but not via CB

I installed:
 
I tried the gprof 2.18.50 & 2.17.50 but I still get the windows "Flat Profile" and "Call Graph" empty. (The Misc windows is ok).

Reverting to gcc 4.3.5 coming with CB 8.1 didn't help.

And, finally, launching the profiler via CB on an old gprof gmon.out file (which worked fine before) resulted in the windows being empty (even if the Misc is ok).


However, if in a command windows I type "gprof test.exe gmon.out > profile.txt"  the flat profile is generated correctly.

So IMO it is not gprof which is at fault but the plugin.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: rhf on September 09, 2008, 06:38:21 pm
I am not sure this is the issue, but there is a problem with the latest gprof binaries. See, for example,

Subject: gprof time accumulation problem
Newsgroups: gmane.comp.gnu.mingw.user
Date: 2008-08-23 20:53:05 GMT

http://article.gmane.org/gmane.comp.gnu.mingw.user/27398

and Danny Smith's response

Subject: Re: gprof time accumulation problem
Newsgroups: gmane.comp.gnu.mingw.user
Date: 2008-08-23 22:58:53 GMT

It sure would be nice if a new release was available.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: Steven 'lazalong' on September 10, 2008, 12:51:37 am
I know this

As I tried to explain I tried a "very recent" gprof and the "before april 2007"
and they work in command line. But the windows don't show the result!

Perhaps I have a separate issue from you - it would be strange though.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: josholig on October 11, 2008, 08:00:21 pm
I don't have very much experience when it comes to installing this kind of thing and I can't for life of me figure out how to install the 2.17.50 over the 2.18.50 release.  Can someone please provide a step to step guide for how to do this I use Windows Vista but even a Windows XP guide would probably be sufficient
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: rhf on October 12, 2008, 06:55:29 pm
Can someone please provide a step to step guide for how to do this I use Windows Vista but even a Windows XP guide would probably be sufficient
josholig, This turns out to not really be a CodeBlocks issue, but I can explain what I did to get gprof to work for me - no guarantees.
(1) Since you might want it back, rename your current version of gprof.exe , typically in C:\MinGW\bin, to say gprof_preview.exe.
(2) Download Current Release of binutils. http://downloads.sourceforge.net/mingw/binutils-2.17.50-20060824-1.tar.gz?modtime=1156941940&big_mirror=1
(3) Make a local temporary directory, extract the files and copy  bin\gprof.exe to C:\MinGW\bin directory.
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: josholig on October 13, 2008, 06:18:51 am
I tried it and it still does not work in code::blocks the only difference was that my C:\MinGw\ is actually in C:\Program Files\CodeBlocks\MinGw\ if that is a problem how can I change that and not mess up CodeBlocks if not is there another possible workaround?

::EDIT:: It did work I just copied the wrong gprof.exe over it works now now though
Title: Re: Code Profiler: Problem with gprof under WINDOWS
Post by: RoBaTte on April 25, 2009, 12:16:25 am
Oh my god! I love you.
2 days reading, trying, getting crazy ending now in a happy end. It works. Thanks a lot!  :D :D


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