@@ -390,22 +390,35 @@ ZStatIterableValue<T>::ZStatIterableValue(const char* group,
390
390
391
391
template <typename T>
392
392
T* ZStatIterableValue<T>::insert() const {
393
- T** current = &_first;
393
+ T* const next = _first;
394
+ _first = (T*)this ;
395
+ return next;
396
+ }
394
397
395
- while (*current != NULL ) {
396
- // First sort by group, then by name
397
- const int group_cmp = strcmp ((*current)->group (), group ());
398
- const int name_cmp = strcmp ((*current)->name (), name ());
399
- if ((group_cmp > 0 ) || (group_cmp == 0 && name_cmp > 0 )) {
400
- break ;
401
- }
398
+ template <typename T>
399
+ void ZStatIterableValue<T>::sort() {
400
+ T* first_unsorted = _first;
401
+ _first = NULL ;
402
+
403
+ while (first_unsorted != NULL ) {
404
+ T* const value = first_unsorted;
405
+ first_unsorted = value->_next ;
406
+ value->_next = NULL ;
407
+
408
+ T** current = &_first;
409
+
410
+ while (*current != NULL ) {
411
+ // First sort by group, then by name
412
+ const int group_cmp = strcmp ((*current)->group (), value->group ());
413
+ if ((group_cmp > 0 ) || (group_cmp == 0 && strcmp ((*current)->name (), value->name ()) > 0 )) {
414
+ break ;
415
+ }
402
416
403
- current = &(*current)->_next ;
417
+ current = &(*current)->_next ;
418
+ }
419
+ value->_next = *current;
420
+ *current = value;
404
421
}
405
-
406
- T* const next = *current;
407
- *current = (T*)this ;
408
- return next;
409
422
}
410
423
411
424
//
@@ -882,6 +895,8 @@ void ZStat::run_service() {
882
895
ZStatSamplerHistory* const history = new ZStatSamplerHistory[ZStatSampler::count ()];
883
896
LogTarget (Info, gc, stats) log ;
884
897
898
+ ZStatSampler::sort ();
899
+
885
900
// Main loop
886
901
while (_metronome.wait_for_tick ()) {
887
902
sample_and_collect (history);
0 commit comments