summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-01-12 14:59:30 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-01-12 14:59:30 +0100
commit5679ee0120ab45829b847d55d3a2253735856b3f (patch)
treed5cd063e87e47994c3ef34cfc1958d6be21cb644 /lib
parent587f850170a38e2642c0de76fb69efdeae930d66 (diff)
downloadgitlab-ce-5679ee0120ab45829b847d55d3a2253735856b3f.tar.gz
Track memory allocated during a transaction
This gives a very rough estimate of how much memory is allocated during a transaction. This only works reliably when using a single-threaded application server and a Ruby implementation with a GIL as otherwise memory allocated by other threads might skew the statistics. Sadly there's no way around this as Ruby doesn't provide a reliable way of gathering accurate object sizes upon allocation on a per-thread basis.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/transaction.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb
index 86606b1c6d6..2578ddc49f4 100644
--- a/lib/gitlab/metrics/transaction.rb
+++ b/lib/gitlab/metrics/transaction.rb
@@ -23,20 +23,29 @@ module Gitlab
@values = Hash.new(0)
@tags = {}
@action = action
+
+ @memory_before = 0
+ @memory_after = 0
end
def duration
@finished_at ? (@finished_at - @started_at) * 1000.0 : 0.0
end
+ def allocated_memory
+ @memory_after - @memory_before
+ end
+
def run
Thread.current[THREAD_KEY] = self
- @started_at = Time.now
+ @memory_before = System.memory_usage
+ @started_at = Time.now
yield
ensure
- @finished_at = Time.now
+ @memory_after = System.memory_usage
+ @finished_at = Time.now
Thread.current[THREAD_KEY] = nil
end
@@ -65,7 +74,7 @@ module Gitlab
end
def track_self
- values = { duration: duration }
+ values = { duration: duration, allocated_memory: allocated_memory }
@values.each do |name, value|
values[name] = value