Merge branch 'use_mktemp' of https://github.com/golharam/arvados into golharam-use_mktemp
[arvados.git] / services / api / test / helpers / time_block.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class ActiveSupport::TestCase
6   def time_block label
7     t0 = Time.now
8     begin
9       yield
10     ensure
11       t1 = Time.now
12       $stderr.puts "#{t1 - t0}s #{label}"
13     end
14   end
15
16   def vmpeak c
17     open("/proc/self/status").each_line do |line|
18       print "Begin #{c} #{line}" if (line =~ /^VmHWM:/)
19     end
20     n = yield
21     open("/proc/self/status").each_line do |line|
22       print "End #{c} #{line}" if (line =~ /^VmHWM:/)
23     end
24     n
25   end
26
27 end