Project

General

Profile

7035-jmx-20230424.patch

Dănuț Filimon, 04/24/2023 08:59 AM

Download (19.1 KB)

View differences:

new/src/com/goldencode/p2j/jmx/FwdJMX.java 2023-04-24 12:33:00 +0000
680 680
   implements OptionalQueryProfiler
681 681
   {
682 682
      /** Query profiler */
683
      QueryProfiler;
683
      QueryProfiler,
684
      /** FQL profiler */
685
      FQLProfiler;
684 686

  
685 687
      /** Profiler instance */
686 688
      private final SimpleQueryProfiler profiler = new SimpleQueryProfiler();
......
766 768
      }
767 769
      
768 770
      /**
771
       * Update the number of meta db hits of a specified query
772
       *
773
       * @param   query
774
       *          the query for which the update is done
775
       * @param   value
776
       *          the number of meta db hits
777
       */
778
      @Override
779
      public void updateMetaDBHits(String query, long value)
780
      {
781
         profiler.updateMetaDBHits(query, value);
782
      }
783
      
784
      /**
785
       * Update the number of meta db misses of a specified query
786
       *
787
       * @param   query
788
       *          the query for which the update is done
789
       * @param   value
790
       *          the number of meta db misses
791
       */
792
      @Override
793
      public void updateMetaDBMisses(String query, long value)
794
      {
795
         profiler.updateMetaDBMisses(query, value);
796
      }
797
      
798
      /**
799
       * Update the number of temp db hits of a specified query
800
       *
801
       * @param   query
802
       *          the query for which the update is done
803
       * @param   value
804
       *          the number of temp db hits
805
       */
806
      @Override
807
      public void updateTempDBHits(String query, long value)
808
      {
809
         profiler.updateTempDBHits(query, value);
810
      }
811
      
812
      /**
813
       * Update the number of temp db misses of a specified query
814
       *
815
       * @param   query
816
       *          the query for which the update is done
817
       * @param   value
818
       *          the number of temp db misses
819
       */
820
      @Override
821
      public void updateTempDBMisses(String query, long value)
822
      {
823
         profiler.updateTempDBMisses(query, value);
824
      }
825
      
826
      /**
827
       * Update the number of dirty db hits of a specified query
828
       *
829
       * @param   query
830
       *          the query for which the update is done
831
       * @param   value
832
       *          the number of dirty db hits
833
       */
834
      @Override
835
      public void updateDirtyDBHits(String query, long value)
836
      {
837
         profiler.updateDirtyDBHits(query, value);
838
      }
839
      
840
      /**
841
       * Update the number of dirty db misses of a specified query
842
       *
843
       * @param   query
844
       *          the query for which the update is done
845
       * @param   value
846
       *          the number of dirty db misses
847
       */
848
      @Override
849
      public void updateDirtyDBMisses(String query, long value)
850
      {
851
         profiler.updateDirtyDBMisses(query, value);
852
      }
853
      
854
      /**
855
       * Update the number of persistent db hits of a specified query
856
       *
857
       * @param   query
858
       *          the query for which the update is done
859
       * @param   value
860
       *          the number of persistent db hits
861
       */
862
      @Override
863
      public void updatePersistentDBHits(String query, long value)
864
      {
865
         profiler.updatePersistentDBHits(query, value);
866
      }
867
      
868
      /**
869
       * Update the number of persistent db misses of a specified query
870
       *
871
       * @param   query
872
       *          the query for which the update is done
873
       * @param   value
874
       *          the number of persistent db misses
875
       */
876
      @Override
877
      public void updatePersistentDBMisses(String query, long value)
878
      {
879
         profiler.updatePersistentDBMisses(query, value);
880
      }
881
      
882
      /**
769 883
       * Return the string representation of a profiled query
770 884
       * 
771 885
       * @param    ts
new/src/com/goldencode/p2j/jmx/QueryProfiler.java 2023-04-24 12:44:15 +0000
109 109
   public void updateHydrateTotalTime(String query, long value);
110 110
   
111 111
   /**
112
    * Update the number of meta db hits of a specified query
113
    *
114
    * @param   query
115
    *          the query for which the update is done
116
    * @param   value
117
    *          the number of meta db hits
118
    */
119
   public void updateMetaDBHits(String query, long value);
120
   
121
   /**
122
    * Update the number of meta db misses of a specified query
123
    *
124
    * @param   query
125
    *          the query for which the update is done
126
    * @param   value
127
    *          the number of meta db misses
128
    */
129
   public void updateMetaDBMisses(String query, long value);
130
   
131
   /**
132
    * Update the number of temp db hits of a specified query
133
    *
134
    * @param   query
135
    *          the query for which the update is done
136
    * @param   value
137
    *          the number of temp db hits
138
    */
139
   public void updateTempDBHits(String query, long value);
140
   
141
   /**
142
    * Update the number of temp db misses of a specified query
143
    *
144
    * @param   query
145
    *          the query for which the update is done
146
    * @param   value
147
    *          the number of temp db misses
148
    */
149
   public void updateTempDBMisses(String query, long value);
150
   
151
   /**
152
    * Update the number of dirty db hits of a specified query
153
    *
154
    * @param   query
155
    *          the query for which the update is done
156
    * @param   value
157
    *          the number of dirty db hits
158
    */
159
   public void updateDirtyDBHits(String query, long value);
160
   
161
   /**
162
    * Update the number of dirty db misses of a specified query
163
    *
164
    * @param   query
165
    *          the query for which the update is done
166
    * @param   value
167
    *          the number of dirty db misses
168
    */
169
   public void updateDirtyDBMisses(String query, long value);
170
   
171
   /**
172
    * Update the number of persistent db hits of a specified query
173
    *
174
    * @param   query
175
    *          the query for which the update is done
176
    * @param   value
177
    *          the number of persistent db hits
178
    */
179
   public void updatePersistentDBHits(String query, long value);
180
   
181
   /**
182
    * Update the number of persistent db misses of a specified query
183
    *
184
    * @param   query
185
    *          the query for which the update is done
186
    * @param   value
187
    *          the number of persistent db misses
188
    */
189
   public void updatePersistentDBMisses(String query, long value);
190
   
191
   /**
112 192
    * Return the string representation of the counter
113 193
    * 
114 194
    * @param  ts
new/src/com/goldencode/p2j/jmx/QueryProfilerJMX.java 2023-04-24 12:22:19 +0000
87 87
   
88 88
   /** Publisher for the total time spent in hydrate */
89 89
   protected final ObjLongConsumer<String> publishHydrateTotalTime;
90
   
91
   /** Publisher for the number of meta db hits */
92
   protected final ObjLongConsumer<String> publishMetaDBHits;
93
   
94
   /** Publisher for the number of temp db hits */
95
   protected final ObjLongConsumer<String> publishTempDBHits;
96
   
97
   /** Publisher for the number of dirty db hits */
98
   protected final ObjLongConsumer<String> publishDirtyDBHits;
99
   
100
   /** Publisher for the number of persistent db hits */
101
   protected final ObjLongConsumer<String> publishPersistentDBHits;
90 102

  
91 103
   /**
92 104
    * Create and register instance
......
101 113
      QueryProfilerJMX simple = new QueryProfilerJMX(profiler::updateRowsCount, 
102 114
               profiler::updateCacheHits, 
103 115
               profiler::updateCacheMisses,
104
               profiler::updateHydrateTotalTime);
116
               profiler::updateHydrateTotalTime,
117
               profiler::updateMetaDBHits,
118
               profiler::updateTempDBHits,
119
               profiler::updateDirtyDBHits,
120
               profiler::updatePersistentDBHits);
105 121
       simple.setEnabler(simple::setEnabled); //prevent GC
106 122
       profiler.register(simple.getEnabler());
107 123
       return simple;
......
122 138
   protected QueryProfilerJMX(ObjLongConsumer<String> publishRowsCount, 
123 139
                              ObjLongConsumer<String> publishCacheHits, 
124 140
                              ObjLongConsumer<String> publishCacheMisses, 
125
                              ObjLongConsumer<String> publishHydrateTotalTime)
141
                              ObjLongConsumer<String> publishHydrateTotalTime,
142
                              ObjLongConsumer<String> publishMetaDBHits,
143
                              ObjLongConsumer<String> publishTempDBHits,
144
                              ObjLongConsumer<String> publishDirtyDBHits,
145
                              ObjLongConsumer<String> publishPersistentDBHits)
126 146
   {
127 147
      this.publishRowsCount = publishRowsCount;
128 148
      this.publishCacheHits = publishCacheHits;
129 149
      this.publishCacheMisses = publishCacheMisses;
130 150
      this.publishHydrateTotalTime = publishHydrateTotalTime;
151
      this.publishMetaDBHits = publishMetaDBHits;
152
      this.publishTempDBHits = publishTempDBHits;
153
      this.publishDirtyDBHits = publishDirtyDBHits;
154
      this.publishPersistentDBHits = publishPersistentDBHits;
131 155
   }
132 156
   
133 157
   /**
......
273 297
         }
274 298
      }
275 299
   }
300
   
301
   /**
302
    * Update the number of meta db hits of a specified query
303
    *
304
    * @param query
305
    *        the query for which the update is done
306
    * @param value
307
    *        the number of meta db hits
308
    */
309
   public void updateMetaDBHits(String query, long value)
310
   {
311
      if (enabled)
312
      {
313
         publishMetaDBHits.accept(query, value);
314
      }
315
   }
316
   
317
   /**
318
    * Update the number of temp db hits of a specified query
319
    *
320
    * @param query
321
    *        the query for which the update is done
322
    * @param value
323
    *        the number of temp db hits
324
    */
325
   public void updateTempDBHits(String query, long value)
326
   {
327
      if (enabled)
328
      {
329
         publishTempDBHits.accept(query, value);
330
      }
331
   }
332
   
333
   /**
334
    * Update the number of dirty db hits of a specified query
335
    *
336
    * @param query
337
    *        the query for which the update is done
338
    * @param value
339
    *        the number of dirty db hits
340
    */
341
   public void updateDirtyDBHits(String query, long value)
342
   {
343
      if (enabled)
344
      {
345
         publishDirtyDBHits.accept(query, value);
346
      }
347
   }
348
   
349
   /**
350
    * Update the number of persistent db hits of a specified query
351
    *
352
    * @param query
353
    *        the query for which the update is done
354
    * @param value
355
    *        the number of persistent db hits
356
    */
357
   public void updatePersistentDBHits(String query, long value)
358
   {
359
      if (enabled)
360
      {
361
         publishPersistentDBHits.accept(query, value);
362
      }
363
   }
276 364
}
new/src/com/goldencode/p2j/jmx/SimpleQueryProfiler.java 2023-04-24 12:45:00 +0000
93 93
      /** Represent the number of cache misses done by each query */
94 94
      CACHE_MISSES,
95 95
      /** Represent the number nano-seconds spent to hydrate */
96
      HYDRATE_TOTAL_TIME
96
      HYDRATE_TOTAL_TIME,
97
      /** Represent the number of meta db hits done by each query */
98
      META_DB_HITS,
99
      /** Represent the number of meta db misses done by each query */
100
      META_DB_MISSES,
101
      /** Represent the number of temp db hits done by each query */
102
      TEMP_DB_HITS,
103
      /** Represent the number of temp db misses done by each query */
104
      TEMP_DB_MISSES,
105
      /** Represent the number of dirty db hits done by each query */
106
      DIRTY_DB_HITS,
107
      /** Represent the number of dirty db misses done by each query */
108
      DIRTY_DB_MISSES,
109
      /** Represent the number of persistent db hits done by each query */
110
      PERSISTENT_DB_HITS,
111
      /** Represent the number of persistent db misses done by each query */
112
      PERSISTENT_DB_MISSES
97 113
   }
98 114
   
99 115
   /**
......
156 172
             .computeIfAbsent(QueryInfo.HYDRATE_TOTAL_TIME.toString(), k -> new AtomicLong(0))
157 173
             .addAndGet(value);
158 174
   }
175
   
176
   /**
177
    * Update the number of meta db hits of a specified query
178
    *
179
    * @param   query
180
    *          the query for which the update is done
181
    * @param   value
182
    *          the number of meta db hits
183
    */
184
   public void updateMetaDBHits(String query, long value)
185
   {
186
      if (checkExistentQuery(query))
187
      {
188
         queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
189
                .computeIfAbsent(QueryInfo.META_DB_HITS.toString(), k -> new AtomicLong(0))
190
                .addAndGet(value);
191
         return;
192
      }
193
      updateMetaDBMisses(query, value);
194
   }
195
   
196
   /**
197
    * Update the number of meta db misses of a specified query
198
    *
199
    * @param   query
200
    *          the query for which the update is done
201
    * @param   value
202
    *          the number of meta db misses
203
    */
204
   public void updateMetaDBMisses(String query, long value)
205
   {
206
      queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
207
             .computeIfAbsent(QueryInfo.META_DB_MISSES.toString(), k -> new AtomicLong(0))
208
             .addAndGet(value);
209
   }
210
   
211
   /**
212
    * Update the number of temp db hits of a specified query
213
    *
214
    * @param   query
215
    *          the query for which the update is done
216
    * @param   value
217
    *          the number of temp db hits
218
    */
219
   public void updateTempDBHits(String query, long value)
220
   {
221
      if (checkExistentQuery(query))
222
      {
223
         queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
224
                .computeIfAbsent(QueryInfo.TEMP_DB_HITS.toString(), k -> new AtomicLong(0))
225
                .addAndGet(value);
226
         return;
227
      }
228
      updateTempDBMisses(query, value);
229
   }
230
   
231
   /**
232
    * Update the number of temp db misses of a specified query
233
    *
234
    * @param   query
235
    *          the query for which the update is done
236
    * @param   value
237
    *          the number of temp db misses
238
    */
239
   public void updateTempDBMisses(String query, long value)
240
   {
241
      queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
242
             .computeIfAbsent(QueryInfo.TEMP_DB_MISSES.toString(), k -> new AtomicLong(0))
243
             .addAndGet(value);
244
   }
245
   
246
   /**
247
    * Update the number of dirty db hits of a specified query
248
    *
249
    * @param   query
250
    *          the query for which the update is done
251
    * @param   value
252
    *          the number of dirty db hits
253
    */
254
   public void updateDirtyDBHits(String query, long value)
255
   {
256
      if (checkExistentQuery(query))
257
      {
258
         queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
259
                .computeIfAbsent(QueryInfo.DIRTY_DB_HITS.toString(), k -> new AtomicLong(0))
260
                .addAndGet(value);
261
         return;
262
      }
263
      updateDirtyDBMisses(query, value);
264
   }
265
   
266
   /**
267
    * Update the number of dirty db misses of a specified query
268
    *
269
    * @param   query
270
    *          the query for which the update is done
271
    * @param   value
272
    *          the number of dirty db misses
273
    */
274
   public void updateDirtyDBMisses(String query, long value)
275
   {
276
      queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
277
             .computeIfAbsent(QueryInfo.DIRTY_DB_MISSES.toString(), k -> new AtomicLong(0))
278
             .addAndGet(value);
279
   }
280
   
281
   /**
282
    * Update the number of persistent db hits of a specified query
283
    *
284
    * @param   query
285
    *          the query for which the update is done
286
    * @param   value
287
    *          the number of persistent db hits
288
    */
289
   public void updatePersistentDBHits(String query, long value)
290
   {
291
      if (checkExistentQuery(query))
292
      {
293
         queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
294
                .computeIfAbsent(QueryInfo.PERSISTENT_DB_HITS.toString(), k -> new AtomicLong(0))
295
                .addAndGet(value);
296
         return;
297
      }
298
      updatePersistentDBMisses(query, value);
299
   }
300
   
301
   /**
302
    * Update the number of persistent db misses of a specified query
303
    *
304
    * @param   query
305
    *          the query for which the update is done
306
    * @param   value
307
    *          the number of persistent db misses
308
    */
309
   public void updatePersistentDBMisses(String query, long value)
310
   {
311
      queries.computeIfAbsent(query, k -> new ConcurrentHashMap<>())
312
             .computeIfAbsent(QueryInfo.PERSISTENT_DB_MISSES.toString(), k -> new AtomicLong(0))
313
             .addAndGet(value);
314
   }
315
   
316
   /**
317
    * Check if a query was already profiled.
318
    * 
319
    * @param   query
320
    *          the query that is checked
321
    *          
322
    * @return  {@code true} if the query was already profiled,
323
    *          {@code false} otherwise.
324
    */
325
   public boolean checkExistentQuery(String query)
326
   {
327
      return queries.containsKey(query);
328
   }
159 329

  
160 330
   /**
161 331
    * Retrieve the values accumulated for each query.
new/src/com/goldencode/p2j/persist/FQLPreprocessor.java 2023-04-24 12:45:36 +0000
360 360
import antlr.collections.*;
361 361
import com.goldencode.ast.*;
362 362
import com.goldencode.util.*;
363
import com.goldencode.p2j.jmx.*;
363 364
import com.goldencode.p2j.persist.dialect.*;
364 365
import com.goldencode.p2j.persist.hql.*;
365 366
import com.goldencode.p2j.persist.pl.*;
......
667 668
   /** Flag indicating that the query depends on mutable SESSION attribute(s). */
668 669
   private boolean dependsOnSessionAttribute = false;
669 670
   
671
   /** Profiler done for FQLs */
672
   private static final QueryProfilerJMX SIMPLE_FQL_PROFILER =
673
      QueryProfilerJMX.getInstance(FwdJMX.QueryProfiler.FQLProfiler);
674
   
670 675
   /**
671 676
    * Factory method which accepts an unprocessed where clause, the database
672 677
    * instance and the database dialect associated with the enclosing query,
......
1610 1615
         // Emit the preprocessed FQL expression text.
1611 1616
         this.fql = emit(root, false);
1612 1617
         
1618
         boolean found = false;
1619
         if (database.isMeta())
1620
         {
1621
            SIMPLE_FQL_PROFILER.updateMetaDBHits(this.fql.toString(), 1);
1622
            found = true;
1623
         }
1624
         
1625
         if (database.isDirty())
1626
         {
1627
            SIMPLE_FQL_PROFILER.updateDirtyDBHits(this.fql.toString(), 1);
1628
            found = true;
1629
         }
1630
         
1631
         if (database.equals(DatabaseManager.TEMP_TABLE_DB))
1632
         {
1633
            SIMPLE_FQL_PROFILER.updateTempDBHits(this.fql.toString(), 1);
1634
            found = true;
1635
         }
1636
         
1637
         if (!found)
1638
         {
1639
            SIMPLE_FQL_PROFILER.updatePersistentDBHits(this.fql.toString(), 1);
1640
         }
1641
         
1613 1642
         if (LOG.isLoggable(Level.FINEST))
1614 1643
         {
1615 1644
            String sep = System.getProperty("line.separator");