Skip to content

Commit

Permalink
[Truffle] Log command in jt.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Feb 10, 2016
1 parent 5ca98ef commit c352813
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions tool/jt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ def metrics(command, *args)
def metrics_alloc(*args)
samples = []
METRICS_REPS.times do
print '.' if STDOUT.tty?
log '.', 'sampling'
r, w = IO.pipe
run '-Xtruffle.metrics.memory_used_on_exit=true', '-J-verbose:gc', *args, {err: w, out: w}, :no_print_cmd
w.close
samples.push memory_allocated(r.read)
r.close
end
puts if STDOUT.tty?
log "\n", nil
puts "#{human_size(samples.inject(:+)/samples.size)}, max #{human_size(samples.max)}"
end

Expand All @@ -617,20 +617,20 @@ def metrics_minheap(*args)
# reliably. To slightly improve on a basic linear search, we check to see
# if it looks like we can run in 40 MB, and if we can't then we start
# testing there.
print '~' if STDOUT.tty?
log '~', "Trying #{HIGHER_HEAP} MB"
if can_run_in_heap(HIGHER_HEAP, *args)
print '<' if STDOUT.tty?
log '<', "Passed, so starting at 1 MB"
heap = 1
else
print '>' if STDOUT.tty?
log '>', "Failed, so starting at #{HIGHER_HEAP} MB"
heap = HIGHER_HEAP
end
successful = 0
loop do
if successful > 0
print '?' if STDOUT.tty?
log '?', "Verifying #{heap} MB"
else
print '+' if STDOUT.tty?
log '+', "Trying #{heap} MB"
end
if can_run_in_heap(heap, *args)
successful += 1
Expand All @@ -640,7 +640,7 @@ def metrics_minheap(*args)
successful = 0
end
end
puts if STDOUT.tty?
log "\n", nil
puts "#{heap} MB"
end

Expand All @@ -651,7 +651,7 @@ def can_run_in_heap(heap, *command)
def metrics_time(*args)
samples = []
METRICS_REPS.times do
print '.' if STDOUT.tty?
log '.', 'sampling'
r, w = IO.pipe
start = Time.now
run '-Xtruffle.metrics.time=true', *args, {err: w, out: w}, :no_print_cmd
Expand All @@ -660,7 +660,7 @@ def metrics_time(*args)
samples.push get_times(r.read, finish - start)
r.close
end
puts if STDOUT.tty?
log "\n", nil
samples[0].each_key do |region|
region_samples = samples.map { |s| s[region] }
puts "#{region} #{(region_samples.inject(:+)/samples.size).round(2)} s"
Expand Down Expand Up @@ -708,6 +708,14 @@ def human_size(bytes)
"#{(bytes/1024.0**4).round(2)} TB"
end
end

def log(tty_message, full_message)
if STDOUT.tty?
print(tty_message) unless tty_message.nil?
else
puts full_message unless full_message.nil?
end
end

def check_ambiguous_arguments
ENV.delete "JRUBY_ECLIPSE" # never run from the Eclipse launcher here
Expand Down

0 comments on commit c352813

Please sign in to comment.