Skip to content

Commit

Permalink
Added elapsed time to result metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladd-bit committed Oct 5, 2022
1 parent 001627e commit cea4bf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/tika/model/TikaProcessingResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ public class TikaProcessingResult {
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
OffsetDateTime timestamp;

// total elapsed time in seconds
long processingElapsedTime;
}
3 changes: 3 additions & 0 deletions src/main/java/tika/processor/CompositeTikaProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public void reset() throws Exception {

protected TikaProcessingResult processStream(TikaInputStream stream) {

var currentTimeNanos = System.nanoTime();

TikaProcessingResult result;
try {
final int MIN_TEXT_BUFFER_SIZE = 1;
Expand Down Expand Up @@ -217,6 +219,7 @@ else if (isDocumentOfHTMLType(stream)) {
.metadata(resultMeta)
.success(true)
.timestamp(OffsetDateTime.now())
.processingElapsedTime((long) ((System.nanoTime() - currentTimeNanos) * 1e-9))
.build();

outStream.close();
Expand Down

0 comments on commit cea4bf7

Please sign in to comment.