Profiling with AMD CodeAnalyst - how to measure outer functions call times?

Started by
5 comments, last by maxest 14 years, 1 month ago
I really didn't know where to put this thread... I have 3 functions, where first is called in second, and second is called in third. I want to profile my program so I use AMD CodeAnalyst. The problem is that it shows time duration only of the most inner (the first) function, whereas I would like also to see times of second and third functions call - I want absolute times for all functions. Does anyone know what should I switch to get that information? Here's the code of my program:

#include "stdafx.h"
#include <cmath>



double inin(int x)
{
	double res = 1.0;

	for (int i = 1; i <= x; i++)
		res *= sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt((double)i))))))))))))))));

	return res;
}



double outout(int x)
{
	double total = 0.0;

	for (int i = 0; i < x; i++)
	{
		double res = inin(100000*i);
		total += res;
		printf("%f\n", res);
	}

	return total;
}



void doit()
{
	for (int i = 10; i < 12; i++)
		printf("\ntotal = %f\n\n\n", outout(i));
}



int _tmain(int argc, _TCHAR* argv[])
{
	doit();

	getchar();
	return 0;
}
And all I get from CodeAnalyst is:

CS:EIP   	Symbol + Offset 	64-bit 	Timer samples 	
0x401000 	inin            	       	63.95         	
0x401258 	sqrt            	       	36.05         	

2 functions, 33 instructions, Total: 233 samples, 100.00% of samples in the module, 1.67% of total session samples
. So as you can see, I don't have times for outout and doit functions.
Advertisement
Quote:2 functions, 33 instructions, Total: 233 samples


Profiler executed your application. Every once in a while (233 times total), it looked where the program is by checking program counter. Since majority of time was spent in those two functions, samples were taken only in those two.

Other functions do not appear since they take so little time to execute that profiler happened to never interrupt them.

Sampling profiling is used to determine bottlenecks via Monte Carlo method. By randomly interrupting the execution, chance of interrupting functions which execute most often is greater than chance of interrupting functions which rarely execute or take little time.

Results of your measurement are not times - they are samples. They are indicative of which parts of code execute most of the time.

The advantage of such profiling is that it doesn't put any load on application being profiled, nor does it affect it any meaningful sense. Instrumentation-based profilers (which track every entry/exit of functions) not only slow down the execution anywhere between factor 1000 and a million, but also drastically affect execution characteristics. For whole application profiling, sampling is only viable method.
Yes I know these are all samples. This "time" I mentioned was just a mental abbrevation :).
And to be honest, I don't actually see how to find bottleneck when using this Monte Carlo method. Let's say I have dozens of call of function aaa and bbb in whole application. Let's now say I have a function ccc which does many calls of aaa and bbb. The function will probably not be listed because profiler is spending it's whole time in aaa and bbb. So how can I find this way that ccc is a problem? I would like to see absolute samples count including all "child" functions. Can this be turned on via CodeAnalyst?
Quote:Original post by maxest
Yes I know these are all samples. This "time" I mentioned was just a mental abbrevation :).
And to be honest, I don't actually see how to find bottleneck when using this Monte Carlo method. Let's say I have dozens of call of function aaa and bbb in whole application. Let's now say I have a function ccc which does many calls of aaa and bbb. The function will probably not be listed because profiler is spending it's whole time in aaa and bbb. So how can I find this way that ccc is a problem? I would like to see absolute samples count including all "child" functions. Can this be turned on via CodeAnalyst?

How would it know? Let's say you have another function ddd which only calls aaa (and not bbb). How does CodeAnalyst know whether aaa was called by ccc or ddd?

It might be technically possible (I never used CodeAnalyst), but from what Antheus said the only way the program would know what function you were in would be to look at the stack.

OK, I did some searching on the internet and found "call stack sampling" described here.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

CodeAnalyst is a decent way to start profiling, but lately I've become very fond of Very Sleepy. It isn't the most feature-rich program out there, but using it is absolutely effortless, and it gets you some very nice data like call stack graphs and so on. Check it out.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Do you know whether Very Sleepy understands any non-PDB debugging formats? Right now I'm using the MinGW compiler that came with Code::Blocks to compile my Win32 game.
I've just checked this VerySleepy. And I must say it's exactly what I would expect from a profiler :). Thanks a lot for hint about existing such a tool :).

This topic is closed to new replies.

Advertisement