Skip to content

Commit 89a4c92

Browse files
committed
Add HtmlGraphPrinter and comment each test
For easier running each item is commented with how to run it. But I'm now realizing I'm not profiling minitest, just Rails so creating new files to run around each minitest test.
1 parent 1a982fb commit 89a4c92

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

test/controllers/documents_controller_test.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
require 'test_helper'
22

33
class DocumentsControllerTest < ActionController::TestCase
4+
# standard test
45
test "index" do
56
get :index
67
assert_equal 200, response.status
78
end
89

10+
# will create a call stack and html graph output
11+
# ruby -I lib:test test/controllers/documents_controller_test.rb -n test_index_rp
912
test "index rp" do
1013
result = RubyProf.profile do
1114
get :index
1215
assert_equal 200, response.status
1316
end
14-
printer = RubyProf::CallStackPrinter.new(result)
15-
printer.print(STDOUT, {})
17+
File.open('graphs/inside_minitest/index_controller_callstack.html', 'w') do |file|
18+
RubyProf::CallStackPrinter.new(result).print(file)
19+
end
20+
21+
File.open('graphs/inside_minitest/index_controller_htmlgraph.html', 'w') do |file|
22+
RubyProf::GraphHtmlPrinter.new(result).print(file)
23+
end
1624
end
1725

26+
# ruby -I lib:test test/controllers/documents_controller_test.rb -n test_index_flame
1827
test "index flame" do
19-
Flamegraph.generate("graphs/#{Time.now}_controller_index.html") do
28+
Flamegraph.generate("graphs/inside_minitest/index_controller_flamegraph.html") do
2029
get :index
2130
assert_equal 200, response.status
2231
end
2332
end
2433

34+
# standard test
2535
test "create" do
2636
post :create, document: { title: "New things", content: "Doing them" }
2737

@@ -30,6 +40,7 @@ class DocumentsControllerTest < ActionController::TestCase
3040
assert_equal 'Doing them', document.content
3141
end
3242

43+
# ruby -I lib:test test/controllers/documents_controller_test.rb -n test_create_rp
3344
test "create rp" do
3445
result = RubyProf.profile do
3546
post :create, document: { title: "New things", content: "Doing them" }
@@ -38,12 +49,18 @@ class DocumentsControllerTest < ActionController::TestCase
3849
assert_equal 'New things', document.title
3950
assert_equal 'Doing them', document.content
4051
end
41-
printer = RubyProf::CallStackPrinter.new(result)
42-
printer.print(STDOUT, {})
52+
File.open('graphs/inside_minitest/create_controller_callstack.html', 'w') do |file|
53+
RubyProf::CallStackPrinter.new(result).print(file)
54+
end
55+
56+
File.open('graphs/inside_minitest/create_controller_htmlgraph.html', 'w') do |file|
57+
RubyProf::GraphHtmlPrinter.new(result).print(file)
58+
end
4359
end
4460

61+
# ruby -I lib:test test/controllers/documents_controller_test.rb -n test_create_flame
4562
test "create flame" do
46-
Flamegraph.generate("graphs/#{Time.now}_controller_create.html") do
63+
Flamegraph.generate("graphs/inside_minitest/create_controller_flamegraph.html") do
4764
post :create, document: { title: "New things", content: "Doing them" }
4865

4966
document = Document.last

test/integration/documents_integration_test.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
require 'test_helper'
22

33
class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
4+
# standard test
45
test "index" do
56
get '/documents'
67
assert_equal 200, response.status
78
end
89

10+
# ruby -I lib:test test/integration/documents_integration_test.rb -n test_index_rp
911
test "index rp" do
1012
result = RubyProf.profile do
1113
get '/documents'
1214
assert_equal 200, response.status
1315
end
14-
printer = RubyProf::CallStackPrinter.new(result)
15-
printer.print(STDOUT, {})
16+
File.open('graphs/inside_minitest/index_integration_callstack.html', 'w') do |file|
17+
RubyProf::CallStackPrinter.new(result).print(file)
18+
end
19+
20+
File.open('graphs/inside_minitest/index_integration_htmlgraph.html', 'w') do |file|
21+
RubyProf::GraphHtmlPrinter.new(result).print(file)
22+
end
1623
end
1724

25+
# ruby -I lib:test test/integration/documents_integration_test.rb -n test_index_flame
1826
test "index flame" do
19-
Flamegraph.generate("graphs/#{Time.now}_integration_index.html") do
27+
Flamegraph.generate("graphs/inside_minitest/index_integration_flamegraph.html") do
2028
get '/documents'
2129
assert_equal 200, response.status
2230
end
2331
end
2432

33+
# standard test
2534
test "create" do
2635
post '/documents', document: { title: "New things", content: "Doing them" }
2736

@@ -30,6 +39,7 @@ class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
3039
assert_equal 'Doing them', document.content
3140
end
3241

42+
# ruby -I lib:test test/integration/documents_integration_test.rb -n test_create_rp
3343
test "create rp" do
3444
result = RubyProf.profile do
3545
post '/documents', document: { title: "New things", content: "Doing them" }
@@ -38,12 +48,18 @@ class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
3848
assert_equal 'New things', document.title
3949
assert_equal 'Doing them', document.content
4050
end
41-
printer = RubyProf::CallStackPrinter.new(result)
42-
printer.print(STDOUT, {})
51+
File.open('graphs/inside_minitest/create_integration_callstack.html', 'w') do |file|
52+
RubyProf::CallStackPrinter.new(result).print(file)
53+
end
54+
55+
File.open('graphs/inside_minitest/create_integration_htmlgraph.html', 'w') do |file|
56+
RubyProf::GraphHtmlPrinter.new(result).print(file)
57+
end
4358
end
4459

60+
# ruby -I lib:test test/integration/documents_integration_test.rb -n test_create_flame
4561
test "create flame" do
46-
Flamegraph.generate("graphs/#{Time.now}_integration_create.html") do
62+
Flamegraph.generate("graphs/inside_minitest/create_integration_flamegraph.html") do
4763
post '/documents', document: { title: "New things", content: "Doing them" }
4864

4965
document = Document.last

0 commit comments

Comments
 (0)