00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifdef __RUSAGE_TIME__
00011
00012 #include <stdio.h>
00013 #include <sys/resource.h>
00014 #include "timer.h"
00015
00016
00017 struct rusage diffrusagetime(struct rusage stop,struct rusage start)
00018
00019
00020
00021
00022
00023
00024
00025 {
00026 struct rusage diff;
00027
00028 getrusage (RUSAGE_SELF,&diff);
00029
00030 diff.ru_utime.tv_sec = stop.ru_utime.tv_sec-start.ru_utime.tv_sec;
00031 diff.ru_utime.tv_usec = stop.ru_utime.tv_usec-start.ru_utime.tv_usec;
00032 if (diff.ru_utime.tv_usec<0)
00033 {
00034 --diff.ru_utime.tv_sec;
00035 diff.ru_utime.tv_usec = 1000000+diff.ru_utime.tv_usec;
00036 }
00037 diff.ru_stime.tv_sec = stop.ru_stime.tv_sec-start.ru_stime.tv_sec;
00038 diff.ru_stime.tv_usec = stop.ru_stime.tv_usec-start.ru_stime.tv_usec;
00039 if (diff.ru_stime.tv_usec<0)
00040 {
00041 --diff.ru_stime.tv_sec;
00042 diff.ru_stime.tv_usec = 1000000+diff.ru_stime.tv_usec;
00043 }
00044 return diff;
00045 }
00046
00047 struct rusage sumrusagetime(struct rusage stop,struct rusage start)
00048
00049
00050
00051
00052
00053
00054
00055 {
00056 struct rusage sum;
00057 sum.ru_utime.tv_sec = stop.ru_utime.tv_sec+start.ru_utime.tv_sec;
00058 sum.ru_utime.tv_usec = stop.ru_utime.tv_usec+start.ru_utime.tv_usec;
00059 if (sum.ru_utime.tv_usec>1000000)
00060 {
00061 ++sum.ru_utime.tv_sec;
00062 sum.ru_utime.tv_usec = sum.ru_utime.tv_usec-1000000;
00063 }
00064 sum.ru_stime.tv_sec = stop.ru_stime.tv_sec+start.ru_stime.tv_sec;
00065 sum.ru_stime.tv_usec = stop.ru_stime.tv_usec+start.ru_stime.tv_usec;
00066 if (sum.ru_stime.tv_usec>1000000)
00067 {
00068 ++sum.ru_stime.tv_sec;
00069 sum.ru_stime.tv_usec = sum.ru_stime.tv_usec-1000000;
00070 }
00071 return sum;
00072 }
00073
00074 void writerusagesystemtime(FILE *file,struct rusage time)
00075
00076
00077
00078
00079
00080 {
00081 double system = (double)time.ru_stime.tv_sec+1e-6*(double)time.ru_stime.tv_usec;
00082 fprintf(file,"%.6f sec",system);
00083 }
00084
00085 void writerusageusertime(FILE *file,struct rusage time)
00086
00087
00088
00089
00090
00091 {
00092 double user = (double)time.ru_utime.tv_sec+1e-6*(double)time.ru_utime.tv_usec;
00093 fprintf(file,"%.6f sec",user);
00094 }
00095
00096 void writerusagetime(FILE *file,struct rusage time)
00097
00098
00099
00100
00101
00102 {
00103 double user = (double)time.ru_utime.tv_sec+1e-6*(double)time.ru_utime.tv_usec;
00104 double system = (double)time.ru_stime.tv_sec+1e-6*(double)time.ru_stime.tv_usec;
00105 fprintf(file,"system : ");
00106 fprintf(file,"%.6f sec",system);
00107 fprintf(file,"\tuser : ");
00108 fprintf(file,"%.6f sec",user);
00109 fprintf(file,"\tsum : ");
00110 fprintf(file,"%.6f sec",user+system);
00111 }
00112
00113
00114 void writerusagetime2(char *strg , struct rusage time)
00115
00116
00117
00118
00119
00120 {
00121 double user = (double)time.ru_utime.tv_sec+1e-6*(double)time.ru_utime.tv_usec;
00122 double system = (double)time.ru_stime.tv_sec+1e-6*(double)time.ru_stime.tv_usec;
00123 printf("%s system : ",strg);
00124 printf("%.6f sec",system);
00125 printf("\tuser : ");
00126 printf("%.6f sec",user);
00127 printf("\tsum : ");
00128 printf("%.6f sec",user+system);
00129 }
00130
00131
00132
00133 #else
00134 #include <time.h>
00135 #include <stdio.h>
00136 #include "timer.h"
00137
00138 #endif