|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.carbide.cpp.pi.memory; |
|
19 |
|
20 import java.io.ByteArrayInputStream; |
|
21 import java.io.DataInputStream; |
|
22 import java.io.EOFException; |
|
23 import java.io.File; |
|
24 import java.io.FileInputStream; |
|
25 import java.util.Enumeration; |
|
26 import java.util.Hashtable; |
|
27 import java.util.Vector; |
|
28 |
|
29 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace; |
|
30 import com.nokia.carbide.cpp.internal.pi.model.ParsedTraceData; |
|
31 import com.nokia.carbide.cpp.internal.pi.model.Parser; |
|
32 import com.nokia.carbide.cpp.pi.priority.PriSample; |
|
33 import com.nokia.carbide.cpp.pi.priority.PriThread; |
|
34 import com.nokia.carbide.cpp.pi.priority.PriTrace; |
|
35 import com.nokia.carbide.cpp.pi.util.GeneralMessages; |
|
36 |
|
37 |
|
38 public class MemTraceParser extends Parser |
|
39 { |
|
40 private boolean debug = false; |
|
41 private String version; |
|
42 |
|
43 private Vector<MemThread> memSamples = new Vector<MemThread>(); |
|
44 private Vector<PriThread> priSamples = new Vector<PriThread>(); |
|
45 private char[] buffer = new char[80]; |
|
46 private String threadName; |
|
47 private String processName; |
|
48 private int threadId; |
|
49 private int sampleTime; |
|
50 private int heapSize; |
|
51 private int stackSize; |
|
52 private int processPriority; |
|
53 private int threadPriority; |
|
54 private int defaultSamplingTime = 3000; |
|
55 private int samplingTime; |
|
56 private MemSample sample; |
|
57 private MemTrace memTrace; |
|
58 private PriSample priSample; |
|
59 private PriTrace priTrace; |
|
60 private byte a, b, c, d; |
|
61 private int readCount = 0; |
|
62 |
|
63 // constants |
|
64 public static int SAMPLE_CODE_INITIAL_CHUNK = 0; |
|
65 public static int SAMPLE_CODE_NEW_CHUNK = 1; |
|
66 public static int SAMPLE_CODE_UPDATE_CHUNK = 2; |
|
67 public static int SAMPLE_CODE_DELETE_CHUNK = 3; |
|
68 |
|
69 public MemTraceParser() //throws Exception |
|
70 { |
|
71 } |
|
72 |
|
73 public ParsedTraceData parse(File file) throws Exception |
|
74 { |
|
75 if (!file.exists() || file.isDirectory()) |
|
76 { |
|
77 throw new Exception(Messages.getString("MemTraceParser.cannotOpenTraceFile")); //$NON-NLS-1$ |
|
78 } |
|
79 if (debug) |
|
80 System.out.println(Messages.getString("MemTraceParser.traceFileLength") + file.length()); //$NON-NLS-1$ |
|
81 |
|
82 parseMemTrace(file); |
|
83 int versionNumber = convertVersionStringToInt(version); |
|
84 memTrace.setVersion(versionNumber); |
|
85 |
|
86 samplingTime = calcSamplingTime(); |
|
87 |
|
88 ParsedTraceData ptd = new ParsedTraceData(); |
|
89 ptd.traceData = this.getTrace(); |
|
90 |
|
91 /* TODO some debug prints remove |
|
92 MemTrace memTrace = (MemTrace)ptd.traceData; |
|
93 int ii = 1; |
|
94 for (Enumeration e = memTrace.getSamples(); e.hasMoreElements(); ) |
|
95 { |
|
96 MemSample memSample = (MemSample) e.nextElement(); |
|
97 |
|
98 |
|
99 if(memSample.thread.threadId == 0xc81dc318){ |
|
100 System.out.println("Threadname: " + memSample.thread.threadName + ", time:" + Long.toString(memSample.sampleSynchTime) + ", stack:" + Integer.toString(memSample.stackSize) + ", heap:" + Integer.toString(memSample.heapSize)); |
|
101 ii++; |
|
102 } |
|
103 }*/ |
|
104 |
|
105 return ptd; |
|
106 } |
|
107 |
|
108 private void parseNewMemFile(String version,DataInputStream dis) throws Exception |
|
109 { |
|
110 if (version.equals("0.85") || version.equals("0.91") || version.equals("1.00")||version.equals("1.10")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
111 { |
|
112 parseV085MemFile(dis); |
|
113 } |
|
114 else throw new Exception(Messages.getString("MemTraceParser.traceVersionException1") + version //$NON-NLS-1$ |
|
115 + Messages.getString("MemTraceParser.traceVersionException2")); //$NON-NLS-1$ |
|
116 } |
|
117 |
|
118 private void parseV085MemFile(DataInputStream dis) throws Exception |
|
119 { |
|
120 // read the version again |
|
121 byte[] version = readElementWithLength(dis); |
|
122 if (debug)System.out.println(Messages.getString("MemTraceParser.readVersionDebug") + new String(version)); //$NON-NLS-1$ |
|
123 this.version = new String(version); |
|
124 |
|
125 this.readV085MemSample(dis); |
|
126 } |
|
127 |
|
128 private void parseV110MemFile(DataInputStream dis) throws Exception |
|
129 { |
|
130 // read the version again |
|
131 byte[] version = readElementWithLength(dis); |
|
132 if (debug) System.out.println(Messages.getString("MemTraceParser.readVersionDebug") + new String(version)); //$NON-NLS-1$ |
|
133 this.version = new String(version); |
|
134 |
|
135 this.readV110MemSample(dis); |
|
136 } |
|
137 |
|
138 private void parseV155MemFile(DataInputStream dis) throws Exception |
|
139 { |
|
140 // read the version again |
|
141 byte[] version = readElementWithLength(dis); |
|
142 if (debug) System.out.println(Messages.getString("MemTraceParser.readVersion")+new String(version)); //$NON-NLS-1$ |
|
143 this.version = new String(version); |
|
144 |
|
145 this.readV155MemSample(dis); |
|
146 } |
|
147 |
|
148 private void parseV157MemFile(DataInputStream dis) throws Exception |
|
149 { |
|
150 // read the version again |
|
151 byte[] version = readElementWithLength(dis); |
|
152 if (debug) System.out.println("Read version "+new String(version)); |
|
153 this.version = new String(version); |
|
154 |
|
155 this.readV157MemSample(dis); |
|
156 } |
|
157 |
|
158 private void parseV110PriFile(DataInputStream dis) throws Exception |
|
159 { |
|
160 // read the version again |
|
161 byte[] version = readElementWithLength(dis); |
|
162 if (debug) System.out.println(Messages.getString("MemTraceParser.readVersionDebug") + new String(version)); //$NON-NLS-1$ |
|
163 this.version = new String(version); |
|
164 |
|
165 this.readV110PriSample(dis); |
|
166 } |
|
167 |
|
168 public String getProfilerVersion() |
|
169 { |
|
170 return version; |
|
171 } |
|
172 |
|
173 private void readV085MemSample(DataInputStream dis) throws Exception |
|
174 { |
|
175 Vector<long[]> rawV085Samples = new Vector<long[]>(); |
|
176 Vector<long[]> lastSampleRaw = new Vector<long[]>(); |
|
177 |
|
178 memTrace = new MemTrace(); |
|
179 priTrace = new PriTrace(); |
|
180 |
|
181 // first there should be 4 bytes of sample time |
|
182 long sample = this.readTUintWithLength(dis); |
|
183 |
|
184 // then read if there is thread name data |
|
185 int length = dis.readUnsignedByte();readCount++; |
|
186 if (length != 1) |
|
187 throw new Exception(Messages.getString("MemTraceParser.parseErrorTypeMissing")); //$NON-NLS-1$ |
|
188 |
|
189 int mode = dis.readUnsignedByte(); readCount++; |
|
190 |
|
191 try |
|
192 { |
|
193 // read the first length |
|
194 length = dis.readUnsignedByte(); readCount++; |
|
195 |
|
196 Thread.currentThread().setPriority(Thread.MIN_PRIORITY); |
|
197 |
|
198 while(true) |
|
199 { |
|
200 //System.out.println("ReadCount:"+this.readCount); |
|
201 if (length == 0) //haxor =) |
|
202 { |
|
203 // end of sample |
|
204 // read new length |
|
205 |
|
206 // first there should be 4 bytes of sample time |
|
207 sample = this.readTUintWithLength(dis); |
|
208 |
|
209 length = dis.readUnsignedByte(); readCount++; |
|
210 |
|
211 if (length == 4) |
|
212 { |
|
213 // there was only the sample header here |
|
214 System.out.println(Messages.getString("MemTraceParser.missingSampleNumber") + sample); //$NON-NLS-1$ |
|
215 mode = 0x00; |
|
216 } |
|
217 else if (length != 1) |
|
218 { |
|
219 throw new Exception(Messages.getString("MemTraceParser.parseErrorWrongLength") + length); //$NON-NLS-1$ |
|
220 } |
|
221 else |
|
222 { |
|
223 lastSampleRaw.clear(); |
|
224 } |
|
225 } |
|
226 |
|
227 if (length == 1) |
|
228 { |
|
229 mode = dis.readUnsignedByte(); readCount++; |
|
230 |
|
231 // read the next length |
|
232 length = dis.readUnsignedByte(); readCount++; |
|
233 |
|
234 lastSampleRaw.clear(); //lisätty 16.11.05 -aniskane |
|
235 } |
|
236 |
|
237 if (mode == 0xaa) |
|
238 { |
|
239 // reading thread names |
|
240 String rawName = readThreadName(dis,length); |
|
241 long threadId = readTUint(dis); |
|
242 int index = rawName.indexOf(':'); |
|
243 if (index != -1) |
|
244 { |
|
245 processName = rawName.substring(0,index); |
|
246 threadName = rawName.substring(rawName.lastIndexOf(':')+ 1, rawName.length()); |
|
247 } |
|
248 else |
|
249 { |
|
250 processName = rawName; |
|
251 threadName = rawName; |
|
252 } |
|
253 |
|
254 memTrace.addFirstSynchTime(new Integer((int)threadId),new Integer((int)sample)); |
|
255 memSamples.add(new MemThread(new Integer((int)threadId), threadName, processName)); |
|
256 priTrace.addFirstSynchTime(new Integer((int)threadId), new Integer(sampleTime)); |
|
257 priSamples.add(new PriThread(new Integer((int)threadId), threadName, processName)); |
|
258 |
|
259 // read the next length |
|
260 length = dis.readUnsignedByte(); readCount++; |
|
261 //System.out.println("Next length " + length); |
|
262 } |
|
263 else if (mode == 0xdd) |
|
264 { |
|
265 // reading data |
|
266 long[] elements = this.readDataElements085Mem(dis, length, sample); |
|
267 |
|
268 rawV085Samples.add(elements); |
|
269 lastSampleRaw.add(elements); |
|
270 |
|
271 // read the next length |
|
272 length = dis.readUnsignedByte(); readCount++; |
|
273 } |
|
274 else if (mode == 0x00) |
|
275 { |
|
276 // duplicate the previous sample to replace the missing sample |
|
277 Enumeration<long[]> e = lastSampleRaw.elements(); |
|
278 while(e.hasMoreElements()) |
|
279 { |
|
280 long[] element = e.nextElement(); |
|
281 long[] newElement = new long[7]; |
|
282 newElement[0] = element[0]; |
|
283 newElement[1] = element[1]; |
|
284 newElement[2] = element[2]; |
|
285 newElement[3] = element[3]; |
|
286 newElement[4] = element[4]; |
|
287 newElement[5] = element[5]; |
|
288 // replace the sample number with the missing one |
|
289 newElement[6] = sample; |
|
290 // add the duplicated sample |
|
291 rawV085Samples.add(newElement); |
|
292 } |
|
293 |
|
294 // read the length, it is already known |
|
295 sample = readTUint(dis); |
|
296 System.out.println(Messages.getString("MemTraceParser.sampleRead") + sample); //$NON-NLS-1$ |
|
297 length = dis.readUnsignedByte(); readCount++;; |
|
298 } |
|
299 else |
|
300 { |
|
301 throw new Exception(Messages.getString("MemTraceParser.parseErrorWrongMode") + mode); //$NON-NLS-1$ |
|
302 } |
|
303 } |
|
304 } |
|
305 catch (EOFException e) |
|
306 { |
|
307 if (debug) System.out.println(Messages.getString("MemTraceParser.finishedReading")); //$NON-NLS-1$ |
|
308 this.addRawV085Samples(rawV085Samples); |
|
309 } |
|
310 } |
|
311 |
|
312 private void readV110MemSample(DataInputStream dis) throws Exception |
|
313 { |
|
314 Vector<long[]> rawV110MemSamples = new Vector<long[]>(); |
|
315 Vector<long[]> lastSampleRaw = new Vector<long[]>(); |
|
316 |
|
317 memTrace = new MemTrace(); |
|
318 |
|
319 // first there should be 4 bytes of sample time |
|
320 long sample = this.readTUintWithLength(dis); |
|
321 |
|
322 // then read if there is thread name data |
|
323 int length = dis.readUnsignedByte(); readCount++; |
|
324 if (length != 1) |
|
325 throw new Exception(Messages.getString("MemTraceParser.parseErrorTypeMissing")); //$NON-NLS-1$ |
|
326 |
|
327 int mode = dis.readUnsignedByte(); readCount++; |
|
328 |
|
329 try |
|
330 { |
|
331 length = dis.readUnsignedByte(); readCount++; |
|
332 |
|
333 while(true) |
|
334 { |
|
335 if (length == 0) |
|
336 { |
|
337 // end of sample |
|
338 // read new length |
|
339 |
|
340 // first there should be 4 bytes of sample time |
|
341 sample = this.readTUintWithLength(dis); |
|
342 |
|
343 length = dis.readUnsignedByte(); readCount++; |
|
344 |
|
345 if (length == 4) |
|
346 { |
|
347 // there was only the sample header here |
|
348 System.out.println(Messages.getString("MemTraceParser.missingSampleNumber") + sample); //$NON-NLS-1$ |
|
349 mode = 0x00; |
|
350 } |
|
351 else if (length != 1) |
|
352 { |
|
353 throw new Exception(Messages.getString("MemTraceParser.parseErrorWrongLength") + length); //$NON-NLS-1$ |
|
354 } |
|
355 else |
|
356 { |
|
357 lastSampleRaw.clear(); |
|
358 } |
|
359 } |
|
360 |
|
361 if (length == 1) |
|
362 { |
|
363 mode = dis.readUnsignedByte(); readCount++; |
|
364 |
|
365 // read the next length |
|
366 length = dis.readUnsignedByte(); readCount++; |
|
367 |
|
368 lastSampleRaw.clear(); //lisätty 16.11.05 -aniskane |
|
369 } |
|
370 |
|
371 if (mode == 0xaa) |
|
372 { |
|
373 // reading thread names |
|
374 String rawName = readThreadName(dis,length); |
|
375 long threadId = readTUint(dis); |
|
376 |
|
377 int index = rawName.indexOf(':'); |
|
378 if (index != -1) |
|
379 { |
|
380 processName = rawName.substring(0,index); |
|
381 threadName = rawName.substring(rawName.lastIndexOf(':') + 1, rawName.length()); |
|
382 } |
|
383 else |
|
384 { |
|
385 processName = rawName; |
|
386 threadName = rawName; |
|
387 } |
|
388 |
|
389 memTrace.addFirstSynchTime(new Integer((int)threadId), new Integer((int)sample)); |
|
390 memSamples.add(new MemThread(new Integer((int)threadId), threadName, processName)); |
|
391 |
|
392 length = dis.readUnsignedByte(); readCount++; |
|
393 } |
|
394 else if (mode == 0xdd) |
|
395 { |
|
396 // reading data |
|
397 long[] elements = this.readDataElements110Mem(dis, length, sample); |
|
398 |
|
399 rawV110MemSamples.add(elements); |
|
400 lastSampleRaw.add(elements); |
|
401 |
|
402 // read the next length |
|
403 length = dis.readUnsignedByte(); readCount++; |
|
404 } |
|
405 else if (mode == 0x00) |
|
406 { |
|
407 // duplicate the previous sample to replace the missing sample |
|
408 Enumeration<long[]> e = lastSampleRaw.elements(); |
|
409 while(e.hasMoreElements()) |
|
410 { |
|
411 long[] element = e.nextElement(); |
|
412 long[] newElement = new long[7]; |
|
413 newElement[0] = element[0]; |
|
414 newElement[1] = element[1]; |
|
415 newElement[2] = element[2]; |
|
416 newElement[3] = element[3]; |
|
417 newElement[4] = element[4]; |
|
418 |
|
419 // replace the sample number with the missing one |
|
420 newElement[5] = sample; |
|
421 |
|
422 // add the duplicated sample |
|
423 rawV110MemSamples.add(newElement); |
|
424 } |
|
425 |
|
426 // read the length, it is already known |
|
427 sample = readTUint(dis); |
|
428 if (debug) System.out.println(Messages.getString("MemTraceParser.sampleRead") + sample); //$NON-NLS-1$ |
|
429 length = dis.readUnsignedByte();readCount++;; |
|
430 } |
|
431 else |
|
432 { |
|
433 throw new Exception(Messages.getString("MemTraceParser.parseErrorWrongMode")+mode); //$NON-NLS-1$ |
|
434 } |
|
435 } |
|
436 } |
|
437 catch (EOFException e) |
|
438 { |
|
439 System.out.println(Messages.getString("MemTraceParser.finishedReading")); //$NON-NLS-1$ |
|
440 this.addRawV110MemSamples(rawV110MemSamples); |
|
441 } |
|
442 } |
|
443 |
|
444 private void readV155MemSample(DataInputStream dis) throws Exception |
|
445 { |
|
446 Vector<long[]> rawV155MemSamples = new Vector<long[]>(); |
|
447 Vector<long[]> lastSampleRaw = new Vector<long[]>(); |
|
448 |
|
449 memTrace = new MemTrace(); |
|
450 |
|
451 // first there should be 4 bytes of sample time |
|
452 long sample = this.readTUintWithLength(dis); |
|
453 |
|
454 // then read if there is thread name data |
|
455 int length = dis.readUnsignedByte();readCount++; |
|
456 if (length != 1) throw new Exception(Messages.getString("MemTraceParser.missingType")); //$NON-NLS-1$ |
|
457 |
|
458 int mode = dis.readUnsignedByte();readCount++; |
|
459 |
|
460 try |
|
461 { |
|
462 length = dis.readUnsignedByte();readCount++; |
|
463 |
|
464 while(true) |
|
465 { |
|
466 if (length == 0) |
|
467 { |
|
468 if (debug)System.out.println(Messages.getString("MemTraceParser.newSample")); //$NON-NLS-1$ |
|
469 // end of sample |
|
470 // read new length |
|
471 |
|
472 // first there should be 4 bytes of sample time |
|
473 sample = this.readTUintWithLength(dis); |
|
474 |
|
475 length = dis.readUnsignedByte();readCount++; |
|
476 |
|
477 if (length == 4) |
|
478 { |
|
479 // there was only the sample header here |
|
480 System.out.println(Messages.getString("MemTraceParser.missingSampleNum")+sample); //$NON-NLS-1$ |
|
481 mode = 0x00; |
|
482 } |
|
483 else if (length != 1) |
|
484 { |
|
485 throw new Exception(Messages.getString("MemTraceParser.wrongLength")+length); //$NON-NLS-1$ |
|
486 } |
|
487 else |
|
488 { |
|
489 lastSampleRaw.clear(); |
|
490 } |
|
491 } |
|
492 |
|
493 if (length == 1) |
|
494 { |
|
495 mode = dis.readUnsignedByte();readCount++; |
|
496 |
|
497 // read the next length |
|
498 length = dis.readUnsignedByte();readCount++; |
|
499 if (debug)System.out.println(Messages.getString("MemTraceParser.nextLength")+length); //$NON-NLS-1$ |
|
500 lastSampleRaw.clear(); //lisätty 16.11.05 -aniskane |
|
501 } |
|
502 |
|
503 if (mode == 0xaa) |
|
504 { |
|
505 // reading thread names |
|
506 String rawName = readThreadName(dis,length); |
|
507 long threadId = readTUint(dis); |
|
508 if (debug)System.out.println(Messages.getString("MemTraceParser.rawName1")+rawName+Messages.getString("MemTraceParser.rawName2")+threadId); //$NON-NLS-1$ //$NON-NLS-2$ |
|
509 int index = rawName.indexOf(':'); |
|
510 if (index != -1) |
|
511 { |
|
512 processName = rawName.substring(0,index); |
|
513 //threadName = rawName.substring(rawName.lastIndexOf(':')+1,rawName.length()); |
|
514 threadName = rawName.substring(rawName.indexOf(':')+2,rawName.length()); |
|
515 } |
|
516 else |
|
517 { |
|
518 processName = rawName; |
|
519 threadName = rawName; |
|
520 } |
|
521 if (processName.startsWith("T_")) //$NON-NLS-1$ |
|
522 { |
|
523 processName = processName.substring(2); |
|
524 threadName += "_T"; //$NON-NLS-1$ |
|
525 } |
|
526 else if (processName.startsWith("C_")) //$NON-NLS-1$ |
|
527 { |
|
528 processName = processName.substring(2); |
|
529 threadName += "_C"; //$NON-NLS-1$ |
|
530 } |
|
531 memTrace.addFirstSynchTime(new Integer((int)threadId),new Integer((int)sample)); |
|
532 memSamples.add(new MemThread(new Integer((int)threadId), threadName, processName)); |
|
533 |
|
534 length = dis.readUnsignedByte();readCount++; |
|
535 } |
|
536 else if (mode == 0xdd) |
|
537 { |
|
538 // reading data |
|
539 long[] elements = this.readDataElements110Mem(dis,length,sample); |
|
540 |
|
541 //if (debug)System.out.println(" sample: "+sample); |
|
542 //if ((elements[0] > 0xffff || elements[0] < 0) && ((int)elements[0] != 0xbabbeaaa)) |
|
543 // System.out.println( "Chunk Data" |
|
544 // + ",pointer address,0x" + Integer.toHexString((int)elements[0]) |
|
545 // + ",c.iSize," + elements[1] |
|
546 // + ",c.iAttributes,0x" + Integer.toHexString((int)elements[2]) |
|
547 // + ",memory model," + (elements[4] & 0xf) |
|
548 // + ",time," + elements[5]); |
|
549 //else System.out.println( "Thread Data" |
|
550 // + ",t.Id," + elements[0] |
|
551 // + ",t.iUserStackSize," + elements[1] |
|
552 // + ",t.iUserStackRunAddress,0x" + Integer.toHexString((int)elements[2]) |
|
553 // + ",time," + elements[5]); |
|
554 |
|
555 rawV155MemSamples.add(elements); |
|
556 lastSampleRaw.add(elements); |
|
557 |
|
558 // read the length, it is already known |
|
559 //sample = readTUint(dis); |
|
560 |
|
561 // read the next length |
|
562 length = dis.readUnsignedByte();readCount++; |
|
563 } |
|
564 else if (mode == 0x00) |
|
565 { |
|
566 // read the length, it is already known |
|
567 sample = readTUint(dis); |
|
568 System.out.println(Messages.getString("MemTraceParser.nextSampleNum")+sample); //$NON-NLS-1$ |
|
569 length = dis.readUnsignedByte();readCount++;; |
|
570 } |
|
571 else |
|
572 { |
|
573 throw new Exception(Messages.getString("MemTraceParser.wrongMode")+mode); //$NON-NLS-1$ |
|
574 } |
|
575 } |
|
576 } |
|
577 catch (EOFException e) |
|
578 { |
|
579 System.out.println(Messages.getString("MemTraceParser.readingDone")); //$NON-NLS-1$ |
|
580 this.addRawV155MemSamples(rawV155MemSamples); |
|
581 } |
|
582 } |
|
583 |
|
584 @SuppressWarnings("unchecked") |
|
585 private void readV157MemSample(DataInputStream dis) throws Exception { |
|
586 Vector rawV157MemSamples = new Vector(); |
|
587 int counter = 0; |
|
588 String createdThread = ""; |
|
589 |
|
590 memTrace = new MemTrace(); |
|
591 |
|
592 MemThread thread; |
|
593 |
|
594 // first there should be 4 bytes of sample time |
|
595 long sample = this.readTUintWithLength(dis); |
|
596 |
|
597 // then read if there is thread name data |
|
598 int length = dis.readUnsignedByte();readCount++; |
|
599 if(length != 1) throw new Exception("Parse error, type after sample missing"); |
|
600 |
|
601 int mode = dis.readUnsignedByte();readCount++; |
|
602 |
|
603 try { |
|
604 length = dis.readUnsignedByte();readCount++; |
|
605 |
|
606 while(true) { |
|
607 if(length == 0) { |
|
608 // if(debug) System.out.println("Length = 0, New sample"); |
|
609 // end of sample |
|
610 // read new length |
|
611 |
|
612 // first there should be 4 bytes of sample time |
|
613 sample = this.readTUintWithLength(dis); |
|
614 |
|
615 length = dis.readUnsignedByte();readCount++; |
|
616 |
|
617 if(length == 4) { |
|
618 // there was only the sample header here |
|
619 System.out.println("Missing sample #"+sample); |
|
620 mode = 0x00; |
|
621 } |
|
622 else if(length != 1) { |
|
623 throw new Exception("Parse error, wrong length "+length+", readCount: "+readCount); |
|
624 } |
|
625 // else { |
|
626 // lastSampleRaw.clear(); |
|
627 // } |
|
628 } |
|
629 |
|
630 if(length == 1) { |
|
631 mode = dis.readUnsignedByte();readCount++; |
|
632 |
|
633 // read the next length |
|
634 length = dis.readUnsignedByte();readCount++; |
|
635 } |
|
636 |
|
637 if(mode == 0xaa) { |
|
638 // reading thread names |
|
639 String rawName = readThreadName(dis,length); |
|
640 long threadId = readTUint(dis); |
|
641 |
|
642 if(debug) System.out.println("New raw name "+rawName+" at #"+sample+", thread id: "+Long.toHexString(threadId)); |
|
643 |
|
644 int index = rawName.indexOf(':'); |
|
645 if(index != -1) { |
|
646 processName = rawName.substring(0,index); |
|
647 //threadName = rawName.substring(rawName.lastIndexOf(':')+1,rawName.length()); |
|
648 threadName = rawName.substring(rawName.indexOf(':')+2,rawName.length()); |
|
649 } |
|
650 else { |
|
651 processName = rawName; |
|
652 threadName = rawName; |
|
653 } |
|
654 if (processName.startsWith("T_")) { |
|
655 processName = processName.substring(2); |
|
656 threadName += "_T"; |
|
657 } |
|
658 else if (processName.startsWith("C_")) { |
|
659 processName = processName.substring(2); |
|
660 threadName += "_C"; |
|
661 } |
|
662 |
|
663 memTrace.addFirstSynchTime(new Integer((int)threadId),new Integer((int)sample)); |
|
664 thread = new MemThread(new Integer((int)threadId), threadName, processName); |
|
665 memSamples.add(thread); |
|
666 createdThread = processName+"::"+threadName; |
|
667 if(debug)System.out.println("Name sample: "+sample+", created thread: "+createdThread+", vector size: "+memSamples.size()); |
|
668 length = dis.readUnsignedByte();readCount++; |
|
669 } |
|
670 else if(mode == 0xdd) { |
|
671 long[] elements = this.readDataElements110Mem(dis,length,sample); |
|
672 if(elements[0] != (int)0xffffffffbabbeaaaL || counter == 0) { |
|
673 elements[6] = MemTraceParser.SAMPLE_CODE_INITIAL_CHUNK; |
|
674 } else if (elements[0] == (int)0xffffffffbabbeaaaL){ |
|
675 elements[6] = MemTraceParser.SAMPLE_CODE_UPDATE_CHUNK; |
|
676 } |
|
677 MemThread tempThr = ((MemThread)memSamples.get(counter)); |
|
678 // reading data |
|
679 elements[7] = sum(tempThr.processName+"::"+tempThr.threadName); |
|
680 if(debug)System.out.println("Data sample: "+sample+", hash: "+elements[7]+", created thread: "+tempThr.processName+"::"+tempThr.threadName); |
|
681 |
|
682 rawV157MemSamples.add(elements); |
|
683 |
|
684 // read the next length |
|
685 length = dis.readUnsignedByte();readCount++; |
|
686 createdThread = ""; |
|
687 |
|
688 // hack since total memory code added for top of both thread and chunk lists |
|
689 if(elements[0] != (int)0xffffffffbabbeaaaL || counter == 0) { |
|
690 counter++; |
|
691 } |
|
692 } |
|
693 else if(mode == 0xda) { // new chunk code found |
|
694 // read the chunk data |
|
695 long[] elements = this.readDataElements110Mem(dis,length,sample); |
|
696 elements[6] = MemTraceParser.SAMPLE_CODE_NEW_CHUNK; |
|
697 elements[7] = sum(createdThread); |
|
698 if(debug) System.out.println("New chunk #"+Long.toHexString(elements[0])+", with name: "+createdThread+" found @"+sample); |
|
699 |
|
700 rawV157MemSamples.add(elements); |
|
701 |
|
702 // read the next length |
|
703 length = dis.readUnsignedByte();readCount++; |
|
704 } |
|
705 else if(mode == 0xdb) { // chunk update code found |
|
706 // read the chunk data |
|
707 long[] elements = this.readDataElements110Mem(dis,length,sample); |
|
708 elements[6] = MemTraceParser.SAMPLE_CODE_UPDATE_CHUNK; |
|
709 if(debug) System.out.println("Chunk #"+Long.toHexString(elements[0])+" update found #"+sample); |
|
710 |
|
711 rawV157MemSamples.add(elements); |
|
712 // read the next length |
|
713 length = dis.readUnsignedByte();readCount++; |
|
714 createdThread = ""; |
|
715 } |
|
716 else if(mode == 0xdc) { // chunk remove code found |
|
717 // read the chunk data |
|
718 long[] elements = this.readDataElements110Mem(dis,length,sample); |
|
719 elements[6] = MemTraceParser.SAMPLE_CODE_DELETE_CHUNK; |
|
720 |
|
721 if (debug) System.out.println("Chunk #"+Long.toHexString(elements[0])+" remove found #"+sample); |
|
722 |
|
723 rawV157MemSamples.add(elements); |
|
724 // read the next length |
|
725 length = dis.readUnsignedByte();readCount++; |
|
726 createdThread = ""; |
|
727 } |
|
728 else if(mode == 0x00) { |
|
729 // duplicate the previous sample to replace the missing sample |
|
730 |
|
731 // read the length, it is already known |
|
732 sample = readTUint(dis); |
|
733 if(debug) System.out.println("Read next sample #"+sample); |
|
734 length = dis.readUnsignedByte();readCount++;; |
|
735 } |
|
736 else |
|
737 { |
|
738 throw new Exception("Parse error, wrong mode "+mode); |
|
739 } |
|
740 } |
|
741 } |
|
742 catch (EOFException e) |
|
743 { |
|
744 System.out.println("Finished reading"); |
|
745 this.addRawV157MemSamples(rawV157MemSamples); |
|
746 } |
|
747 } |
|
748 |
|
749 /* |
|
750 * A method for calculating hash value for a string |
|
751 */ |
|
752 public static long sum(String arg) { |
|
753 int total = 0; |
|
754 for(int i = 0; i < arg.length(); i++){ |
|
755 total += (long)arg.charAt(i); |
|
756 } return total; // returns the sum of the chars after cast |
|
757 } |
|
758 |
|
759 @SuppressWarnings("unchecked") |
|
760 private void addRawV157MemSamples(Vector rawV157MemSamples) { |
|
761 |
|
762 Hashtable startedThreads; // store the id/name of the thread for recognizing the right chunk (same chunk id may be reused) |
|
763 |
|
764 String tempThreadName = ""; |
|
765 String str = ""; |
|
766 int chunkMode = MemTraceParser.SAMPLE_CODE_INITIAL_CHUNK; |
|
767 long nameHash = 0; |
|
768 MemThread[] memThreads = new MemThread[memSamples.size()]; |
|
769 memSamples.copyInto((MemThread[]) memThreads); |
|
770 memTrace.setThreads(memThreads); |
|
771 |
|
772 // container for started threads, some of the chunks may share the id (i.e. the chunk start address) |
|
773 startedThreads = new Hashtable(memSamples.size()); |
|
774 |
|
775 Enumeration rawEnum = rawV157MemSamples.elements(); |
|
776 |
|
777 while(rawEnum.hasMoreElements()) { |
|
778 long[] element = (long[])rawEnum.nextElement(); |
|
779 threadId = (int)element[0]; |
|
780 heapSize = (int)element[3]; |
|
781 stackSize = (int)element[4]; |
|
782 sampleTime = (int)element[5]; |
|
783 chunkMode = (int)element[6]; // chunk mode for deciding the periods of memory usage per thread/chunk |
|
784 nameHash = element[7]; // for checking the right thread/raw sample pairs |
|
785 |
|
786 // total memory consumption |
|
787 if(element[0] == 0xffffffffbabbeaaaL) { |
|
788 int totalRam = (int)element[1]; |
|
789 int freeRam = (int)element[3]; |
|
790 |
|
791 heapSize = totalRam-freeRam; |
|
792 stackSize = freeRam; |
|
793 if(debug) System.out.println("Used RAM: " + heapSize+" B, free RAM: "+stackSize+" B"); |
|
794 } |
|
795 |
|
796 // handle different sample types |
|
797 switch(chunkMode) { |
|
798 case 0: // MemTraceParser.SAMPLE_CODE_INITIAL_CHUNK |
|
799 // search for a correct sample for the ID of a raw sample |
|
800 for (Enumeration e = memSamples.elements();e.hasMoreElements();) { |
|
801 MemThread mt = (MemThread)e.nextElement(); |
|
802 |
|
803 // find corresponding thread ID among the MemThreads |
|
804 if (mt.threadId.intValue() == threadId ) { |
|
805 // create a new sample to memory trace |
|
806 sample = new MemSample(mt, heapSize, stackSize, sampleTime, MemTraceParser.SAMPLE_CODE_INITIAL_CHUNK); |
|
807 tempThreadName = mt.processName+"::"+mt.threadName; |
|
808 |
|
809 // add the thread into started hash table |
|
810 startedThreads.put((int)threadId, (String)tempThreadName); |
|
811 |
|
812 memTrace.addSample(sample); |
|
813 break; |
|
814 } |
|
815 } |
|
816 break; |
|
817 case 1: // MemTraceParser.SAMPLE_CODE_NEW_CHUNK |
|
818 // add to the started threads hash table |
|
819 for (Enumeration e = memSamples.elements();e.hasMoreElements();) { |
|
820 MemThread mt = (MemThread)e.nextElement(); |
|
821 tempThreadName = mt.processName+"::"+mt.threadName; |
|
822 |
|
823 // find corresponding thread ID among the MemThreads |
|
824 if (mt.threadId.intValue() == threadId && sum(tempThreadName) == nameHash) { |
|
825 // create a new sample to memory trace |
|
826 sample = new MemSample(mt, heapSize, stackSize, sampleTime, MemTraceParser.SAMPLE_CODE_NEW_CHUNK); |
|
827 |
|
828 // add the thread into started hash table |
|
829 startedThreads.put((int)threadId, (String)tempThreadName); |
|
830 |
|
831 // add sample to main trace data structure |
|
832 memTrace.addSample(sample); |
|
833 break; |
|
834 } |
|
835 } |
|
836 break; |
|
837 case 2: // MemTraceParser.SAMPLE_CODE_UPDATE_CHUNK |
|
838 str = (String)startedThreads.get(threadId); |
|
839 if(str == null) |
|
840 str = ""; |
|
841 // add to the started threads hash table |
|
842 for (Enumeration e = memSamples.elements();e.hasMoreElements();) { |
|
843 MemThread mt = (MemThread)e.nextElement(); |
|
844 tempThreadName = mt.processName+"::"+mt.threadName; |
|
845 |
|
846 // find corresponding thread ID among the MemThreads |
|
847 if (mt.threadId.intValue() == threadId ) { |
|
848 if((str).equalsIgnoreCase(tempThreadName)) { |
|
849 // create a new sample to memory trace |
|
850 sample = new MemSample(mt, heapSize, stackSize, sampleTime, MemTraceParser.SAMPLE_CODE_UPDATE_CHUNK); |
|
851 |
|
852 // add sample to main trace data structure |
|
853 memTrace.addSample(sample); |
|
854 break; |
|
855 } |
|
856 } |
|
857 } |
|
858 break; |
|
859 case 3: // MemTraceParser.SAMPLE_CODE_DELETE_CHUNK |
|
860 // add to the started threads hash table |
|
861 for (Enumeration e = memSamples.elements();e.hasMoreElements();) { |
|
862 MemThread mt = (MemThread)e.nextElement(); |
|
863 tempThreadName = mt.processName+"::"+mt.threadName; |
|
864 |
|
865 // find corresponding thread ID among the MemThreads |
|
866 if (mt.threadId.intValue() == threadId) { |
|
867 if(((String)startedThreads.get(threadId)).equalsIgnoreCase(tempThreadName)) { |
|
868 // create a new sample to memory trace |
|
869 sample = new MemSample(mt, heapSize, stackSize, sampleTime, MemTraceParser.SAMPLE_CODE_DELETE_CHUNK); |
|
870 |
|
871 // remove from the started threads hash table |
|
872 if(startedThreads.remove(threadId) == null) { |
|
873 System.out.println(" No match on started list"); |
|
874 } |
|
875 |
|
876 // add sample to main trace data structure |
|
877 memTrace.addSample(sample); |
|
878 break; |
|
879 } |
|
880 } |
|
881 } |
|
882 break; |
|
883 default: |
|
884 break; |
|
885 } |
|
886 |
|
887 // add end mark for the thread |
|
888 memTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
889 |
|
890 } |
|
891 if (debug) System.out.println("Done parsing, size: "+memTrace.samples.size()); |
|
892 } |
|
893 |
|
894 private void addRawV110MemSamples(Vector<long[]> rawV110MemSamples) |
|
895 { |
|
896 MemThread[] memTreads = new MemThread[memSamples.size()]; |
|
897 memSamples.copyInto((MemThread[]) memTreads); |
|
898 memTrace.setThreads(memTreads); |
|
899 |
|
900 Enumeration<long[]> rawEnum = rawV110MemSamples.elements(); |
|
901 while(rawEnum.hasMoreElements()) |
|
902 { |
|
903 long[] element = rawEnum.nextElement(); |
|
904 threadId = (int)element[0]; |
|
905 heapSize = (int)element[3]; // NOTE: in older versions this was element[1]; |
|
906 stackSize = (int)element[4]; |
|
907 sampleTime = (int)element[5]; |
|
908 |
|
909 for (Enumeration<MemThread> e = memSamples.elements(); e.hasMoreElements(); ) |
|
910 { |
|
911 MemThread mt = e.nextElement(); |
|
912 if (mt.threadId.intValue() == threadId) |
|
913 { |
|
914 sample = new MemSample(mt, heapSize, stackSize, sampleTime); |
|
915 memTrace.addSample(sample); |
|
916 break; |
|
917 } |
|
918 } |
|
919 |
|
920 memTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
921 } |
|
922 if (debug) System.out.println(Messages.getString("MemTraceParser.parsingDone")); //$NON-NLS-1$ |
|
923 } |
|
924 |
|
925 private int calcV155SamplingTime(Vector<long[]> rawV155MemSamples) |
|
926 { |
|
927 long[] element = rawV155MemSamples.firstElement(); |
|
928 int time = (int)element[5]; |
|
929 Enumeration<long[]> rawEnum = rawV155MemSamples.elements(); |
|
930 while(rawEnum.hasMoreElements()) |
|
931 { |
|
932 element = rawEnum.nextElement(); |
|
933 if (time != (int)element[5]) |
|
934 { |
|
935 time = (int)element[5] - time; |
|
936 break; |
|
937 } |
|
938 } |
|
939 return time; |
|
940 } |
|
941 |
|
942 private void addRawV155MemSamples(Vector<long[]> rawV155MemSamples) throws Exception |
|
943 { |
|
944 //int largest = 0; |
|
945 MemThread[] memTreads = new MemThread[memSamples.size()]; |
|
946 memSamples.copyInto((MemThread[]) memTreads); |
|
947 memTrace.setThreads(memTreads); |
|
948 |
|
949 int samplingTime = calcV155SamplingTime(rawV155MemSamples); |
|
950 |
|
951 Enumeration<long[]> rawEnum = rawV155MemSamples.elements(); |
|
952 |
|
953 while(rawEnum.hasMoreElements()) |
|
954 { |
|
955 long[] element = rawEnum.nextElement(); |
|
956 threadId = (int)element[0]; |
|
957 heapSize = (int)element[3]; |
|
958 stackSize = (int)element[4]; |
|
959 sampleTime = (int)element[5]; |
|
960 |
|
961 if (element[0] == 0xffffffffbabbeaaaL) |
|
962 { |
|
963 int totalRam = (int)element[1]; |
|
964 int freeRam = (int)element[3]; |
|
965 |
|
966 heapSize = totalRam-freeRam; |
|
967 stackSize = freeRam; |
|
968 } |
|
969 else |
|
970 { |
|
971 if (element[0] == 0xffffffffbabbea20L && this.traceVersion.startsWith("Bappea_V2.01")) //$NON-NLS-1$ |
|
972 { |
|
973 if (this.traceVersion.startsWith("Bappea_V2.01") && memTrace.getMemoryModel() == MemTrace.MEMORY_UNKNOWN) //$NON-NLS-1$ |
|
974 { |
|
975 memTrace.setMemoryModel(element[2]); |
|
976 } |
|
977 } |
|
978 else |
|
979 { |
|
980 if (Math.abs(threadId) > 10000) |
|
981 { |
|
982 sampleTime -= samplingTime; |
|
983 } |
|
984 |
|
985 if (sampleTime % (samplingTime*2) != samplingTime) { |
|
986 System.out.println(Messages.getString("MemTraceParser.invalidSampleNum") + sampleTime); //$NON-NLS-1$ |
|
987 throw new Exception(Messages.getString("MemTraceParser.invalidSample")); //$NON-NLS-1$ |
|
988 } |
|
989 } |
|
990 } |
|
991 |
|
992 for (Enumeration<MemThread> e = memSamples.elements();e.hasMoreElements();) |
|
993 { |
|
994 MemThread mt = e.nextElement(); |
|
995 if (mt.threadId.intValue() == threadId) |
|
996 { |
|
997 sample = new MemSample(mt, heapSize, stackSize, sampleTime); |
|
998 |
|
999 if (element[0] != 0xffffffffbabbeaaaL) |
|
1000 { |
|
1001 memTrace.addSample(sample); |
|
1002 } |
|
1003 else if ((sampleTime/samplingTime)%2 != 0) |
|
1004 { |
|
1005 memTrace.addSample(sample); |
|
1006 } |
|
1007 break; |
|
1008 } |
|
1009 } |
|
1010 |
|
1011 memTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1012 } |
|
1013 |
|
1014 if (debug) System.out.println(Messages.getString("MemTraceParser.sizeOfParse")+memTrace.samples.size()/*+" largest "+largest*/); //$NON-NLS-1$ |
|
1015 } |
|
1016 |
|
1017 private void addRawV085Samples(Vector<long[]> rawV085Samples) |
|
1018 { |
|
1019 MemThread[] memTreads = new MemThread[memSamples.size()]; |
|
1020 memSamples.copyInto((MemThread[]) memTreads); |
|
1021 memTrace.setThreads(memTreads); |
|
1022 |
|
1023 PriThread[] priThreads = new PriThread[priSamples.size()]; |
|
1024 priSamples.copyInto((PriThread[]) priThreads); |
|
1025 priTrace.setThreads(priThreads); |
|
1026 |
|
1027 Enumeration<long[]> rawEnum = rawV085Samples.elements(); |
|
1028 while(rawEnum.hasMoreElements()) |
|
1029 { |
|
1030 long[] element = rawEnum.nextElement(); |
|
1031 threadId = (int)element[0]; |
|
1032 threadPriority = (int)element[5]; |
|
1033 |
|
1034 // for the null thread, converts 8bit unsigned to signed |
|
1035 if (threadPriority > 32768) |
|
1036 threadPriority = threadPriority - 65536; |
|
1037 heapSize = (int)element[3]; // NOTE: in older versions this was element[1]; |
|
1038 stackSize = (int)element[4]; |
|
1039 sampleTime = (int)element[6]; |
|
1040 |
|
1041 for (Enumeration<MemThread> e = memSamples.elements(); e.hasMoreElements(); ) |
|
1042 { |
|
1043 MemThread mt = e.nextElement(); |
|
1044 if (mt.threadId.intValue() == threadId) |
|
1045 { |
|
1046 sample = new MemSample(mt, heapSize, stackSize, sampleTime); |
|
1047 memTrace.addSample(sample); |
|
1048 break; |
|
1049 } |
|
1050 } |
|
1051 |
|
1052 for (Enumeration<PriThread> e = priSamples.elements(); e.hasMoreElements(); ) |
|
1053 { |
|
1054 PriThread pt = e.nextElement(); |
|
1055 if (pt.threadId.intValue() == threadId) |
|
1056 { |
|
1057 //int priority = solveAbsolutPriority(processPriority, threadPriority); |
|
1058 priSample = new PriSample(pt, threadPriority, sampleTime); |
|
1059 priTrace.addSample(priSample); |
|
1060 break; |
|
1061 } |
|
1062 } |
|
1063 memTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1064 priTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1065 } |
|
1066 if (debug) System.out.println(Messages.getString("MemTraceParser.parsingDone")); //$NON-NLS-1$ |
|
1067 } |
|
1068 |
|
1069 private void readV110PriSample(DataInputStream dis) throws Exception |
|
1070 { |
|
1071 Vector<long[]> rawV110PriSamples = new Vector<long[]>(); |
|
1072 Vector<long[]> lastSampleRaw = new Vector<long[]>(); |
|
1073 |
|
1074 //memTrace = new MemTrace(); |
|
1075 priTrace = new PriTrace(); |
|
1076 |
|
1077 // first there should be 4 bytes of sample time |
|
1078 long sample = this.readTUintWithLength(dis); |
|
1079 |
|
1080 // then read if there is thread name data |
|
1081 int length = dis.readUnsignedByte(); readCount++; |
|
1082 if (length != 1) |
|
1083 throw new Exception(Messages.getString("MemTraceParser.parseErrorTypeMissing")); //$NON-NLS-1$ |
|
1084 |
|
1085 int mode = dis.readUnsignedByte(); readCount++; |
|
1086 |
|
1087 try |
|
1088 { |
|
1089 // read the first length |
|
1090 length = dis.readUnsignedByte(); readCount++; |
|
1091 |
|
1092 Thread.currentThread().setPriority(Thread.MIN_PRIORITY); |
|
1093 |
|
1094 while(true) |
|
1095 { |
|
1096 if (length == 0) |
|
1097 { |
|
1098 // end of sample |
|
1099 // read new length |
|
1100 |
|
1101 // first there should be 4 bytes of sample time |
|
1102 sample = this.readTUintWithLength(dis); |
|
1103 |
|
1104 length = dis.readUnsignedByte(); readCount++; |
|
1105 |
|
1106 if (length == 4) |
|
1107 { |
|
1108 // there was only the sample header here |
|
1109 System.out.println(Messages.getString("MemTraceParser.missingSampleNumber") + sample); //$NON-NLS-1$ |
|
1110 mode = 0x00; |
|
1111 } |
|
1112 else if (length != 1) |
|
1113 { |
|
1114 throw new Exception(Messages.getString("MemTraceParser.parseErrorWrongLength") + length); //$NON-NLS-1$ |
|
1115 } |
|
1116 else |
|
1117 { |
|
1118 lastSampleRaw.clear(); |
|
1119 } |
|
1120 } |
|
1121 |
|
1122 if (length == 1) |
|
1123 { |
|
1124 mode = dis.readUnsignedByte(); readCount++; |
|
1125 |
|
1126 // read the next length |
|
1127 length = dis.readUnsignedByte(); readCount++; |
|
1128 |
|
1129 lastSampleRaw.clear(); //lisätty 16.11.05 -aniskane |
|
1130 } |
|
1131 |
|
1132 if (mode == 0xaa) |
|
1133 { |
|
1134 // reading thread names |
|
1135 String rawName = readThreadName(dis,length); |
|
1136 long threadId = readTUint(dis); |
|
1137 |
|
1138 int index = rawName.indexOf(':'); |
|
1139 if (index != -1) |
|
1140 { |
|
1141 processName = rawName.substring(0,index); |
|
1142 threadName = rawName.substring(rawName.lastIndexOf(':') + 1, rawName.length()); |
|
1143 } |
|
1144 else |
|
1145 { |
|
1146 processName = rawName; |
|
1147 threadName = rawName; |
|
1148 } |
|
1149 |
|
1150 priTrace.addFirstSynchTime(new Integer((int)threadId), new Integer(sampleTime)); |
|
1151 priSamples.add(new PriThread(new Integer((int)threadId), threadName, processName)); |
|
1152 |
|
1153 // read the next length |
|
1154 length = dis.readUnsignedByte(); readCount++; |
|
1155 } |
|
1156 else if (mode == 0xdd) |
|
1157 { |
|
1158 // reading data |
|
1159 long[] elements = this.readDataElements110Pri(dis, length, sample); |
|
1160 |
|
1161 rawV110PriSamples.add(elements); |
|
1162 lastSampleRaw.add(elements); |
|
1163 |
|
1164 // read the next length |
|
1165 length = dis.readUnsignedByte(); readCount++; |
|
1166 } |
|
1167 else if (mode == 0x00) |
|
1168 { |
|
1169 // duplicate the previous sample to replace the missing sample |
|
1170 Enumeration<long[]> e = lastSampleRaw.elements(); |
|
1171 while(e.hasMoreElements()) |
|
1172 { |
|
1173 long[] element = e.nextElement(); |
|
1174 long[] newElement = new long[7]; |
|
1175 newElement[0] = element[0]; |
|
1176 newElement[1] = element[1]; |
|
1177 //newElement[2] = element[2]; |
|
1178 //newElement[3] = element[3]; |
|
1179 //newElement[4] = element[4]; |
|
1180 //newElement[5] = element[5]; |
|
1181 // replace the sample number with the missing one |
|
1182 newElement[2] = sample; |
|
1183 // add the duplicated sample |
|
1184 rawV110PriSamples.add(newElement); |
|
1185 } |
|
1186 |
|
1187 // read the length, it is already known |
|
1188 sample = readTUint(dis); |
|
1189 System.out.println(Messages.getString("MemTraceParser.sampleRead") + sample); //$NON-NLS-1$ |
|
1190 length = dis.readUnsignedByte(); readCount++;; |
|
1191 } |
|
1192 else |
|
1193 { |
|
1194 throw new Exception(Messages.getString("MemTraceParser.parseErrorWrongMode") + mode); //$NON-NLS-1$ |
|
1195 } |
|
1196 } |
|
1197 } |
|
1198 catch (EOFException e) |
|
1199 { |
|
1200 System.out.println(Messages.getString("MemTraceParser.finishedReading")); //$NON-NLS-1$ |
|
1201 this.addRawV110PriSamples(rawV110PriSamples); |
|
1202 } |
|
1203 } |
|
1204 |
|
1205 private void addRawV110PriSamples(Vector<long[]> rawV110PriSamples) |
|
1206 { |
|
1207 PriThread[] priThreads = new PriThread[priSamples.size()]; |
|
1208 priSamples.copyInto((PriThread[]) priThreads); |
|
1209 priTrace.setThreads(priThreads); |
|
1210 |
|
1211 Enumeration<long[]> rawEnum = rawV110PriSamples.elements(); |
|
1212 while(rawEnum.hasMoreElements()) |
|
1213 { |
|
1214 long[] element = rawEnum.nextElement(); |
|
1215 threadId = (int)element[0]; |
|
1216 threadPriority = (int)element[1]; |
|
1217 |
|
1218 // for the null thread, converts 8bit unsigned to signed |
|
1219 if (threadPriority > 32768) |
|
1220 threadPriority = threadPriority - 65536; |
|
1221 |
|
1222 sampleTime = (int)element[2]; |
|
1223 |
|
1224 for (Enumeration<PriThread> e = priSamples.elements(); e.hasMoreElements(); ) |
|
1225 { |
|
1226 PriThread pt = e.nextElement(); |
|
1227 if (pt.threadId.intValue() == threadId) |
|
1228 { |
|
1229 priSample = new PriSample(pt, threadPriority, sampleTime); |
|
1230 priTrace.addSample(priSample); |
|
1231 break; |
|
1232 } |
|
1233 } |
|
1234 |
|
1235 priTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1236 } |
|
1237 if (debug) System.out.println(Messages.getString("MemTraceParser.parsingDone")); //$NON-NLS-1$ |
|
1238 } |
|
1239 |
|
1240 private long[] readDataElements085Mem(DataInputStream dis,int length,long sampleTime) throws Exception |
|
1241 { |
|
1242 if (length != 0) |
|
1243 { |
|
1244 long[] elements = new long[7]; |
|
1245 elements[0] = this.readTUint(dis); |
|
1246 elements[1] = this.readTUint(dis); |
|
1247 elements[2] = this.readTUint(dis); |
|
1248 elements[3] = this.readTUint(dis); |
|
1249 elements[4] = this.readTUint(dis); |
|
1250 elements[5] = this.readShort(dis); |
|
1251 elements[6] = sampleTime; |
|
1252 |
|
1253 return elements; |
|
1254 } |
|
1255 else |
|
1256 { |
|
1257 System.out.println(Messages.getString("MemTraceParser.dataLengthIs0")); //$NON-NLS-1$ |
|
1258 return null; |
|
1259 } |
|
1260 } |
|
1261 |
|
1262 private long[] readDataElements110Mem(DataInputStream dis,int length,long sampleTime) throws Exception |
|
1263 { |
|
1264 if (length != 0) |
|
1265 { |
|
1266 long[] elements = new long[8]; // added two elements for sample type and name hash, 07092009 |
|
1267 elements[0] = this.readTUint(dis); |
|
1268 elements[1] = this.readTUint(dis); |
|
1269 elements[2] = this.readTUint(dis); |
|
1270 elements[3] = this.readTUint(dis); |
|
1271 elements[4] = this.readTUint(dis); |
|
1272 elements[5] = sampleTime; |
|
1273 |
|
1274 if (elements[3] != 0 && elements[4] != 0) |
|
1275 if (debug) System.err.println(Messages.getString("MemTraceParser.bothHeapAndStack")); //$NON-NLS-1$ |
|
1276 |
|
1277 return elements; |
|
1278 } |
|
1279 else |
|
1280 { |
|
1281 System.out.println(Messages.getString("MemTraceParser.dataLengthIs0")); //$NON-NLS-1$ |
|
1282 return null; |
|
1283 } |
|
1284 } |
|
1285 |
|
1286 private long[] readDataElements110Pri(DataInputStream dis, int length, long sampleTime) throws Exception |
|
1287 { |
|
1288 if (length != 0) |
|
1289 { |
|
1290 long[] elements = new long[3]; |
|
1291 elements[0] = this.readTUint(dis); //thread ID |
|
1292 elements[1] = this.readShort(dis); //Priority |
|
1293 elements[2] = sampleTime; //sample number |
|
1294 |
|
1295 return elements; |
|
1296 } |
|
1297 else |
|
1298 { |
|
1299 System.out.println(Messages.getString("MemTraceParser.dataLengthIs0")); //$NON-NLS-1$ |
|
1300 return null; |
|
1301 } |
|
1302 } |
|
1303 |
|
1304 private String readThreadName(DataInputStream dis, int length) throws Exception |
|
1305 { |
|
1306 if (length != 0) |
|
1307 { |
|
1308 length -=4; |
|
1309 |
|
1310 byte[] element = new byte[length]; |
|
1311 dis.read(element, 0, length); |
|
1312 readCount+=length; |
|
1313 return new String(element); |
|
1314 } |
|
1315 else |
|
1316 return null; |
|
1317 } |
|
1318 |
|
1319 private byte[] readElementWithLength(DataInputStream dis) throws Exception |
|
1320 { |
|
1321 byte length = dis.readByte(); readCount++; |
|
1322 if (length != 0) |
|
1323 { |
|
1324 |
|
1325 byte[] element = new byte[length]; |
|
1326 dis.read(element, 0, length); |
|
1327 readCount += length; |
|
1328 return element; |
|
1329 } |
|
1330 else return null; |
|
1331 } |
|
1332 |
|
1333 private long readShort(DataInputStream dis) throws Exception |
|
1334 { |
|
1335 long result = dis.readUnsignedByte(); |
|
1336 readCount++; |
|
1337 result += dis.readUnsignedByte() << 8; |
|
1338 readCount++; |
|
1339 return result; |
|
1340 } |
|
1341 |
|
1342 private long readTUint(DataInputStream dis) throws Exception |
|
1343 { |
|
1344 long result = dis.readUnsignedByte(); |
|
1345 readCount++; |
|
1346 result += dis.readUnsignedByte() << 8; |
|
1347 readCount++; |
|
1348 result += dis.readUnsignedByte() << 16; |
|
1349 readCount++; |
|
1350 result += dis.readUnsignedByte() << 24; |
|
1351 readCount++; |
|
1352 return result; |
|
1353 } |
|
1354 |
|
1355 private long readTUintWithLength(DataInputStream dis) throws Exception |
|
1356 { |
|
1357 byte length = (byte)dis.readUnsignedByte(); |
|
1358 readCount++; |
|
1359 |
|
1360 if (length != 4) |
|
1361 { |
|
1362 throw new Exception(Messages.getString("MemTraceParser.parseErrorTUint1") + length + Messages.getString("MemTraceParser.parseErrorTUint2")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
1363 } |
|
1364 long result = dis.readUnsignedByte(); |
|
1365 readCount++; |
|
1366 result += dis.readUnsignedByte() << 8; |
|
1367 readCount++; |
|
1368 result += dis.readUnsignedByte() << 16; |
|
1369 readCount++; |
|
1370 result += dis.readUnsignedByte() << 24; |
|
1371 readCount++; |
|
1372 |
|
1373 return result; |
|
1374 } |
|
1375 |
|
1376 private void parseMemTrace(File file) throws Exception |
|
1377 { |
|
1378 DataInputStream dis = new DataInputStream(new FileInputStream(file)); |
|
1379 byte[] traceArray = new byte[(int)file.length()]; |
|
1380 dis.readFully(traceArray); |
|
1381 |
|
1382 // test the mem trace version |
|
1383 if (traceArray.length > 257) |
|
1384 { |
|
1385 String s = new String(traceArray,1,traceArray[0]); |
|
1386 if (!s.startsWith("Bappea_V2.01") && !s.startsWith("Bappea_V1.56")) //up to 1.10 version //$NON-NLS-1$ //$NON-NLS-2$ |
|
1387 { |
|
1388 if (s.startsWith("Bappea_V1.10")) //$NON-NLS-1$ |
|
1389 { |
|
1390 //String version = s.substring(8,12); |
|
1391 parseVersion110Trace(traceArray,s); |
|
1392 |
|
1393 return; |
|
1394 } |
|
1395 else if(s.startsWith("Bappea_V2.02")) |
|
1396 { |
|
1397 parseVersion157Trace(traceArray,s); |
|
1398 return; |
|
1399 } |
|
1400 |
|
1401 String version = s.substring(8, 12); |
|
1402 String traceType = s.substring(13, s.length()); |
|
1403 System.out.println(Messages.getString("MemTraceParser.foundVersion1") + version + Messages.getString("MemTraceParser.foundVersion2") + traceType + Messages.getString("MemTraceParser.foundVersion3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
1404 if (!traceType.equals("MEM")) //$NON-NLS-1$ |
|
1405 { |
|
1406 GeneralMessages.showErrorMessage(Messages.getString("MemTraceParser.wrongTraceType1") + traceType + Messages.getString("MemTraceParser.wrongTraceType2")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
1407 throw new Exception(Messages.getString("MemTraceParser.wrongTraceType1") + traceType + Messages.getString("MemTraceParser.wrongTraceType2")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
1408 } |
|
1409 else |
|
1410 { |
|
1411 ByteArrayInputStream bais = new ByteArrayInputStream(traceArray); |
|
1412 dis = new DataInputStream(bais); |
|
1413 parseNewMemFile(version,dis); |
|
1414 return; |
|
1415 } |
|
1416 } |
|
1417 else //handling 1.55 and newer versions |
|
1418 { |
|
1419 this.traceVersion = s; |
|
1420 parseVersion155Trace(traceArray,s); |
|
1421 |
|
1422 return; |
|
1423 } |
|
1424 } |
|
1425 System.out.println(Messages.getString("MemTraceParser.parsingOldVersion")); //$NON-NLS-1$ |
|
1426 |
|
1427 ByteArrayInputStream bais = new ByteArrayInputStream(traceArray); |
|
1428 dis = new DataInputStream(bais); |
|
1429 |
|
1430 int listLength = this.findThreadListLength(dis, traceArray.length); |
|
1431 if (listLength == -1) |
|
1432 { |
|
1433 GeneralMessages.showErrorMessage(Messages.getString("MemTraceParser.invalidTraceFileOverflow")); //$NON-NLS-1$ |
|
1434 System.out.println(Messages.getString("MemTraceParser.invalidTraceFile")); //$NON-NLS-1$ |
|
1435 throw new Exception(Messages.getString("MemTraceParser.invalidTraceFile")); //$NON-NLS-1$ |
|
1436 } |
|
1437 memTrace = new MemTrace(); |
|
1438 priTrace = new PriTrace(); |
|
1439 |
|
1440 for (int i = 0; i < listLength; ) |
|
1441 { |
|
1442 int j = 0; |
|
1443 for (j = 0; j < buffer.length; j++) |
|
1444 { |
|
1445 byte tmpByte = dis.readByte(); |
|
1446 if (tmpByte != 0) |
|
1447 { |
|
1448 buffer[j] = (char)tmpByte; |
|
1449 } |
|
1450 else |
|
1451 { |
|
1452 dis.skipBytes(buffer.length - j - 1); |
|
1453 break; |
|
1454 } |
|
1455 } |
|
1456 |
|
1457 d = dis.readByte(); |
|
1458 c = dis.readByte(); |
|
1459 b = dis.readByte(); |
|
1460 a = dis.readByte(); |
|
1461 threadId = (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff)); |
|
1462 |
|
1463 d = dis.readByte(); |
|
1464 c = dis.readByte(); |
|
1465 b = dis.readByte(); |
|
1466 a = dis.readByte(); |
|
1467 sampleTime = (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff)); |
|
1468 String unparsedName = new String(buffer); |
|
1469 int index = 0; |
|
1470 while ((unparsedName.charAt(index++) != ':') && (index < buffer.length)){} |
|
1471 processName = unparsedName.substring(0, index - 1); |
|
1472 threadName = unparsedName.substring(index + 1, j); |
|
1473 |
|
1474 memTrace.addFirstSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1475 memSamples.add(new MemThread(new Integer(threadId), threadName, processName)); |
|
1476 priTrace.addFirstSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1477 priSamples.add(new PriThread(new Integer(threadId), threadName, processName)); |
|
1478 |
|
1479 i += buffer.length + 8; |
|
1480 } |
|
1481 MemThread[] threads = new MemThread[memSamples.size()]; |
|
1482 memSamples.copyInto((MemThread[]) threads); |
|
1483 memTrace.setThreads(threads); |
|
1484 PriThread[] priThreads = new PriThread[priSamples.size()]; |
|
1485 priSamples.copyInto((PriThread[]) priThreads); |
|
1486 priTrace.setThreads(priThreads); |
|
1487 dis.skipBytes(8); //skipping "LIST_END" text |
|
1488 for (int k = 0; k < traceArray.length - listLength - 8; ) |
|
1489 { |
|
1490 d = dis.readByte(); |
|
1491 c = dis.readByte(); |
|
1492 b = dis.readByte(); |
|
1493 a = dis.readByte(); |
|
1494 |
|
1495 threadId = ((c & 0xff) << 8) | (d & 0xff); |
|
1496 processPriority = b; |
|
1497 threadPriority = a; |
|
1498 |
|
1499 d = dis.readByte(); |
|
1500 c = dis.readByte(); |
|
1501 b = dis.readByte(); |
|
1502 a = dis.readByte(); |
|
1503 heapSize = (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff)); |
|
1504 |
|
1505 d = dis.readByte(); |
|
1506 c = dis.readByte(); |
|
1507 b = dis.readByte(); |
|
1508 a = dis.readByte(); |
|
1509 stackSize = (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff)); |
|
1510 |
|
1511 d = dis.readByte(); |
|
1512 c = dis.readByte(); |
|
1513 b = dis.readByte(); |
|
1514 a = dis.readByte(); |
|
1515 sampleTime = (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff)); |
|
1516 for (Enumeration<MemThread> e = memSamples.elements(); e.hasMoreElements(); ) |
|
1517 { |
|
1518 MemThread mt = e.nextElement(); |
|
1519 if (mt.threadId.intValue() == threadId) |
|
1520 { |
|
1521 sample = new MemSample(mt, heapSize, stackSize, sampleTime); |
|
1522 memTrace.addSample(sample); |
|
1523 break; |
|
1524 } |
|
1525 } |
|
1526 for (Enumeration<PriThread> e = priSamples.elements(); e.hasMoreElements(); ) |
|
1527 { |
|
1528 PriThread pt = e.nextElement(); |
|
1529 if (pt.threadId.intValue() == threadId) |
|
1530 { |
|
1531 int priority = solveAbsolutPriority(processPriority, threadPriority); |
|
1532 priSample = new PriSample(pt, priority, sampleTime); |
|
1533 priTrace.addSample(priSample); |
|
1534 break; |
|
1535 } |
|
1536 } |
|
1537 memTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1538 priTrace.addLastSynchTime(new Integer(threadId), new Integer(sampleTime)); |
|
1539 k += 16; |
|
1540 } |
|
1541 if (debug) System.out.println(Messages.getString("MemTraceParser.parsingDone")); //$NON-NLS-1$ |
|
1542 |
|
1543 } |
|
1544 |
|
1545 private void parseVersion110Trace(byte[] traceArray, String version_data) throws Exception |
|
1546 { |
|
1547 |
|
1548 String version = version_data.substring(8, 12); |
|
1549 ByteArrayInputStream bais = new ByteArrayInputStream(traceArray); |
|
1550 DataInputStream dis = new DataInputStream(bais); |
|
1551 |
|
1552 if (version_data.indexOf("MEM") > 0 && version_data.indexOf("PRI") > 0) //version 1.10 or newer //$NON-NLS-1$ //$NON-NLS-2$ |
|
1553 { |
|
1554 parseNewMemFile(version,dis); |
|
1555 } |
|
1556 else if (version_data.indexOf("MEM") > 0) //only memtrace //$NON-NLS-1$ |
|
1557 { |
|
1558 this.parseV110MemFile(dis); |
|
1559 } |
|
1560 else if (version_data.indexOf("PRI") > 0) //only pritrace //$NON-NLS-1$ |
|
1561 { |
|
1562 this.parseV110PriFile(dis); |
|
1563 } |
|
1564 } |
|
1565 |
|
1566 private void parseVersion155Trace(byte[] traceArray, String version_data) throws Exception |
|
1567 { |
|
1568 if (version_data.indexOf("MEM")>0) //version 1.55 or newer //$NON-NLS-1$ |
|
1569 { |
|
1570 ByteArrayInputStream bais = new ByteArrayInputStream(traceArray); |
|
1571 DataInputStream dis = new DataInputStream(bais); |
|
1572 |
|
1573 this.parseV155MemFile(dis); |
|
1574 } |
|
1575 } |
|
1576 |
|
1577 private void parseVersion157Trace(byte[] traceArray, String version_data) throws Exception |
|
1578 { |
|
1579 |
|
1580 // String version = version_data.substring(8,12); |
|
1581 // String traceType = version_data.substring(13,version_data.length()); |
|
1582 ByteArrayInputStream bais = new ByteArrayInputStream(traceArray); |
|
1583 DataInputStream dis = new DataInputStream(bais); |
|
1584 |
|
1585 if (version_data.indexOf("MEM")>0) //version 1.57 or newer |
|
1586 { |
|
1587 this.parseV157MemFile(dis); |
|
1588 } |
|
1589 } |
|
1590 |
|
1591 private int calcSamplingTime() |
|
1592 { |
|
1593 long time; |
|
1594 |
|
1595 if (memTrace != null) //if memtrace exists |
|
1596 { |
|
1597 time = memTrace.getFirstSampleNumber(); |
|
1598 for (Enumeration e = memTrace.getSamples(); e.hasMoreElements(); ) |
|
1599 { |
|
1600 MemSample tmp = (MemSample) e.nextElement(); |
|
1601 if (tmp.sampleSynchTime != time) |
|
1602 { |
|
1603 time = tmp.sampleSynchTime - time; |
|
1604 return (int) time; |
|
1605 } |
|
1606 } |
|
1607 return defaultSamplingTime; |
|
1608 } |
|
1609 else if (priTrace != null) //if pritrace exists |
|
1610 { |
|
1611 time = priTrace.getFirstSampleNumber(); |
|
1612 for (Enumeration e = priTrace.getSamples(); e.hasMoreElements(); ) |
|
1613 { |
|
1614 PriSample tmp = (PriSample) e.nextElement(); |
|
1615 if (tmp.sampleSynchTime != time) |
|
1616 { |
|
1617 time = tmp.sampleSynchTime - time; |
|
1618 return (int) time; |
|
1619 } |
|
1620 } |
|
1621 } |
|
1622 //else |
|
1623 System.out.println(Messages.getString("MemTraceParser.shouldNotHappen")); //$NON-NLS-1$ |
|
1624 return 0; |
|
1625 } |
|
1626 |
|
1627 private GenericSampledTrace getTrace() |
|
1628 { |
|
1629 return (GenericSampledTrace) memTrace; |
|
1630 } |
|
1631 |
|
1632 public ParsedTraceData getPriorityTrace() |
|
1633 { |
|
1634 if (priTrace != null) |
|
1635 { |
|
1636 if (priTrace.getPriSample(0).priority != 0) |
|
1637 { |
|
1638 priTrace.setSamplingTime(samplingTime); |
|
1639 ParsedTraceData ptd = new ParsedTraceData(); |
|
1640 ptd.traceData = priTrace; |
|
1641 return ptd; |
|
1642 } |
|
1643 } |
|
1644 |
|
1645 return null; |
|
1646 } |
|
1647 |
|
1648 private int solveAbsolutPriority(int processPriority, int threadPriority) |
|
1649 { |
|
1650 int tPriority = threadPriority * 10 - 30; |
|
1651 int pPriority = processPriority * 10; |
|
1652 switch (tPriority) |
|
1653 { |
|
1654 case 100: //EPriorityAbsoluteVeryLow |
|
1655 return 100; |
|
1656 case 200: //EPriorityAbsoluteLow |
|
1657 return 200; |
|
1658 case 300: //EPriorityAbsoluteBackground |
|
1659 return 300; |
|
1660 case 400: //EPriorityAbsoluteForeground |
|
1661 return 400; |
|
1662 case 500: //EPriorityAbsoluteHigh |
|
1663 return 500; |
|
1664 case -30: //EPriorityNull |
|
1665 return 0; |
|
1666 case 30: //EPriorityRealTime |
|
1667 return 850; |
|
1668 case -20: //EPriorityMuchLess |
|
1669 return pPriority - 20; |
|
1670 case -10: //EPriorityLess |
|
1671 return pPriority - 10; |
|
1672 case 0: //EPriorityNormal |
|
1673 return pPriority; |
|
1674 case 10: //EPriorityMore |
|
1675 return pPriority + 10; |
|
1676 case 20: //EPriorityMuchMore |
|
1677 return pPriority + 20; |
|
1678 default: |
|
1679 return 0; |
|
1680 } |
|
1681 } |
|
1682 |
|
1683 private int findThreadListLength(DataInputStream dis, int traceLength) throws Exception |
|
1684 { |
|
1685 char[] buf = new char[8]; |
|
1686 for (int i = 0; i < traceLength / 8; i++) |
|
1687 { |
|
1688 for (int j = 0; j < 8; j++) |
|
1689 { |
|
1690 buf[j % 8] = (char)dis.readByte(); |
|
1691 } |
|
1692 if (new String(buf).matches("LIST_END")) //$NON-NLS-1$ |
|
1693 { |
|
1694 dis.reset(); |
|
1695 return i * 8; |
|
1696 } |
|
1697 } |
|
1698 dis.reset(); |
|
1699 return -1; |
|
1700 } |
|
1701 |
|
1702 private int convertVersionStringToInt(String version){ |
|
1703 // Coverts version number from string to int |
|
1704 int i = 0; |
|
1705 int versionInt = 0; |
|
1706 String versionString = ""; |
|
1707 |
|
1708 // goes string thru and copies all digits into another string |
|
1709 while( i < version.length() ){ |
|
1710 if( Character.isDigit(version.charAt(i)) ){ |
|
1711 versionString += version.charAt(i); |
|
1712 } |
|
1713 i++; |
|
1714 |
|
1715 } |
|
1716 |
|
1717 // convert string to int |
|
1718 try { |
|
1719 versionInt = Integer.parseInt(versionString); |
|
1720 } catch (Exception e) { |
|
1721 e.printStackTrace(); |
|
1722 } |
|
1723 return versionInt; |
|
1724 } |
|
1725 } |