|
27 | 27 | #include "osapi/osapi.h" // for multi-thread macros |
28 | 28 |
|
29 | 29 |
|
30 | | - |
31 | | -#ifndef NDEBUG |
32 | | - #define USE_TIMING |
33 | | -#endif |
34 | | - |
35 | 30 | #ifdef _WIN32 |
36 | 31 | static longlong Timer_last_value = 0, Timer_base = 0, Timer_freq = 0; |
37 | 32 | static const int precision = 1; |
@@ -288,219 +283,3 @@ int timestamp_has_time_elapsed(int stamp, int time) |
288 | 283 | return 0; |
289 | 284 | } |
290 | 285 |
|
291 | | -// timing functions ------------------------------------------------------------------------------- |
292 | | - |
293 | | -#define MAX_TIMING_EVENTS 15 |
294 | | - |
295 | | -// timing struct |
296 | | -#ifdef USE_TIMING |
297 | | - |
298 | | -typedef struct timing { |
299 | | - char name[64]; |
300 | | - int microseconds_total; |
301 | | - int start; |
302 | | - int ref_count; |
303 | | -} timing; |
304 | | - |
305 | | -timing Timing_frame; |
306 | | -timing Timing_events[MAX_TIMING_EVENTS]; |
307 | | -int Timing_event_count = 0; |
308 | | - |
309 | | -#endif |
310 | | - |
311 | | -// lookup a timing event |
312 | | -int timing_event_lookup(char *event_name) |
313 | | -{ |
314 | | -#ifndef USE_TIMING |
315 | | - return -1; |
316 | | -#else |
317 | | - int idx; |
318 | | - |
319 | | - // sanity |
320 | | - if(event_name == NULL){ |
321 | | - return -1; |
322 | | - } |
323 | | - |
324 | | - // look through all events |
325 | | - for(idx=0; idx<MAX_TIMING_EVENTS; idx++){ |
326 | | - if(!stricmp(Timing_events[idx].name, event_name)){ |
327 | | - return idx; |
328 | | - } |
329 | | - } |
330 | | - |
331 | | - return -1; |
332 | | -#endif |
333 | | -} |
334 | | - |
335 | | -// start timing frame stuff |
336 | | -void timing_frame_start() |
337 | | -{ |
338 | | -#ifndef USE_TIMING |
339 | | - return; |
340 | | -#else |
341 | | - int idx; |
342 | | - |
343 | | - // restart the frame |
344 | | - Timing_event_count = 0; |
345 | | - Timing_frame.start = timer_get_microseconds(); |
346 | | - for(idx=0; idx<MAX_TIMING_EVENTS; idx++){ |
347 | | - Timing_events[idx].microseconds_total = 0; |
348 | | - strcpy_s(Timing_events[idx].name, ""); |
349 | | - Timing_events[idx].ref_count = 0; |
350 | | - } |
351 | | -#endif |
352 | | -} |
353 | | - |
354 | | -// done timing the frame |
355 | | -void timing_frame_stop() |
356 | | -{ |
357 | | -#ifndef USE_TIMING |
358 | | - return; |
359 | | -#else |
360 | | - int stop_time; |
361 | | - |
362 | | - // stop time |
363 | | - stop_time = timer_get_microseconds(); |
364 | | - |
365 | | - // calc times |
366 | | - Timing_frame.microseconds_total = stop_time - Timing_frame.start; |
367 | | -#endif |
368 | | -} |
369 | | - |
370 | | -// get the total frame time in microseconds |
371 | | -int timing_frame_total() |
372 | | -{ |
373 | | -#ifndef USE_TIMING |
374 | | - return 0; |
375 | | -#else |
376 | | - return Timing_frame.microseconds_total; |
377 | | -#endif |
378 | | -} |
379 | | - |
380 | | -// time an individual event |
381 | | -void timing_event_start(char *event_name) |
382 | | -{ |
383 | | -#ifndef USE_TIMING |
384 | | - return; |
385 | | -#else |
386 | | - int event; |
387 | | - |
388 | | - // sanity |
389 | | - if(event_name == NULL){ |
390 | | - return; |
391 | | - } |
392 | | - |
393 | | - // try and find the event |
394 | | - event = timing_event_lookup(event_name); |
395 | | - |
396 | | - // if we already have one |
397 | | - if(event != -1){ |
398 | | - Assert(Timing_events[event].ref_count == 0); |
399 | | - Timing_events[event].start = timer_get_microseconds(); |
400 | | - Timing_events[event].ref_count++; |
401 | | - } |
402 | | - // if we need to add a new one |
403 | | - else { |
404 | | - if(Timing_event_count < MAX_TIMING_EVENTS){ |
405 | | - strcpy_s(Timing_events[Timing_event_count].name, event_name); |
406 | | - Timing_events[Timing_event_count].start = timer_get_microseconds(); |
407 | | - Timing_events[Timing_event_count++].ref_count++; |
408 | | - } |
409 | | - } |
410 | | -#endif |
411 | | -} |
412 | | - |
413 | | -// stop timing an event |
414 | | -void timing_event_stop(char *event_name) |
415 | | -{ |
416 | | -#ifndef USE_TIMING |
417 | | - return; |
418 | | -#else |
419 | | - int event; |
420 | | - |
421 | | - // sanity |
422 | | - if(event_name == NULL){ |
423 | | - return; |
424 | | - } |
425 | | - |
426 | | - // try and find the event |
427 | | - event = timing_event_lookup(event_name); |
428 | | - |
429 | | - // if we already have one |
430 | | - if(event != -1){ |
431 | | - Assert(Timing_events[event].ref_count == 1); |
432 | | - Timing_events[event].microseconds_total += timer_get_microseconds() - Timing_events[event].start; |
433 | | - Timing_events[event].ref_count--; |
434 | | - } |
435 | | -#endif |
436 | | -} |
437 | | - |
438 | | -// get the total time for an event in microseconds |
439 | | -int timing_event_total(char *event_name) |
440 | | -{ |
441 | | -#ifndef USE_TIMING |
442 | | - return -1; |
443 | | -#else |
444 | | - int event; |
445 | | - |
446 | | - // sanity |
447 | | - if(event_name == NULL){ |
448 | | - return -1; |
449 | | - } |
450 | | - |
451 | | - // try and find the event |
452 | | - event = timing_event_lookup(event_name); |
453 | | - if(event == -1){ |
454 | | - return -1; |
455 | | - } |
456 | | - |
457 | | - return Timing_events[event].microseconds_total; |
458 | | -#endif |
459 | | -} |
460 | | - |
461 | | -// get the percentage of total frametime for the event (0.0 to 1.0) |
462 | | -float timing_event_pct(char *event_name) |
463 | | -{ |
464 | | -#ifndef USE_TIMING |
465 | | - return 0.0f; |
466 | | -#else |
467 | | - int event; |
468 | | - |
469 | | - // sanity |
470 | | - if(event_name == NULL){ |
471 | | - return -1.0f; |
472 | | - } |
473 | | - |
474 | | - // try and find the event |
475 | | - event = timing_event_lookup(event_name); |
476 | | - if(event == -1){ |
477 | | - return -1.0f; |
478 | | - } |
479 | | - |
480 | | - return (float)((double)Timing_events[event].microseconds_total / (double)Timing_frame.microseconds_total); |
481 | | -#endif |
482 | | -} |
483 | | - |
484 | | -// display timing |
485 | | -void timing_display(int x, int y) |
486 | | -{ |
487 | | -#ifndef USE_TIMING |
488 | | - return; |
489 | | -#else |
490 | | - int idx; |
491 | | - |
492 | | - int line_height = gr_get_font_height() + 1; |
493 | | - |
494 | | - gr_set_color_fast(&Color_bright_blue); |
495 | | - |
496 | | - // total time |
497 | | - gr_printf_no_resize(x, y, "Total time %f\n", (float)timing_frame_total() / 1000000.0f); |
498 | | - y += line_height; |
499 | | - |
500 | | - // each event percentage |
501 | | - for(idx=0; idx<Timing_event_count; idx++){ |
502 | | - gr_printf_no_resize(x, y, "%s: %f\n", Timing_events[idx].name, timing_event_pct(Timing_events[idx].name)); |
503 | | - y += line_height; |
504 | | - } |
505 | | -#endif |
506 | | -} |
0 commit comments