Class: AbstractImporter::Reporters::PerformanceReporter
- Inherits:
-
BaseReporter
- Object
- BaseReporter
- AbstractImporter::Reporters::PerformanceReporter
show all
- Defined in:
- lib/abstract_importer/reporters/performance_reporter.rb
Instance Attribute Summary collapse
Attributes inherited from BaseReporter
#io
Instance Method Summary
collapse
#batch_inserted, #count_error, #count_notice, #finish_all, #finish_setup, #finish_teardown, #start_all
Constructor Details
Returns a new instance of PerformanceReporter.
8
9
10
11
12
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 8
def initialize(io, options={})
super io
@sample_size = options.fetch(:sample_size, 50)
ObjectSpace.trace_object_allocations_start
end
|
Instance Attribute Details
#sample_size ⇒ Object
Returns the value of attribute sample_size.
6
7
8
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 6
def sample_size
@sample_size
end
|
Instance Method Details
#finish_collection(collection, summary) ⇒ Object
22
23
24
25
26
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 22
def finish_collection(collection, summary)
@collection = nil
return if @i.zero?
find_objects_holding_onto_references_to_a collection.model
end
|
#print_stats ⇒ Object
39
40
41
42
43
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 39
def print_stats
stats = GC.stat
objects = ObjectSpace.count_objects
puts "gc[minor]: #{stats[:minor_gc_count]}, gc[major]: #{stats[:major_gc_count]}, objects: #{objects[:TOTAL] - objects[:FREE]}, memsize: #{(ObjectSpace.memsize_of_all / 1048576.0).round(3)}MB, #{collection.name}: #{ObjectSpace.each_object(collection.model).count}"
end
|
#record_created(record) ⇒ Object
28
29
30
31
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 28
def record_created(record)
print_stats if @i % sample_size == 0
@i += 1
end
|
#record_failed(record, hash) ⇒ Object
33
34
35
36
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 33
def record_failed(record, hash)
print_stats if @i % sample_size == 0
@i += 1
end
|
#start_collection(collection) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/abstract_importer/reporters/performance_reporter.rb', line 15
def start_collection(collection)
super
@collection = collection
@major_gc_runs = GC.stat[:major_gc_count]
@i = 0
end
|