@@ -72,6 +72,10 @@ class Rttest
7272 rttest_sample_buffer sample_buffer;
7373 struct rusage prev_usage;
7474
75+ // The iteration that the results were cleared at
76+ // Gets set when cleared_statistics() is called
77+ size_t cleared_iteration = 0 ;
78+
7579 pthread_t thread_id;
7680
7781 int record_jitter (
@@ -122,6 +126,8 @@ class Rttest
122126
123127 int calculate_statistics (struct rttest_results * results);
124128
129+ void clear_statistics ();
130+
125131 int get_sample_at (const size_t iteration, int64_t & sample) const ;
126132
127133 int write_results ();
@@ -754,23 +760,25 @@ int Rttest::calculate_statistics(struct rttest_results * output)
754760 return -1 ;
755761 }
756762
757- output->min_latency = *std::min_element (
758- this ->sample_buffer .latency_samples .begin (), this ->sample_buffer .latency_samples .end ());
759- output->max_latency = *std::max_element (
760- this ->sample_buffer .latency_samples .begin (), this ->sample_buffer .latency_samples .end ());
763+ std::vector<int64_t > latency_samples (
764+ this ->sample_buffer .latency_samples .begin () + this ->cleared_iteration + 1 ,
765+ this ->sample_buffer .latency_samples .end ());
766+
767+ output->min_latency = *std::min_element (latency_samples.begin (), latency_samples.end ());
768+ output->max_latency = *std::max_element (latency_samples.begin (), latency_samples.end ());
761769 output->mean_latency = std::accumulate (
762- this -> sample_buffer . latency_samples .begin (),
763- this -> sample_buffer . latency_samples .end (), 0.0 ) / this -> sample_buffer . latency_samples .size ();
770+ latency_samples.begin (),
771+ latency_samples.end (), 0.0 ) / latency_samples.size ();
764772
765773 // Calculate standard deviation and try to avoid overflow
766- output->latency_stddev = calculate_stddev (this -> sample_buffer . latency_samples );
774+ output->latency_stddev = calculate_stddev (latency_samples);
767775
768776 output->minor_pagefaults = std::accumulate (
769- this ->sample_buffer .minor_pagefaults .begin (),
777+ this ->sample_buffer .minor_pagefaults .begin () + this -> cleared_iteration + 1 ,
770778 this ->sample_buffer .minor_pagefaults .end (), 0 );
771779
772780 output->major_pagefaults = std::accumulate (
773- this ->sample_buffer .major_pagefaults .begin (),
781+ this ->sample_buffer .major_pagefaults .begin () + this -> cleared_iteration + 1 ,
774782 this ->sample_buffer .major_pagefaults .end (), 0 );
775783
776784 return 0 ;
@@ -785,6 +793,34 @@ int rttest_calculate_statistics(struct rttest_results * results)
785793 return thread_rttest_instance->calculate_statistics (results);
786794}
787795
796+ void Rttest::clear_statistics ()
797+ {
798+ size_t i;
799+ if (this ->params .iterations == 0 ) {
800+ i = 0 ;
801+ } else {
802+ i = this ->results .iteration ;
803+ }
804+ this ->cleared_iteration = i;
805+
806+ // Reset the properties of the current results
807+ this ->results .max_latency = this ->sample_buffer .latency_samples [i];
808+ this ->results .min_latency = this ->results .max_latency ;
809+ this ->results .mean_latency = this ->results .max_latency ;
810+ this ->results .minor_pagefaults = this ->sample_buffer .minor_pagefaults [i];
811+ this ->results .major_pagefaults = this ->sample_buffer .major_pagefaults [i];
812+ }
813+
814+ int rttest_clear_statistics ()
815+ {
816+ auto thread_rttest_instance = get_rttest_thread_instance (pthread_self ());
817+ if (!thread_rttest_instance) {
818+ return -1 ;
819+ }
820+ thread_rttest_instance->clear_statistics ();
821+ return 0 ;
822+ }
823+
788824int rttest_get_statistics (struct rttest_results * output)
789825{
790826 if (output == NULL ) {
0 commit comments