Skip to content
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

Update the resource-utilization calc: average over the last N ms #127

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions performance_metrics/src/resource_usage_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ void ResourceUsageLogger::start(std::chrono::milliseconds period)
std::cout << "[ResourceUsageLogger]: Logging to " << m_filename << std::endl;

m_t1_real_start = std::chrono::steady_clock::now();
m_t1_user = std::clock();
m_t1_real = std::chrono::steady_clock::now();
m_logger_thread_done = false;

// create a detached thread that monitors resource usage periodically
m_logger_thread = std::thread(
[ = ]() {
int64_t i = 1;
while (m_is_logging) {
// Updating m_t1_user and m_t1_real here will have the effect of calculating
// resource utilization only over the last `period` milliseconds, *not*
// since program start.
m_t1_user = std::clock();
m_t1_real = std::chrono::steady_clock::now();
Copy link
Contributor Author

@jfinken jfinken Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauropasse

Ok note here how both of these members are updated right before sleep_until. Now the denominator, time_elapsed_real_ms, should reflect the period duration here.

Note that I don't think you can compare the actual value from top to what you see in the resources.txt file. As I understand it, top expresses %CPU as a percentage of total CPU time. However, here we are expressing our cpu% as the approximate CPU time used by our process over monotonic wall-clock time. e.g.

// cpu time of our process   /  monotonic wall clock time, using these
std::clock()                 / std::chrono::steady_clock::now();

I think top and our calculation are somewhat different, but I could certainly be wrong.

Copy link
Collaborator

@mauropasse mauropasse Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right, top and our calculation are a bit different. If you multiply the CPU% we get in our way, by the number of cores of your system, the values are quite similar.
I mostly refered to the top approach of averaging every 1 or 2 seconds, so it doesn't reflect the past before that.
For that, the CPU load is what helps. I don't think we care about that so our approach is fine!

std::this_thread::sleep_until(m_t1_real_start + period * i);
if (i == 1) {
_print_header(m_file);
Expand Down
2 changes: 1 addition & 1 deletion performance_test_factory/src/cli_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Options::Options()
name_threads = true;
duration_sec = 5;
csv_out = false;
resources_sampling_per_ms = 500;
resources_sampling_per_ms = 1000;
tracking_options.is_enabled = false;
tracking_options.late_percentage = 20;
tracking_options.late_absolute_us = 5000;
Expand Down
Loading