Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / results.txt
Last active August 29, 2015 14:13
rbx segv in ossl_raise
Running "agent_only" for Envfile entry 0
Starting tests in child PID 35877 at 2015-01-20 11:22:53 -0800
ffi2-generators (0.1.1), json (1.8.2), metaclass (0.0.4), minitest (4.7.5), mocha (0.14.0), newrelic_rpm (3.9.9), racc (1.4.12), rack (1.4.5), rack-test (0.6.2), rb-readline (0.5.2), rubysl (2.1.0), rubysl-abbrev (2.0.4), rubysl-base64 (2.0.0), rubysl-benchmark (2.0.1), rubysl-bigdecimal (2.0.2), rubysl-cgi (2.0.1), rubysl-cgi-session (2.0.1), rubysl-cmath (2.0.0), rubysl-complex (2.0.0), rubysl-continuation (2.0.0), rubysl-coverage (2.0.3), rubysl-csv (2.0.2), rubysl-curses (2.0.1), rubysl-date (2.0.8), rubysl-delegate (2.0.1), rubysl-digest (2.0.3), rubysl-drb (2.0.1), rubysl-e2mmap (2.0.0), rubysl-english (2.0.0), rubysl-enumerator (2.0.0), rubysl-erb (2.0.2), rubysl-etc (2.0.3), rubysl-expect (2.0.0), rubysl-fcntl (2.0.4), rubysl-fiber (2.0.0), rubysl-fileutils (2.0.3), rubysl-find (2.0.1), rubysl-forwardable (2.0.1), rubysl-getoptlong (2.0.0), rubysl-gserver (2.0.0), rubysl-io-console (2.0.0), rubysl-i
@benweint
benweint / forwardabletest.rb
Last active August 29, 2015 14:14
forwardable
#!/usr/bin/env ruby
require 'benchmark'
require 'forwardable'
class Horse
def bark(n); end
end
class ForwardedHorse
@benweint
benweint / allocs.rb
Last active August 29, 2015 14:15
rbx allocation counting
#!/usr/bin/env ruby
def log_allocated_objects
value = Rubinius::Metrics.data[:'memory.large.objects.total']
puts "memory.large.objects.total = #{value}, class = #{value.class}"
end
loop do
log_allocated_objects
10000.times { Object.new }