C中函数的调用次数跟处理时间

C中函数的调用次数和处理时间
在C中怎么看每个函数的调用次数和消耗的处理器时间?貌似gprof可以,不过怎么用啊?在window系统中也可以用吗?求大侠指点C中函数的调用次数跟处理时间
------解决方案--------------------
你在windows上用的什么编译器,如果用gcc,应该可以使用。
------解决方案--------------------
windows自带的GetTickCount
------解决方案--------------------
函数调用次数很简单,设置一个全局变量Count = 0,在要计算次数的函数后面加一句 Count++; 最后输出Count就搞定了。
运行时间的话可以利用clock()函数(百度一下用法吧)。在要计算时间的函数前后分别clock一次,做差就得到函数调用消耗的时间了。
------解决方案--------------------
引用:
用VS编译的,可以用吗?

VS有自己的profiler.
------解决方案--------------------
可以在函数总定义一个static int count = 0;由于是静态变量,因此只会在第一次调用时初始化,而后在函数末尾对count++;即可实现计数。
------解决方案--------------------
VC6
 
Enable Profiling
Home 
------解决方案--------------------
  Overview 
------解决方案--------------------
  Details

Feature Only in Professional and Enterprise Editions   Profiling is supported only in Visual C++ Professional and Enterprise Editions. For more information, see Visual C++ Editions.

Before using the profiler, you must build the current project with profiling enabled (equivalent to the command line setting LINK /PROFILE). If you want to perform function profiling only in the current project, you only need to enable profiling for the linker.

If you want to do line profiling, you also need to include debugging information.

To build your project for function profiling 

On the Build menu, click Settings to display the Project Settings dialog box.


Click the Link tab.


In the Category drop-down list box, click General.


Select the Enable Profiling check box.


Click OK.


On the Build menu, click Build projectname.exe. 
Note   Selecting the Enable Profiling check box turns off incremental linking. To re-enable incremental linking, clear the Enable Profiling option.

To build your project for line profiling 

Perform the procedure to enable function profiling described earlier in this topic.


Select the Generate Debug Info check box.


Click the C/C++ tab.


In the Category drop-down list box, click General.


In the Debug Info drop-down list box, click Program Database or Line Numbers Only.


Click OK.


On the Build menu, click Build projectname.exe. 
When the build is complete, the project is ready to be profiled.

------解决方案--------------------
推荐 Luke Stackwalker  

其实自己写也成:
1,利用vs或者gcc编译,并生成pdb等符号文件;
2,解析符号文件,得到 tuple<function_name,begin_line,end_line>;
3,运行目标程序,每隔x ms中断该进程,采样程序计数器位置,采样点多一点;
4,分析所有函数的执行次数,这个就代表函数总共执行时间了。
------解决方案--------------------
7楼内容请不要无视。