-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogAnalysis.java
424 lines (337 loc) · 14.9 KB
/
LogAnalysis.java
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
package ibmcodes;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import ibmcodes.SyncPipe;
public class LogAnalysis {
public static void countFrequencies(ArrayList<String> list)
{
// hashmap to store the frequency of element
Map<String, Integer> hm = new HashMap<String, Integer>();
for (String i : list) {
Integer j = hm.get(i);
hm.put(i, (j == null) ? 1 : j + 1);
}
// displaying the occurrence of elements in the arraylist
System.out.println("-----------------------------------------------------------------------------");
System.out.printf("%30s %20s", "TraceEntry", "Count");
System.out.println();
System.out.println("-----------------------------------------------------------------------------");
for (Map.Entry<String, Integer> val : hm.entrySet()) {
System.out.format("%30s %20s",val.getKey(), val.getValue());
System.out.println();
// System.out.print(val.getKey() + "\t\t\t "+ val.getKey());
// System.out.println();
}
}
public static void main(String[] args) {
String[] command =
{
"cmd",
};
Process p;
HashMap<Double,String> hmm=new HashMap<Double,String>();
HashMap<Double,String> hm=new HashMap<Double,String>();
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> lis = new ArrayList<String>();
try {
//Converting to log file
p = Runtime.getRuntime().exec(command);
new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
PrintWriter stdin = new PrintWriter(p.getOutputStream());
IbmGuiWindow g = new IbmGuiWindow();
String str = g.getPassingFile();
String str2 = g.getFailingFile();
if(str.equals("") && str2.equals("")) {
System.out.println("Enter appropriate names of the java files.");
}
else {
stdin.println("cd C:\\Users\\Dell pc\\Desktop\\IBM hackathon\\OpenJDK8-OPENJ9_x64_Windows_jdk8u181-b13_openj9-0.9.0 (1)");
stdin.println("javac "+str+".java");
stdin.println("java "+str);
stdin.println(".\\jdk8u181-b13\\bin\\java -Xtrace:none -Xtrace:methods="+str+",trigger=method{" +str+",jstacktrace},maximal=mt,output="+str+"Trace.trc "+str);
stdin.println(".\\jdk8u181-b13\\bin\\java com.ibm.jvm.format.TraceFormat "+str+"Trace.trc "+str+"LogFile.log");
stdin.close();
p.waitFor();
System.out.println("\n");
//Check Exception
File f1 = new File("C:\\Users\\Dell pc\\Desktop\\IBM hackathon\\OpenJDK8-OPENJ9_x64_Windows_jdk8u181-b13_openj9-0.9.0 (1)\\WorldLogFile.log");
Scanner sc1 = new Scanner(f1);
File f2 = new File("C:\\Users\\Dell pc\\Desktop\\IBM hackathon\\OpenJDK8-OPENJ9_x64_Windows_jdk8u181-b13_openj9-0.9.0 (1)\\WorldExLogFile.log");
Scanner sc2 = new Scanner(f2);
String class1="null",class2="null";
int class1Length = 0, class2Length = 0;
int countStar = 0;
String line,type, traceEntry;
Stack<String> jstack1 = new Stack<String>();
Stack<String> jstack2 = new Stack<String>();
Stack<String> jstack1Line = new Stack<String>();
//Skipping unnecessary content
while(sc1.hasNextLine()) {
String read = (sc1.nextLine()).trim();
class1 = str;
class1Length = class1.length();
if(read.indexOf("J9 timer(UTC)") == 0) {
break;
}
}
while(sc2.hasNextLine()) {
String read = (sc2.nextLine()).trim();
class2 = str2;
class2Length = class2.length();
if(read.indexOf("J9 timer(UTC)") == 0) {
break;
}
}
//jstacktrace
while(sc1.hasNextLine()){
line = sc1.nextLine();
String [] details1 = line.split("\\s+");
type = details1[3];
traceEntry =details1[4];
if(type.equals("Event")== true && traceEntry.equals("jstacktrace:")== false){
String methodName = (details1[5]).substring(class1Length+1);
if(jstack1.search(methodName)<1) {
jstack1.push(methodName);
jstack1Line.push(details1[6]);
}
}
}
while(sc2.hasNextLine()){
line = sc2.nextLine();
String [] details1 = line.split("\\s+");
type = details1[3];
traceEntry =details1[4];
if(type.equals("Event")== true && traceEntry.equals("jstacktrace:")== false){
String methodName = (details1[5]).substring(class2Length+1);
if(jstack2.search(methodName)<1) {
jstack2.push(methodName);
}
}
//Count number of stars to check if exception exists
if(traceEntry.charAt(0) == '*' && type.equals("Debug")== false) {
countStar++;
break;
}
}
//Display whether exception exists or not
if(countStar==1) {
System.out.println("Exception exists");
}else {
System.out.println("No exception");
}
System.out.println("------------------------------------------");
//Display the anomalies in the jstacktrace files
System.out.println("Anomalies in jstacktrace for files\n" +class1+ ".java and "+class2+ ".java :\n");
while(jstack1.empty() == false) {
String s1 = jstack1.peek();
String s2 = jstack2.peek();
if(s1.equals(s2) == true){
jstack1.pop();
jstack2.pop();
jstack1Line.pop();
}else{
System.out.println(jstack1.peek() +"() " + jstack1Line.peek());
jstack1.pop();
jstack1Line.pop();
}
}
System.out.println("-----------------------------------------------------");
sc1.close();
sc2.close();
File f = new File("C:\\Users\\Dell pc\\Desktop\\IBM hackathon\\OpenJDK8-OPENJ9_x64_Windows_jdk8u181-b13_openj9-0.9.0 (1)\\WorldLogFile.log");
File exp= new File("C:\\Users\\Dell pc\\Desktop\\IBM hackathon\\OpenJDK8-OPENJ9_x64_Windows_jdk8u181-b13_openj9-0.9.0 (1)\\WorldExLogFile.log");
Scanner sc = new Scanner(f);
Scanner sci = new Scanner(exp);
//Skipping unnecessary content
while(sc.hasNextLine()) {
String read = sc.nextLine();
if(read.indexOf("J9 timer(UTC)") == 0) {
break;
}
}
while(sci.hasNextLine()) {
String rea = sci.nextLine();
if(rea.indexOf("J9 timer(UTC)") == 0) {
break;
}
}
//String line, timer, thdID, tpID, type, traceEntry;
String time1="ki", time2="ki";
String tim1="null",tim2="null";
Stack<String> stack = new Stack<>();
Stack<String> stac = new Stack<>();
//HashMap<Double,String> hm=new HashMap<Double,String>();
System.out.println("Passing case");
while(sc.hasNextLine()){
line = sc.nextLine();
String[] details = line.split("\\s+");
String timer = (details[0]);
//String thdID = (details[1]);
//String tpID= (details[2]);
type = (details[3]);
traceEntry = (details[4]);
if(type.equals("Entry")==true){
stack.push(timer);
}else if(type.equals("Exit")==true){
time2=timer;
list.add(traceEntry);
time1 = stack.peek();
String popResult = stack.pop();
//System.out.println();
System.out.println("\n"+traceEntry);
System.out.println("Entry Time = "+time1);
System.out.println("Exit Time = "+time2);
String dateStart = time1;
String dateStop = time2;
String h1,m1,s1;
h1=null;
m1=null;
s1=null;
char[] ch=dateStart.toCharArray();
char []hr={ch[0],ch[1]};
char []min={ch[3],ch[4]};
h1=new String(hr);
m1=new String(min);
s1 = dateStart.substring(6);
String h2,m2,s2;
h2=null;
m2=null;
s2=null;
char[] c=dateStop.toCharArray();
char []hrl={c[0],c[1]};
char []minl={c[3],c[4]};
h2=new String(hrl);
m2=new String(minl);
s2 = dateStop.substring(6);
double d1=Double.parseDouble(s1) + (Double.parseDouble(h1))*3600 + (Double.parseDouble(m1))*60;
double d2=Double.parseDouble(s2)+ (Double.parseDouble(h2))*3600 + (Double.parseDouble(m2))*60;
double timetaken=d2-d1;
System.out.println("Execution Time = "+timetaken+" seconds");
String methodname;
if(traceEntry.charAt(0)=='*'){
methodname=traceEntry.substring(1);
}else{
methodname=traceEntry;
}
hm.put(timetaken,methodname);
}
}
System.out.println("\nFailing case");
while(sci.hasNextLine()){
String lin = sci.nextLine();
String[] detail = lin.split("\\s+");
String time = (detail[0]);
//String thdI = (detail[1]);
//String tpI= (detail[2]);
String typ = (detail[3]);
String traceEntr = (detail[4]);
if(typ.equals("Entry")==true){
stac.push(time);
}
if(typ.equals("Exit")==true){
lis.add(traceEntr);
tim2=time;
tim1 = stac.peek();
String popResul = stac.pop();
System.out.println("\n"+traceEntr);
System.out.println("Entry Time = "+tim1);
System.out.println("Exit Time = "+tim2);
String dateStar = tim1;
String dateSto = tim2;
String h1,m1,s1;
h1=null;
m1=null;
s1=null;
char[] ch=dateStar.toCharArray();
char []hr={ch[0],ch[1]};
char []min={ch[3],ch[4]};
h1=new String(hr);
m1=new String(min);
s1=dateStar.substring(6);
String h2,m2,s2;
h2=null;
m2=null;
s2=null;
char[] c=dateSto.toCharArray();
char []hrl={c[0],c[1]};
char []minl={c[3],c[4]};
h2=new String(hrl);
m2=new String(minl);
s2=dateSto.substring(6);
double d1=Double.parseDouble(s1);
double d2=Double.parseDouble(s2);
double timetaken=d2-d1;
System.out.println("Execution Time = "+timetaken+ " seconds");
String methodname;
if(traceEntr.charAt(0)=='*')
{
methodname=traceEntr.substring(1);
}
else{
methodname=traceEntr;
}
hmm.put(timetaken,methodname);
}
/*for(Map.Entry m:hm.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
} */
}
//Comparing Files passing and failing, and analysing if method takes longer time to execute
Iterator<Map.Entry<Double, String>> itr = hmm.entrySet().iterator(); //passing
Iterator<Map.Entry<Double, String>> it = hm.entrySet().iterator(); //failing
int flag=0;
while(itr.hasNext())
{
Map.Entry<Double, String> entry = itr.next();
String nm=entry.getValue();
double pass=entry.getKey();
while(it.hasNext())
{
Map.Entry<Double, String> entr = it.next();
String name=entr.getValue();
String a,b;
a=null;
b=null;
double fail=entr.getKey();
//System.out.println("Value fail"+name+" Value pass "+nm);
int i;
for(i=0;i<name.length();i++){
if(name.charAt(i)=='.'){
a=name.substring(i+1);
}
}
int j;
for(j=0;j<nm.length();j++){
if(nm.charAt(j)=='.')
{
b=nm.substring(j+1);
}
}
if(a.equals(b)==true){
double diff=pass - fail;
System.out.println("\nPassing case takes "+ diff + " seconds more to execute.");
System.out.println();
flag=1;
break;
}
}
if(flag==1){
break;
}
}
countFrequencies(list);
sc.close();
sci.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}