summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-20 22:35:12 +0800
committerruki <[email protected]>2022-05-20 22:35:12 +0800
commite0c42d493f49eb2ede38daeb078dddd6e6f581ce (patch)
tree58a1572b8556c13a61f6b7d522c923fa6a9c3b1f
parent654a849bbaba584a1aeb61a4afaea879e191d4da (diff)
dump cache stats
-rw-r--r--xmake/actions/build/main.lua7
-rw-r--r--xmake/modules/private/cache/build_cache.lua16
2 files changed, 22 insertions, 1 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 0f5cdde40..a970b9faf 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -32,6 +32,7 @@ import("build")
import("build_files")
import("cleaner")
import("statistics")
+import("private.cache.build_cache")
import("private.service.remote_build.action", {alias = "remote_build_action"})
-- do build for the third-party buildsystem
@@ -147,8 +148,12 @@ function main()
-- do build
_do_build(targetname, group_pattern)
- end,
+ -- dump cache stats
+ if option.get("diagnosis") then
+ build_cache.dump_stats()
+ end
+ end,
catch
{
function (errors)
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 16655a632..3da7e35f0 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -85,6 +85,21 @@ function hitrate()
return 0
end
+
+-- dump stats
+function dump_stats()
+ local hit_count = (_g.hit_count or 0)
+ local total_count = (_g.total_count or 0)
+ local files_count = (_g.files_count or 0)
+ vprint("")
+ vprint("build cache stats:")
+ vprint("cache directory: %s", rootdir())
+ vprint("cache hit rate: %d%%", hitrate())
+ vprint("cache hit: %d", hit_count)
+ vprint("cache miss: %d", total_count - hit_count)
+ vprint("files in cache: %d", files_count)
+end
+
-- get object file
function get(cachekey)
_g.total_count = (_g.total_count or 0) + 1
@@ -99,6 +114,7 @@ end
function put(cachekey, objectfile)
local objectfile_cached = path.join(rootdir(), cachekey:sub(1, 2):lower(), cachekey)
os.cp(objectfile, objectfile_cached)
+ _g.files_count = (_g.files_count or 0) + 1
end
-- build with cache