00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 #include <iomanip>
00082
00083
00084
00085 #define CYCLE_SPEED 450e6
00086
00087
00088 #define s3_timer_init( proc ) \
00089 long long s3timer_start_##proc = 0; \
00090 long long s3timer_stop_##proc = 0; \
00091 long long s3timer_total_##proc = 0
00092
00093 #define s3_timer_extern( proc ) \
00094 extern long long s3timer_start_##proc; \
00095 extern long long s3timer_stop_##proc; \
00096 extern long long s3timer_total_##proc
00097
00098 #define s3_timer_reset( proc ) \
00099 s3timer_total_##proc = 0
00100
00101 #define s3_timer_start( proc ) \
00102 asm volatile("rdtsc" : "=A"(*( &s3timer_start_##proc)))
00103
00104 #define s3_timer_stop_add( proc ) \
00105 asm volatile("rdtsc" : "=A"(*(&s3timer_stop_##proc))); \
00106 s3timer_total_##proc += (s3timer_stop_##proc - s3timer_start_##proc )
00107
00108 #define s3_timer_get_seconds( proc ) \
00109 ( (float)s3timer_total_##proc / (float)CYCLE_SPEED )
00110
00111 #define WIDTH_NAME 15
00112 #define WIDTH_TOTAL_SECS 23
00113 #define WIDTH_PER_SECS 23
00114 #define WIDTH_PERCENT 15
00115
00116
00117 #define s3_timer_header( total_time, number_trials ) \
00118 std::cout << std::setw(WIDTH_NAME) << "Name" \
00119 << std::setw(WIDTH_TOTAL_SECS) << "Total time [secs]" \
00120 << std::setw(WIDTH_PER_SECS) << "Time per trial [ms]" \
00121 << std::setw(WIDTH_PERCENT) << "Percentage " \
00122 << std::endl; \
00123 for (int i=0; i<WIDTH_NAME+WIDTH_TOTAL_SECS+WIDTH_PER_SECS+WIDTH_PERCENT; i++)\
00124 std::cout << "-"; std::cout << std::endl; \
00125 s3timer_precentage_accum = 0; \
00126 s3timer_time_accum = 0; \
00127 s3timer_number_trials = number_trials; \
00128 s3timer_total_time = total_time
00129
00130 #define s3_timer_report_init \
00131 float s3timer_precentage_accum = 0; \
00132 float s3timer_time_accum = 0; \
00133 float s3timer_number_trials = 0; \
00134 float s3timer_total_time = 04
00135
00136
00137 #define s3_timer_line( proc, str_name ) \
00138 std::cout << std::setw(WIDTH_NAME) << str_name \
00139 << std::setw(WIDTH_TOTAL_SECS-2) << std::setfill(' ') << std::setprecision(4) << \
00140 (float)s3timer_total_##proc / (float)CYCLE_SPEED \
00141 << std::setw(WIDTH_PER_SECS) << std::setfill(' ') << std::setprecision(4) << \
00142 (float)s3timer_total_##proc / (float)CYCLE_SPEED / \
00143 s3timer_number_trials * 1000 \
00144 << std::setw(WIDTH_PERCENT) << std::setfill(' ') << std::setprecision(4) << \
00145 (float)s3timer_total_##proc / (float)CYCLE_SPEED / \
00146 s3timer_total_time*100 \
00147 << std::endl; \
00148 s3timer_time_accum += \
00149 (float)s3timer_total_##proc / (float)CYCLE_SPEED; \
00150 s3timer_precentage_accum += \
00151 (float)s3timer_total_##proc / (float)CYCLE_SPEED / \
00152 s3timer_total_time
00153
00154 #define s3_timer_footer \
00155 for (int j=0; j<WIDTH_NAME+WIDTH_TOTAL_SECS+WIDTH_PER_SECS+WIDTH_PERCENT; j++)\
00156 std::cout << "-"; std::cout.setf(std::ios::fixed); std::cout << std::endl \
00157 << std::setw(WIDTH_NAME) << "Total:" << \
00158 std::setw(WIDTH_TOTAL_SECS-2) << std::setfill(' ') << std::setprecision(4) << \
00159 s3timer_time_accum \
00160 << std::setw(WIDTH_PER_SECS+WIDTH_PERCENT-0) << \
00161 s3timer_precentage_accum*100 << " %" << std::endl