Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Feature/eggwatch #1296

Closed
wants to merge 22 commits into from
Closed

Draft: Feature/eggwatch #1296

wants to merge 22 commits into from

Conversation

Birkow
Copy link
Contributor

@Birkow Birkow commented Sep 7, 2024

lua script adding similar functionality to nestboxes with enhancements allowing to limit number of eggs forbidden per race and include live children/adult animals count in limit check.

@ab9rf
Copy link
Member

ab9rf commented Sep 7, 2024

there's no reason nestboxes should be a plugin, and replacing it with a more featureful script is entirely ok with me even if it does mean retiring my very first contributions to dfhack :)

@myk002
Copy link
Member

myk002 commented Sep 7, 2024

I'd like to understand the performance profile for a script that runs as frequently as this will. Can you show a perf report? Enable eggwatch, save the game, load it, and play "normally" for 5-10 minutes. Then save the game again. You can get the perf report from the savegame directory.

@ab9rf
Copy link
Member

ab9rf commented Sep 7, 2024

the nestbox scan itself should not be that expensive but the scan to count animals is likely to be more so. it might be an idea to run that scan less frequently and cache its results for use in the more frequent nestbox scan, which has to be run frequently or there's a chance that newly laid eggs will get snagged by hauler

but it's probably best to see profiling data before determining if such an optimization is needed

@Birkow
Copy link
Contributor Author

Birkow commented Sep 7, 2024

Is it correct file? this one is from save after running game with eggwatch script for ~10 minutes
https://drive.google.com/file/d/1Si389dgAXzuWuldrbvYKPsthX-YeAG8X/view?usp=drive_link
Edit:
Most of calls to script will end as soon as it's determined that created item is not fertile egg.
Edit2: fixed issue with link

@Birkow
Copy link
Contributor Author

Birkow commented Sep 8, 2024

Did some refactoring, added tags for script-enable-api, added hook dfhack.onStateChange, replaced internal use of creature_id with race. Pref report after last changes below:

dfhack-perf-counters.dat Summary -------

Measuring unpaused time only

elapsed 1757311 ms (29m 17s)
dfhack 110260 ms ( 6.27% of elapsed)

DFHack details

keybinding 0 ms ( 0.00% of dfhack, 0.00% of elapsed)
update 21603 ms ( 19.59% of dfhack, 1.23% of elapsed)
overlay 88595 ms ( 80.35% of dfhack, 5.04% of elapsed)
zscreen 62 ms ( 0.06% of dfhack, 0.00% of elapsed)

Update details

event manager 4356 ms ( 20.16% of update, 0.25% of elapsed)
plugin onUpdate 11768 ms ( 54.47% of update, 0.67% of elapsed)
lua timers 5103 ms ( 23.62% of update, 0.29% of elapsed)

Event manager per event type

      UNIT_NEW_ACTIVE     1470 ms ( 33.75% of event manager,   0.08% of elapsed)
        JOB_COMPLETED     1013 ms ( 23.26% of event manager,   0.06% of elapsed)
          JOB_STARTED      716 ms ( 16.44% of event manager,   0.04% of elapsed)
        JOB_INITIATED      439 ms ( 10.08% of event manager,   0.02% of elapsed)
             BUILDING      310 ms (  7.12% of event manager,   0.02% of elapsed)
         ITEM_CREATED       62 ms (  1.42% of event manager,   0.00% of elapsed)

            framework      346 ms (  7.94% of event manager,   0.02% of elapsed)
        all subtimers     4010 ms ( 92.06% of event manager,   0.23% of elapsed)

Event manager JOB_INITIATED event per plugin

             eventful      267 ms ( 60.82% of event type,   0.02% of elapsed)
       suspendmanager       47 ms ( 10.71% of event type,   0.00% of elapsed)

            framework      125 ms ( 28.47% of event type,   0.01% of elapsed)
        all subtimers      314 ms ( 71.53% of event type,   0.02% of elapsed)

Event manager JOB_STARTED event per plugin

            framework      716 ms (100.00% of event type,   0.04% of elapsed)
        all subtimers        0 ms (  0.00% of event type,   0.00% of elapsed)

Event manager JOB_COMPLETED event per plugin

            framework     1013 ms (100.00% of event type,   0.06% of elapsed)
        all subtimers        0 ms (  0.00% of event type,   0.00% of elapsed)

Event manager ITEM_CREATED event per plugin

             eventful       46 ms ( 74.19% of event type,   0.00% of elapsed)

            framework       16 ms ( 25.81% of event type,   0.00% of elapsed)
        all subtimers       46 ms ( 74.19% of event type,   0.00% of elapsed)

Event manager UNIT_NEW_ACTIVE event per plugin

             eventful       31 ms (  2.11% of event type,   0.00% of elapsed)

            framework     1439 ms ( 97.89% of event type,   0.08% of elapsed)
        all subtimers       31 ms (  2.11% of event type,   0.00% of elapsed)

Update per plugin

              overlay     7680 ms ( 65.26% of update,   0.44% of elapsed)
             autofarm      691 ms (  5.87% of update,   0.04% of elapsed)
             autochop      565 ms (  4.80% of update,   0.03% of elapsed)
       preserve-rooms      373 ms (  3.17% of update,   0.02% of elapsed)
            logistics      235 ms (  2.00% of update,   0.01% of elapsed)
               tailor      233 ms (  1.98% of update,   0.01% of elapsed)
             dwarfvet      189 ms (  1.61% of update,   0.01% of elapsed)
            nestboxes      110 ms (  0.93% of update,   0.01% of elapsed)
              3dveins       94 ms (  0.80% of update,   0.01% of elapsed)
            seedwatch       80 ms (  0.68% of update,   0.00% of elapsed)
 RemoteFortressReader       79 ms (  0.67% of update,   0.00% of elapsed)
          autobutcher       63 ms (  0.54% of update,   0.00% of elapsed)
            autolabor       48 ms (  0.41% of update,   0.00% of elapsed)
             eventful       48 ms (  0.41% of update,   0.00% of elapsed)
         pet-uncapper       48 ms (  0.41% of update,   0.00% of elapsed)
         buildingplan       47 ms (  0.40% of update,   0.00% of elapsed)
         autoclothing       47 ms (  0.40% of update,   0.00% of elapsed)
               design       32 ms (  0.27% of update,   0.00% of elapsed)
          add-spatter       32 ms (  0.27% of update,   0.00% of elapsed)
                tweak       31 ms (  0.26% of update,   0.00% of elapsed)
       suspendmanager       31 ms (  0.26% of update,   0.00% of elapsed)
                 zone       31 ms (  0.26% of update,   0.00% of elapsed)
          autonestbox       30 ms (  0.25% of update,   0.00% of elapsed)
            fastdwarf       30 ms (  0.25% of update,   0.00% of elapsed)
            getplants       30 ms (  0.25% of update,   0.00% of elapsed)
                  dig       30 ms (  0.25% of update,   0.00% of elapsed)
           prospector       16 ms (  0.14% of update,   0.00% of elapsed)
               burrow       16 ms (  0.14% of update,   0.00% of elapsed)
           stonesense       16 ms (  0.14% of update,   0.00% of elapsed)
            cxxrandom       16 ms (  0.14% of update,   0.00% of elapsed)
              liquids       16 ms (  0.14% of update,   0.00% of elapsed)
           cleanowned       16 ms (  0.14% of update,   0.00% of elapsed)
            faststart       16 ms (  0.14% of update,   0.00% of elapsed)
                 lair       16 ms (  0.14% of update,   0.00% of elapsed)
            tiletypes       16 ms (  0.14% of update,   0.00% of elapsed)
                 sort       16 ms (  0.14% of update,   0.00% of elapsed)
               stocks       16 ms (  0.14% of update,   0.00% of elapsed)
                probe       16 ms (  0.14% of update,   0.00% of elapsed)
           xlsxreader       15 ms (  0.13% of update,   0.00% of elapsed)
          strangemood       15 ms (  0.13% of update,   0.00% of elapsed)
               misery       15 ms (  0.13% of update,   0.00% of elapsed)

            framework      624 ms (  5.30% of update,   0.04% of elapsed)
        all subtimers    11144 ms ( 94.70% of update,   0.63% of elapsed)

State change per plugin

            framework    11768 ms (100.00% of update,   0.67% of elapsed)
        all subtimers        0 ms (  0.00% of update,   0.00% of elapsed)

Lua timer details

                    control-panel/combine     1624 ms ( 31.82% of lua timers,   0.09% of elapsed)
              control-panel/fix/ownership      856 ms ( 16.77% of lua timers,   0.05% of elapsed)
         control-panel/fix/general-strike      547 ms ( 10.72% of lua timers,   0.03% of elapsed)
     control-panel/fix/noexert-exhaustion      485 ms (  9.50% of lua timers,   0.03% of elapsed)
                                 autofish      408 ms (  8.00% of lua timers,   0.02% of elapsed)
            control-panel/fix/dry-buckets      405 ms (  7.94% of lua timers,   0.02% of elapsed)
     control-panel/fix/empty-wheelbarrows      235 ms (  4.61% of lua timers,   0.01% of elapsed)
          control-panel/fix/stuck-worship      112 ms (  2.19% of lua timers,   0.01% of elapsed)
      control-panel/fix/stuck-instruments       62 ms (  1.21% of lua timers,   0.00% of elapsed)
             control-panel/fix/engravings       60 ms (  1.18% of lua timers,   0.00% of elapsed)
                control-panel/orders-sort       16 ms (  0.31% of lua timers,   0.00% of elapsed)
             control-panel/fix/dead-units       16 ms (  0.31% of lua timers,   0.00% of elapsed)
                   control-panel/automilk       16 ms (  0.31% of lua timers,   0.00% of elapsed)
                  control-panel/autoshear       15 ms (  0.29% of lua timers,   0.00% of elapsed)

                                framework      246 ms (  4.82% of lua timers,   0.01% of elapsed)
                            all subtimers     4857 ms ( 95.18% of lua timers,   0.28% of elapsed)

Overlay details

              agitation-rebalance.monitor    17260 ms ( 19.48% of overlay,   0.98% of elapsed)
             gui/civ-alert.big_red_button    11458 ms ( 12.93% of overlay,   0.65% of elapsed)
                         gui/notify.panel    10291 ms ( 11.62% of overlay,   0.59% of elapsed)
                             hotkeys.menu     3347 ms (  3.78% of overlay,   0.19% of elapsed)
                                sort.slab     1735 ms (  1.96% of overlay,   0.10% of elapsed)
                   suspendmanager.overlay     1714 ms (  1.93% of overlay,   0.10% of elapsed)
                                sort.info      894 ms (  1.01% of overlay,   0.05% of elapsed)
                              sort.places      611 ms (  0.69% of overlay,   0.03% of elapsed)
                      sort.elevate_barony      587 ms (  0.66% of overlay,   0.03% of elapsed)
                          sort.candidates      513 ms (  0.58% of overlay,   0.03% of elapsed)
                   sort.location_selector      392 ms (  0.44% of overlay,   0.02% of elapsed)
                               sort.world      361 ms (  0.41% of overlay,   0.02% of elapsed)

                                framework    39432 ms ( 44.51% of overlay,   2.24% of elapsed)
                            all subtimers    49163 ms ( 55.49% of overlay,   2.80% of elapsed)

ZScreen details

                                 launcher       62 ms (100.00% of zscreen,   0.00% of elapsed)

                                framework        0 ms (  0.00% of zscreen,   0.00% of elapsed)
                            all subtimers       62 ms (100.00% of zscreen,   0.00% of elapsed)

@Birkow
Copy link
Contributor Author

Birkow commented Sep 18, 2024

moved to DFHack/dfhack#4947

@Birkow Birkow closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants