Skip to content

Commit 64cda8f

Browse files
committed
add write xref latency meter
1 parent 4dc0b67 commit 64cda8f

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import org.opengrok.indexer.logger.LoggerFactory;
120120
import org.opengrok.indexer.search.QueryBuilder;
121121
import org.opengrok.indexer.util.IOUtils;
122+
import org.opengrok.indexer.util.Statistics;
122123
import org.opengrok.indexer.web.Util;
123124

124125
/**
@@ -658,12 +659,15 @@ private static void populateDocumentHistory(Document doc, File file) {
658659
* @param defs definitions for the source file, if available
659660
* @param annotation Annotation information for the file
660661
* @param project Project the file belongs to
662+
* @param file file object, used only for logging
661663
* @throws java.io.IOException If an error occurs while creating the output
662664
*/
663665
public static void writeXref(AnalyzerFactory factory, Reader in,
664666
Writer out, Definitions defs,
665-
Annotation annotation, Project project)
667+
Annotation annotation, Project project, File file)
666668
throws IOException {
669+
670+
Statistics stat = new Statistics();
667671
Reader input = in;
668672
if (factory.getGenre() == AbstractAnalyzer.Genre.PLAIN) {
669673
// This is some kind of text file, so we need to expand tabs to
@@ -681,13 +685,14 @@ public static void writeXref(AnalyzerFactory factory, Reader in,
681685
analyzer.setScopesEnabled(env.isScopesEnabled());
682686
analyzer.setFoldingEnabled(env.isFoldingEnabled());
683687
analyzer.writeXref(args);
688+
689+
stat.report(LOGGER, Level.FINEST, String.format("wrote xref for '%s'", file), "xref.write.latency");
684690
}
685691

686692
/**
687-
* Writes a browse-able version of the file transformed for immediate
688-
* serving to a web client.
693+
* Writes a browse-able version of the file transformed for immediate serving to a web client.
689694
* @param contextPath the web context path for
690-
* {@link Util#dumpXref(java.io.Writer, java.io.Reader, java.lang.String)}
695+
* {@link Util#dumpXref(java.io.Writer, java.io.Reader, java.lang.String, File)}
691696
* @param factory the analyzer factory for this file type
692697
* @param in the input stream containing the data
693698
* @param out a defined instance to write
@@ -698,13 +703,12 @@ public static void writeXref(AnalyzerFactory factory, Reader in,
698703
*/
699704
public static void writeDumpedXref(String contextPath,
700705
AnalyzerFactory factory, Reader in, Writer out,
701-
Definitions defs, Annotation annotation, Project project)
702-
throws IOException {
706+
Definitions defs, Annotation annotation, Project project, File file) throws IOException {
703707

704708
File xrefTemp = File.createTempFile("ogxref", ".html");
705709
try {
706710
try (FileWriter tmpout = new FileWriter(xrefTemp)) {
707-
writeXref(factory, in, tmpout, defs, annotation, project);
711+
writeXref(factory, in, tmpout, defs, annotation, project, file);
708712
}
709713
Util.dumpXref(out, xrefTemp, false, contextPath);
710714
} finally {

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2019, Chris Fraire <cfraire@me.com>.
2323
* Portions Copyright (c) 2020, Ric Harris <harrisric@users.noreply.github.com>.
2424
*/
@@ -400,7 +400,7 @@ void testXref() throws IOException {
400400
}
401401
try (FileReader in = new FileReader(f); StringWriter out = new StringWriter()) {
402402
try {
403-
AnalyzerGuru.writeXref(factory, in, out, null, null, null);
403+
AnalyzerGuru.writeXref(factory, in, out, null, null, null, f);
404404
} catch (UnsupportedOperationException exp) {
405405
// ignore
406406
}

opengrok-web/src/main/webapp/list.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ document.pageReady.push(function() { pageReadyList();});
264264
r = IOUtils.createBOMStrippedReader(bin,
265265
StandardCharsets.UTF_8.name());
266266
AnalyzerGuru.writeDumpedXref(request.getContextPath(), a,
267-
r, out, defs, annotation, project);
267+
r, out, defs, annotation, project, resourceFile);
268268
%></pre>
269269
</div><%
270270
} else {

opengrok-web/src/main/webapp/xref.jspf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ org.opengrok.indexer.web.QueryParameters"
126126
r = IOUtils.createBOMStrippedReader(in, StandardCharsets.UTF_8.name());
127127
AnalyzerGuru.writeDumpedXref(request.getContextPath(),
128128
a, r, out,
129-
defs, annotation, project);
129+
defs, annotation, project, resourceFile);
130130
} else if (g == AbstractAnalyzer.Genre.IMAGE) {
131131
%></pre>
132132
<img src="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %><%= Util.uriEncode(rev) %>" alt="Image from Source Repository"/>

0 commit comments

Comments
 (0)