@@ -390,22 +390,35 @@ ZStatIterableValue<T>::ZStatIterableValue(const char* group,
390390
391391template <typename T>
392392T* ZStatIterableValue<T>::insert() const {
393- T** current = &_first;
393+ T* const next = _first;
394+ _first = (T*)this ;
395+ return next;
396+ }
394397
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+ }
402416
403- current = &(*current)->_next ;
417+ current = &(*current)->_next ;
418+ }
419+ value->_next = *current;
420+ *current = value;
404421 }
405-
406- T* const next = *current;
407- *current = (T*)this ;
408- return next;
409422}
410423
411424//
@@ -882,6 +895,8 @@ void ZStat::run_service() {
882895 ZStatSamplerHistory* const history = new ZStatSamplerHistory[ZStatSampler::count ()];
883896 LogTarget (Info, gc, stats) log;
884897
898+ ZStatSampler::sort ();
899+
885900 // Main loop
886901 while (_metronome.wait_for_tick ()) {
887902 sample_and_collect (history);
0 commit comments