From b84cd416ae78a9ce8df21655927c668945c67308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Thu, 18 Jul 2024 01:10:39 +0200 Subject: [PATCH] Use perf-tools for allocations/fiber tracking, USR1 to report --- shard.lock | 4 ++++ shard.yml | 2 ++ src/lavinmq/launcher.cr | 20 +++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/shard.lock b/shard.lock index cc7bf0a629..08a406cd34 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/crystal-lang/perf-tools.git + version: 0.1.0+git.commit.72f0956c9edfb2a67d4eb18e134a34c711a9d94a + systemd: git: https://github.com/84codes/systemd.cr.git version: 2.0.0 diff --git a/shard.yml b/shard.yml index ec2ca34f61..e7df069991 100644 --- a/shard.yml +++ b/shard.yml @@ -36,6 +36,8 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba + perf_tools: + github: crystal-lang/perf-tools crystal: 1.13.0 diff --git a/src/lavinmq/launcher.cr b/src/lavinmq/launcher.cr index 4e170e6859..1f6f7418a3 100644 --- a/src/lavinmq/launcher.cr +++ b/src/lavinmq/launcher.cr @@ -1,3 +1,7 @@ +{% unless flag?(:release) %} + require "perf_tools/mem_prof" + require "perf_tools/fiber_trace" +{% end %} require "log" require "file" require "systemd" @@ -165,9 +169,19 @@ module LavinMQ puts " marker threads: #{ps.markers_m1}" puts " reclaimed bytes during last GC: #{ps.bytes_reclaimed_since_gc.humanize_bytes}" puts " reclaimed bytes before last GC: #{ps.reclaimed_bytes_before_gc.humanize_bytes}" - puts "Fibers:" - Fiber.list { |f| puts f.inspect } - LavinMQ::Reporter.report(@amqp_server) + # puts "Fibers:" + # Fiber.list { |f| puts f.inspect } + # LavinMQ::Reporter.report(@amqp_server) + {% unless flag?(:release) %} + puts "Object counts:" + PerfTools::MemProf.log_object_counts(STDOUT) + puts "Object sizes:" + PerfTools::MemProf.log_object_sizes(STDOUT) + puts "Allocations:" + PerfTools::MemProf.log_allocations(STDOUT) + puts "Fibers:" + PerfTools::FiberTrace.log_fibers(STDOUT) + {% end %} STDOUT.flush end