Skip to content

Instantly share code, notes, and snippets.

View tmm1's full-sized avatar

Aman Gupta Karmani tmm1

View GitHub Profile
@tmm1
tmm1 / flamegraph.html
Last active August 29, 2015 13:56
flamegraph viewer
<html>
<head>
<title>flamegraph</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Monaco, "Liberation Mono", Courier, monospace;
font-size: 10pt;
}
Ruby 2.1.0 in Production: known bugs and patches
Last week, we upgraded the github.com rails app to ruby 2.1.0 in production.
While testing the new build for rollout, we ran into a number of bugs. Most of
these have been fixed on trunk already, but I've documented them below to help
anyone else who might be testing ruby 2.1 in production.
@naruse I think we should backport these patches to the ruby_2_1 branch and
release 2.1.1 sooner rather than later, as some of the bugs are quite critical.
I'm happy to offer any assistance I can to expedite this process.
diff --git a/src/gperftools/profiler.h b/src/gperftools/profiler.h
index 95b107f..816468d 100644
--- a/src/gperftools/profiler.h
+++ b/src/gperftools/profiler.h
@@ -139,6 +139,8 @@ PERFTOOLS_DLL_DECL void ProfilerStop();
*/
PERFTOOLS_DLL_DECL void ProfilerFlush();
+PERFTOOLS_DLL_DECL void ProfilerPause();
+PERFTOOLS_DLL_DECL void ProfilerResume();
@tmm1
tmm1 / gist:7998799
Created December 17, 2013 02:10
systemtap method-cache-clear probe for ruby 2.1
$ cat ruby_mcache.stp
probe process("/usr/bin/ruby").mark("method__cache__clear")
{
module = kernel_string($arg1)
file = kernel_string($arg2)
line = $arg3
printf("%s(%d) %s %s:%d cleared `%s'\n", execname(), pid(), $$name, file, line, module)
}
$ sudo stap ruby_mcache.stp
@tmm1
tmm1 / gc_hook.rb
Last active December 30, 2015 03:09
# gc_hook.rb
# Usage: RUBYOPT=-r./gc_hook.rb ruby app.rb
=begin
GC::Profiler.enable
at_exit{ GC::Profiler.raw_data.map{ |d| p(d) } }
=end
require 'objspace'
ObjectSpace.gc_hook = proc { |before, after|
@tmm1
tmm1 / vimrc
Created November 26, 2013 10:07 — forked from alloy/gist:7527832
" These VIM rules match the MRI C indentation rules.
"
" To enable use of this project specific config, add the following to your
" ~/.vimrc:
"
" " Enable per-directory .vimrc files
" set exrc
" " Disable unsafe commands in local .vimrc files
" set secure
@tmm1
tmm1 / rbtree.patch
Created November 23, 2013 00:52
rbtree 2.1 compat
diff --git a/extconf.rb b/extconf.rb
index 9f6f0c7..674eb08 100644
--- a/extconf.rb
+++ b/extconf.rb
@@ -9,6 +9,7 @@ have_header('ruby/st.h')
have_func('rb_exec_recursive', 'ruby.h')
have_func('rb_exec_recursive_paired', 'ruby.h')
have_func('rb_proc_lambda_p', 'ruby.h')
+have_func('rb_obj_hide', 'ruby.h')
if Hash.method_defined?(:flatten)
@tmm1
tmm1 / heapprof.rb
Last active December 28, 2015 21:09
# encoding: utf-8
require 'set'
require 'json'
require 'pp'
class HeapDump
def initialize(data)
@objects = data.split("\n").map.with_index{ |line, idx|
begin
JSON.parse(line)
@tmm1
tmm1 / 1.txt
Created October 29, 2013 06:42
GC.start(oob: true) experiment
## without patch
2000 requests to https://github.com/rails/rails/pull/11955 as (anonymous)
cpu time: 154,548ms total (77ms avg/req, 68ms - 205ms)
oob gc: 0 / 0ms
in-request gc: 150 / 6,004ms total (40ms avg/req, 30ms - 124ms)
allocations: 154,895,372 objs total (77,447 objs avg/req, 77,332 objs - 79,043 objs)
## with patch