derailed_benchmarks 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24d0d07556d2d6676ea8b2c06d58583071fd9302c056d36db05d252480889308
4
- data.tar.gz: 0c783db16c1612173975c12760b101fc30cbd5765d296b2fd66506992305ac69
3
+ metadata.gz: c0f29e3b52bfe2c3c549a9908cf835ec63430afc8d8c733f8ccbf73646b0aa07
4
+ data.tar.gz: c43b9cc6602884bc33c3e6479b75250564ef4b54f895b87a6d0b5f79f4469704
5
5
  SHA512:
6
- metadata.gz: e37aa667a5fe031a384a343de999a34ef9f1e0ba98f8190d6f86d326ee30f968e3555344fbaf8841f99da85354c2b4383fe1b75ab166eb0df9134d20ee48fd95
7
- data.tar.gz: 3f581637e835d808b8264786ffd70159fe534c4147e72e65f5649fe7ecb0b92b9edc215c9edd43e2ca51a510793ae475da3e0318262103bb741823746d9f3421
6
+ metadata.gz: 23583aa213f4f2ddb8ead5c9325972bd8fc696289303e16faf34023e5f732288d51cd9d5fe9edb0f37a44c0a1f3ebbe32d74c6355ba85b4f9dd1793e8e3359d5
7
+ data.tar.gz: f4074b2f83fd12c4b81e4f9714bae62a0ed15e012d2a4a821d2c038fc537b9b511475482e4928d689421ba473cfb91543431866d1cd424cf6db101b792bcfdb8
data/Appraisals CHANGED
@@ -1,26 +1,26 @@
1
1
  # -*- mode: ruby -*-
2
2
  # vi: set ft=ruby :
3
3
 
4
- appraise "rails-3-2" do
5
- gem "rails", "~> 3.2.0"
6
- end
4
+ # appraise "rails-3-2" do
5
+ # gem "rails", "~> 3.2.0"
6
+ # end
7
7
 
8
- appraise "rails-4-0" do
9
- gem "rails", "~> 4.0.0"
10
- end
8
+ # appraise "rails-4-0" do
9
+ # gem "rails", "~> 4.0.0"
10
+ # end
11
11
 
12
- appraise "rails-4-1" do
13
- gem "rails", "~> 4.1.0"
14
- end
12
+ # appraise "rails-4-1" do
13
+ # gem "rails", "~> 4.1.0"
14
+ # end
15
15
 
16
- appraise "rails-4-2" do
17
- gem "rails", "~> 4.2.0"
18
- end
16
+ # appraise "rails-4-2" do
17
+ # gem "rails", "~> 4.2.0"
18
+ # end
19
19
 
20
- appraise "rails-5-0" do
21
- gem "rails", "~> 5.0.0"
22
- end
20
+ # appraise "rails-5-0" do
21
+ # gem "rails", "~> 5.0.0"
22
+ # end
23
23
 
24
24
  appraise "rails-5-1" do
25
- gem "rails", "~> 5.1.0"
25
+ gem "rails", "~> 5.1.7"
26
26
  end
@@ -1,5 +1,10 @@
1
1
  ## HEAD
2
2
 
3
+ ## 1.8.1
4
+
5
+ - Derailed now tracks memory use from `load` in addition to `require` (https://github.com/schneems/derailed_benchmarks/pull/178)
6
+ - Correct logging of unsuccessful curl requests to file (https://github.com/schneems/derailed_benchmarks/pull/172)
7
+
3
8
  ## 1.8.0
4
9
 
5
10
  - Ruby 2.2 is now officialy supported and tested (https://github.com/schneems/derailed_benchmarks/pull/177)
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # BUNDLE_GEMFILE="gemfiles/rails_5_1.gemfile" bundle exec m test/integration/tasks_test.rb:30
4
+ #
3
5
  # This file was generated by Appraisal
4
6
 
5
7
  source "https://rubygems.org"
6
8
 
7
- gem "rails", "~> 5.1.0"
9
+ gem "rails", "~> 5.1.7"
8
10
 
9
11
  group :development, :test do
10
12
  gem "sqlite3", platform: [:ruby, :mswin, :mingw]
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
2
+ #
3
+ # BUNDLE_GEMFILE="gemfiles/rails_5_2.gemfile" bundle exec m test/integration/tasks_test.rb:30
4
4
 
5
5
  source "https://rubygems.org"
6
6
 
7
- gem "rails", "~> 5.2.0"
7
+ gem "rails", "~> 5.2.4.4"
8
8
 
9
9
  group :development, :test do
10
10
  gem "sqlite3", platform: [:ruby, :mswin, :mingw]
@@ -17,12 +17,16 @@ module Kernel
17
17
 
18
18
  alias_method :original_require, :require
19
19
  alias_method :original_require_relative, :require_relative
20
+ alias_method(:original_load, :load)
21
+
22
+ def load(file, wrap = false)
23
+ measure_memory_impact(file) do |file|
24
+ original_load(file)
25
+ end
26
+ end
20
27
 
21
28
  def require(file)
22
29
  measure_memory_impact(file) do |file|
23
- # "source_annotation_extractor" is deprecated in Rails 6
24
- # # if we don't skip the library it leads to a crash
25
- # next if file == "rails/source_annotation_extractor" && Rails.version >= '6.0'
26
30
  original_require(file)
27
31
  end
28
32
  end
@@ -67,22 +71,29 @@ module Kernel
67
71
  end
68
72
  end
69
73
 
70
- # Top level node that will store all require information for the entire app
71
- TOP_REQUIRE = DerailedBenchmarks::RequireTree.new("TOP")
72
- REQUIRE_STACK.push(TOP_REQUIRE)
73
74
 
75
+ # I honestly have no idea why this Object delegation is needed
76
+ # I keep staring at bootsnap and it doesn't have to do this
77
+ # is there a bug in their implementation they haven't caught or
78
+ # am I doing something different?
74
79
  class Object
75
80
  private
81
+ def load(path, wrap = false)
82
+ Kernel.load(path, wrap)
83
+ end
76
84
 
77
85
  def require(path)
78
86
  Kernel.require(path)
79
87
  end
80
88
  end
81
89
 
82
- # Don't forget to assign a cost to the top level
83
- cost_before_requiring_anything = GetProcessMem.new.mb
84
- TOP_REQUIRE.cost = cost_before_requiring_anything
90
+ # Top level node that will store all require information for the entire app
91
+ TOP_REQUIRE = DerailedBenchmarks::RequireTree.new("TOP")
92
+ REQUIRE_STACK.push(TOP_REQUIRE)
93
+ TOP_REQUIRE.cost = GetProcessMem.new.mb
94
+
85
95
  def TOP_REQUIRE.print_sorted_children(*args)
86
96
  self.cost = GetProcessMem.new.mb - self.cost
87
97
  super
88
98
  end
99
+
@@ -110,7 +110,7 @@ namespace :perf do
110
110
  STDERR.puts "Bad request to #{cmd.inspect} \n\n***RESPONSE***:\n\n#{ response.inspect }"
111
111
 
112
112
  FileUtils.mkdir_p("tmp")
113
- File.open("tmp/fail.html", "w+") {|f| f.write response.body }
113
+ File.open("tmp/fail.html", "w+") {|f| f.write response }
114
114
 
115
115
  `open #{File.expand_path("tmp/fail.html")}` if ENV["DERAILED_DEBUG"]
116
116
 
@@ -13,6 +13,16 @@ module DerailedBenchmarks
13
13
  def initialize(name)
14
14
  @name = name
15
15
  @children = {}
16
+ @cost = 0
17
+ end
18
+
19
+ def self.reset!
20
+ REQUIRED_BY.clear
21
+ if defined?(Kernel::REQUIRE_STACK)
22
+ Kernel::REQUIRE_STACK.clear
23
+
24
+ Kernel::REQUIRE_STACK.push(TOP_REQUIRE)
25
+ end
16
26
  end
17
27
 
18
28
  def <<(tree)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DerailedBenchmarks
4
- VERSION = "1.8.0"
4
+ VERSION = "1.8.1"
5
5
  end
@@ -3,7 +3,6 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class KernelRequireTest < ActiveSupport::TestCase
6
-
7
6
  setup do
8
7
  require 'derailed_benchmarks/core_ext/kernel_require'
9
8
  GC.disable
@@ -11,23 +10,83 @@ class KernelRequireTest < ActiveSupport::TestCase
11
10
 
12
11
  teardown do
13
12
  GC.enable
13
+ DerailedBenchmarks::RequireTree.reset!
14
+ end
15
+
16
+ test "profiles load" do
17
+ in_fork do
18
+ require fixtures_dir("require/load_parent.rb")
19
+
20
+ parent = assert_node_in_parent("load_parent.rb", TOP_REQUIRE)
21
+
22
+ assert_node_in_parent("load_child.rb", parent)
23
+ end
24
+ end
25
+
26
+ test "profiles autoload" do
27
+ skip if RUBY_VERSION.start_with?("2.2") # Fails on CI, I can't install Ruby 2.2 locally to debug https://stackoverflow.com/questions/63926460/install-ruby-2-2-on-mac-osx-catalina-with-ruby-install, https://github.com/postmodern/ruby-install/issues/375
28
+
29
+ in_fork do
30
+ require fixtures_dir("require/autoload_parent.rb")
31
+ parent = assert_node_in_parent("autoload_parent.rb", TOP_REQUIRE)
32
+
33
+ assert_node_in_parent("autoload_child.rb", parent)
34
+ end
14
35
  end
15
36
 
37
+ test "core extension profiles useage" do
38
+ in_fork do
39
+ require fixtures_dir("require/parent_one.rb")
40
+ parent = assert_node_in_parent("parent_one.rb", TOP_REQUIRE)
41
+ assert_node_in_parent("child_one.rb", parent)
42
+ child_two = assert_node_in_parent("child_two.rb", parent)
43
+ assert_node_in_parent("relative_child", parent)
44
+ assert_node_in_parent("relative_child_two", parent)
45
+ assert_node_in_parent("raise_child.rb", child_two)
46
+ end
47
+ end
48
+
49
+ # Checks to see that the given file name is present in the
50
+ # parent tree node and that the memory of that file
51
+ # is less than the parent (since the parent should include itself
52
+ # plus its children)
53
+ #
54
+ # Returns the child node
16
55
  def assert_node_in_parent(file_name, parent)
17
56
  file = fixtures_dir(File.join("require", file_name))
18
57
  node = parent[file]
19
- assert node, "Expected:\n#{parent.children}\nto include:\n#{file.inspect}"
20
- assert node.cost < parent.cost, "Expected:\n#{node.inspect}\nto cost less than:\n#{parent.inspect}" unless parent == TOP_REQUIRE
58
+ assert node, "Expected: #{parent.name} to include: #{file.to_s} but it did not.\nChildren: #{parent.children.map(&:name).map(&:to_s)}"
59
+ unless parent == TOP_REQUIRE
60
+ assert node.cost < parent.cost, "Expected: #{node.name.inspect} (#{node.cost}) to cost less than: #{parent.name.inspect} (#{parent.cost})"
61
+ end
21
62
  node
22
63
  end
23
64
 
24
- test "core extension profiles useage" do
25
- require fixtures_dir("require/parent_one.rb")
26
- parent = assert_node_in_parent("parent_one.rb", TOP_REQUIRE)
27
- assert_node_in_parent("child_one.rb", parent)
28
- child_two = assert_node_in_parent("child_two.rb", parent)
29
- assert_node_in_parent("relative_child", parent)
30
- assert_node_in_parent("relative_child_two", parent)
31
- assert_node_in_parent("raise_child.rb", child_two)
65
+ # Used to get semi-clean process memory
66
+ # It would be better to run the requires in a totally different process
67
+ # but...that would take engineering
68
+ #
69
+ # If I was going to do that, I would find a way to serialize RequireTree
70
+ # into a json structure with file names and costs, run the script
71
+ # dump the json to a file, then in this process read the file and
72
+ # run assertions
73
+ def in_fork
74
+ Tempfile.create("stdout") do |tmp_file|
75
+ pid = fork do
76
+ $stdout.reopen(tmp_file, "w")
77
+ $stderr.reopen(tmp_file, "w")
78
+ $stdout.sync = true
79
+ $stderr.sync = true
80
+ yield
81
+ Kernel.exit!(0) # needed for https://github.com/seattlerb/minitest/pull/683
82
+ end
83
+ Process.waitpid(pid)
84
+
85
+ if $?.success?
86
+ print File.read(tmp_file)
87
+ else
88
+ raise File.read(tmp_file)
89
+ end
90
+ end
32
91
  end
33
92
  end
@@ -9,7 +9,7 @@ class RequireTree < ActiveSupport::TestCase
9
9
  end
10
10
 
11
11
  def teardown
12
- DerailedBenchmarks::RequireTree.const_set("REQUIRED_BY", {})
12
+ DerailedBenchmarks::RequireTree.reset!
13
13
  end
14
14
 
15
15
  test "default_cost" do
@@ -0,0 +1,5 @@
1
+ @retained = String.new("")
2
+ 1_000_000.times.map { @retained << "A" }
3
+
4
+ module AutoLoadChild
5
+ end
@@ -0,0 +1,8 @@
1
+ @retained = String.new("")
2
+ 1_000_000.times.map { @retained << "A" }
3
+
4
+ autoload :AutoLoadChild, File.join(__dir__, 'autoload_child.rb')
5
+
6
+ if AutoLoadChild
7
+ # yay
8
+ end
@@ -0,0 +1,3 @@
1
+ @retained = String.new("")
2
+ 1_000_000.times.map { @retained << "A" }
3
+
@@ -0,0 +1,5 @@
1
+ @retained = String.new("")
2
+ 1_000_000.times.map { @retained << "A" }
3
+
4
+ load File.join(__dir__, "load_child.rb")
5
+
@@ -51,7 +51,6 @@ class ActiveSupport::IntegrationCase
51
51
  end
52
52
  end
53
53
 
54
-
55
54
  def fixtures_dir(name = "")
56
55
  root_path("test/fixtures").join(name)
57
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: derailed_benchmarks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Schneeman
@@ -272,8 +272,12 @@ files:
272
272
  - test/derailed_benchmarks/require_tree_test.rb
273
273
  - test/derailed_benchmarks/stats_from_dir_test.rb
274
274
  - test/derailed_test.rb
275
+ - test/fixtures/require/autoload_child.rb
276
+ - test/fixtures/require/autoload_parent.rb
275
277
  - test/fixtures/require/child_one.rb
276
278
  - test/fixtures/require/child_two.rb
279
+ - test/fixtures/require/load_child.rb
280
+ - test/fixtures/require/load_parent.rb
277
281
  - test/fixtures/require/parent_one.rb
278
282
  - test/fixtures/require/raise_child.rb
279
283
  - test/fixtures/require/relative_child.rb
@@ -358,8 +362,12 @@ test_files:
358
362
  - test/derailed_benchmarks/require_tree_test.rb
359
363
  - test/derailed_benchmarks/stats_from_dir_test.rb
360
364
  - test/derailed_test.rb
365
+ - test/fixtures/require/autoload_child.rb
366
+ - test/fixtures/require/autoload_parent.rb
361
367
  - test/fixtures/require/child_one.rb
362
368
  - test/fixtures/require/child_two.rb
369
+ - test/fixtures/require/load_child.rb
370
+ - test/fixtures/require/load_parent.rb
363
371
  - test/fixtures/require/parent_one.rb
364
372
  - test/fixtures/require/raise_child.rb
365
373
  - test/fixtures/require/relative_child.rb