Page 1 of 1

patch: performance meter

Posted: 16 Jul 2007 16:22
by skidd13
I've been working on a patch to get a impression of the current performance of the code (for developers who want to optimize their code) and for normal users to get their FPS (TPS (Realtime) ≙ FPS). The initial design has been made by Zojj due to testing his "simplified realistic acceleration" patch.

[list]Changelog
[*]Overtake Zojj's patch
[*]Moved the the globals to a struct
[*]Optimisation & simplification of code
[*]More comments
[*]Start/stop button
[*]Sticky button
[*]Split the code off from the main gui to it's own files
[*]Toolbar entry
[*]Shortcut [alt]+[ctrl]+[p]
[*]Added type timestamp
[*]Moved code to C++
[*]Added switch for realtime/cputime[/list]
  • Different modes:
  • Ticks/Frames per second realtime (This value has influences from the environment)
  • Ticks per second CPU time (Here is only the time counted on which the process runs on the CPU / environment independent)
  • CPU cycles per code call (take a look at town_cmd.cpp how to use the stuff)
If you want to use the patch don't forget to replace your openttd.grf with the attatched one.

Thanks to B. N. SmatZ! for debuging my code.
:bow: Big thanks to KUDr for improving my programming skills.

Re: patch: performance meter

Posted: 16 Jul 2007 16:57
by Bilbo
Hmmm ... I wonder it it would be possible to add also frames per second indicator there. Or is 1 frame always equal to 1 tick?

Re: patch: performance meter

Posted: 16 Jul 2007 17:01
by skidd13
Bilbo wrote:Hmmm ... I wonder it it would be possible to add also frames per second indicator there. Or is 1 frame always equal to 1 tick?
1 tick includes AFAIK 1 redraw, so it should be the same.

Re: patch: performance meter

Posted: 16 Jul 2007 17:07
by Bilbo
skidd13 wrote:
Bilbo wrote:Hmmm ... I wonder it it would be possible to add also frames per second indicator there. Or is 1 frame always equal to 1 tick?
1 tick includes AFAIK 1 redraw, so it should be the same.
Hmm .. so maybe I thought of one improvement for OpenTTD. When in fast forward mode, do not draw more than X frames per second. Humans can't distinguish between 120 and 1200 fps anyway, especially if they have 60Hz LCD panel :)

So perhaps add code like "if time from last frame was less than 1/X, skip drawing :)".
This may be useful, as it will make the fast forward mode even faster :)

Re: patch: performance meter

Posted: 16 Jul 2007 18:31
by skidd13
Bilbo wrote:
skidd13 wrote:
Bilbo wrote:Hmmm ... I wonder it it would be possible to add also frames per second indicator there. Or is 1 frame always equal to 1 tick?
1 tick includes AFAIK 1 redraw, so it should be the same.
Hmm .. so maybe I thought of one improvement for OpenTTD. When in fast forward mode, do not draw more than X frames per second. Humans can't distinguish between 120 and 1200 fps anyway, especially if they have 60Hz LCD panel :)

So perhaps add code like "if time from last frame was less than 1/X, skip drawing :)".
This may be useful, as it will make the fast forward mode even faster :)
I discussed that with B. N. SmatZ too (IIRC it was him). But only one step by one. ;)

Re: patch: performance meter

Posted: 17 Jul 2007 18:23
by Mchl
How about having also min and max t/s apart from current and average values?

These are useful. If your min and max stay close to average, then your perfomance is steady. On the other hand, when they're spread apart your game may be quite a strange experience.

Re: patch: performance meter

Posted: 20 Jul 2007 19:50
by Bilbo
Ok, when I tried it, it won't compile with mingw + msys:

[SRC] Compiling performance_gui.cpp
e:/p/svn.openttd.org/trunk/src/performance_gui.cpp: In function `timestamp GetTimestamp()':
e:/p/svn.openttd.org/trunk/src/performance_gui.cpp:60: error: `SYSTEMTIME' undeclared (first use this function)
e:/p/svn.openttd.org/trunk/src/performance_gui.cpp:60: error: (Each undeclared identifier is reported only once for each function it appears in.)
e:/p/svn.openttd.org/trunk/src/performance_gui.cpp:60: error: expected `;' before "st"
e:/p/svn.openttd.org/trunk/src/performance_gui.cpp:61: error: `st' undeclared (first use this function)
e:/p/svn.openttd.org/trunk/src/performance_gui.cpp:61: error: `GetSystemTime' undeclared (first use this function)
make[1]: *** [performance_gui.o] Error 1
make[1]: Leaving directory `/e/p/svn.openttd.org/trunk/objs/release'

When I replaced body of GetTimestamp() with following line:

return ((clock() * 1000) / CLOCKS_PER_SEC);

it compiled fine.

Re: patch: performance meter

Posted: 20 Jul 2007 20:03
by skidd13
Bilbo wrote:Ok, when I tried it, it won't compile with mingw + msys:

When I replaced body of GetTimestamp() with following line:

return ((clock() * 1000) / CLOCKS_PER_SEC);

it compiled fine.
The patch is a bit outdated for now. I'm working on it. The systemtime is something done by Zojj. It'll be replaced with the clock thing in the next version.

Re: patch: performance meter

Posted: 20 Jul 2007 20:23
by Bilbo
Also, I noticed one a bit weird thing, when not using fast forward, the "current" reads 40 ticks/s (though it ocassionaly flips to 30 or 50) but average says 31.3 /s :) Perhaps a bit inconsistent :)

Re: patch: performance meter

Posted: 27 Jul 2007 10:39
by skidd13
Bilbo wrote:Also, I noticed one a bit weird thing, when not using fast forward, the "current" reads 40 ticks/s (though it ocassionaly flips to 30 or 50) but average says 31.3 /s :) Perhaps a bit inconsistent :)
To have a correct measure you need a full load CPU. If you have huge games like the ones from the coop server you'll get even without FF to full CPU load.

[EDIT]Patch updated again.[/EDIT]

Re: patch: performance meter

Posted: 27 Jul 2007 22:38
by l_Blue_l
i have so needed this to test some patches of mine. Great work to all involved. Just wondering what about a way to time how long a single operation takes and produce a log file.

Edit: There allready is i just didnt know about it.

Re: patch: performance meter

Posted: 28 Jul 2007 07:51
by peter1138
The TIC() and TOC(s, n) macros have existed for just that purpose for a long time...

Re: patch: performance meter

Posted: 28 Jul 2007 08:24
by l_Blue_l
:roll: well silly me then. Thanks for letting me know. I will have to give it a try sometime

Re: patch: performance meter

Posted: 08 Aug 2007 20:15
by skidd13
Patch updated with a new type CPU cycles per code call. To use this type check town_cmd.cpp in the diff. Then remove the edits from there and add them there where you want to test your code. Happy benchmarks. ;)

[EDIT] Patch updated. Last version had a few bugs. Sorry