48
48
*/
49
49
@ NotThreadSafe
50
50
public class PerformanceStatsImpl implements PerformanceStats {
51
- public static final String CDATA = "CDATA" ;
52
- public static final String SOURCE = "source" ;
53
- public static final String ELAPSED = "elapsed" ;
54
- public static final String CALLS = "calls" ;
55
- public static final String QUERY = "query" ;
56
- public static final String NAME = "name" ;
57
- public static final String TYPE = "type" ;
51
+ private static final String CALLS = "calls" ;
52
+ private static final String CDATA = "CDATA" ;
53
+ private static final String ELAPSED = "elapsed" ;
54
+ private static final String NAME = "name" ;
55
+ private static final String OPTIMIZATION_LEVEL = "optimization-level" ;
56
+ private static final String QUERY = "query" ;
57
+ private static final String SOURCE = "source" ;
58
+ private static final String TYPE = "type" ;
58
59
59
- private static class IndexStats {
60
+ private final Map <String , QueryStats > queries = new HashMap <>();
61
+ private final Map <FunctionStats , FunctionStats > functions = new HashMap <>();
62
+ private final Map <IndexStats , IndexStats > indexStats = new HashMap <>();
63
+ private final Set <OptimizationStats > optimizations = new HashSet <>();
64
+ private final Enabler enabler ;
65
+
66
+ private boolean enabled ;
60
67
68
+ public PerformanceStatsImpl (final boolean enabled ) {
69
+ this (enabled , x -> x );
70
+ }
71
+
72
+ public PerformanceStatsImpl (final boolean enabled , final Enabler enabler ) {
73
+ this .enabled = enabled ;
74
+ this .enabler = enabler ;
75
+ }
76
+
77
+ private static class IndexStats {
61
78
final String source ;
62
79
final String indexType ;
63
80
final int line ;
64
81
final int column ;
65
82
final IndexOptimizationLevel indexOptimizationLevel ;
83
+
66
84
int usageCount = 1 ;
67
85
long executionTime = 0 ;
68
86
@@ -102,13 +120,13 @@ public boolean equals(final Object obj) {
102
120
}
103
121
104
122
private static class QueryStats {
105
-
106
123
final String source ;
124
+
107
125
long executionTime = 0 ;
108
126
int callCount = 1 ;
109
127
110
128
QueryStats (final String source ) {
111
- this .source = ( source != null ? source : "" ) ;
129
+ this .source = source == null ? "" : source ;
112
130
}
113
131
114
132
public static QueryStats copy (final QueryStats other ) {
@@ -169,36 +187,16 @@ public boolean equals(final Object obj) {
169
187
}
170
188
171
189
@ ThreadSafe
172
- private static class OptimizationStats {
173
- final String source ;
174
- final OptimizationType type ;
175
- final int line ;
176
- final int column ;
177
-
190
+ private record OptimizationStats (String source , OptimizationType type , int line , int column ) {
178
191
OptimizationStats (final String source , final OptimizationType type , final int line , final int column ) {
179
- this .source = source != null ? source : "" ;
192
+ this .source = source == null ? "" : source ;
180
193
this .type = type ;
181
194
this .line = line ;
182
195
this .column = column ;
183
196
}
184
-
185
- @ Override
186
- public int hashCode () {
187
- return 32 * type .hashCode () + source .hashCode () + line + column ;
188
- }
189
-
190
- @ Override
191
- public boolean equals (final Object obj ) {
192
- if (obj instanceof OptimizationStats other ) {
193
- return source .equals (other .source ) && type == other .type &&
194
- line == other .line && column == other .column ;
195
- }
196
- return false ;
197
- }
198
197
}
199
198
200
199
private static class CompareByTime implements Comparator <FunctionStats > {
201
-
202
200
@ Override
203
201
public int compare (final FunctionStats o1 , final FunctionStats o2 ) {
204
202
return Long .compare (o1 .executionTime , o2 .executionTime );
@@ -210,24 +208,6 @@ public interface Enabler {
210
208
boolean enabled (final boolean enabled );
211
209
}
212
210
213
- private final Map <String , QueryStats > queries = new HashMap <>();
214
- private final Map <FunctionStats , FunctionStats > functions = new HashMap <>();
215
- private final Map <IndexStats , IndexStats > indexStats = new HashMap <>();
216
- private final Set <OptimizationStats > optimizations = new HashSet <>();
217
-
218
- private final Enabler enabler ;
219
-
220
- private boolean enabled = false ;
221
-
222
- public PerformanceStatsImpl (final boolean enabled ) {
223
- this (enabled , x -> x );
224
- }
225
-
226
- public PerformanceStatsImpl (final boolean enabled , final Enabler enabler ) {
227
- this .enabled = enabled ;
228
- this .enabler = enabler ;
229
- }
230
-
231
211
@ Override
232
212
public void setEnabled (final boolean enabled ) {
233
213
this .enabled = enabled ;
@@ -388,7 +368,7 @@ public void serialize(final MemTreeBuilder builder) {
388
368
attrs .addAttribute ("" , NAME , NAME , CDATA , stats .qname .getStringValue ());
389
369
attrs .addAttribute ("" , ELAPSED , ELAPSED , CDATA , Double .toString (stats .executionTime / 1000.0 ));
390
370
attrs .addAttribute ("" , CALLS , CALLS , CDATA , Integer .toString (stats .callCount ));
391
- if (stats .source != null ) {
371
+ if (! stats .source . isEmpty () ) {
392
372
attrs .addAttribute ("" , SOURCE , SOURCE , CDATA , stats .source );
393
373
}
394
374
builder .startElement (new QName ("function" , XML_NAMESPACE , XML_PREFIX ), attrs );
@@ -401,7 +381,7 @@ public void serialize(final MemTreeBuilder builder) {
401
381
attrs .addAttribute ("" , SOURCE , SOURCE , CDATA , "%s [%s:%s]" .formatted (stats .source , stats .line , stats .column ));
402
382
attrs .addAttribute ("" , ELAPSED , ELAPSED , CDATA , Double .toString (stats .executionTime / 1000.0 ));
403
383
attrs .addAttribute ("" , CALLS , CALLS , CDATA , Integer .toString (stats .usageCount ));
404
- attrs .addAttribute ("" , "optimization-level" , "optimization" , CDATA , stats .indexOptimizationLevel .name ());
384
+ attrs .addAttribute ("" , OPTIMIZATION_LEVEL , OPTIMIZATION_LEVEL , CDATA , stats .indexOptimizationLevel .name ());
405
385
builder .startElement (new QName ("index" , XML_NAMESPACE , XML_PREFIX ), attrs );
406
386
builder .endElement ();
407
387
}
0 commit comments