-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_thread_traces.py
More file actions
86 lines (75 loc) · 2.11 KB
/
get_thread_traces.py
File metadata and controls
86 lines (75 loc) · 2.11 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
import os, sys
import signal
stage_names=set()
output=open("stage_output","a+")
def get_stages():
global stage_names
with open("stage_names") as f:
content = f.readlines()
stage_names=set(content)
def update_stages(stack_trace):
global stage_names
f = open("stage_names","a")
f.write(stack_trace+"\n")
def get_trace(file_name):
set_content = set()
with open(file_name) as f:
content = f.readlines()
start = 0
string =""
for line in content:
#if line contains "stack", new stack
if "Stack:" in line:
#print ("found stack start")
start = 1
if(start == 1):
#print ("found stack start")
string=string+line.rstrip('\n')
#find the last line of the trace
if not line.rstrip('\n'):
#print ("found stack end")
#print(string)
start = 0
set_content.add(string)
string = ""
return set_content
def stage_detection(signal, frame):
current_content=get_trace("current_traces")
previous_content=get_trace("previous_traces")
with open("bash_script_id") as f:
script_id = f.readline().rstrip('\n')
command="kill -2 "+script_id
diff=current_content.symmetric_difference(previous_content)
if(bool(diff)):
#print("Found new stage")
#see if present in the previous stage library
stage_name=""
#TODO: do you need prev_stage->current_stage or just
#current_stage is fine to define a stage
#for x in sorted(previous_content):
# stage_name = stage_name+x.rstrip('\n')
#stage_name = stage_name + "-->"
for x in sorted(current_content):
stage_name = stage_name+x.rstrip('\n')
#stage_found = 0
#with open("stage_names") as f1:
# for line in f1:
# if (stage_name in line.rstrip('\n')):
# stage_found = 1
# break
if(stage_name not in stage_names):
#new stage
#print("Found new stage\n")
output.write("Found new stage\n")
sys.stdout.flush()
#f = open("stage_names","a")
#f.write(stage_name+"\n")
stage_names.add(stage_name)
else:
#print("***stage change with previous stage***\n")
output.write("***stage change with previous stage***\n")
sys.stdout.flush()
os.system(command)
signal.signal(signal.SIGINT, stage_detection)
while True:
i = 1