Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a688222
commit 73262d7
Showing
9 changed files
with
516 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
# Rails compatibility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# to be used to compare ruby heaps generated in 2.1 | ||
# can isolate memory leaks | ||
# | ||
# rbtrace -p 15193 -e 'Thread.new{require "objspace"; ObjectSpace.trace_object_allocations_start; GC.start(full_mark: true); ObjectSpace.dump_all(output: File.open("heap.json","w"))}.join' | ||
# | ||
# | ||
require 'set' | ||
require 'json' | ||
|
||
if ARGV.length != 2 | ||
puts "Usage: diff_heaps [ORIG.json] [AFTER.json]" | ||
exit 1 | ||
end | ||
|
||
origs = Set.new | ||
|
||
File.open(ARGV[0], "r").each_line do |line| | ||
parsed = JSON.parse(line) | ||
origs << parsed["address"] if parsed && parsed["address"] | ||
end | ||
|
||
diff = [] | ||
|
||
File.open(ARGV[1], "r").each_line do |line| | ||
parsed = JSON.parse(line) | ||
if parsed && parsed["address"] | ||
diff << parsed unless origs.include? parsed["address"] | ||
end | ||
end | ||
|
||
diff.group_by do |x| | ||
[x["type"], x["file"], x["line"]] | ||
end.map { |x, y| | ||
[x, y.count] | ||
}.sort { |a, b| | ||
b[1] <=> a[1] | ||
}.each { |x, y| | ||
puts "Leaked #{y} #{x[0]} objects at: #{x[1]}:#{x[2]}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
# using this script to try figure out why Ruby 2 is slower than 1.9 | ||
require 'flamegraph' | ||
|
||
Flamegraph.generate('test.html', fidelity: 2) do | ||
require File.expand_path("../../config/environment", __FILE__) | ||
end | ||
exit | ||
|
||
require 'memory_profiler' | ||
|
||
result = MemoryProfiler.report do | ||
require File.expand_path("../../config/environment", __FILE__) | ||
end | ||
result.pretty_print | ||
|
||
exit | ||
|
||
require 'benchmark' | ||
|
||
def profile_allocations(name) | ||
GC.disable | ||
initial_size = ObjectSpace.count_objects | ||
yield | ||
changes = ObjectSpace.count_objects | ||
changes.each do |k, _| | ||
changes[k] -= initial_size[k] | ||
end | ||
puts "#{name} changes" | ||
changes.sort { |a, b| b[1] <=> a[1] }.each do |a, b| | ||
next if b <= 0 | ||
# 1 extra hash for tracking | ||
puts "#{a} #{a == :T_HASH ? b - 1 : b}" | ||
end | ||
GC.enable | ||
end | ||
|
||
def profile(name, &block) | ||
puts "Profiling all object allocation for #{name}" | ||
GC.start | ||
GC.disable | ||
|
||
items = [] | ||
objs = [] | ||
|
||
ObjectSpace.trace_object_allocations do | ||
block.call | ||
|
||
ObjectSpace.each_object do |o| | ||
objs << o | ||
end | ||
|
||
objs.each do |o| | ||
g = ObjectSpace.allocation_generation(o) | ||
if g | ||
l = ObjectSpace.allocation_sourceline(o) | ||
f = ObjectSpace.allocation_sourcefile(o) | ||
c = ObjectSpace.allocation_class_path(o) | ||
m = ObjectSpace.allocation_method_id(o) | ||
items << "Allocated #{c} in #{m} #{f}:#{l}" | ||
end | ||
end | ||
end | ||
|
||
items.group_by { |x| x }.sort { |a, b| b[1].length <=> a[1].length }.each do |row, group| | ||
puts "#{row} x #{group.length}" | ||
end | ||
|
||
GC.enable | ||
profile_allocations(name, &block) | ||
end | ||
|
||
def stuff | ||
u = User.first | ||
r = TopicQuery.new(u, {}).list_latest | ||
r.topics.to_a | ||
end | ||
|
||
stuff | ||
profile_allocations "stuff" do | ||
stuff | ||
end | ||
|
||
# Benchmark.bmbm do |x| | ||
# | ||
# x.report("find") do | ||
# 100.times{stuff} | ||
# end | ||
# | ||
# end | ||
# | ||
# x.report("grab 10 users id") do | ||
# 100.times{User.limit(10).select(:id).to_a} | ||
# end | ||
# | ||
# x.report("grab 10 users") do | ||
# 100.times{User.limit(10).to_a} | ||
# end | ||
# | ||
# profile("topic query") do | ||
# r = TopicQuery.new(u, {}).list_latest | ||
# r.topics.to_a | ||
# end | ||
|
||
# | ||
# RubyProf.start | ||
# | ||
# r = TopicQuery.new(u, {}).list_latest | ||
# r.topics.to_a | ||
# | ||
# result = RubyProf.stop | ||
# printer = RubyProf::GraphPrinter.new(result) | ||
# # printer = RubyProf::FlatPrinter.new(result) | ||
# printer.print(STDOUT, :min_percent => 2) | ||
# | ||
# exit | ||
# | ||
# # User.limit(10).to_a | ||
# User.limit(10).select(:created_at).to_a | ||
# | ||
# profile("limit 10") do | ||
# User.limit(10).select(:created_at).to_a | ||
# end | ||
# | ||
# exit | ||
# User.limit(10).to_a | ||
# exit | ||
# | ||
# User.select('id, 2 bob').first | ||
# Benchmark.bmbm do |x| | ||
# | ||
# x.report("find") do | ||
# 100.times{User.find(1)} | ||
# end | ||
# | ||
# x.report("grab 10 users created_at") do | ||
# 100.times{User.limit(10).select(:created_at).to_a} | ||
# end | ||
# | ||
# x.report("grab 10 users id") do | ||
# 100.times{User.limit(10).select(:id).to_a} | ||
# end | ||
# | ||
# x.report("grab 10 users") do | ||
# 100.times{User.limit(10).to_a} | ||
# end | ||
# | ||
# | ||
# x.report("pg direct grab 10 users") do | ||
# 100.times do | ||
# r = ActiveRecord::Base.connection.raw_connection.async_exec("select * from users limit 10") | ||
# r.fields.each_with_index do |f,i| | ||
# r.ftype(i) | ||
# end | ||
# r.each_row do |x| | ||
# x | ||
# end | ||
# end | ||
# end | ||
# | ||
# end | ||
# | ||
|
||
# profile("find") do | ||
# User.find(1) | ||
# end | ||
# puts | ||
# profile("where") do | ||
# User.where(id: 1).first | ||
# end |
Oops, something went wrong.