How to use exclude_common_methods method of RubyProf Package

Best Test-prof_ruby code snippet using RubyProf.exclude_common_methods

ruby_prof.rb

Source:ruby_prof.rb Github

copy

Full Screen

...41 "call_stack" => "html"42 }.freeze43 LOGFILE_PREFIX = "ruby-prof-report"44 attr_accessor :printer, :mode, :min_percent,45 :include_threads, :exclude_common_methods,46 :test_prof_exclusions_enabled,47 :custom_exclusions48 def initialize49 @printer = ENV["TEST_RUBY_PROF"].to_sym if PRINTERS.key?(ENV["TEST_RUBY_PROF"])50 @printer ||= ENV.fetch("TEST_RUBY_PROF_PRINTER", :flat).to_sym51 @mode = ENV.fetch("TEST_RUBY_PROF_MODE", :wall).to_sym52 @min_percent = 153 @include_threads = false54 @exclude_common_methods = true55 @test_prof_exclusions_enabled = true56 @custom_exclusions = {}57 end58 def include_threads?59 include_threads == true60 end61 def exclude_common_methods?62 exclude_common_methods == true63 end64 def test_prof_exclusions_enabled?65 @test_prof_exclusions_enabled == true66 end67 # Returns an array of printer type (ID) and class.68 def resolve_printer69 return ["custom", printer] if printer.is_a?(Module)70 type = printer.to_s71 raise ArgumentError, "Unknown printer: #{type}" unless72 PRINTERS.key?(type)73 [type, ::RubyProf.const_get(PRINTERS[type])]74 end75 end76 # Wrapper over RubyProf profiler and printer77 class Report78 include TestProf::Logging79 def initialize(profiler)80 @profiler = profiler81 end82 # Stop profiling and generate the report83 # using provided name.84 def dump(name)85 result = @profiler.stop86 printer_type, printer_class = config.resolve_printer87 if %w[call_tree multi].include?(printer_type)88 path = TestProf.create_artifact_dir89 printer_class.new(result).print(90 path: path,91 profile: "#{RubyProf::Configuration::LOGFILE_PREFIX}-#{printer_type}-" \92 "#{config.mode}-#{name}",93 min_percent: config.min_percent94 )95 else96 path = build_path name, printer_type97 File.open(path, "w") do |f|98 printer_class.new(result).print(f, min_percent: config.min_percent)99 end100 end101 log :info, "RubyProf report generated: #{path}"102 end103 private104 def build_path(name, printer)105 TestProf.artifact_path(106 "#{RubyProf::Configuration::LOGFILE_PREFIX}-#{printer}-#{config.mode}-#{name}" \107 ".#{RubyProf::Configuration::PRINTER_EXTENSTION.fetch(printer, "txt")}"108 )109 end110 def config111 RubyProf.config112 end113 end114 class << self115 include Logging116 def config117 @config ||= Configuration.new118 end119 def configure120 yield config121 end122 # Run RubyProf and automatically dump123 # a report when the process exits.124 #125 # Use this method to profile the whole run.126 def run127 report = profile128 return unless report129 @locked = true130 log :info, "RubyProf enabled globally"131 at_exit { report.dump("total") }132 end133 def profile134 if locked?135 log :warn, <<~MSG136 RubyProf is activated globally, you cannot generate per-example report.137 Make sure you haven's set the TEST_RUBY_PROF environmental variable.138 MSG139 return140 end141 return unless init_ruby_prof142 options = {143 merge_fibers: true144 }145 options[:include_threads] = [Thread.current] unless146 config.include_threads?147 profiler = ::RubyProf::Profile.new(options)148 profiler.exclude_common_methods! if config.exclude_common_methods?149 if config.test_prof_exclusions_enabled?150 # custom test-prof exclusions151 exclude_rspec_methods(profiler)152 # custom global exclusions153 exclude_common_methods(profiler)154 end155 config.custom_exclusions.each do |klass, mids|156 profiler.exclude_methods! klass, *mids157 end158 profiler.start159 Report.new(profiler)160 end161 private162 def locked?163 @locked == true164 end165 def init_ruby_prof166 return @initialized if instance_variable_defined?(:@initialized)167 ENV["RUBY_PROF_MEASURE_MODE"] = config.mode.to_s168 @initialized = TestProf.require(169 "ruby-prof",170 <<~MSG171 Please, install 'ruby-prof' first:172 # Gemfile173 gem 'ruby-prof', '>= 0.16.0', require: false174 MSG175 ) { check_ruby_prof_version }176 end177 def check_ruby_prof_version178 if Utils.verify_gem_version("ruby-prof", at_least: "0.17.0")179 true180 else181 log :error, <<~MGS182 Please, upgrade 'ruby-prof' to version >= 0.17.0.183 MGS184 false185 end186 end187 def exclude_rspec_methods(profiler)188 return unless TestProf.rspec?189 RSpecExclusions.generate.each do |klass, mids|190 profiler.exclude_methods!(klass, *mids)191 end192 end193 def exclude_common_methods(profiler)194 profiler.exclude_methods!(195 TSort,196 :tsort_each197 )198 profiler.exclude_methods!(199 TSort.singleton_class,200 :tsort_each, :each_strongly_connected_component,201 :each_strongly_connected_component_from202 )203 profiler.exclude_methods!(204 BasicObject,205 :instance_exec206 )207 end...

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1printer = RubyProf::FlatPrinter.new(result)2printer.print(STDOUT)3printer = RubyProf::GraphPrinter.new(result)4printer.print(STDOUT, :min_percent => 1)5printer = RubyProf::CallStackPrinter.new(result)6printer.print(STDOUT, :min_percent => 1)7printer = RubyProf::CallTreePrinter.new(result)8printer.print(:path => ".", :profile => "profile")9printer = RubyProf::FlatPrinter.new(result)10printer.print(File.open("profile.html", "w+"), :min_percent => 1)11printer = RubyProf::GraphPrinter.new(result)12printer.print(File.open("profile.html", "w+"), :min_percent => 1)13printer = RubyProf::CallStackPrinter.new(result)14printer.print(File.open("profile.html", "w+"), :min_percent => 1)15printer = RubyProf::CallTreePrinter.new(result)16printer.print(:path => ".", :profile => "profile")17printer = RubyProf::FlatPrinter.new(result)18printer.print(File.open("profile.json", "w+"), :min_percent => 1)19printer = RubyProf::GraphPrinter.new(result)20printer.print(File.open("profile.json", "w+"), :min_percent => 1)21printer = RubyProf::CallStackPrinter.new(result)22printer.print(File.open("profile.json", "w+"), :min_percent => 1)23printer = RubyProf::CallTreePrinter.new(result)24printer.print(:path => ".", :profile => "profile")25printer = RubyProf::FlatPrinter.new(result)26printer.print(File.open("profile.yaml", "w+"), :min_percent => 1)27printer = RubyProf::GraphPrinter.new(result)28printer.print(File.open("profile.yaml", "w+"), :min_percent =>

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1printer = RubyProf::GraphHtmlPrinter.new(result)2printer.print(File.open('graph.html', 'w'))3printer = RubyProf::CallTreePrinter.new(result)4printer.print(path: 'callgrind.out', profile: 'profile')5printer = RubyProf::CallStackPrinter.new(result)6printer.print(path: 'stack.html', profile: 'profile')7printer = RubyProf::CallTreePrinter.new(result)8printer.print(path: 'callgrind.out', profile: 'profile', exclude_common_methods: true)9printer = RubyProf::CallStackPrinter.new(result)10printer.print(path: 'stack.html', profile: 'profile', exclude_common_methods: true)11printer = RubyProf::GraphHtmlPrinter.new(result)12printer.print(File.open('graph.html', 'w'), exclude_common_methods: true)13printer = RubyProf::GraphPrinter.new(result)14printer.print(File.open('graph.txt', 'w'), exclude_common_methods: true)15printer = RubyProf::MultiPrinter.new(result)16printer.print(path: '.', profile: 'profile', exclude_common_methods: true)

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1printer = RubyProf::FlatPrinter.new(result)2printer.print(STDOUT)3printer = RubyProf::GraphPrinter.new(result)4printer.print(STDOUT, :min_percent => 1)5printer = RubyProf::CallStackPrinter.new(result)6printer.print(STDOUT, :min_percent => 1)7printer = RubyProf::CallTreePrinter.new(result)8printer.print(:path => ".", :profile => "profile")9printer = RubyProf::FlatPrinter.new(result)10printer.print(File.open("profile.html", "w+"), :min_percent => 1)11printer = RubyProf::GraphPrinter.new(result)12printer.print(File.open("profile.html", "w+"), :min_percent => 1)13printer = RubyProf::CallStackPrinter.new(result)14printer.print(File.open("profile.html", "w+"), :min_percent => 1)15printer = RubyProf::CallTreePrinter.new(result)16printer.print(:path => ".", :profile => "profile")17printer = RubyProf::FlatPrinter.new(result)18printer.print(File.open("profile.json", "w+"), :min_percent => 1)19printer = RubyProf::GraphPrinter.new(result)20printer.print(File.open("profile.json", "w+"), :min_percent => 1)21printer = RubyProf::CallStackPrinter.new(result)22printer.print(File.open("profile.json", "w+"), :min_percent => 1)23printer = RubyProf::CallTreePrinter.new(result)24printer.print(:path => ".", :profile => "profile")25printer = RubyProf::FlatPrinter.new(result)26printer.print(File.open("profile.yaml", "w+"), :min_percent => 1)27printer = RubyProf::GraphPrinter.new(result)28printer.print(File.open("profile.yaml", "w+"), :min_percent =>

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1printer = RubyProf::GraphHtmlPrinter.new(result)2printer.print(STDOUT)3printer = RubyProf::GraphHtmlPrinter.new(result)4printer.print(STDOUT)

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1def fib(n)2 fib(n-1) + fib(n-2)3fib(35)4printer = RubyProf::GraphHtmlPrinter.new(result)5printer.print(File.open('1.html', 'w'))

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1printer = RubyProf::GraphHtmlPrinter.new(result)2printer.print(STDOUT, :exclude_common_methods => true)3printer = RubyProf::GraphHtmlPrinter.new(result)4printer.print(STDOUT, :exclude_common_methods => true)

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1RubyProf.exclude_common_methods(result)2printer = RubyProf::FlatPrinter.new(result)3printer.print(STDOUT, 0)

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1Net::HTTP.get('www.google.com', '/')2printer = RubyProf::GraphHtmlPrinter.new(result)3printer.print(File.new('1.html', 'w+'))4Net::HTTP.get('www.google.com', '/')5printer = RubyProf::GraphPrinter.new(result)6printer.print(File.new('2.html', 'w+'))7Ruby | RubyProf::CallTreePrinter (with Line Numbers)8Ruby | RubyProf::CallTreePrinter (with Source Code)9Ruby | RubyProf::CallTreePrinter (with Source Code and Line Numbers)10Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers and Method Names)11Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names and Thread Names)12Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names and Time)13Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time and Children)14Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time, Children and Total Time)15Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time, Children, Total Time and Wait Time)16Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time, Children, Total Time, Wait Time and Extra Data)17printer = RubyProf::CallTreePrinter.new(result)18printer.print(:path => '.', :profile => 'profile', :exclude_common_methods => true)19printer = RubyProf::FlatPrinter.new(result)20printer.print(STDOUT, :exclude_common_methods => true)21printer = RubyProf::FlatPrinterWithLineNumbers.new(result)22printer.print(STDOUT, :exclude_common_methods => true)23printer = RubyProf::GraphPrinter.new(result)24printer.print(STDOUT, :exclude_common_methods => true)25printer = RubyProf::CallStackPrinter.new(result)26printer.print(STDOUT, :exclude_common_methods => true)

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1RubyProf.exclude_common_methods(result)2printer = RubyProf::FlatPrinter.new(result)3printer.print(STDOUT, 0)

Full Screen

Full Screen

exclude_common_methods

Using AI Code Generation

copy

Full Screen

1Net::HTTP.get('www.google.com', '/')2printer = RubyProf::GraphHtmlPrinter.new(result)3printer.print(File.new('1.html', 'w+'))4Net::HTTP.get('www.google.com', '/')5printer = RubyProf::GraphPrinter.new(result)6printer.print(File.new('2.html', 'w+'))7Ruby | RubyProf::CallTreePrinter (with Line Numbers)8Ruby | RubyProf::CallTreePrinter (with Source Code)9Ruby | RubyProf::CallTreePrinter (with Source Code and Line Numbers)10Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers and Method Names)11Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names and Thread Names)12Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names and Time)13Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time and Children)14Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time, Children and Total Time)15Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time, Children, Total Time and Wait Time)16Ruby | RubyProf::CallTreePrinter (with Source Code, Line Numbers, Method Names, Thread Names, Time, Children, Total Time, Wait Time and Extra Data)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Test-prof_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful