Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 6f06ade

Browse files
committed
Merge branch 'develop'
2 parents 8ea3222 + 67e3628 commit 6f06ade

File tree

26 files changed

+487
-265
lines changed

26 files changed

+487
-265
lines changed

edu.rice.cs.hpc.data/src/edu/rice/cs/hpc/data/db/version3/DataCommon.java

+45-8
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
***************************************************/
2020
abstract public class DataCommon
2121
{
22-
public final static int HEADER_COMMON_SIZE = 23;
23-
private final static int MESSAGE_SIZE = 18;
22+
public final static int HEADER_COMMON_SIZE = 24;
23+
private final static int MESSAGE_SIZE = 16;
2424

2525
protected long numItems;
26-
protected int version;
26+
protected short numSections;
27+
28+
protected byte versionMajor;
29+
protected byte versionMinor;
30+
31+
protected DataSection []sections;
32+
2733
protected String filename;
2834

2935
private FileInputStream fis;
@@ -50,11 +56,24 @@ public void open(final String file)
5056
// read the common header
5157
readHeader(file, fis, buffer);
5258

53-
channel.position(HEADER_COMMON_SIZE);
59+
// read the section headers
60+
numSections = (short) (numSections - 2);
61+
buffer.clear();
62+
buffer = ByteBuffer.allocate(numSections * 16);
63+
numBytes = channel.read(buffer);
64+
buffer.rewind();
65+
66+
sections = new DataSection[numSections];
67+
for(int i=0; i<numSections; i++) {
68+
sections[i] = new DataSection();
69+
sections[i].size = buffer.getLong();
70+
sections[i].offset = buffer.getLong();
71+
}
72+
5473
// -------------------------------------------------------------
5574
// Read the next header (implemented by derived class)
5675
// -------------------------------------------------------------
57-
if ( readNextHeader(channel) )
76+
if ( readNextHeader(channel, sections) )
5877
{
5978
// the implementer can perform other operations
6079
}
@@ -68,7 +87,7 @@ public void open(final String file)
6887
public void printInfo( PrintStream out)
6988
{
7089
out.println("Filename: " + filename);
71-
out.println("Version: " + version);
90+
out.println("Version: " + versionMajor);
7291
out.println("Num items: " + numItems);
7392
}
7493

@@ -114,7 +133,8 @@ protected void readHeader(String file, FileInputStream fis, ByteBuffer buffer)
114133
// -------------------------------------------------------------
115134
// read the version
116135
// -------------------------------------------------------------
117-
version = buffer.get();
136+
versionMajor = buffer.get();
137+
versionMinor = buffer.get();
118138

119139
// -------------------------------------------------------------
120140
// read the number of items
@@ -123,9 +143,26 @@ protected void readHeader(String file, FileInputStream fis, ByteBuffer buffer)
123143
buffer.get(itemBytes, 0, 4);
124144
ByteBuffer byteBuffer = ByteBuffer.wrap(itemBytes);
125145
numItems = byteBuffer.getInt();
146+
147+
// -------------------------------------------------------------
148+
// read the number of sections
149+
// -------------------------------------------------------------
150+
final byte []sectionBytes = new byte[2];
151+
buffer.get(sectionBytes);
152+
ByteBuffer secBuffer = ByteBuffer.wrap(sectionBytes);
153+
numSections = secBuffer.getShort();
154+
}
155+
156+
protected static long getMultiplyOf(long v, int mask) {
157+
return (v + mask) & ~mask;
126158
}
127159

160+
protected static long getMultiplyOf8(long v) {
161+
return getMultiplyOf(v, 7);
162+
}
163+
164+
128165
protected abstract boolean isTypeFormatCorrect(long type);
129166
protected abstract boolean isFileHeaderCorrect(String header);
130-
protected abstract boolean readNextHeader(FileChannel input) throws IOException;
167+
protected abstract boolean readNextHeader(FileChannel input, DataSection []sections) throws IOException;
131168
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package edu.rice.cs.hpc.data.db.version3;
2+
3+
public class DataSection
4+
{
5+
public long size;
6+
public long offset;
7+
8+
@Override
9+
public String toString() {
10+
return "@" + offset + ": " + size + " bytes";
11+
}
12+
}

edu.rice.cs.hpc.data/src/edu/rice/cs/hpc/data/db/version3/DataSummary.java

+28-24
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class DataSummary extends DataCommon
2929
// --------------------------------------------------------------------
3030
// constants
3131
// --------------------------------------------------------------------
32-
private final static String HEADER_MAGIC_STR = "HPCPROF-tmsdb_____";
32+
private final static String HEADER_MAGIC_STR = "HPCPROF-tmsdb___";
3333
private static final int METRIC_VALUE_SIZE = 8 + 2;
3434
private static final int CCT_RECORD_SIZE = 4 + 8;
3535
private static final int MAX_LEVELS = 8;
@@ -254,9 +254,8 @@ public List<MetricValueSparse> getMetrics(int profileNum, int cct_id)
254254
// read the cct context
255255
// -------------------------------------------
256256

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;
260259

261260
FileChannel channel = file.getChannel();
262261
byte []arrayBytes = new byte[numBytesCCT];
@@ -269,8 +268,7 @@ public List<MetricValueSparse> getMetrics(int profileNum, int cct_id)
269268
profileNumberCache = profileNum;
270269
}
271270

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);
274272

275273
if (indexes == null)
276274
// 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) {
405403
}
406404

407405
@Override
408-
protected boolean readNextHeader(FileChannel input)
406+
protected boolean readNextHeader(FileChannel input, DataSection []sections)
409407
throws IOException
410408
{
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);
413414

414415
return true;
415416
}
@@ -426,24 +427,19 @@ protected boolean readNextHeader(FileChannel input)
426427
* @param input FileChannel
427428
* @throws IOException
428429
*/
429-
private void readIdTuple(FileChannel input)
430+
private void readIdTuple(FileChannel input, DataSection idTupleSection)
430431
throws IOException
431432
{
433+
input.position(idTupleSection.offset);
434+
432435
// -----------------------------------------
433436
// 1. Read the id tuples section from the thread.db
434437
// -----------------------------------------
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+
443439
listIdTuple = new ArrayList<IdTuple>((int) numItems-1);
444440
listIdTupleShort = new ArrayList<IdTuple>((int) numItems-1);
445441

446-
ByteBuffer buffer = ByteBuffer.allocate((int) idTupleSize);
442+
ByteBuffer buffer = ByteBuffer.allocate((int) idTupleSection.size);
447443

448444
int numBytes = input.read(buffer);
449445
assert (numBytes > 0);
@@ -481,6 +477,8 @@ private void readIdTuple(FileChannel input)
481477
if (mapLevelToHash[j] == null)
482478
mapLevelToHash[j] = new HashMap<Long, Integer>();
483479

480+
// compute the number of appearances of a given kind and level
481+
// this is important to know if there's invariant or not
484482
Long hash = convertIdTupleToHash(j, item.kind[j], item.index[j]);
485483
Integer count = mapLevelToHash[j].get(hash);
486484
if (count == null) {
@@ -489,6 +487,7 @@ private void readIdTuple(FileChannel input)
489487
count++;
490488
mapLevelToHash[j].put(hash, count);
491489

490+
// find min and max for each level
492491
minIndex[j] = Math.min(minIndex[j], item.index[j]);
493492
maxIndex[j] = Math.min(maxIndex[j], item.index[j]);
494493
}
@@ -612,7 +611,10 @@ private long convertIdTupleToHash(int level, int kind, long index) {
612611
* @param input FileChannel
613612
* @throws IOException
614613
*/
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+
616618
listProfInfo = new ArrayList<DataSummary.ProfInfo>((int) numItems);
617619

618620
long position_profInfo = input.position();
@@ -685,7 +687,8 @@ private long[] binarySearch(int index, int first, int last, ByteBuffer buffer) {
685687
* @return int
686688
*/
687689
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);
689692
return buffer.getInt();
690693
}
691694

@@ -711,7 +714,7 @@ private long getCCTOffset(ByteBuffer buffer, int position) {
711714
*/
712715
private long[] newtonSearch(int cct, int first, int last, ByteBuffer buffer) {
713716
int left_index = first;
714-
int right_index = last - CCT_RECORD_SIZE;
717+
int right_index = last - 1;
715718

716719
int left_cct = getCCTIndex(buffer, left_index);
717720
int right_cct = getCCTIndex(buffer, right_index);
@@ -778,10 +781,11 @@ private void printMetrics(PrintStream out, int cct)
778781
List<MetricValueSparse> values = getMetrics(cct);
779782
if (values == null)
780783
return;
781-
/*
784+
782785
for(MetricValueSparse value: values) {
783786
System.out.print(value.getIndex() + ": " + value.getValue() + " , ");
784-
}*/
787+
}
788+
System.out.println();
785789
} catch (IOException e) {
786790
e.printStackTrace();
787791
} finally {

edu.rice.cs.hpc.data/src/edu/rice/cs/hpc/data/db/version3/DataTrace.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*******************************************************************************/
2121
public class DataTrace extends DataCommon
2222
{
23-
private final static String HEADER = "HPCPROF-tracedb___";
23+
private final static String HEADER = "HPCPROF-tracedb_";
2424
private final static int TRACE_HDR_RECORD_SIZE = 22;
2525
private final static int TRACE_RECORD_SIZE = 8 + 4;
2626

@@ -68,9 +68,11 @@ protected boolean isFileHeaderCorrect(String header) {
6868
* (non-Javadoc)
6969
* @see edu.rice.cs.hpc.data.db.DataCommon#readNextHeader(java.nio.channels.FileChannel)
7070
*/
71-
protected boolean readNextHeader(FileChannel input)
71+
protected boolean readNextHeader(FileChannel input, DataSection []sections)
7272
throws IOException
7373
{
74+
input.position(sections[0].offset);
75+
7476
// -------------------------------------------------
7577
// reading the next 256 byte header
7678
// -------------------------------------------------
@@ -101,6 +103,9 @@ protected boolean readNextHeader(FileChannel input)
101103
}
102104
buffer.clear();
103105

106+
long nextPosition = sections[0].offset + getMultiplyOf8( sections[0].size);
107+
input.position(nextPosition);
108+
104109
return true;
105110
}
106111

0 commit comments

Comments
 (0)