diff --git a/msfconsole b/msfconsole index ce2e62dfb2..8eb73f1504 100755 --- a/msfconsole +++ b/msfconsole @@ -11,6 +11,33 @@ require 'pathname' +if ENV['METASPLOIT_FRAMEWORK_PROFILE'] == 'true' + gem 'perftools.rb' + require 'perftools' + + formatted_time = Time.now.strftime('%Y%m%d%H%M%S') + root = Pathname.new(__FILE__).parent + profile_pathname = root.join('tmp', 'profiles', 'msfconsole', formatted_time) + + profile_pathname.parent.mkpath + PerfTools::CpuProfiler.start(profile_pathname.to_path) + + at_exit { + PerfTools::CpuProfiler.stop + + puts "Generating pdf" + + pdf_pathname = "#{profile_pathname}.pdf" + + + if Bundler.clean_system("pprof.rb --pdf #{profile_pathname} > #{pdf_pathname}") + puts "PDF saved to #{pdf_pathname}" + + system("open #{pdf_pathname}") + end + } +end + # # Project #