Skip to content

Instantly share code, notes, and snippets.

@benweint
benweint / gdb.txt
Created November 14, 2014 17:45
Rubinius hang in segv handler
[ben@ruby-build-box-3 ~]$ cat gdb.txt
Thread 5 (Thread 0x7f32595a4700 (LWP 12251)):
#0 0x00007f32611de5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x0000000000637b95 in wait (this=0x210bb20, state=0x7f32595a3dc0) at /tmp/ruby-build.20140805092211.19382/rubinius-2.2.10/vm/util/thread.hpp:431
#2 rubinius::SignalHandler::perform (this=0x210bb20, state=0x7f32595a3dc0) at vm/signal.cpp:184
#3 0x0000000000637e1c in rubinius::signal_handler_tramp (state=<value optimized out>) at vm/signal.cpp:47
#4 0x00000000006c7842 in rubinius::Thread::in_new_thread (ptr=0x210bd70) at vm/builtin/thread.cpp:259
#5 0x00007f32611da9d1 in start_thread () from /lib64/libpthread.so.0
#6 0x00007f3260787b5d in clone () from /lib64/libc.so.6
@benweint
benweint / socktest.rb
Created August 13, 2014 16:37
getaddrinfo and TCPSocket.new
#!/usr/bin/env ruby
require 'socket'
require 'resolv'
require 'resolv-replace'
puts "Run this to trace getaddrinfo calls:"
puts "sudo dtrace -p #{$$} -n 'pid$target::getaddrinfo:entry { ustack(); }'"
loop do
@benweint
benweint / example.rb
Created June 11, 2014 16:54
Using ControllerInstrumentation without a host class
#!/usr/bin/env ruby
require 'newrelic_rpm'
def do_something
puts 'working!'
sleep(3)
end
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
@benweint
benweint / monitor-test.rb
Created April 30, 2014 20:01
Demonstration of issue with MonitorMixin on Ruby 1.8
#!/usr/bin/env ruby
require 'thread'
require 'rubygems'
require 'monitor'
class Dummy
include MonitorMixin
def sync
@benweint
benweint / gc-profiler.rb
Created April 11, 2014 18:07
Demo of GC::Profiler.total time returning wrong units on JRuby
#!/usr/bin/env ruby
t0 = Time.now
GC::Profiler.enable
100000.times do
String.new('a' * 1000)
end
gc_time = GC::Profiler.total_time
@benweint
benweint / standalone.rb
Created March 13, 2014 00:10
Ruby GC timing discrepancy
#!/usr/bin/env ruby
puts "Run this in another terminal:"
puts ""
puts " sudo ./trace-gc-standalone.sh #{$$}"
puts ""
puts "... wait for the 'Ready!' message, switch back here and press enter to start."
GC::Profiler.enable
$stdin.gets
@benweint
benweint / test.rb
Last active August 29, 2015 13:56
Demonstration of behavior difference between Ruby 1.9.3 and 2.0+
module A
def foo
puts "foo from A"
end
end
class B
include A
def foo
@benweint
benweint / string-subclass-encodings.rb
Created January 21, 2014 22:53
String subclasses and encodings in Rubinius
#!/usr/bin/env ruby
class BadString < String; end
original = (0..255).to_a.pack("C*").force_encoding("UTF-8")
subclass = BadString.new(original)
round_tripped = subclass.to_s
puts "encoding: original = #{original.encoding}, subclass = #{subclass.encoding}, round_tripped = #{round_tripped.encoding}"
puts "valid_encoding? original = #{original.valid_encoding?}, subclass = #{subclass.valid_encoding?}, round_tripped = #{round_tripped.valid_encoding?}"
@benweint
benweint / array-racc.rb
Created January 21, 2014 00:10
Array / racc / rbx bug demo
#!/usr/bin/env ruby
string = "\n\v"
puts "before racc require: #{Array(string).inspect}"
require 'racc'
puts "after racc require: #{Array(string).inspect}"
(gdb) t a a bt
Thread 5 (process 11796):
#0 0x00000001003d8e4f in llvm::SelectionDAG::getFrameIndex ()
#1 0x000000010027d55b in (anonymous namespace)::X86DAGToDAGISel::getAddressOperands ()
#2 0x000000010027da18 in (anonymous namespace)::X86DAGToDAGISel::SelectAddr ()
#3 0x000000010027a78c in (anonymous namespace)::X86DAGToDAGISel::CheckComplexPattern ()
#4 0x000000010043994c in llvm::SelectionDAGISel::SelectCodeCommon ()
#5 0x0000000100274536 in (anonymous namespace)::X86DAGToDAGISel::Select ()
#6 0x000000010043bc41 in llvm::SelectionDAGISel::DoInstructionSelection ()