Method: TestingMemory.generate_mem_report

Defined in:
lib/testing_memory/testing_memory.rb

.generate_mem_reportObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/testing_memory/testing_memory.rb', line 142

def generate_mem_report
  # Generate memory report
  current_objects_counters = {}

  count = ObjectSpace.each_object(String).count
  current_objects_counters['String'] = count
  count = ObjectSpace.each_object(ContentData::ContentData).count
  current_objects_counters['ContentData'] = count
  dir_count = ObjectSpace.each_object(FileMonitoring::DirStat).count
  current_objects_counters['DirStat'] = dir_count
  file_count = ObjectSpace.each_object(FileMonitoring::FileStat).count
  current_objects_counters['FileStat'] = file_count

  # Generate report and update global counters
  report = ""
  current_objects_counters.each_key { |type|
    report += "Type:#{type} count:#{current_objects_counters[type]}   \n"
  }
  unless Gem::win_platform?
    memory_of_process = `ps -o rss= -p #{Process.pid}`.to_i / 1000
  else
    memory_of_process = `tasklist /FI \"PID eq #{Process.pid}\" /NH /FO \"CSV\"`.split(',')[4]
  end
  final_report = "Time:#{Time.now}.  Process memory:#{memory_of_process}[M]\nCount report:\n#{report}"
  puts "Process memory:#{memory_of_process}[M]"
  $testing_memory_log.info(final_report)
  final_report
end