-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to clear statistics #118
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,10 @@ class Rttest | |
rttest_sample_buffer sample_buffer; | ||
struct rusage prev_usage; | ||
|
||
// The iteration that the results were cleared at | ||
// Gets set when cleared_statistics() is called | ||
size_t cleared_iteration = 0; | ||
|
||
pthread_t thread_id; | ||
|
||
int record_jitter( | ||
|
@@ -122,6 +126,8 @@ class Rttest | |
|
||
int calculate_statistics(struct rttest_results * results); | ||
|
||
void clear_statistics(); | ||
|
||
int get_sample_at(const size_t iteration, int64_t & sample) const; | ||
|
||
int write_results(); | ||
|
@@ -754,23 +760,25 @@ int Rttest::calculate_statistics(struct rttest_results * output) | |
return -1; | ||
} | ||
|
||
output->min_latency = *std::min_element( | ||
this->sample_buffer.latency_samples.begin(), this->sample_buffer.latency_samples.end()); | ||
output->max_latency = *std::max_element( | ||
this->sample_buffer.latency_samples.begin(), this->sample_buffer.latency_samples.end()); | ||
std::vector<int64_t> latency_samples( | ||
this->sample_buffer.latency_samples.begin() + this->cleared_iteration + 1, | ||
this->sample_buffer.latency_samples.end()); | ||
|
||
output->min_latency = *std::min_element(latency_samples.begin(), latency_samples.end()); | ||
output->max_latency = *std::max_element(latency_samples.begin(), latency_samples.end()); | ||
output->mean_latency = std::accumulate( | ||
this->sample_buffer.latency_samples.begin(), | ||
this->sample_buffer.latency_samples.end(), 0.0) / this->sample_buffer.latency_samples.size(); | ||
latency_samples.begin(), | ||
latency_samples.end(), 0.0) / latency_samples.size(); | ||
|
||
// Calculate standard deviation and try to avoid overflow | ||
output->latency_stddev = calculate_stddev(this->sample_buffer.latency_samples); | ||
output->latency_stddev = calculate_stddev(latency_samples); | ||
|
||
output->minor_pagefaults = std::accumulate( | ||
this->sample_buffer.minor_pagefaults.begin(), | ||
this->sample_buffer.minor_pagefaults.begin() + this->cleared_iteration + 1, | ||
this->sample_buffer.minor_pagefaults.end(), 0); | ||
|
||
output->major_pagefaults = std::accumulate( | ||
this->sample_buffer.major_pagefaults.begin(), | ||
this->sample_buffer.major_pagefaults.begin() + this->cleared_iteration + 1, | ||
this->sample_buffer.major_pagefaults.end(), 0); | ||
|
||
return 0; | ||
|
@@ -785,6 +793,34 @@ int rttest_calculate_statistics(struct rttest_results * results) | |
return thread_rttest_instance->calculate_statistics(results); | ||
} | ||
|
||
void Rttest::clear_statistics() | ||
{ | ||
size_t i; | ||
if (this->params.iterations == 0) { | ||
i = 0; | ||
} else { | ||
i = this->results.iteration; | ||
} | ||
this->cleared_iteration = i; | ||
|
||
// Reset the properties of the current results | ||
this->results.max_latency = this->sample_buffer.latency_samples[i]; | ||
this->results.min_latency = this->results.max_latency; | ||
this->results.mean_latency = this->results.max_latency; | ||
this->results.minor_pagefaults = this->sample_buffer.minor_pagefaults[i]; | ||
this->results.major_pagefaults = this->sample_buffer.major_pagefaults[i]; | ||
Comment on lines
+806
to
+811
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be wrong in my understanding here, but this isn't really "clearing" the results. What it is doing is setting a marker at the current set of samples, and then we'll only consider samples from this point forward. If my understanding is correct, then I think we should rename this function to reflect that usage more. Maybe "mark_statistics" or something like that? |
||
} | ||
|
||
int rttest_clear_statistics() | ||
{ | ||
auto thread_rttest_instance = get_rttest_thread_instance(pthread_self()); | ||
if (!thread_rttest_instance) { | ||
return -1; | ||
} | ||
thread_rttest_instance->clear_statistics(); | ||
return 0; | ||
} | ||
|
||
int rttest_get_statistics(struct rttest_results * output) | ||
{ | ||
if (output == NULL) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding 1 here? Won't that always skip a sample somewhere along the way?