diff options
author | BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> | 2020-05-04 10:03:45 +0200 |
---|---|---|
committer | BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> | 2020-05-04 10:03:45 +0200 |
commit | 17915aa4c5d17ccdbc2f1d68e98d66cd0a945092 (patch) | |
tree | 632f3f7636097cf6a1c8303fc53d8f33d67f2814 | |
parent | a6c03a3206527a00385c4b7d05ec2de3f2747e15 (diff) | |
download | mesecons_debug-17915aa4c5d17ccdbc2f1d68e98d66cd0a945092.tar.gz mesecons_debug-17915aa4c5d17ccdbc2f1d68e98d66cd0a945092.zip |
modernize a bit
Diffstat (limited to '')
-rw-r--r-- | .github/workflows/luacheck.yml | 17 | ||||
-rw-r--r-- | README.md | 57 | ||||
-rw-r--r-- | chatcommands.lua | 16 | ||||
-rw-r--r-- | context.lua | 83 | ||||
-rw-r--r-- | init.lua | 2 | ||||
-rw-r--r-- | overrides.lua | 83 |
6 files changed, 134 insertions, 124 deletions
diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..a03fe92 --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,17 @@ +name: luacheck + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: apt + run: sudo apt-get install -y luarocks + - name: luacheck install + run: luarocks install --local luacheck + - name: luacheck run + run: $HOME/.luarocks/bin/luacheck ./ @@ -1,51 +1,26 @@ # Mesecons Debug Collection -## Settings - -* `mesecons_debug_max_globalstep_time` -* `mesecons_debug_cooldown_steps` -* `mesecons_debug_autoflush` - -## Commands - -All of these commands require the `mesecons_debug` privilege. - -* `/mesecons_flush`. -* `/mesecons_enable`. -* `/mesecons_disable`. - -## Various nodes action_on() effector +Allows to throttle mesecons activity per mapblock -* `mesecons_debug_enable_pipeworks_filter`. -* `mesecons_debug_disable_pipeworks_filter`. +# Overview -* `mesecons_debug_enable_pipeworks_mese_filter`. -* `mesecons_debug_disable_pipeworks_mese_filter`. +There is a cpu quota for every mapblock, if that quota is used up +the mesecons contraptions will be slowed down for that mapblock -* `mesecons_debug_enable_pipeworks_dispenser`. -* `mesecons_debug_disable_pipeworks_dispenser`. +The current mapblock-stats can be viewed with `/mesecons_hud on` -* `mesecons_debug_enable_pipeworks_deployer`. -* `mesecons_debug_disable_pipeworks_deployer`. - -* `mesecons_debug_enable_pipeworks_nodebreaker`. -* `mesecons_debug_disable_pipeworks_nodebreaker`. - -* `mesecons_debug_enable_constructor_mk1`. -* `mesecons_debug_disable_constructor_mk1`. - -* `mesecons_debug_enable_constructor_mk2`. -* `mesecons_debug_disable_constructor_mk2`. - -* `mesecons_debug_enable_constructor_mk3`. -* `mesecons_debug_disable_constructor_mk3`. +## Settings -## Various nodes on_timer() call +* none yet -* `mesecons_debug_enable_blinky_plant`. -* `mesecons_debug_disable_blinky_plant`. +## Commands -## Circuit breaker commands +All of these commands require the `mesecons_debug` privilege. -* `mesecons_debug_circuit_breaker_stats` (no priv needed). -* `mesecons_debug_circuit_breaker_stats_reset`. +* `/mesecons_hud [on|off]` enables or disables the hud +* `/mesecons_flush` Flushes the action queue +* `/mesecons_enable` Enable the mesecons queue +* `/mesecons_disable` Disables the mesecons queue +* `/mesecons_stats` shows some mesecons stats for the current position +* `/mesecons_whitelist_add` adds the current mapblock to the whitelist +* `/mesecons_whitelist_remove` removes the current mapblock from the whitelist diff --git a/chatcommands.lua b/chatcommands.lua index 58792c3..1e61504 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -46,3 +46,19 @@ minetest.register_chatcommand("mesecons_disable", { return true, "mesecons disabled" end }) + +minetest.register_chatcommand("mesecons_whitelist_add", { + description = "adds the current mapblock to the whitelist", + privs = {mesecons_debug=true}, + func = function() + return true, "mesecons disabled" + end +}) + +minetest.register_chatcommand("mesecons_whitelist_remove", { + description = "removes the current mapblock from the whitelist", + privs = {mesecons_debug=true}, + func = function() + return true, "mesecons disabled" + end +}) diff --git a/context.lua b/context.lua new file mode 100644 index 0000000..1bdb338 --- /dev/null +++ b/context.lua @@ -0,0 +1,83 @@ +local has_monitoring = minetest.get_modpath("monitoring") + +local mapblock_count, penalized_mapblock_count + +if has_monitoring then + mapblock_count = monitoring.gauge("mesecons_debug_mapblock_count", "count of tracked mapblocks") + penalized_mapblock_count = monitoring.gauge("mesecons_debug_penalized_mapblock_count", "count of penalized mapblocks") +end + +local function get_blockpos(pos) + return {x = math.floor(pos.x / 16), + y = math.floor(pos.y / 16), + z = math.floor(pos.z / 16)} +end + +-- blockpos-hash => context +local context_store = {} + +mesecons_debug.get_context = function(pos) + local blockpos = get_blockpos(pos) + local hash = minetest.hash_node_position(blockpos) + + local ctx = context_store[hash] + if not ctx then + -- create a new context + ctx = { + -- usage in us + micros = 0, + -- average micros per second + avg_micros = 0, + -- time penalty + penalty = 0, + + -- mtime + mtime = minetest.get_us_time(), + } + context_store[hash] = ctx + end + + return ctx +end + +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 1 then return end + timer=0 + + local penalized_count = 0 + local now = minetest.get_us_time() + local cleanup_time_micros = 300 * 1000 * 1000 + + mesecons_debug.context_store_size = 0 + for hash, ctx in pairs(context_store) do + local time_diff = now - ctx.mtime + if time_diff > cleanup_time_micros then + -- remove item + context_store[hash] = nil + + else + -- calculate stuff + ctx.avg_micros = math.floor((ctx.avg_micros * 0.9) + (ctx.micros * 0.1)) + ctx.micros = 0 + if ctx.avg_micros > mesecons_debug.max_usage_micros then + -- add penalty + ctx.penalty = math.min(ctx.penalty + 0.1, 20) + elseif ctx.penalty > 0 then + -- remove penalty (slowly) + ctx.penalty = math.max(ctx.penalty - 0.01, 0) + end + + mesecons_debug.context_store_size = mesecons_debug.context_store_size + 1 + if ctx.penalty > 0 then + penalized_count = penalized_count + 1 + end + + end + end + + mapblock_count.set(mesecons_debug.context_store_size) + penalized_mapblock_count.set(penalized_count) + +end) @@ -3,6 +3,7 @@ local MP = minetest.get_modpath("mesecons_debug") mesecons_debug = { enabled = true, context_store_size = 0, + -- playername => true hud = {}, @@ -11,6 +12,7 @@ mesecons_debug = { dofile(MP.."/privs.lua") dofile(MP.."/flush.lua") +dofile(MP.."/context.lua") dofile(MP.."/overrides.lua") dofile(MP.."/luacontroller.lua") dofile(MP.."/chatcommands.lua") diff --git a/overrides.lua b/overrides.lua index a87b64a..d68fce3 100644 --- a/overrides.lua +++ b/overrides.lua @@ -1,44 +1,3 @@ -local has_monitoring = minetest.get_modpath("monitoring") - -local mapblock_count, penalized_mapblock_count - -if has_monitoring then - mapblock_count = monitoring.gauge("mesecons_debug_mapblock_count", "count of tracked mapblocks") - penalized_mapblock_count = monitoring.gauge("mesecons_debug_penalized_mapblock_count", "count of penalized mapblocks") -end - - -local function get_blockpos(pos) - return {x = math.floor(pos.x / 16), - y = math.floor(pos.y / 16), - z = math.floor(pos.z / 16)} -end - --- blockpos-hash => context -local context_store = {} - -mesecons_debug.get_context = function(pos) - local blockpos = get_blockpos(pos) - local hash = minetest.hash_node_position(blockpos) - - local ctx = context_store[hash] - if not ctx then - ctx = { - -- usage in us - micros = 0, - -- average micros per second - avg_micros = 0, - -- time penalty - penalty = 0, - - -- mtime - mtime = minetest.get_us_time(), - } - context_store[hash] = ctx - end - - return ctx -end -- execute() local old_execute = mesecon.queue.execute @@ -58,48 +17,6 @@ mesecon.queue.execute = function(self, action) end -local timer = 0 -minetest.register_globalstep(function(dtime) - timer = timer + dtime - if timer < 1 then return end - timer=0 - - local penalized_count = 0 - local now = minetest.get_us_time() - local cleanup_time_micros = 300 * 1000 * 1000 - - mesecons_debug.context_store_size = 0 - for hash, ctx in pairs(context_store) do - local time_diff = now - ctx.mtime - if time_diff > cleanup_time_micros then - -- remove item - context_store[hash] = nil - - else - -- calculate stuff - ctx.avg_micros = math.floor((ctx.avg_micros * 0.9) + (ctx.micros * 0.1)) - ctx.micros = 0 - if ctx.avg_micros > mesecons_debug.max_usage_micros then - -- add penalty - ctx.penalty = math.min(ctx.penalty + 0.1, 20) - elseif ctx.penalty > 0 then - -- remove penalty (slowly) - ctx.penalty = math.max(ctx.penalty - 0.01, 0) - end - - mesecons_debug.context_store_size = mesecons_debug.context_store_size + 1 - if ctx.penalty > 0 then - penalized_count = penalized_count + 1 - end - - end - end - - mapblock_count.set(mesecons_debug.context_store_size) - penalized_mapblock_count.set(penalized_count) - -end) - -- add_action() local old_add_action = mesecon.queue.add_action mesecon.queue.add_action = function(self, pos, func, params, time, overwritecheck, priority) |