LoneGazebo / Community-Patch-DLL

Community Patch for Civilization V - Brave New World
Other
293 stars 160 forks source link

How to run the performance profiler? #7382

Closed RecursiveVision closed 3 years ago

RecursiveVision commented 3 years ago

@ilteroi How do I run the performance profiler? I tried attaching it to a release build and enabling CPU performance profiling, then hitting Break All after 50 turns of autoplay, but I just got this error:

a365147ba26600597e6c79583522043e

There are reports of turn time issues...one suspected culprit is AI Rome, but may also be issues with Barbarians/City-States

RecursiveVision commented 3 years ago

Report on the forums:

The last attack for Capturing cities takes so much time and freezes before the dialogue to puppet/annex/raze shows off.

There's a chance your changes may be related?

HungryForFood commented 3 years ago

I got a similar error, I'm guessing the callstack went outside the DLL or something?

Either way I chose the option to ignore error of this type, and it seems to be working now.

RecursiveVision commented 3 years ago

@HungryForFood Well do let me know of your findings when you're done :)

HungryForFood commented 3 years ago

Hmm, where is the option to ignore error of this type, I swear I did it just now, I can't find it again....

Anyway, I think I found something better. I'll detail it from the top.

Firstly, we launch Civ 5 in debug mode, as usual.

So, when trying to use the CPU usage tool thing in VS2019, by enabling CPU profiling:

image

It will throw this error, presumably because it is looking for functions from the main exe instead of our DLL.

image

We ignore the error, and click on open details.

image

Click on the CPU usage tab, then change current view to modules.

image

Now expand the first CivilizationV_DX11.exe list, then look for CvGameCore_Expansion2.dll. Expand that dropdown, then we should now see some familiar function names.

image

These should contain only our stuff which we are interested in. I haven't run the game long, but the numbers seem sensible?

RecursiveVision commented 3 years ago

If CvPlayer::doTurn is only taking up 3.28% of CPU I don't think my changes can be responsible, as they're largely called in doTurn

RecursiveVision commented 3 years ago

Although it is a large chunk of the GameCoreDLL part to be fair

HungryForFood commented 3 years ago

Ran until I crashed. Last call was this in CvGameCoreUtils.h.

image

Call stack was this:

image

Maybe we need a null check here for szString?

Or maybe it just ran out of memory?

image

Anyway, game ran until Renaissance, top CPU usage is as follows:

image

The only function I remember I changed which showed up:

image

I don't think that was a good test though, game was too peaceful. I'll do another test, with more warmongers and higher difficulty, and also enable BUILDINGS_THOROUGH_PREREQUISITES.

HungryForFood commented 3 years ago

Actually ignore the CPU usage stuff, turns out I didn't select enough of the recording session.

HungryForFood commented 3 years ago

CPU profiling of mostly just an AI capturing a city state in Classical. Highlighted is my function.

image

Test still running.

HungryForFood commented 3 years ago

image

Another city state conquest.

image

And another. At this point I'm thinking I need to do the conquest as a human player though to eliminate all the noise.

RecursiveVision commented 3 years ago

Well, good news for me is, diplomacy AI doesn't seem to be ranking high on any of those. I think that means my performance optimizations were helpful...

Still need to figure out what the actual issue is, though.

HungryForFood commented 3 years ago

I did a test by taking over an AI player, then conquering a city with the help of IGE.

Yes, it was my function.

image

Specifically CvCityBuildings::GetBuildingTypeFromClass when called by CvCity::UpdateHappinessFromBuildingClasses.

image

This line specifically.

image

Now that I see it, I understand why. There's 4 layers of nested for loops there, all BuildingClasses ->all BuildingClasses -> each city for the player -> each building that ever existed in the city. I'll do a quick rewrite to hopefully fix it.

The next chunk of free time I have is Tuesday night my time though, so hopefully the refactor is good.