Skip to content

Commit 21b3d6b

Browse files
committed
Profiling support for msfconsole boot
Set METASPLOIT_FRAMEWORK_PROFILE=true in the environment. Run `./msfconsole -q -x exit`. A pdf will be saved to tmp/profiles/msfconsole/YYYYMMDDHHMMSS.pdf with the call graph with numbers being in 100 samples per second. The pdf is automatically opened with `open`.
1 parent b5c3c87 commit 21b3d6b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

msfconsole

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@
1111

1212
require 'pathname'
1313

14+
if ENV['METASPLOIT_FRAMEWORK_PROFILE'] == 'true'
15+
gem 'perftools.rb'
16+
require 'perftools'
17+
18+
formatted_time = Time.now.strftime('%Y%m%d%H%M%S')
19+
root = Pathname.new(__FILE__).parent
20+
profile_pathname = root.join('tmp', 'profiles', 'msfconsole', formatted_time)
21+
22+
profile_pathname.parent.mkpath
23+
PerfTools::CpuProfiler.start(profile_pathname.to_path)
24+
25+
at_exit {
26+
PerfTools::CpuProfiler.stop
27+
28+
puts "Generating pdf"
29+
30+
pdf_pathname = "#{profile_pathname}.pdf"
31+
32+
33+
if Bundler.clean_system("pprof.rb --pdf #{profile_pathname} > #{pdf_pathname}")
34+
puts "PDF saved to #{pdf_pathname}"
35+
36+
system("open #{pdf_pathname}")
37+
end
38+
}
39+
end
40+
1441
#
1542
# Project
1643
#

0 commit comments

Comments
 (0)