comparison probes.c @ 209:0c83ea8adefc

Close to compilable version of common_ancestor -- still includes HW dep stuff
author Some Random Person <seanhalle@yahoo.com>
date Sun, 04 Mar 2012 14:26:35 -0800
parents eaf7e4c58c9e
children
comparison
equal deleted inserted replaced
15:e7f080727ed6 16:a0d90ce8de7e
11 #include "VMS.h" 11 #include "VMS.h"
12 12
13 13
14 14
15 //==================== Probes ================= 15 //==================== Probes =================
16 #ifdef STATS__USE_TSC_PROBES
17
18 int32
19 VMS__create_histogram_probe( int32 numBins, float32 startValue,
20 float32 binWidth, char *nameStr )
21 { IntervalProbe *newProbe;
22 int32 idx;
23 FloatHist *hist;
24
25 idx = VMS__create_single_interval_probe( nameStr );
26 newProbe = _VMSMasterEnv->intervalProbes[ idx ];
27
28 hist = makeFloatHistogram( numBins, startValue, binWidth );
29 newProbe->hist = hist;
30 return idx;
31 }
32
33 void
34 VMS_impl__record_interval_start_in_probe( int32 probeID )
35 { IntervalProbe *probe;
36
37 probe = _VMSMasterEnv->intervalProbes[ probeID ];
38 probe->startStamp = getTSCount();
39 }
40
41 void
42 VMS_impl__record_interval_end_in_probe( int32 probeID )
43 { IntervalProbe *probe;
44 TSCount endStamp;
45
46 endStamp = getTSCount();
47
48 probe = _VMSMasterEnv->intervalProbes[ probeID ];
49 probe->endStamp = endStamp;
50
51 if( probe->hist != NULL )
52 { TSCount interval = probe->endStamp - probe->startStamp;
53 //if the interval is sane, then add to histogram
54 if( interval < probe->hist->endOfRange * 10 )
55 addToFloatHist( interval, probe->hist );
56 }
57 }
58
59 void
60 VMS_impl__print_stats_of_probe( int32 probeID )
61 { IntervalProbe *probe;
62
63 probe = _VMSMasterEnv->intervalProbes[ probeID ];
64
65 if( probe->hist == NULL )
66 {
67 printf("probe: %s, interval: %.6lf\n", probe->nameStr,probe->interval);
68 }
69
70 else
71 {
72 printf( "probe: %s\n", probe->nameStr );
73 printFloatHist( probe->hist );
74 }
75 }
76 #else
77
78 /* 16 /*
79 * In practice, probe operations are called from the app, from inside slaves 17 * In practice, probe operations are called from the app, from inside slaves
80 * -- so have to be sure each probe is single-VP owned, and be sure that 18 * -- so have to be sure each probe is single-Slv owned, and be sure that
81 * any place common structures are modified it's done inside the master. 19 * any place common structures are modified it's done inside the master.
82 * So -- the only place common structures are modified is during creation. 20 * So -- the only place common structures are modified is during creation.
83 * after that, all mods are to individual instances. 21 * after that, all mods are to individual instances.
84 * 22 *
85 * Thniking perhaps should change the semantics to be that probes are 23 * Thniking perhaps should change the semantics to be that probes are
86 * attached to the virtual processor -- and then everything is guaranteed 24 * attached to the virtual processor -- and then everything is guaranteed
87 * to be isolated -- except then can't take any intervals that span VPs, 25 * to be isolated -- except then can't take any intervals that span Slvs,
88 * and would have to transfer the probes to Master env when VP dissipates.. 26 * and would have to transfer the probes to Master env when Slv dissipates..
89 * gets messy.. 27 * gets messy..
90 * 28 *
91 * For now, just making so that probe creation causes a suspend, so that 29 * For now, just making so that probe creation causes a suspend, so that
92 * the dynamic array in the master env is only modified from the master 30 * the dynamic array in the master env is only modified from the master
93 * 31 *
94 */ 32 */
33
34 //============================ Helpers ===========================
35 inline void
36 doNothing()
37 {
38 }
39
40
95 IntervalProbe * 41 IntervalProbe *
96 create_generic_probe( char *nameStr, SlaveVP *animPr ) 42 create_generic_probe( char *nameStr, SlaveVP *animSlv )
97 { 43 {
98 VMSSemReq reqData; 44 VMSSemReq reqData;
99 45
100 reqData.reqType = createProbe; 46 reqData.reqType = createProbe;
101 reqData.nameStr = nameStr; 47 reqData.nameStr = nameStr;
102 48
103 VMS_WL__send_VMSSem_request( &reqData, animPr ); 49 VMS_WL__send_VMSSem_request( &reqData, animSlv );
104 50
105 return animPr->dataRetFromReq; 51 return animSlv->dataRetFromReq;
106 } 52 }
107 53
108 /*Use this version from outside VMS -- it uses external malloc, and modifies 54 /*Use this version from outside VMS -- it uses external malloc, and modifies
109 * dynamic array, so can't be animated in a slave VP 55 * dynamic array, so can't be animated in a slave Slv
110 */ 56 */
111 IntervalProbe * 57 IntervalProbe *
112 ext__create_generic_probe( char *nameStr ) 58 ext__create_generic_probe( char *nameStr )
113 { IntervalProbe *newProbe; 59 { IntervalProbe *newProbe;
114 int32 nameLen; 60 int32 nameLen;
123 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo ); 69 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
124 70
125 return newProbe; 71 return newProbe;
126 } 72 }
127 73
74 //============================ Fns def in header =======================
75
76 int32
77 VMS_impl__create_single_interval_probe( char *nameStr, SlaveVP *animSlv )
78 { IntervalProbe *newProbe;
79
80 newProbe = create_generic_probe( nameStr, animSlv );
81
82 return newProbe->probeID;
83 }
84
85 int32
86 VMS_impl__create_histogram_probe( int32 numBins, float64 startValue,
87 float64 binWidth, char *nameStr, SlaveVP *animSlv )
88 { IntervalProbe *newProbe;
89 DblHist *hist;
90
91 newProbe = create_generic_probe( nameStr, animSlv );
92
93 hist = makeDblHistogram( numBins, startValue, binWidth );
94 newProbe->hist = hist;
95 return newProbe->probeID;
96 }
97
98
99 int32
100 VMS_impl__record_time_point_into_new_probe( char *nameStr, SlaveVP *animSlv)
101 { IntervalProbe *newProbe;
102 struct timeval *startStamp;
103 float64 startSecs;
104
105 newProbe = create_generic_probe( nameStr, animSlv );
106 newProbe->endSecs = 0;
107
108 gettimeofday( &(newProbe->startStamp), NULL);
109
110 //turn into a double
111 startStamp = &(newProbe->startStamp);
112 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
113 newProbe->startSecs = startSecs;
114
115 return newProbe->probeID;
116 }
117
118 int32
119 VMS_ext_impl__record_time_point_into_new_probe( char *nameStr )
120 { IntervalProbe *newProbe;
121 struct timeval *startStamp;
122 float64 startSecs;
123
124 newProbe = ext__create_generic_probe( nameStr );
125 newProbe->endSecs = 0;
126
127 gettimeofday( &(newProbe->startStamp), NULL);
128
129 //turn into a double
130 startStamp = &(newProbe->startStamp);
131 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
132 newProbe->startSecs = startSecs;
133
134 return newProbe->probeID;
135 }
136
128 137
129 /*Only call from inside master or main startup/shutdown thread 138 /*Only call from inside master or main startup/shutdown thread
130 */ 139 */
131 void 140 void
132 VMS_impl__free_probe( IntervalProbe *probe ) 141 VMS_impl__free_probe( IntervalProbe *probe )
134 if( probe->nameStr != NULL) VMS_int__free( probe->nameStr ); 143 if( probe->nameStr != NULL) VMS_int__free( probe->nameStr );
135 VMS_int__free( probe ); 144 VMS_int__free( probe );
136 } 145 }
137 146
138 147
139 int32 148 void
140 VMS_impl__record_time_point_into_new_probe( char *nameStr, SlaveVP *animPr) 149 VMS_impl__index_probe_by_its_name( int32 probeID, SlaveVP *animSlv )
141 { IntervalProbe *newProbe;
142 struct timeval *startStamp;
143 float64 startSecs;
144
145 newProbe = create_generic_probe( nameStr, animPr );
146 newProbe->endSecs = 0;
147
148 gettimeofday( &(newProbe->startStamp), NULL);
149
150 //turn into a double
151 startStamp = &(newProbe->startStamp);
152 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
153 newProbe->startSecs = startSecs;
154
155 return newProbe->probeID;
156 }
157
158 int32
159 VMS_ext_impl__record_time_point_into_new_probe( char *nameStr )
160 { IntervalProbe *newProbe;
161 struct timeval *startStamp;
162 float64 startSecs;
163
164 newProbe = ext__create_generic_probe( nameStr );
165 newProbe->endSecs = 0;
166
167 gettimeofday( &(newProbe->startStamp), NULL);
168
169 //turn into a double
170 startStamp = &(newProbe->startStamp);
171 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
172 newProbe->startSecs = startSecs;
173
174 return newProbe->probeID;
175 }
176
177 int32
178 VMS_impl__create_single_interval_probe( char *nameStr, SlaveVP *animPr )
179 { IntervalProbe *newProbe;
180
181 newProbe = create_generic_probe( nameStr, animPr );
182
183 return newProbe->probeID;
184 }
185
186 int32
187 VMS_impl__create_histogram_probe( int32 numBins, float64 startValue,
188 float64 binWidth, char *nameStr, SlaveVP *animPr )
189 { IntervalProbe *newProbe;
190 DblHist *hist;
191
192 newProbe = create_generic_probe( nameStr, animPr );
193
194 hist = makeDblHistogram( numBins, startValue, binWidth );
195 newProbe->hist = hist;
196 return newProbe->probeID;
197 }
198
199 void
200 VMS_impl__index_probe_by_its_name( int32 probeID, SlaveVP *animPr )
201 { IntervalProbe *probe; 150 { IntervalProbe *probe;
202 151
203 //TODO: fix this To be in Master -- race condition 152 //TODO: fix this To be in Master -- race condition
204 probe = _VMSMasterEnv->intervalProbes[ probeID ]; 153 probe = _VMSMasterEnv->intervalProbes[ probeID ];
205 154
206 addValueIntoTable(probe->nameStr, probe, _VMSMasterEnv->probeNameHashTbl); 155 addValueIntoTable(probe->nameStr, probe, _VMSMasterEnv->probeNameHashTbl);
207 } 156 }
208 157
158
209 IntervalProbe * 159 IntervalProbe *
210 VMS_impl__get_probe_by_name( char *probeName, SlaveVP *animPr ) 160 VMS_impl__get_probe_by_name( char *probeName, SlaveVP *animSlv )
211 { 161 {
212 //TODO: fix this To be in Master -- race condition 162 //TODO: fix this To be in Master -- race condition
213 return getValueFromTable( probeName, _VMSMasterEnv->probeNameHashTbl ); 163 return getValueFromTable( probeName, _VMSMasterEnv->probeNameHashTbl );
214 } 164 }
215 165
216 166
217 /*Everything is local to the animating procr, so no need for request, do 167 /*Everything is local to the animating procr, so no need for request, do
218 * work locally, in the anim Pr 168 * work locally, in the anim Slv
219 */ 169 */
220 void 170 void
221 VMS_impl__record_sched_choice_into_probe( int32 probeID, SlaveVP *animatingPr ) 171 VMS_impl__record_sched_choice_into_probe( int32 probeID, SlaveVP *animatingSlv )
222 { IntervalProbe *probe; 172 { IntervalProbe *probe;
223 173
224 probe = _VMSMasterEnv->intervalProbes[ probeID ]; 174 probe = _VMSMasterEnv->intervalProbes[ probeID ];
225 probe->schedChoiceWasRecorded = TRUE; 175 probe->schedChoiceWasRecorded = TRUE;
226 probe->coreNum = animatingPr->coreAnimatedBy; 176 probe->coreNum = animatingSlv->coreAnimatedBy;
227 probe->procrID = animatingPr->procrID; 177 probe->slaveID = animatingSlv->procrID;
228 probe->procrCreateSecs = animatingPr->createPtInSecs; 178 probe->slaveCreateSecs = animatingSlv->createPtInSecs;
229 } 179 }
230 180
231 /*Everything is local to the animating procr, so no need for request, do 181 /*Everything is local to the animating procr, so no need for request, do
232 * work locally, in the anim Pr 182 * work locally, in the anim Slv
233 */ 183 */
234 void 184 void
235 VMS_impl__record_interval_start_in_probe( int32 probeID ) 185 VMS_impl__record_interval_start_in_probe( int32 probeID )
236 { IntervalProbe *probe; 186 { IntervalProbe *probe;
237 187
238 DEBUG( dbgProbes, "record start of interval\n" ) 188 DEBUG( dbgProbes, "record start of interval\n" )
239 probe = _VMSMasterEnv->intervalProbes[ probeID ]; 189 probe = _VMSMasterEnv->intervalProbes[ probeID ];
240 gettimeofday( &(probe->startStamp), NULL ); 190 probe->startStamp = getTSCount();
241 } 191 }
242 192
243 193
244 /*Everything is local to the animating procr, so no need for request, do 194 /*Everything is local to the animating procr, so no need for request, do
245 * work locally, in the anim Pr 195 * work locally, in the anim Slv
196 *
197 *This should be safe to run inside SlaveVP -- weird behavior will be due
198 * to the logical error of having more than one interval open in overlapped.
246 */ 199 */
247 void 200 void
248 VMS_impl__record_interval_end_in_probe( int32 probeID ) 201 VMS_impl__record_interval_end_in_probe( int32 probeID )
249 { IntervalProbe *probe; 202 { IntervalProbe *probe;
250 struct timeval *endStamp, *startStamp; 203 TSCount endStamp;
251 float64 startSecs, endSecs; 204
252 205 endStamp = getTSCount();
206
253 DEBUG( dbgProbes, "record end of interval\n" ) 207 DEBUG( dbgProbes, "record end of interval\n" )
254 //possible seg-fault if array resized by diff core right after this 208
255 // one gets probe..? Something like that? Might be safe.. don't care 209 probe = _VMSMasterEnv->intervalProbes[ probeID ];
256 probe = _VMSMasterEnv->intervalProbes[ probeID ]; 210 probe->endStamp = endStamp;
257 gettimeofday( &(probe->endStamp), NULL);
258
259 //now turn into an interval held in a double
260 startStamp = &(probe->startStamp);
261 endStamp = &(probe->endStamp);
262
263 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
264 endSecs = endStamp->tv_sec + ( endStamp->tv_usec / 1000000.0 );
265
266 probe->interval = endSecs - startSecs;
267 probe->startSecs = startSecs;
268 probe->endSecs = endSecs;
269 211
270 if( probe->hist != NULL ) 212 if( probe->hist != NULL )
271 { 213 { TSCount interval = probe->endStamp - probe->startStamp;
272 //if the interval is sane, then add to histogram 214 //if the interval is sane, then add to histogram
273 if( probe->interval < probe->hist->endOfRange * 10 ) 215 if( interval < probe->hist->endOfRange * 10 )
274 addToDblHist( probe->interval, probe->hist ); 216 addToFloatHist( interval, probe->hist );
275 } 217 }
276 } 218 }
219
277 220
278 void 221 void
279 print_probe_helper( IntervalProbe *probe ) 222 print_probe_helper( IntervalProbe *probe )
280 { 223 {
281 printf( "\nprobe: %s, ", probe->nameStr ); 224 printf( "\nprobe: %s, ", probe->nameStr );
282 225
283 226
284 if( probe->schedChoiceWasRecorded ) 227 if( probe->schedChoiceWasRecorded )
285 { printf( "coreNum: %d, procrID: %d, procrCreated: %0.6f | ", 228 { printf( "coreNum: %d, procrID: %d, procrCreated: %0.6f | ",
286 probe->coreNum, probe->procrID, probe->procrCreateSecs ); 229 probe->coreNum, probe->slaveID, probe->slaveCreateSecs );
287 } 230 }
288 231
289 if( probe->endSecs == 0 ) //just a single point in time 232 if( probe->endSecs == 0 ) //just a single point in time
290 { 233 {
291 printf( " time point: %.6f\n", 234 printf( " time point: %.6f\n",
316 259
317 print_probe_helper( probe ); 260 print_probe_helper( probe );
318 } 261 }
319 262
320 263
321 inline void doNothing(){};
322
323 void
324 generic_print_probe( void *_probe )
325 {
326 IntervalProbe *probe = (IntervalProbe *)_probe;
327
328 //TODO segfault in printf
329 //print_probe_helper( probe );
330 }
331
332 void 264 void
333 VMS_impl__print_stats_of_all_probes() 265 VMS_impl__print_stats_of_all_probes()
334 { 266 {
335 forAllInDynArrayDo( _VMSMasterEnv->dynIntervalProbesInfo, 267 forAllInDynArrayDo( _VMSMasterEnv->dynIntervalProbesInfo,
336 &generic_print_probe ); 268 &VMS_impl__print_stats_of_probe );
337 fflush( stdout ); 269 fflush( stdout );
338 } 270 }
339 #endif