Skip to content

Commit

Permalink
json: Add an offset to sorting job
Browse files Browse the repository at this point in the history
The json trace files can have events before the "traceevents": key.
This patch allows the parser to start sorting on the correct entry.

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
MatthewKhouzam committed Dec 9, 2024
1 parent 1801704 commit 66953a2
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public BigDecimal getTs() {
private final String fTsKey;
private final String fPath;
private final ITmfTrace fTrace;
private final long fOffset;


/**
* Constructor
Expand All @@ -112,17 +114,39 @@ public BigDecimal getTs() {
* @param path
* Trace path
* @param tsKey
* Timestamp key, represent the json object key. The value associated
* to this key is the timestamp that will be use to sort
* Timestamp key, represent the json object key. The value
* associated to this key is the timestamp that will be use to
* sort
* @param bracketsToSkip
* Number of bracket to skip
*/
public SortingJob(ITmfTrace trace, String path, String tsKey, int bracketsToSkip) {
this(trace, path, tsKey, bracketsToSkip, 0);
}

/**
* Constructor
*
* @param trace
* Trace to sort
* @param path
* Trace path
* @param tsKey
* Timestamp key, represent the json object key. The value
* associated to this key is the timestamp that will be use to
* sort
* @param bracketsToSkip
* Number of bracket to skip
* @param offset
* offset in bytes to skip in the file.
*/
public SortingJob(ITmfTrace trace, String path, String tsKey, int bracketsToSkip, long offset) {
super(Messages.SortingJob_description);
fTrace = trace;
fPath = path;
fTsKey = tsKey;
fBracketsToSkip = bracketsToSkip;
fOffset = offset;
}

/**
Expand All @@ -148,6 +172,11 @@ protected IStatus run(IProgressMonitor monitor) {
tempDir.mkdirs();
List<File> tracelings = new ArrayList<>();
try (BufferedInputStream parser = new BufferedInputStream(new FileInputStream(fPath))) {
long offset = parser.skip(fOffset);
if (offset != fOffset) {
// already at EOF
return new Status(IStatus.ERROR, getClass(), "Offset " + fOffset + " is greater than the file size.");
}
int data = 0;
for (int nbBracket = 0; nbBracket < fBracketsToSkip; nbBracket++) {
data = parser.read();
Expand Down

0 comments on commit 66953a2

Please sign in to comment.