@@ -29,7 +29,7 @@ public class DataSummary extends DataCommon
29
29
// --------------------------------------------------------------------
30
30
// constants
31
31
// --------------------------------------------------------------------
32
- private final static String HEADER_MAGIC_STR = "HPCPROF-tmsdb_____ " ;
32
+ private final static String HEADER_MAGIC_STR = "HPCPROF-tmsdb___ " ;
33
33
private static final int METRIC_VALUE_SIZE = 8 + 2 ;
34
34
private static final int CCT_RECORD_SIZE = 4 + 8 ;
35
35
private static final int MAX_LEVELS = 8 ;
@@ -254,9 +254,8 @@ public List<MetricValueSparse> getMetrics(int profileNum, int cct_id)
254
254
// read the cct context
255
255
// -------------------------------------------
256
256
257
- long positionCCT = info .offset +
258
- info .num_vals * METRIC_VALUE_SIZE ;
259
- int numBytesCCT = (info .num_nz_contexts +1 ) * CCT_RECORD_SIZE ;
257
+ long positionCCT = info .offset + info .num_vals * METRIC_VALUE_SIZE ;
258
+ int numBytesCCT = (info .num_nz_contexts +1 ) * CCT_RECORD_SIZE ;
260
259
261
260
FileChannel channel = file .getChannel ();
262
261
byte []arrayBytes = new byte [numBytesCCT ];
@@ -269,8 +268,7 @@ public List<MetricValueSparse> getMetrics(int profileNum, int cct_id)
269
268
profileNumberCache = profileNum ;
270
269
}
271
270
272
- long []indexes = newtonSearch (cct_id , 0 , 1 +info .num_nz_contexts , byteBufferCache );
273
- // long []indexes = binarySearch(cct_id, 0, 1+info.num_nz_contexts, byteBufferCache);
271
+ long []indexes = newtonSearch (cct_id , 0 , info .num_nz_contexts , byteBufferCache );
274
272
275
273
if (indexes == null )
276
274
// the cct id is not found or the cct has no metrics. Should we return null or empty list?
@@ -405,11 +403,14 @@ protected boolean isFileHeaderCorrect(String header) {
405
403
}
406
404
407
405
@ Override
408
- protected boolean readNextHeader (FileChannel input )
406
+ protected boolean readNextHeader (FileChannel input , DataSection [] sections )
409
407
throws IOException
410
408
{
411
- readProfInfo (input );
412
- readIdTuple (input );
409
+ readProfInfo (input , sections [0 ]);
410
+ readIdTuple (input , sections [1 ]);
411
+
412
+ long nextPosition = sections [1 ].offset + getMultiplyOf8 ( sections [1 ].size );
413
+ input .position (nextPosition );
413
414
414
415
return true ;
415
416
}
@@ -426,24 +427,19 @@ protected boolean readNextHeader(FileChannel input)
426
427
* @param input FileChannel
427
428
* @throws IOException
428
429
*/
429
- private void readIdTuple (FileChannel input )
430
+ private void readIdTuple (FileChannel input , DataSection idTupleSection )
430
431
throws IOException
431
432
{
433
+ input .position (idTupleSection .offset );
434
+
432
435
// -----------------------------------------
433
436
// 1. Read the id tuples section from the thread.db
434
437
// -----------------------------------------
435
-
436
- byte []buff = new byte [8 ];
437
- ByteBuffer buffTupleSize = ByteBuffer .wrap (buff );
438
- input .read (buffTupleSize );
439
- buffTupleSize .flip ();
440
-
441
- long idTupleSize = buffTupleSize .getLong ();
442
-
438
+
443
439
listIdTuple = new ArrayList <IdTuple >((int ) numItems -1 );
444
440
listIdTupleShort = new ArrayList <IdTuple >((int ) numItems -1 );
445
441
446
- ByteBuffer buffer = ByteBuffer .allocate ((int ) idTupleSize );
442
+ ByteBuffer buffer = ByteBuffer .allocate ((int ) idTupleSection . size );
447
443
448
444
int numBytes = input .read (buffer );
449
445
assert (numBytes > 0 );
@@ -481,6 +477,8 @@ private void readIdTuple(FileChannel input)
481
477
if (mapLevelToHash [j ] == null )
482
478
mapLevelToHash [j ] = new HashMap <Long , Integer >();
483
479
480
+ // compute the number of appearances of a given kind and level
481
+ // this is important to know if there's invariant or not
484
482
Long hash = convertIdTupleToHash (j , item .kind [j ], item .index [j ]);
485
483
Integer count = mapLevelToHash [j ].get (hash );
486
484
if (count == null ) {
@@ -489,6 +487,7 @@ private void readIdTuple(FileChannel input)
489
487
count ++;
490
488
mapLevelToHash [j ].put (hash , count );
491
489
490
+ // find min and max for each level
492
491
minIndex [j ] = Math .min (minIndex [j ], item .index [j ]);
493
492
maxIndex [j ] = Math .min (maxIndex [j ], item .index [j ]);
494
493
}
@@ -612,7 +611,10 @@ private long convertIdTupleToHash(int level, int kind, long index) {
612
611
* @param input FileChannel
613
612
* @throws IOException
614
613
*/
615
- private void readProfInfo (FileChannel input ) throws IOException {
614
+ private void readProfInfo (FileChannel input , DataSection profSection ) throws IOException {
615
+
616
+ input .position (profSection .offset );
617
+
616
618
listProfInfo = new ArrayList <DataSummary .ProfInfo >((int ) numItems );
617
619
618
620
long position_profInfo = input .position ();
@@ -685,7 +687,8 @@ private long[] binarySearch(int index, int first, int last, ByteBuffer buffer) {
685
687
* @return int
686
688
*/
687
689
private int getCCTIndex (ByteBuffer buffer , int position ) {
688
- buffer .position (position * CCT_RECORD_SIZE );
690
+ final int adjustedPosition = position * CCT_RECORD_SIZE ;
691
+ buffer .position (adjustedPosition );
689
692
return buffer .getInt ();
690
693
}
691
694
@@ -711,7 +714,7 @@ private long getCCTOffset(ByteBuffer buffer, int position) {
711
714
*/
712
715
private long [] newtonSearch (int cct , int first , int last , ByteBuffer buffer ) {
713
716
int left_index = first ;
714
- int right_index = last - CCT_RECORD_SIZE ;
717
+ int right_index = last - 1 ;
715
718
716
719
int left_cct = getCCTIndex (buffer , left_index );
717
720
int right_cct = getCCTIndex (buffer , right_index );
@@ -778,10 +781,11 @@ private void printMetrics(PrintStream out, int cct)
778
781
List <MetricValueSparse > values = getMetrics (cct );
779
782
if (values == null )
780
783
return ;
781
- /*
784
+
782
785
for (MetricValueSparse value : values ) {
783
786
System .out .print (value .getIndex () + ": " + value .getValue () + " , " );
784
- }*/
787
+ }
788
+ System .out .println ();
785
789
} catch (IOException e ) {
786
790
e .printStackTrace ();
787
791
} finally {
0 commit comments