diff --git a/shard.lock b/shard.lock index cc7bf0a629..0a1186365a 100644 --- a/shard.lock +++ b/shard.lock @@ -16,6 +16,10 @@ shards: git: https://github.com/84codes/lz4.cr.git version: 1.0.0+git.commit.96d714f7593c66ca7425872fd26c7b1286806d3d + perf_tools: + git: https://github.com/beta-ziliani/perf-tools.git + version: 0.1.0+git.commit.a0f545af92c8347b4339bb3409add5f5f6045a6d + systemd: git: https://github.com/84codes/systemd.cr.git version: 2.0.0 diff --git a/shard.yml b/shard.yml index ec2ca34f61..79ccf17dd5 100644 --- a/shard.yml +++ b/shard.yml @@ -36,6 +36,9 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba + perf_tools: + github: beta-ziliani/perf-tools + branch: feat/refered crystal: 1.13.0 diff --git a/src/lavinmq.cr b/src/lavinmq.cr index 91484cc5fb..4fe0dcc5cd 100644 --- a/src/lavinmq.cr +++ b/src/lavinmq.cr @@ -1,3 +1,4 @@ +require "perf_tools/mem_prof" require "./lavinmq/version" require "./stdlib/*" require "./lavinmq/config" diff --git a/src/lavinmq/launcher.cr b/src/lavinmq/launcher.cr index 4e170e6859..7a5fd4c260 100644 --- a/src/lavinmq/launcher.cr +++ b/src/lavinmq/launcher.cr @@ -172,6 +172,9 @@ module LavinMQ end private def run_gc + STDOUT.puts "Log objects linkted to MFile" + STDOUT.flush + PerfTools::MemProf.log_objects_linked_to_type STDOUT, MFile, true STDOUT.puts "Unmapping all segments" STDOUT.flush @amqp_server.vhosts.each_value do |vhost| diff --git a/src/lavinmq/mfile.cr b/src/lavinmq/mfile.cr index 394bd5c1ea..14b8595720 100644 --- a/src/lavinmq/mfile.cr +++ b/src/lavinmq/mfile.cr @@ -168,6 +168,8 @@ class MFile < IO end def finalize + LibC.printf("mfile#finalize %s\n", @path) + PerfTools::MemProf.untrack self.as(Pointer(Void)) # https://github.com/crystal-lang/perf-tools/issues/19 LibC.close(@fd) if @fd > -1 LibC.munmap(@buffer, @capacity) unless @buffer.null? end