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

[v18.x] src: initialize prev_idle_time_ on ThreadMetrics #157

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
3 changes: 3 additions & 0 deletions src/nsolid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ ThreadMetrics::ThreadMetrics(SharedEnvInst envinst)
stor_.thread_id = thread_id_;
stor_.prev_call_time_ = uv_hrtime();
stor_.current_hrtime_ = stor_.prev_call_time_;
stor_.prev_idle_time_ = uv_metrics_idle_time(envinst->event_loop());
}


Expand All @@ -300,6 +301,8 @@ ThreadMetrics::ThreadMetrics(uint64_t thread_id)
stor_.thread_id = thread_id_;
stor_.prev_call_time_ = uv_hrtime();
stor_.current_hrtime_ = stor_.prev_call_time_;
// Letting prev_idle_time_ be 0 is ok as this is only used by the EnvInst
// constructor.
}


Expand Down
1 change: 1 addition & 0 deletions test/addons/nsolid-env-metrics/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Metrics {

static void got_env_metrics(SharedThreadMetrics tm_sp, Metrics* m) {
assert(tm_sp == m->tm);
assert(tm_sp->Get().loop_utilization <= 1);
cb_cntr++;
delete m;
}
Expand Down
6 changes: 5 additions & 1 deletion test/addons/nsolid-env-metrics/nsolid-env-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ for (let i = 0; i < 10; i++) {
}));
}

binding.getMetrics();
// Let then main thread be a bit idle so we can check that loop_utilization is
// correctly calculdate.
setTimeout(() => {
binding.getMetrics();
}, 100);
Loading