You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The wtdbg2 algorithm is largely OS-independent. However, to collect system and process information, it assumes the OS is Linux. It would be good remove this dependency. Here are some portable ways to get the real time, CPU time and peak RAM of the current process, and the number of CPUs and total RAM of the system. These work for Mac and Linux.
#include<sys/resource.h>#include<sys/time.h>#include<time.h>#include<unistd.h>doublecputime(void) // return in CPU seconds, including both user and system CPU time
{
structrusager;
getrusage(RUSAGE_SELF, &r);
returnr.ru_utime.tv_sec+r.ru_stime.tv_sec+1e-6* (r.ru_utime.tv_usec+r.ru_stime.tv_usec);
}
doublerealtime(void) // return in seconds
{
structtimevaltp;
structtimezonetzp;
gettimeofday(&tp, &tzp);
returntp.tv_sec+tp.tv_usec*1e-6;
}
longpeakrss(void) // return in bytes
{
structrusager;
getrusage(RUSAGE_SELF, &r);
#ifdef__linux__returnr.ru_maxrss*1024;
#elsereturnr.ru_maxrss;
#endif
}
intncpucore(void)
{
returnsysconf(_SC_NPROCESSORS_ONLN);
}
longtotalmem(void) // return in bytes
{
longpages=sysconf(_SC_PHYS_PAGES);
longpage_size=sysconf(_SC_PAGE_SIZE);
returnpages*page_size;
}
#include<stdio.h>#include<stdlib.h>intmain(void)
{
inti, n=1<<20, *p;
p= (int*)calloc(n, sizeof(int));
for (i=0; i<n; ++i) p[i] =i;
fprintf(stderr, "ncpu: %d\n", ncpucore());
fprintf(stderr, "peakrss: %ld\n", peakrss());
fprintf(stderr, "totalmem: %ld\n", totalmem());
return0;
}
The text was updated successfully, but these errors were encountered:
The wtdbg2 algorithm is largely OS-independent. However, to collect system and process information, it assumes the OS is Linux. It would be good remove this dependency. Here are some portable ways to get the real time, CPU time and peak RAM of the current process, and the number of CPUs and total RAM of the system. These work for Mac and Linux.
The text was updated successfully, but these errors were encountered: