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.



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

def initialize()
  @percentCount = 0
end

Instance Method Details

#AnalysisLog(crashFileNames, rawFileSuffix, filePath) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/crash_analysis.rb', line 100

def AnalysisLog(crashFileNames, rawFileSuffix, filePath)
  cmd = "/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash"
  evn = "export DEVELOPER_DIR='/Applications/XCode.app/Contents/Developer'"
  logDir = filePath + "/crash_logs"

  if !File.directory?(logDir)
    Dir.mkdir(logDir)
  end

  for fileName in crashFileNames
    runningThread = Thread.new do
      shortFileName = fileName.split("/").last
      outputFile = logDir + "/" + shortFileName +".log"
      system("#{evn} \n #{cmd} #{fileName}.#{rawFileSuffix} BDPhoneBrowser.app.dSYM > #{outputFile}")
      @percentCount = @percentCount + 1
      precent = ((@percentCount.to_f / crashFileNames.count.to_f) * 10000).round / 10000.0
      str = (precent * 100).to_s
      print "\r #{str[0,4]}%"
      Thread.main.wakeup
    end
    # Maximum run for 10 seconds
    sleep 10
    Thread.kill(runningThread)
  end
  puts "\n Done."
end

#run(filePath, rawFileSuffix) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/crash_analysis.rb', line 48

def run(filePath, rawFileSuffix)
  if rawFileSuffix.nil? || rawFileSuffix.empty?
      puts "error: need 2 arguments DirPath & raw log file suffix like:txt, log, crash..."
      return
    end
    if filePath.nil? || filePath.empty?
      puts "error: need directory path"
    else
      if File.directory?(filePath)
        crashFileNames = traverse(filePath, rawFileSuffix)
        if crashFileNames.nil? || crashFileNames.empty?
          return
        else
           AnalysisLog(crashFileNames, rawFileSuffix, filePath)
        end
      else
        puts "error: not a directory"
      end
    end
end

#traverse(filePath, rawFileSuffix) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/crash_analysis.rb', line 69

def traverse(filePath, rawFileSuffix)
  crashFileNames = Array.new
  countApp = 0
  countDSYM = 0
  if File.directory?(filePath)
    Dir.foreach(filePath) do |fileName|
      fileSuffixArray = fileName.strip.split(".")
      if fileSuffixArray.last == rawFileSuffix
        fileSuffixArray.pop
        crashFileNames << (filePath + "/" + fileSuffixArray.first)
      end
      if fileSuffixArray.last == "app"
        countApp += 1
      end
      if fileSuffixArray.last == "dSYM"
        countDSYM += 1
      end
    end
  else
    puts "Files:" + filePath
  end

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

  return crashFileNames
end