Skip to content

Instantly share code, notes, and snippets.

View KJTsanaktsidis's full-sized avatar

KJ Tsanaktsidis KJTsanaktsidis

View GitHub Profile
@KJTsanaktsidis
KJTsanaktsidis / backtracie crash
Created June 11, 2022 04:10
Backtracie crash
/home/kj/backtracie/spec/unit/backtracie_spec.rb:240: [BUG] Segmentation fault at 0x0000000000000008
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0056 p:---- s:0271 e:000270 CFUNC :backtrace_locations
c:0055 p:0017 s:0266 e:000265 BLOCK /home/kj/backtracie/spec/unit/backtracie_spec.rb:240
c:0054 p:0005 s:0263 e:000262 BLOCK /home/kj/backtracie/spec/unit/backtracie_spec.rb:230 [FINISH]
c:0053 p:0007 s:0259 E:001140 BLOCK /home/kj/backtracie/spec/unit/backtracie_spec.rb:240 [FINISH]
c:0052 p:0006 s:0256 e:000255 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343
c:0051 p:0010 s:0253 e:000249 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179 [FINISH]
@KJTsanaktsidis
KJTsanaktsidis / gist:4917a4cea7d45d6cca01264801841f81
Created June 12, 2022 06:12
Crash calling ruby from newobj
/home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1112: [BUG] unexpected situation - recordd:1 current:0
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0029 p:---- s:0165 e:000164 CFUNC :catch
c:0028 p:0006 s:0160 e:000159 METHOD /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1112
c:0027 p:0019 s:0155 e:000154 METHOD /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1135
c:0026 p:0004 s:0150 e:000149 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:949
c:0025 p:0003 s:0147 e:000146 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1112 [FINISH]
c:0024 p:---- s:0144 e:000143 CFUNC :catch
@KJTsanaktsidis
KJTsanaktsidis / gist:7a72d9ededbec2a01b8d550cc0c54d51
Created June 12, 2022 07:40
recursive event hook backtrace
#0 rb_exec_event_hooks (trace_arg=0x7fad3ded3910, hooks=0x11260d0, pop_p=0) at vm_trace.c:370
#1 0x00007fad42b2d4e3 in rb_exec_event_hook_orig (ec=0x1f96900, hooks=0x11260d0, flag=2097152, self=18549560, id=0, called_id=0, klass=0, data=140381822381360, pop_p=0)
at /home/kj/.rbenv/sources/3.0.4/ruby-3.0.4/vm_core.h:1985
#2 0x00007fad42b30203 in gc_event_hook_body (ec=0x1f96900, objspace=0x11257f0, event=2097152, data=140381822381360) at gc.c:2067
#3 0x00007fad42b317f8 in obj_free (objspace=0x11257f0, obj=140381822381360) at gc.c:2778
#4 0x00007fad42b35a65 in gc_page_sweep (objspace=0x11257f0, heap=0x1125818, sweep_page=0x7fad30a72b40) at gc.c:4891
#5 0x00007fad42b360c8 in gc_sweep_step (objspace=0x11257f0, heap=0x1125818) at gc.c:5098
#6 0x00007fad42b3624e in gc_sweep_rest (objspace=0x11257f0) at gc.c:5151
#7 0x00007fad42b3cd3a in gc_rest (objspace=0x11257f0) at gc.c:8336
#8 0x00007fad42b42a5e in objspace_malloc_increase (objspace=0x11257f0, mem=0x7fad35dac7d0, new_size=904, old_size=0, type=MEMO
@KJTsanaktsidis
KJTsanaktsidis / gist:21d7ed46251fbd87bfa14cccbe704133
Created June 13, 2022 00:58
Backtrace showing st_table doing ruby_xmalloc
#0 heap_page_add_freeobj (objspace=0xeb9800, page=0x153da2c0, obj=139975204190960) at gc.c:1850
#1 0x00007f4e98cf35ab in gc_sweep_plane (objspace=0xeb9800, heap=0xeb9838, p=139975204190960, bitset=1, ctx=0x7ffe5ff47e20) at gc.c:5293
#2 0x00007f4e98cf39ad in gc_sweep_page (objspace=0xeb9800, size_pool=0xeb9828, heap=0xeb9838, ctx=0x7ffe5ff47e20) at gc.c:5389
#3 0x00007f4e98cf3f89 in gc_sweep_step (objspace=0xeb9800, size_pool=0xeb9828, heap=0xeb9838) at gc.c:5665
#4 0x00007f4e98cf485d in gc_sweep (objspace=0xeb9800) at gc.c:5900
#5 0x00007f4e98cf8c49 in gc_marks_rest (objspace=0xeb9800) at gc.c:8100
#6 0x00007f4e98cf8daf in gc_marks (objspace=0xeb9800, full_mark=0) at gc.c:8151
#7 0x00007f4e98cfae13 in gc_start (objspace=0xeb9800, reason=512) at gc.c:8967
#8 0x00007f4e98cfaa8a in garbage_collect (objspace=0xeb9800, reason=512) at gc.c:8853
#9 0x00007f4e98cfb567 in garbage_collect_with_gvl (objspace=0xeb9800, reason=512) at gc.c:9225
kj@kj-thinkpad ruby_memprofiler_pprof % ruby script/benchmark.rb
user system total real
no profiling (1) 15.867480 0.473907 16.341387 ( 16.382863)
no profiling (2) 14.955051 0.031678 14.986729 ( 15.025699)
with profiling (1%, no flush) 22.981310 0.484232 23.465542 ( 23.501221)
with reporting (1%, with flush) 24.261126 0.057177 24.318303 ( 24.353663)
with profiling (10%, no flush) 109.202573 0.291814 109.494387 (109.596998)
with reporting (10%, with flush) 154.720902 0.060936 154.781838 (154.920858)
@KJTsanaktsidis
KJTsanaktsidis / gist:ac4d7bf85bceb171e39f5c5534771995
Created June 13, 2022 06:42
Apparently it's slow because of marking everything?
Samples: 8K of event 'cycles', Event count (approx.): 367381525322, DSO: ruby_memprofiler_pprof_ext.so
Children Self Comm Symbol
+ 60.45% 0.00% ruby [.] collector_cdata_gc_mark ▒
+ 60.34% 0.03% ruby [.] collector_gc_mark_each_heap_sample ▒
+ 60.30% 0.26% ruby [.] mpp_sample_gc_mark ▒
+ 0.74% 0.00% ruby [.] collector_tphook_newobj ▒
0.04% 0.00% ruby [.] collector_tphook_freeobj ▒
0.02% 0.01% ruby [.] mpp_rb_gc_disable_no_rest ▒
0.01% 0.01% ruby [.] backtracie_bt_gc_mark_moveable@plt
With memocache:
kj@kj-thinkpad ruby_memprofiler_pprof % ruby script/benchmark.rb
user system total real
no profiling (1) 15.844936 0.469273 16.314209 ( 16.337021)
no profiling (2) 14.966771 0.034934 15.001705 ( 15.020942)
with profiling (1%, no flush) 15.971306 0.477258 16.448564 ( 16.471195)
with reporting (1%, with flush) 17.402173 0.029948 17.432121 ( 17.454925)
with profiling (10%, no flush) 23.168302 0.289576 23.457878 ( 23.487329)
with reporting (10%, with flush) 48.194583 0.042943 48.237526 ( 48.290087)
@KJTsanaktsidis
KJTsanaktsidis / riak.lua
Created November 17, 2022 09:47
Wireshark protocol dissector for Riak
-- Riak protocol decoder
-- Based on copypasta from https://wiki.wireshark.org/Protobuf.md
-- To use,
-- * Plase in ~/.local/lib/wireshark/plugins/riak.lua
-- * Check out https://github.com/protocolbuffers/protobuf somewhere
-- * Check out https://github.com/basho/riak_pb somewhere
-- * In the "ProtoBuf" protocol preferences, add protobuf/src and riak_pb/src
-- to the search paths. Make sure "load all" is checked for riak_pb, but NOT
-- for protobuf.
-- * right click a stream -> decode as -> "RIAK_PROTO"
@KJTsanaktsidis
KJTsanaktsidis / curl_parallel.c
Created November 21, 2022 06:57
glibc dns timeout reproduction
#include <curl/curl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define NUM_THREADS 20
static pthread_mutex_t outlock = PTHREAD_MUTEX_INITIALIZER;
@KJTsanaktsidis
KJTsanaktsidis / gist:80a7005cd0784f73b83ab121b1b82cc9
Created January 24, 2023 11:47
Renaming an anonymous class in Ruby...
kj@kj-thinkpad ~ % cat rename.rb
#!/usr/bin/env ruby
require 'fiddle'
libruby = Fiddle::Handle.new
rb_set_class_path_string = Fiddle::Function.new(
libruby['rb_set_class_path_string'],
[
Fiddle::TYPE_UINTPTR_T,