Fundynamic / RealBot

Counter-Strike 1.6 - AI Opponent
http://realbot.bots-united.com
53 stars 19 forks source link

rblog() causes extremely low FPS when running on normal magnetic HDD (non-SSD) #13

Closed weimzh closed 5 years ago

weimzh commented 6 years ago

as title.

video: https://youtu.be/5g2ZyasCHQc

I profiled a bit with Instruments tool included with xcode, and found that rblog() (which writes a lot of log messages to reallog.txt) caused problem: screen shot 2018-09-05 at 10 25 25 pm

possible solution: only open the reallog.txt file once, and close it when program exits.

stefanhendriks commented 6 years ago

nice find. I saw that video and noticed that stuttering - not good.

Maybe you can explain to me some time how you run XCode Instruments with RealBot? It would be helpful for me to debug and see myself. (Now I use CLion from Jetbrains and run make from cmd line).

One thing though about this issue. rblog always opened file and such. One thing I change recently is added a printf in that function. Perhaps that causes the stuttering? Or did you also have the stuttering on the 'older' versions of RealBot? (ie build 30xx?)

weimzh commented 6 years ago

the above screenshot already shown that the problem is caused by fopen()/fclose() (under cBot::setGoalNode() call). printf() does not take much time there.

EDIT: check out one of the answers in this question for detailed usage of instruments tool: https://stackoverflow.com/questions/11445619/profiling-c-on-mac-os-x/11445777

stefanhendriks commented 6 years ago

Sure thing. I already started working on this in between work ;-)

stefanhendriks commented 5 years ago

i had some left-over changes. Pushed it regarding this. Basically it opens the file once (on startup). Unfortunately I could not find a quick way to close the file at the right moment.

stefanhendriks commented 5 years ago

@CecilHarvey let me know if you need a binary or you could compile it yourself. I suppose the latter since you managed to get it working on your mac ;-)

stefanhendriks commented 5 years ago

Do note, latest commits (after d566476) have by default logging enabled (debug messages), which spam your log file. So do not use that.

weimzh commented 5 years ago

sorry for late reply

I tested commit d566476 under Fedora GNU/Linux (as latest version of xcode no longer supports compiling for 32-bit - which unfornately means Half-Life for macOS will be dead soon if not updated to 64-bit), and fps is good.

stefanhendriks commented 5 years ago

no probs.

Too bad about macOS, I am still on Sierra, so I'm still good I guess.

Good to hear it was fixed with this patch.

Although I think why i close/reopen the file. I noticed if I don't do this that upon a crash sometimes not all data is flushed to a file.

APGRoboCop commented 5 years ago

Yes well that Mac OS X Catalina is bloody ridiculous along with Apples overpriced computers and phones. So you maybe best off ignoring macOS for the future...

stefanhendriks commented 5 years ago

@CecilHarvey instead of open/close, i use fflush now. All is well, you can use the latest commit now if you want.