Skip to content

Commit

Permalink
use our log function
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxionary committed Jan 30, 2024
1 parent d6bcf04 commit ceab779
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .check_date.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
grep $(date -u -I) mod.conf
exit $?
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ repos:
pass_filenames: true
exclude: .pre-commit-config.yaml
fail_fast: true
- id: date_version
name: date version
language: script
entry: .check_date.sh
files: mod.conf
always_run: true
fail_fast: true
- id: stylua
name: stylua
language: system
Expand Down
16 changes: 8 additions & 8 deletions chatcommands/instrument_mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local f = string.format
local S = debuggery.S

local get_us_time = minetest.get_us_time
local log = minetest.log
local log = debuggery.log
local log_level = minetest.settings:get("debug_log_level") or "action"

local pairs_by_key = futil.table.pairs_by_key
Expand All @@ -17,17 +17,17 @@ local num_instrumented = 0

local function instrument(name, value, _cache)
if type(value) == "function" then
debuggery.log("action", "instrumenting %q", name)
log("action", "instrumenting %q", name)
return function(...)
if s.instrument_log_every_call then
debuggery.log("action", "%s(%s)", name, dump({ ... }))
log("action", "%s(%s)", name, dump({ ... }))
end
local begin = get_us_time()
local rvs = { value(...) }
total_elapsed[name] = (total_elapsed[name] or 0) + (get_us_time() - begin)
total_calls[name] = (total_calls[name] or 0) + 1
if s.instrument_log_every_call then
debuggery.log("action", "%s(...) -> %s", name, dump(rvs))
log("action", "%s(...) -> %s", name, dump(rvs))
end
return unpack(rvs)
end
Expand Down Expand Up @@ -58,14 +58,14 @@ local function instrument(name, value, _cache)
end

local function instrument_mod(mod)
debuggery.log("action", "instrumenting %s", mod)
log("action", "instrumenting %s", mod)
old_values[mod] = _G[mod]
_G[mod] = instrument(mod, _G[mod])
num_instrumented = num_instrumented + 1
end

local function uninstrument_mod(mod)
debuggery.log("action", "uninstrumenting %s", mod)
log("action", "uninstrumenting %s", mod)
_G[mod] = old_values[mod]
old_values[mod] = nil
num_instrumented = num_instrumented - 1
Expand Down Expand Up @@ -113,14 +113,14 @@ futil.register_globalstep({
local now = get_us_time()
if last_call then
local elapsed = now - last_call
log(log_level, f("[instrument_mod] in %sus,", elapsed))
log(log_level, "[instrument_mod] in %sus,", elapsed)
end
last_call = now

for name, num_calls in pairs_by_key(total_calls) do
local te = math.round(total_elapsed[name])

log(log_level, f("[instrument_mod] %s was called %s times, used %s us", name, num_calls, te))
log(log_level, "[instrument_mod] %s was called %s times, used %s us", name, num_calls, te)
end

total_calls = {}
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ website = https://content.minetest.net/packages/rheo/debuggery/
author = fluxionary
license = LGPL-3.0-or-later
media_license = CC-BY-SA-4.0
version = 2022-11-27
version = 2024-01-30
min_minetest_version = 5.7.0
supported_games = *
depends = fmod, futil, action_queues
Expand Down

0 comments on commit ceab779

Please sign in to comment.