Lets say, I have a function (or functions) which takes a long time (wall time) to execute, for example:
#include "stdafx.h"
#include <math.h>
#include <windows.h>
void fun()
{
  long sum = 0L;
  for (long long i = 1; i < 10000000; i++){
        sum += log((double)i);
    }
 }
double cputimer()
{
    FILETIME createTime;
    FILETIME exitTime;
    FILETIME kernelTime;
    FILETIME userTime;
    if ( GetProcessTimes( GetCurrentProcess( ),
        &createTime, &exitTime, &kernelTime, &userTime ) != -1 )
    {
        SYSTEMTIME userSystemTime;
        if ( FileTimeToSystemTime( &userTime, &userSystemTime ) != -1 )
            return (double)userSystemTime.wHour * 3600.0 +
            (double)userSystemTime.wMinute * 60.0 +
            (double)userSystemTime.wSecond +
            (double)userSystemTime.wMilliseconds / 1000.0;
    }
}
int _tmain(int argc, _TCHAR* argv[])
{
    double start, stop;
    start = cputimer();
    fun();
    stop = cputimer();
    printf("Time taken: %f [seconds]\n", stop - start);
    return 0;
}
I would like to measure a CPU load of this function and RAM usage that this function call uses. Is that possible? How can I do this? Im interested in Windows and Linux solutions.
 
     
     
    