Archived

This topic is now archived and is closed to further replies.

Russell

CompuWare DevPartner Profiler (with VC++ .NET 2003)

Recommended Posts

Russell    118
I''m trying out the CompuWare DevPartner Profiler (Community Edition, free) with Visual Studio .NET 2003, and at first I compiled a C program and everything looked great. Then I compiled a C++ program, and the only thing that shows up in the profile are global functions, of which there are only 3, one of which is main. Guess which function gets 100% of the time? You guessed it, main(). So that is useless information. Has anytone else had this problem? Anything I might be doing wrong?

Share this post


Link to post
Share on other sites
Russell    118
Yes, instrumentation was turned on. I even took the Solution that I already got to profile correctly, removed all of the source and header files from it, put the other source code in that Solution and recompiled, and only the three global functions show up. This morning I tried moving a member function from the inline definition to being defined outside of the class, and that didn''t help anything.

I just wrote up this little thing, and nothing about Foo or bar() show up anywhere in the profile. Only main(), and the global_func()''s.

#include <iostream>
#include <ctime>

using namespace std;

const clock_t how_long = 5 * CLOCKS_PER_SEC;

unsigned int global_func1 ()
{
unsigned int a = 0;
for (int i = 0; i < 1000; i++)
{
unsigned r = rand() ^ (rand() << 15);
if (a & 1)
a += (r * 10);
if (a & 2)
a++;
if (a & 4)
a <<= 1;
if (a & 8)
a += 2;
}
return a;
}

unsigned int global_func2 ()
{
unsigned int a = 0;
for (int i = 0; i < 1000; i++)
{
unsigned r = rand() ^ (rand() << 15);
if (a & 1)
a ^= r;
if (a & 2)
a ^= !r;
if (a & 4)
a *= r;
if (a & 8)
a += r;
}
return a;
}

class Foo
{
public:
Foo ()
: foo_(0)
{

}

void bar ()
{
for (int i = 0; i < 1000; i++)
foo_ ^= rand() * rand();
}

unsigned value () const { return foo_; }
private:
unsigned foo_;
};

int main ()
{
Foo foo;
unsigned int result;
clock_t start = clock();
for (;;)
{
result ^= global_func1();
result ^= global_func2();
foo.bar();
if ((clock() - start) > how_long)
break;
}
cout << result << endl;
cout << foo.value() << endl;
}


Here is what the profiler outputs (probably not formatted, but whatever).

Method Name % in Method % with Children Called Average
global_func2 33.9 49 517 382.6
global_func1 33.5 48.4 517 377.4
rand 30 30 2,068,000 0.1
main 1.8 100 1 10,571.30
clock 0.7 0.7 518 7.9
GetSystemTimeAsFileTime 0.1 0.1 520 0.6
GetModuleHandleA 0 0 3 23.5
WriteFile 0 0 12 4.2
RtlAllocateHeap 0 0 68 0.6
ExitProcess 0 0 1 33.3
GetEnvironmentStringsW 0 0 1 27.5
HeapCreate 0 0 1 19.1
WideCharToMultiByte 0 0 4 4.2
GetFileType 0 0 3 4.8
LCMapStringW 0 0 5 2.2
GetStringTypeW 0 0 2 4.3
GetProcAddress 0 0 1 8.5
RtlFreeHeap 0 0 23 0.3
GetModuleFileNameA 0 0 1 7.8
MultiByteToWideChar 0 0 6 1
GetVersionExA 0 0 1 3.7
QueryPerformanceCounter 0 0 1 2.6
GetStartupInfoA 0 0 1 1.6
GetCPInfo 0 0 2 0.6
GetStdHandle 0 0 3 0.4
SetUnhandledExceptionFilter 0 0 2 0.5
RtlSizeHeap 0 0 7 0.1
GetACP 0 0 1 0.6
FreeEnvironmentStringsA 0 0 1 0.6
SetHandleCount 0 0 1 0.3
IsProcessorFeaturePresent 0 0 1 0.2
GetCommandLineA 0 0 1 0.1
GetCurrentProcessId 0 0 1 0.1
GetTickCount 0 0 1 0.1
GetCurrentThreadId 0 0 1 0.1
[Program Start] 0 100 0 0
[Thread Start - 644] 0 0 0 0

Share this post


Link to post
Share on other sites
Russell    118
I reinstalled and now if member functions which are NOT defined inline in the class declaration show up in the profile. In other words, this function would NOT show up in the profile:


class Foo {
// ...
void bar () { ... };
// ...
};


But this function would:


class Foo {
// ...
void bar ();
// ...
};

void Foo::bar () { ... }


Not sure why it matters, but apparently it does. I guess I can''t complain since it''s free

Share this post


Link to post
Share on other sites
Russell    118
quote:
Original post by ChaosEngine
of course it matters...if you''re profiling you''re using a release build and your inline functions are part of the calling function (i.e. main).

"That''s not a bug, it''s a feature!"
--me


So you''re saying that everything just got inlined, and that is why it isn''t showing up in the profile? Okay, but the entire program shouldn''t be inlined, should it? In the simple example, sure, but for a 2500 line program? 2500 lines is not that big, but I still wouldn''t imagine everything being inlined. Or am I wrong there? I added /Ob0 to turn off all inlining except for __forceinline, but still no member functions that are defined inline in the class definition show up in the profile.

Share this post


Link to post
Share on other sites
sjelkjd    171
why don''t you check the assembly output and see just exactly how much of your code got inlined. Also, it should have a source code view which should indicate what % of cpu time went to which source lines.

Share this post


Link to post
Share on other sites