Class: CrashAnalysis::Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/crash_analysis.rb

Instance Method Summary collapse

Constructor Details

#initializeAnalysis

Returns a new instance of Analysis.



41
42
43
# File 'lib/crash_analysis.rb', line 41

def initialize()
  @dSYM_file_name = ""
end

Instance Method Details

#analysis_action(crash_files, log_file_suffix, logs_dir_path, symbolicatecrash_path) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/crash_analysis.rb', line 78

def analysis_action(crash_files, log_file_suffix, logs_dir_path, symbolicatecrash_path)
  evn = "export DEVELOPER_DIR='/Applications/XCode.app/Contents/Developer'"
  output_log_dir = logs_dir_path + "/crash_logs"
  percent_count = 0
  if !File.directory?(output_log_dir)
    Dir.mkdir(output_log_dir)
  end

  for file in crash_files
    running_thread = Thread.new do
      short_file_name = file.split("/").last

      output_file = output_log_dir + "/" + short_file_name
      current_log_file = logs_dir_path + "/" + file
      system("#{evn} \n #{symbolicatecrash_path} #{current_log_file} #{@dSYM_file_name} > #{output_file}")
      
      percent_count = percent_count + 1
      precent = ((percent_count.to_f / crash_files.count.to_f) * 10000).round / 10000.0
      str = (precent * 100).to_s
      puts "#{str[0,4]}% || analyzing file: #{file}"
      Thread.main.wakeup
    end
    # Maximum run for 10 seconds
    sleep 10
    Thread.kill(running_thread)
  end
  puts "\n Done."
end

#run(logs_dir_path, log_file_suffix, symbolicatecrash_path) ⇒ Object



45
46
47
48
# File 'lib/crash_analysis.rb', line 45

def run(logs_dir_path, log_file_suffix, symbolicatecrash_path)
  crash_files = traverse(logs_dir_path, log_file_suffix)
  analysis_action(crash_files, log_file_suffix, logs_dir_path, symbolicatecrash_path)
end

#traverse(logs_dir_path, log_file_suffix) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/crash_analysis.rb', line 50

def traverse(logs_dir_path, log_file_suffix)
  crash_files = Array.new
  count_app = 0
  count_dSYM = 0

  Dir.foreach(logs_dir_path) do |file|
    file_suffix_array = file.strip.split(".")
    if file_suffix_array.last == log_file_suffix
      file_suffix_array.pop
      crash_files << (file)
    end
    if file_suffix_array.last == "app"
      count_app += 1
    end
    if file_suffix_array.last == "dSYM"
      @dSYM_file_name = file
      count_dSYM += 1
    end
  end

  if count_app != 1 || count_dSYM !=1 || crash_files.count < 1
      puts "error:\n"
      puts "make sure the directory contains those files: 1 .app file & 1 .dSYM file & related crash files"
    return
  end
  return crash_files
end