Conversation
valich
left a comment
There was a problem hiding this comment.
Some (mostly) code style problems must be addressed before merging
bin/rdebug-ide
Outdated
| options.evaluation_timeout = timeout | ||
| end | ||
| opts.on('--stop', 'stop when the script is loaded') {options.stop = true} | ||
|
|
| end | ||
| else | ||
| Debugger.debug_program(options) | ||
| end |
lib/ruby-debug-ide/xml_printer.rb
Outdated
| end | ||
|
|
||
| def inspect_with_allocation_control(slice, memory_limit) | ||
| x = Thread.current |
There was a problem hiding this comment.
Can we conceive a better name for this variable? Like current_thread, start_thread or alike
lib/ruby-debug-ide/xml_printer.rb
Outdated
| trace = TracePoint.new(:c_call, :call) do |tp| | ||
| curr_alloc_size = ObjectSpace.memsize_of_all | ||
|
|
||
| if(curr_alloc_size - start_alloc_size > 1e6*memory_limit) |
lib/ruby-debug-ide/xml_printer.rb
Outdated
| end | ||
| end | ||
|
|
||
| trace.enable |
There was a problem hiding this comment.
I think it's better to use TracePoint#enable( &block) here
There was a problem hiding this comment.
TracePoint#enable( &block) works differently
There was a problem hiding this comment.
Could you please elaborate more?
There was a problem hiding this comment.
If a block is given, the trace will only be enabled within the scope of the block.
There was a problem hiding this comment.
In my implementation, the checks are carried out more often, which means that the probability of detecting an overflow increases
There was a problem hiding this comment.
Yes, so I suggest changing these three lines with
trace.enable { slice.inspect }
In my implementation, the checks are carried out more often, which means that the probability of detecting an overflow increases
Sorry, did not get what overflow you're talking about.
lib/ruby-debug-ide/xml_printer.rb
Outdated
| slice.inspect | ||
| trace.disable | ||
| rescue MemoryLimitError | ||
| return nil |
There was a problem hiding this comment.
Do you think it makes sense to add some logging for such cases? Or return something very special
There was a problem hiding this comment.
I think printing also a stacktrace of an exception may help investigating the problems in inspect calls for users.
There was a problem hiding this comment.
This backtrack will end with the calls of our debase and r-d-i methods. I think that this is not very useful.
lib/ruby-debug-ide/xml_printer.rb
Outdated
| slice = value[0..10] | ||
| compact = slice.inspect | ||
|
|
||
| if (defined?(JRUBY_VERSION) || ENV['DEBUGGER_MEMORY_LIMIT'].to_i <= 0) |
There was a problem hiding this comment.
this could be replaced with compact = if (...)
There was a problem hiding this comment.
I do not think that this is applicable in this case
There was a problem hiding this comment.
Why so? Please see https://github.com/bbatsov/ruby-style-guide#use-if-case-returns
lib/ruby-debug-ide/xml_printer.rb
Outdated
| end | ||
|
|
||
| end | ||
| end No newline at end of file |
a6dff63 to
9665253
Compare
lib/ruby-debug-ide/command.rb
Outdated
| begin | ||
| str = str.to_s | ||
| str.force_encoding('UTF-8') if(RUBY_VERSION > 2.0) | ||
| str.force_encoding('UTF-8') if(RUBY_VERSION > '2.0') |
There was a problem hiding this comment.
does this relate to the logging changes?
lib/ruby-debug-ide/xml_printer.rb
Outdated
| end | ||
|
|
||
| def print_msg(*args) | ||
| puts 'def print_msg(*args)' |
lib/ruby-debug-ide/xml_printer.rb
Outdated
| slice.inspect | ||
| else | ||
| compact = inspect_with_allocation_control(slice, ENV['DEBUGGER_MEMORY_LIMIT'].to_i) | ||
| compact = inspect_with_allocation_control(slice, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, value.object_id.to_s) |
There was a problem hiding this comment.
I am not sure object_id us really useful for logging purposes: it does not tell anything about the object. I think the previous message already a good start.
lib/ruby-debug-ide/xml_printer.rb
Outdated
| trace.disable | ||
| result | ||
| rescue MemoryLimitError => e | ||
| print_msg(e.message) |
There was a problem hiding this comment.
I think one may make use of --debug option here:
opts.on("-d", "--debug", "Debug self - prints information for debugging ruby-debug itself") do
Debugger.cli_debug = true
options.cli_debug = true
end
bin/rdebug-ide
Outdated
|
|
||
| ENV['DEBUGGER_MEMORY_LIMIT'] = '10' | ||
| opts.on("-m", "--memory-limit LIMIT", Integer, "evaluation memory limit in mb (default: 10)") do |limit| | ||
| ENV['DEBUGGER_MEMORY_LIMIT'] = '1' |
There was a problem hiding this comment.
What stands behind such defaults change? Could you please reason it?
There was a problem hiding this comment.
With 10 you have to wait for a pretty long time
lib/ruby-debug-ide/xml_printer.rb
Outdated
| curr_thread.raise MemoryLimitError, "Out of memory: evaluation of inspect took more than #{memory_limit}mb." if curr_thread.alive? | ||
| end | ||
| if Thread.respond_to?(:critical) and Thread.critical | ||
| raise ThreadError, "memory_limit within critical session" |
There was a problem hiding this comment.
AFAIU the execution of that line does not mean memory limit is exceeded. What does this check?
lib/ruby-debug-ide/xml_printer.rb
Outdated
| start_alloc_size = ObjectSpace.memsize_of_all | ||
| trace = TracePoint.new(:c_call, :call) do |tp| | ||
| curr_alloc_size = ObjectSpace.memsize_of_all | ||
| start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size) |
lib/ruby-debug-ide/xml_printer.rb
Outdated
| result = nil | ||
| inspect_thread = DebugThread.start { | ||
| start_alloc_size = ObjectSpace.memsize_of_all | ||
| trace = TracePoint.new(:c_call, :call) do |tp| |
There was a problem hiding this comment.
Do you need trace variable? I don't see any usages..
There was a problem hiding this comment.
I'll disable it through 'trace'
lib/ruby-debug-ide/xml_printer.rb
Outdated
|
|
||
| if(curr_alloc_size - start_alloc_size > 1e6 * memory_limit) | ||
| curr_thread.raise MemoryLimitError, "Out of memory: evaluation of inspect took more than #{memory_limit}mb. \n#{caller.map{|l| "\t#{l}"}.join("\n")}" | ||
| inspect_thread.kill |
There was a problem hiding this comment.
I'd rather move this kill to line 410, after join. It seems strange to me to kill the thread from this thread itself.
lib/ruby-debug-ide/xml_printer.rb
Outdated
| @@ -389,9 +392,19 @@ def inspect_with_allocation_control(slice, memory_limit) | |||
| result = nil | |||
| inspect_thread = DebugThread.start { | |||
| start_alloc_size = ObjectSpace.memsize_of_all | |||
There was a problem hiding this comment.
Overall looks nice. One last question: do you think such checks on every call will slow down the execution?
The possible solution there is to make these checks only in 10% of calls (like Math.random > 0.9) or alike
There was a problem hiding this comment.
Most often 'inspect' works fast and requires little memory, so in general the performance should not slow down. And in case of heavy inspect-s, when using probability, everything can crush with a high probability. Then why was this fix at all?)
There was a problem hiding this comment.
Perhaps, it is worth running a :call and :c_call handler a little less often. Every fifth, for example.
There was a problem hiding this comment.
Perhaps, it is worth running a :call and :c_call handler a little less often. Every fifth, for example.
That's what I'm talking about.
inspect often works fast, but
- We add constant overhead on each call which may slow execution down in dozens of times;
- There are many
inspectsduring variables collection so in total this matters
There was a problem hiding this comment.
I still getting an INTERNAL ERROR (pipe or something) when using probabilistic scheme. Apparently, it is better to abandon this proposal.
https://pastebin.com/SL8R1DGc
There was a problem hiding this comment.
Can you show the snippet you're using to achieve the result?
lib/ruby-debug-ide/xml_printer.rb
Outdated
| inspect_thread = DebugThread.start { | ||
| start_alloc_size = ObjectSpace.memsize_of_all | ||
| start_time = Time.now | ||
| max_time = Debugger.evaluation_timeout |
There was a problem hiding this comment.
I think 10s evaluation timeout is too much for this place. The reason is that evaluation is an explicit user action so it's OK to try to wait for a possibly long evaluation. In the case of convenience infos calculated dozens of times per breakpoint, 10s does not make much sense to me. I'd say we should make it somewhere between 100 and 500ms.
valich
left a comment
There was a problem hiding this comment.
Minor changes still needed
lib/ruby-debug-ide/xml_printer.rb
Outdated
| end | ||
|
|
||
|
|
||
| def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, flag) |
There was a problem hiding this comment.
what does flag mean? Not a helpful name for a parameter
lib/ruby-debug-ide/xml_printer.rb
Outdated
| attr_reader :message | ||
| attr_reader :backtrace | ||
|
|
||
| def initialize(message, backtrace) |
There was a problem hiding this comment.
This one does not provide default backtrace value and the one below does. Is that intentional?
lib/ruby-debug-ide/xml_printer.rb
Outdated
| rescue MemoryLimitError, TimeLimitError => e | ||
| print_debug(e.message + "\n" + e.backtrace) | ||
|
|
||
| return nil if flag |
|
Squashed and merged into master. |
Sets a memory limit for execution of inspect (default 10mb)