-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrolFlowextraction_sortedLinkedList.java
More file actions
239 lines (173 loc) · 8.14 KB
/
controlFlowextraction_sortedLinkedList.java
File metadata and controls
239 lines (173 loc) · 8.14 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
package org.eclipse.tracecompass.incubator.anomaly.detection.core.controlFlow;
import java.util.Collections;
import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.StateValues;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import java.util.List;
import java.util.LinkedList;
import java.io.FileWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule;
import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
public class controlFlowExtraction extends TmfAbstractAnalysisModule {
static @Nullable ITmfStateSystem myStateSystem = null;
TmfGraphBuilderModule cpaModule = null;
TmfGraph graph = null;
@Override
protected boolean executeAnalysis(@NonNull IProgressMonitor monitor) throws TmfAnalysisException {
//Read trace
ITmfTrace trace2 = getTrace();
@NonNull
ITmfTrace trace = trace2;
String outpDir = "./";
System.out.println(outpDir);
KernelAnalysisModule an = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID);
checkNotNull(an);
boolean flag = false;
Iterable<IAnalysisModule> dependentAnalyses = getDependentAnalyses();
for (IAnalysisModule module : dependentAnalyses) {
System.out.println(module.getClass());
if (!(module instanceof KernelAnalysisModule)) {
System.out.println(false);
}
System.out.println(flag);
flag = module.waitForCompletion();
}
if (flag == true && an!=null) {
myStateSystem = an.getStateSystem();
checkNotNull(myStateSystem);
writeFeatures(myStateSystem, outpDir);
}
if (myStateSystem!=null)
{
List<Integer> quarks = myStateSystem.getQuarks("CPUs","*");
System.out.println(quarks);
// System.out.println("duration(milisecond):"+(myStateSystem.getCurrentEndTime())/1000000);//-myStateSystem.getStartTime())/1000000);
}
System.out.println("finished");
return false;
}
@Override
protected void canceling() {
// TODO Auto-generated method stub
}
@Override
protected Iterable<IAnalysisModule> getDependentAnalyses() {
ITmfTrace trace = getTrace();
cpaModule = TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfGraphBuilderModule.class, CPA_ID);
checkNotNull(cpaModule);
return Collections.singleton(cpaModule);
}
private static <T> @NonNull T checkNotNull(@Nullable T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
private static void writeFeatures(ITmfStateSystem stateSystem, String outpDir) {
List<Integer> syscalls_quarks = stateSystem.getQuarks("Threads", "*", "System_call");
List<Integer> exec_name_quarks = stateSystem.getQuarks("Threads", "*", "Exec_name");
Integer[] integers = new Integer[1];
integers[0] = 1033;
List<Integer> threads_quarks = stateSystem.getQuarks("Threads","*");
checkNotNull(syscalls_quarks);
long start = stateSystem.getStartTime();
long end = stateSystem.getCurrentEndTime();
long duration = (end -start);
System.out.println("duration"+duration);
Iterable<ITmfStateInterval> iterable=null;
Iterable<ITmfStateInterval> proc_name_iterable=null;
Iterable<ITmfStateInterval> threads_iterable=null;
try {
syscalls_iterable = stateSystem.query2D(syscalls_quarks, start, end);
proc_name_iterable = stateSystem.query2D(proc_name_quarks, start, end);
threads_iterable = stateSystem.query2D(threads_quarks, start, end);
} catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
/*
for (ITmfStateInterval interval : proc_name_iterable) {//iterate over all intervals and collect metrics
Integer quark = interval.getAttribute();
Object tmp = interval.getValue();
if (tmp!=null) {
if (tmp.toString().toLowerCase().contains("mysql".toLowerCase()))
{
System.out.println(interval);
System.out.println(quark);
System.out.println(interval.getValue());
System.out.println(interval.getStateValue());
}
}
}
*/
/* for (ITmfStateInterval interval : syscalls_iterable) {//iterate over all intervals and collect metrics
Integer quark = interval.getAttribute();
System.out.println(interval);
System.out.println(quark);
}*/
// reads intervals of "mysql" thread and sort it while reading. The quark of MySql is 1033
LinkedList<ITmfStateInterval> ll_sortedIntervals = new LinkedList<>();
Long nxtstarttime;
if (threads_iterable != null)
{
for (ITmfStateInterval interval : threads_iterable) {//iterate over all intervals and collect metrics
Integer quark = interval.getAttribute();
if (quark ==1033) { // find based on proc_name =="mysql"
if (ll_sortedIntervals.size() == 0) {
ll_sortedIntervals.add(0,interval);
}
else {
Iterator<ITmfStateInterval> iter_itvl1 = ll_sortedIntervals.iterator();
Integer index_ll = 0;
while(iter_itvl1.hasNext()){
nxtstarttime = iter_itvl1.next().getStartTime();
if (nxtstarttime > interval.getStartTime()) {
ll_sortedIntervals.add(index_ll, interval);
break;
}
index_ll ++;
}
if (index_ll == ll_sortedIntervals.size()) { // interval time is bigger than current list element
ll_sortedIntervals.add(index_ll,interval);
}
}
}
}
}
System.out.println(" The intervals are sorted");
System.out.println("ll_sortedIntervals size:" + ll_sortedIntervals.size());
// Write the sorted interval in a file
Iterator<ITmfStateInterval> iter_itvl1 = ll_sortedIntervals.iterator();
FileWriter fileItvl;
String FileNameItvl = "intvl_sorted.txt";
try { // to check for fileItvl
fileItvl = new FileWriter(outpDir+FileNameItvl);
while(iter_itvl1.hasNext()){
fileItvl.write(iter_itvl1.next().toString()+"\n");
}
fileItvl.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}