Module: Metasploit::Framework::Profiler

Defined in:
lib/metasploit/framework/profiler.rb

Class Method Summary collapse

Class Method Details

.record_cpuObject


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/metasploit/framework/profiler.rb', line 42

def record_cpu
  require 'ruby-prof'

  results_path = tmp_cpu_results_path
  profile = RubyProf::Profile.new
  profile.start

  yield

  result = profile.stop
  save_cpu_result(result, path: results_path)
end

.record_memoryObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/metasploit/framework/profiler.rb', line 55

def record_memory
  raise 'Cannot mix global memory recording and localised memory recording' if record_global_memory?

  require 'memory_profiler'

  results_path = tmp_memory_results_path
  profile = MemoryProfiler
  profile.start

  yield

  result = profile.stop
  save_memory_result(result, path: results_path)
end

.startObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/metasploit/framework/profiler.rb', line 10

def start
  return unless record_global_cpu? || record_global_memory?
  raise 'Cannot profile memory and cpu at the same time' if record_global_cpu? && record_global_memory?

  if record_global_cpu?
    require 'ruby-prof'

    results_path = tmp_cpu_results_path
    profile = RubyProf::Profile.new
    profile.start

    at_exit do
      result = profile.stop
      save_cpu_result(result, path: results_path)
    end
  end

  if record_global_memory?
    require 'memory_profiler'

    results_path = tmp_memory_results_path
    profile = MemoryProfiler
    profile.start

    at_exit do
      puts "Generating memory dump #{results_path}"
      result = profile.stop
      save_memory_result(result, path: results_path)
    end
  end
end