# HG changeset patch # User Darkvater # Date 1143407709 0 # Node ID b8febc9509d7e7f9c3780919fbde4331238c4546 # Parent eb5021cb6639f5b4b2d885e8a90570e61c6acd5b (svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later. diff -r eb5021cb6639 -r b8febc9509d7 Makefile --- a/Makefile Sun Mar 26 21:13:16 2006 +0000 +++ b/Makefile Sun Mar 26 21:15:09 2006 +0000 @@ -670,6 +670,7 @@ SRCS += openttd.c SRCS += order_cmd.c SRCS += order_gui.c +SRCS += os_timer.c SRCS += pathfind.c SRCS += player_gui.c SRCS += players.c diff -r eb5021cb6639 -r b8febc9509d7 debug.h --- a/debug.h Sun Mar 26 21:13:16 2006 +0000 +++ b/debug.h Sun Mar 26 21:15:09 2006 +0000 @@ -26,4 +26,27 @@ void SetDebugString(const char *s); const char *GetDebugString(void); +/* MSVC of course has to have a different syntax for long long *sigh* */ +#ifdef _MSC_VER +# define OTTD_PRINTF64 "I64" +#else +# define OTTD_PRINTF64 "ll" +#endif + +// Used for profiling +#define TIC() {\ + extern uint64 _rdtsc(void);\ + uint64 _xxx_ = _rdtsc();\ + static uint64 __sum__ = 0;\ + static uint32 __i__ = 0; + +#define TOC(str, count)\ + __sum__ += _rdtsc() - _xxx_;\ + if (++__i__ == count) {\ + printf("[%s]: %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\ + __i__ = 0;\ + __sum__ = 0;\ + }\ +} + #endif /* DEBUG_H */ diff -r eb5021cb6639 -r b8febc9509d7 functions.h --- a/functions.h Sun Mar 26 21:13:16 2006 +0000 +++ b/functions.h Sun Mar 26 21:15:09 2006 +0000 @@ -116,12 +116,6 @@ uint32 InteractiveRandom(void); /* Used for random sequences that are not the same on the other end of the multiplayer link */ uint InteractiveRandomRange(uint max); - -// Used for profiling -#define TIC() { extern uint32 _rdtsc(void); uint32 _xxx_ = _rdtsc(); static float __avg__; -#define TOC(s) _xxx_ = _rdtsc() - _xxx_; __avg__=__avg__*0.99+_xxx_*0.01; printf("%s: %8d %f\n", s, _xxx_,__avg__); } - - void SetDate(uint date); /* facedraw.c */ void DrawPlayerFace(uint32 face, int color, int x, int y); diff -r eb5021cb6639 -r b8febc9509d7 openttd.dsp --- a/openttd.dsp Sun Mar 26 21:13:16 2006 +0000 +++ b/openttd.dsp Sun Mar 26 21:15:09 2006 +0000 @@ -339,6 +339,12 @@ # End Source File # Begin Source File +SOURCE=.\os_timer.c +# End Source File +# Begin Source File + +# Begin Source File + SOURCE=.\pathfind.c # End Source File # Begin Source File diff -r eb5021cb6639 -r b8febc9509d7 openttd.vcproj --- a/openttd.vcproj Sun Mar 26 21:13:16 2006 +0000 +++ b/openttd.vcproj Sun Mar 26 21:15:09 2006 +0000 @@ -299,6 +299,9 @@ RelativePath=".\ottdres.rc"> + +