Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions gems/pure-ruby-tracer/lib/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

require 'fileutils'

DEBUG_TRACER = ENV['CODETRACER_RUBY_TRACER_DEBUG'] == '1'

CallRecord = Struct.new(:function_id, :args) do
def to_data_for_json
res = to_h
Expand Down Expand Up @@ -246,9 +248,7 @@ def load_exprs(path)
end

def serialize(program, out_dir = nil)
if ENV["CODETRACER_RUBY_TRACER_DEBUG"] == "1"
pp @events
end
pp @events if DEBUG_TRACER

output = @events.map { |kind, event| [[kind, event.to_data_for_json]].to_h }

Expand Down Expand Up @@ -277,8 +277,10 @@ def serialize(program, out_dir = nil)
File.write(trace_metadata_path, metadata_json_output)
File.write(trace_paths_path, paths_json_output)

$stderr.write("=================================================\n")
$stderr.write("codetracer ruby tracer: saved trace to #{trace_folder}\n")
if DEBUG_TRACER
$stderr.write("=================================================\n")
$stderr.write("codetracer ruby tracer: saved trace to #{trace_folder}\n")
end
end
end

Expand Down Expand Up @@ -353,7 +355,7 @@ def to_value(v, depth=10)
end
$VALUE_COUNT += 1
if $VALUE_COUNT % 10_000 == 0
$stderr.write("value #{$VALUE_COUNT}\n")
$stderr.write("value #{$VALUE_COUNT}\n") if DEBUG_TRACER
end
case v
when Integer
Expand Down
22 changes: 13 additions & 9 deletions gems/pure-ruby-tracer/lib/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require 'optparse'
require_relative 'recorder'

DEBUG_TRACER = ENV['CODETRACER_RUBY_TRACER_DEBUG'] == '1'

# Warning:
# probably related to our development env:
# if we hit an `incompatible library version` error, like
Expand Down Expand Up @@ -158,7 +160,7 @@ def record_call(tp)
method_name_prefix = module_name == 'Object' ? '' : "#{module_name}#"
method_name = "#{method_name_prefix}#{tp.method_id}"

old_puts "call #{method_name} with #{tp.parameters}"
old_puts "call #{method_name} with #{tp.parameters}" if DEBUG_TRACER

arg_records = prepare_args(tp)

Expand All @@ -170,7 +172,7 @@ def record_call(tp)

def record_return(tp)
if self.tracks_call?(tp)
old_puts "return"
old_puts "return" if DEBUG_TRACER
return_value = to_value(tp.return_value)
@record.register_step(tp.path, tp.lineno)
# return value support inspired by existing IDE-s/envs like
Expand Down Expand Up @@ -281,13 +283,15 @@ def load_variables(binding)
begin
Kernel.load(program)
rescue Exception => e
old_puts ''
old_puts '==== trace.rb error while tracing program ==='
old_puts 'ERROR'
old_puts e
old_puts e.backtrace
old_puts '====================='
old_puts ''
if DEBUG_TRACER
old_puts ''
old_puts '==== trace.rb error while tracing program ==='
old_puts 'ERROR'
old_puts e
old_puts e.backtrace
old_puts '====================='
old_puts ''
end
end

$tracer.stop_tracing
Expand Down
Loading