Skip to content

Commit df7bc58

Browse files
committed
[bugfix] Allow previously collected Performance Stats to be serialized
1 parent dcc8782 commit df7bc58

File tree

1 file changed

+62
-40
lines changed

1 file changed

+62
-40
lines changed

exist-core/src/main/java/org/exist/xquery/PerformanceStatsImpl.java

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -19,7 +43,6 @@
1943
* License along with this library; if not, write to the Free Software
2044
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2145
*/
22-
2346
package org.exist.xquery;
2447

2548
import net.jcip.annotations.NotThreadSafe;
@@ -365,48 +388,47 @@ private FunctionStats[] sort() {
365388

366389
@Override
367390
public void serialize(final MemTreeBuilder builder) {
368-
builder.startElement(new QName(XML_ELEMENT_CALLS, XML_NAMESPACE, XML_PREFIX), null);
369-
if (isEnabled()) {
370-
final AttributesImpl attrs = new AttributesImpl();
371-
for (final QueryStats stats : queries.values()) {
372-
attrs.clear();
391+
final AttributesImpl attrs = new AttributesImpl();
392+
attrs.addAttribute("", "tracing-enabled", "tracing-enabled", "CDATA", Boolean.toString(isEnabled()));
393+
builder.startElement(new QName(XML_ELEMENT_CALLS, XML_NAMESPACE, XML_PREFIX), attrs);
394+
for (final QueryStats stats : queries.values()) {
395+
attrs.clear();
396+
attrs.addAttribute("", "source", "source", "CDATA", stats.source);
397+
attrs.addAttribute("", "elapsed", "elapsed", "CDATA", Double.toString(stats.executionTime / 1000.0));
398+
attrs.addAttribute("", "calls", "calls", "CDATA", Integer.toString(stats.callCount));
399+
builder.startElement(new QName("query", XML_NAMESPACE, XML_PREFIX), attrs);
400+
builder.endElement();
401+
}
402+
for (final FunctionStats stats : functions.values()) {
403+
attrs.clear();
404+
attrs.addAttribute("", "name", "name", "CDATA", stats.qname.getStringValue());
405+
attrs.addAttribute("", "elapsed", "elapsed", "CDATA", Double.toString(stats.executionTime / 1000.0));
406+
attrs.addAttribute("", "calls", "calls", "CDATA", Integer.toString(stats.callCount));
407+
if (stats.source != null) {
373408
attrs.addAttribute("", "source", "source", "CDATA", stats.source);
374-
attrs.addAttribute("", "elapsed", "elapsed", "CDATA", Double.toString(stats.executionTime / 1000.0));
375-
attrs.addAttribute("", "calls", "calls", "CDATA", Integer.toString(stats.callCount));
376-
builder.startElement(new QName("query", XML_NAMESPACE, XML_PREFIX), attrs);
377-
builder.endElement();
378-
}
379-
for (final FunctionStats stats : functions.values()) {
380-
attrs.clear();
381-
attrs.addAttribute("", "name", "name", "CDATA", stats.qname.getStringValue());
382-
attrs.addAttribute("", "elapsed", "elapsed", "CDATA", Double.toString(stats.executionTime / 1000.0));
383-
attrs.addAttribute("", "calls", "calls", "CDATA", Integer.toString(stats.callCount));
384-
if (stats.source != null) {
385-
attrs.addAttribute("", "source", "source", "CDATA", stats.source);
386-
}
387-
builder.startElement(new QName("function", XML_NAMESPACE, XML_PREFIX), attrs);
388-
builder.endElement();
389-
}
390-
for (final IndexStats stats : indexStats.values()) {
391-
attrs.clear();
392-
attrs.addAttribute("", "type", "type", "CDATA", stats.indexType);
393-
attrs.addAttribute("", "source", "source", "CDATA", stats.source + " [" + stats.line + ":" +
394-
stats.column + "]");
395-
attrs.addAttribute("", "elapsed", "elapsed", "CDATA", Double.toString(stats.executionTime / 1000.0));
396-
attrs.addAttribute("", "calls", "calls", "CDATA", Integer.toString(stats.usageCount));
397-
attrs.addAttribute("", "optimization-level", "optimization", "CDATA", stats.indexOptimizationLevel.name());
398-
builder.startElement(new QName("index", XML_NAMESPACE, XML_PREFIX), attrs);
399-
builder.endElement();
400409
}
401-
for (final OptimizationStats stats : optimizations) {
402-
attrs.clear();
403-
attrs.addAttribute("", "type", "type", "CDATA", stats.type.toString());
404-
if (stats.source != null) {
405-
attrs.addAttribute("", "source", "source", "CDATA", stats.source + " [" + stats.line + ":" + stats.column + "]");
406-
}
407-
builder.startElement(new QName("optimization", XML_NAMESPACE, XML_PREFIX), attrs);
408-
builder.endElement();
410+
builder.startElement(new QName("function", XML_NAMESPACE, XML_PREFIX), attrs);
411+
builder.endElement();
412+
}
413+
for (final IndexStats stats : indexStats.values()) {
414+
attrs.clear();
415+
attrs.addAttribute("", "type", "type", "CDATA", stats.indexType);
416+
attrs.addAttribute("", "source", "source", "CDATA", stats.source + " [" + stats.line + ":" +
417+
stats.column + "]");
418+
attrs.addAttribute("", "elapsed", "elapsed", "CDATA", Double.toString(stats.executionTime / 1000.0));
419+
attrs.addAttribute("", "calls", "calls", "CDATA", Integer.toString(stats.usageCount));
420+
attrs.addAttribute("", "optimization-level", "optimization", "CDATA", stats.indexOptimizationLevel.name());
421+
builder.startElement(new QName("index", XML_NAMESPACE, XML_PREFIX), attrs);
422+
builder.endElement();
423+
}
424+
for (final OptimizationStats stats : optimizations) {
425+
attrs.clear();
426+
attrs.addAttribute("", "type", "type", "CDATA", stats.type.toString());
427+
if (stats.source != null) {
428+
attrs.addAttribute("", "source", "source", "CDATA", stats.source + " [" + stats.line + ":" + stats.column + "]");
409429
}
430+
builder.startElement(new QName("optimization", XML_NAMESPACE, XML_PREFIX), attrs);
431+
builder.endElement();
410432
}
411433
builder.endElement();
412434
}

0 commit comments

Comments
 (0)