Sha256: 48ee6219fc2bca5f869c931f21729ab11000867529599256536a1f0554d0c450

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

module BetterRailsDebugger
  class AnalysisRecorderJob < ApplicationJob
    queue_as :default

    def perform(recorded={})
      recorded = recorded.symbolize_keys
      if not recorded[:instance_id].present?
        Rails.logger.error "[BetterRailsDebugger AnalysisRecorderJob] intance_id not found. Skiping..."
        return
      end

      instance = GroupInstance.find recorded[:instance_id]
      if not instance.present?
        Rails.logger.error "[BetterRailsDebugger AnalysisRecorderJob] GroupInstance '#{recorded[:instance_id]}' not found. Skiping..."
        return
      end
      instance.status = 'processing'
      instance.save

      # Now, with the group present... we can start to work on it
      # group = instance.analysis_group

      allocations_per_file = Hash.new(0)
      memsize_per_file = Hash.new(0)
      instance.objects.all.each do |object|
        allocations_per_file[object.source_file] += 1
        memsize_per_file[object.source_file] += object.memsize
        start = (l = object.source_line - 4) >= 0 ? l : 0
        # TODO: Optimize this
        object.source_code =  IO.readlines(object.source_file)[start..(object.source_line + 4)].join("\n")
        object.save
      end
      instance.allocations_per_file = allocations_per_file.to_json
      instance.memsize_per_file = memsize_per_file.to_json
      instance.status = 'finished'
      instance.save

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
better_rails_debugger-0.2.1 app/jobs/better_rails_debugger/analysis_recorder_job.rb
better_rails_debugger-0.2.0 app/jobs/better_rails_debugger/analysis_recorder_job.rb
better_rails_debugger-0.1.1 app/jobs/better_rails_debugger/analysis_recorder_job.rb
better_rails_debugger-0.0.4 app/jobs/better_rails_debugger/analysis_recorder_job.rb