-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker_util.py
More file actions
369 lines (326 loc) · 11.6 KB
/
worker_util.py
File metadata and controls
369 lines (326 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
77
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# -*- coding: utf-8 -*-
import datetime
import pytz
import os
import ConfigParser
import sys
import uuid
from worker_model import Eventpaths, Instancelog
import time
__author__ = 'dookim'
class Ignore_clib:
list = [
'libWVStreamControlAPI_L1',
'libwebviewchromium',
'libLLVM.so',
'libdvm.so',
'libc.so',
'libcutils.so',
'app_process',
'libandroid_runtime.so',
'libutils.so',
'libbinder.so',
'libjavacore.so',
'librs_jni.so',
'linker',
]
def get_translated_time(origin_time):
return origin_time[:10]
def get_translated_time1(origin_time):
return origin_time[:19]
def get_translated_time2(origin_time):
now_minute = int(origin_time[14:16])
if 0 <= now_minute and now_minute < 15:
now_minute_str = '00'
elif 15 <= now_minute and now_minute < 30:
now_minute_str = '15'
elif 30 <= now_minute and now_minute < 45:
now_minute_str = '30'
elif 45 <= now_minute and now_minute < 60:
now_minute_str = '45'
translated_minute = origin_time[:14]+now_minute_str + ":00"
return translated_minute
def naive2aware(time_str):
naivetime = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S")
return naivetime.replace(tzinfo=pytz.utc)
def get_or_create(session, model, **kwargs):
instance = session.query(model).filter_by(**kwargs).first()
if instance:
return instance, False
else:
instance = model(**kwargs)
session.add(instance)
session.flush()
return instance, True
def get_or_create2(session, model, defaults=None, **kwargs):
query = session.query(model).filter_by(**kwargs)
instance = query.first()
if instance :
print "this is read operation"
return instance, False
else:
print "this is write operation"
if not defaults == None :
kwargs.update(defaults)
instance = model(**kwargs)
session.add(instance)
session.flush()
return instance, True
def make_random_file_with_content(content,path) :
temp_file_name = str(uuid.uuid1());
temp_path_and_name = os.path.join(path,temp_file_name + ".txt");
fp = open(temp_path_and_name , 'wb');
fp.write(content);
fp.close();
return temp_path_and_name;
def proguard_retrace_errors(retrace_class, errorname, errorclassname, linenum, callstack, map_path, map_filename) :
start_time = time.time();
query = 'at\t'+errorname+'\t(:%s)' % linenum + "\n";
query += 'at\t'+errorclassname+'\t(:%s)' % linenum + "\n";
query += callstack + "\n";
print "before callstack"
print callstack
map_path_and_name=os.path.join(map_path,map_filename);
print map_path_and_name
temp_result = retrace_class.getRetracedResult(query, map_path_and_name)
print "temp result"
print temp_result
splited_temp_result = temp_result.split("\n");
errorname = splited_temp_result[0]
errorclassname = splited_temp_result[1]
callstack = ""
for i in range(2, len(splited_temp_result)):
callstack += splited_temp_result[i] + "\n"
print "errorname"
print errorname
print "errorclassname"
print errorclassname
print "callstack"
print callstack
end_time = time.time()
print "processed time : " + str(end_time - start_time)
return errorname, errorclassname, callstack;
def save_event_pathes(session,retrace_class, event_path, instanceElement, errorElement ,mapElement, map_path):
if len(event_path) == 0:
print "event path is 0"
return;
depth = 10
if mapElement == None:
for event in reversed(event_path):
classname = event['classname'];
methodname = event['methodname']
linenum = event['linenum']
if not 'label' in event: #event path에 label적용, 기존버전과 호환성을 확보하기위해 'label'초기화를 해줌 client ver 0.91 ->
event['label'] = ""
label = event['label'];
#label이 300byte가 넘어갈경우 잘라줌
if(len(label) > 300) :
label = label[0:300];
eventpathInstance=Eventpaths(
idinstance = instanceElement.idinstance,
iderror = errorElement.iderror,
ins_count = errorElement.numofinstances,
datetime = naive2aware(event['datetime']),
classname = classname,
methodname = methodname,
linenum = linenum,
label = label,
depth = depth
)
session.add(eventpathInstance)
session.flush()
depth -= -1;
else :
#step 1 : make proguard query
query = get_event_path_queries(event_path);
map_path_and_name=os.path.join(map_path,mapElement.filename);
print "query"
print query
temp_result = retrace_class.getRetracedResult(query, map_path_and_name)
print "temp result"
print temp_result
result_list = temp_result.split('\n')
print "result_list"
print result_list
i = 0
print "len of event path : " +str(len(event_path))
for event in reversed(event_path):
temp_str = result_list[i]
print "class and method"
print temp_str
flag = temp_str.rfind('.')
classname = temp_str[0:flag]
methodname = temp_str[flag+1:]
linenum = event['linenum']
if not 'label' in event: #event path에 label적용, 기존버전과 호환성을 확보하기위해 'label'초기화를 해줌 client ver 0.91 ->
event['label'] = ""
eventpathInstance=Eventpaths(
idinstance = instanceElement.idinstance,
iderror = errorElement.iderror,
ins_count = errorElement.numofinstances,
datetime = naive2aware(event['datetime']),
classname = classname,
methodname = methodname,
linenum = linenum,
label = event['label'],
depth = depth
)
session.add(eventpathInstance)
session.flush()
depth -= -1;
i += 1;
def get_event_path_queries(event_path):
proguard_query = ""
for event in reversed(event_path):
temp_str = event['classname'] + '.' + event['methodname']
linenum = event['linenum'];
proguard_query += 'at\t'+temp_str+'\t(:%s)' % linenum + "\n";
return proguard_query;
def proguard_retrace_event_pathes(retrace_class, query, map_path, map_filename):
map_path_and_name=os.path.join(map_path,map_filename);
print map_path_and_name
temp_result = retrace_class.getRetracedResult(query, map_path_and_name)
result_list = temp_result.split('\n')
return result_list;
def proguard_retrace_callstack(retrace_class, content, map_path, map_filename) :
print "before callstack"
print content
temp_path_and_name = make_random_file_with_content(content,map_path);
print temp_path_and_name
map_path_and_name=os.path.join(map_path,map_filename);
print map_path_and_name
arg = ['-verbose',map_path_and_name,temp_path_and_name]
result=retrace_class.getRetracedResult(arg)
print "after callstack"
print result
os.remove(temp_path_and_name)
return result
def save_log(session, idinstance, log, savetime):
instancelog=Instancelog(
idinstance = idinstance,
log = log,
savetime= savetime
)
session.add(instancelog);
session.flush();
def client_data_validate(jsonData):
oriData = jsonData.copy();
errorFlag = 0
if not 'apikey' in jsonData:
jsonData['apikey'] = 'unknown'
errorFlag = 1
if not 'errorname' in jsonData:
jsonData['errorname'] = 'unknown'
errorFlag = 1
if not 'errorclassname' in jsonData:
jsonData['errorclassname'] = 'unknown'
errorFlag = 1
if not 'linenum' in jsonData:
jsonData['linenum'] = 'unknown'
errorFlag = 1
if not 'callstack' in jsonData:
jsonData['callstack'] = 'unknown'
errorFlag = 1
if not 'wifion' in jsonData:
jsonData['wifion'] = 0
errorFlag = 1
if not 'gpson' in jsonData:
jsonData['gpson'] = 0
errorFlag = 1
if not 'mobileon' in jsonData:
jsonData['mobileon'] = 0
errorFlag = 1
if not 'appversion' in jsonData:
jsonData['appversion'] = 'unknown'
errorFlag = 1
if not 'osversion' in jsonData:
jsonData['osversion'] = 'unknown'
errorFlag = 1
if not 'device' in jsonData:
jsonData['device'] = 'unknown'
errorFlag = 1
if not 'country' in jsonData:
jsonData['country'] = 'unknown'
errorFlag = 1
if not 'lastactivity' in jsonData:
jsonData['lastactivity'] = 'unknown'
errorFlag = 1
if not 'rank' in jsonData:
jsonData['rank'] = RANK.Critical
errorFlag = 1
if int(jsonData['rank']) < 0 or int(jsonData['rank']) > 4:
jsonData['rank'] = RANK.Critical
errorFlag = 1
if not 'sdkversion' in jsonData:
jsonData['sdkversion'] = 'unknown'
errorFlag = 1
if not 'kernelversion' in jsonData:
jsonData['kernelversion'] = 'unknown'
errorFlag = 1
if not 'appmemmax' in jsonData:
jsonData['appmemmax'] = 'unknown'
errorFlag = 1
if not 'appmemfree' in jsonData:
jsonData['appmemfree'] = 'unknown'
errorFlag = 1
if not 'appmemtotal' in jsonData:
jsonData['appmemtotal'] = 'unknown'
errorFlag = 1
if not 'locale' in jsonData:
jsonData['locale'] = 'unknown'
errorFlag = 1
if not 'rooted' in jsonData:
jsonData['rooted'] = 0
errorFlag = 1
if not 'scrheight' in jsonData:
jsonData['scrheight'] = 0
errorFlag = 1
if not 'scrwidth' in jsonData:
jsonData['scrwidth'] = 0
errorFlag = 1
if not 'scrorientation' in jsonData:
jsonData['scrorientation'] = 0
errorFlag = 1
if not 'sysmemlow' in jsonData:
jsonData['sysmemlow'] = 'unknown'
errorFlag = 1
if not 'batterylevel' in jsonData:
jsonData['batterylevel'] = 0
errorFlag = 1
if not 'availsdcard' in jsonData:
jsonData['availsdcard'] = 0
errorFlag = 1
if not 'xdpi' in jsonData:
jsonData['xdpi'] = 0
errorFlag = 1
if not 'ydpi' in jsonData:
jsonData['ydpi'] = 0
errorFlag = 1
if not 'eventpaths' in jsonData:
jsonData['eventpaths'] = 'unknown'
errorFlag = 1
#길이 체크 로직
#errorFlag는 데이터를 한번이라도 수정했는지 검사하는 부분임
if len(jsonData['errorname']) >= 499:
jsonData['errorname'] = jsonData['errorname'][0:499]
errorFlag = 1
if len(jsonData['errorclassname']) >= 299:
jsonData['errorclassname'] = jsonData['errorclassname'][0:299]
errorFlag = 1
if len(jsonData['kernelversion']) > 45:
jsonData['kernelversion'] = jsonData['kernelversion'][0:45]
errorFlag = 1
if errorFlag == 1:
print >> sys.stderr, 'exception Data Error: ', oriData
print >> sys.stderr, 'Revise JSON Data : ', jsonData
return jsonData
class RANK:
toString = ['Unhandle','Native','Critical','Major','Minor']
Suspense = -1
Unhandle = 0
Native = 1
Critical = 2
Major = 3
Minor = 4
rankcolor = ['gray','purple','red','blue','green']
rankcolorbit = ["#de6363", "#9d61dd", "#dca763", "#5a9ccc", "#72c380" ]