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

Replace int with string on thread monitor stat collection #310

Merged
merged 2 commits into from
Jun 28, 2022
Merged
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
17 changes: 11 additions & 6 deletions src/handlers/input_resources/ThreadMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ThreadMonitor
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#elif __APPLE__
#elif __linux__
static constexpr size_t PROC_STAT_POS_UTIME = 13;
static constexpr size_t PROC_STAT_POS_STIME = 14;
uint64_t _last_system_time = 0;
uint64_t _last_thread_time = 0;
#endif
Expand All @@ -46,17 +48,20 @@ class ThreadMonitor
}
system_total_time = system_total_time / sysconf(_SC_NPROCESSORS_ONLN);

std::vector<uint64_t> stats;
std::vector<std::string> stats;
std::ifstream thread_stat("/proc/thread-self/stat");
thread_stat.ignore(' ');
while (thread_stat >> stat) {
stats.push_back(stat);
std::string stat_str;
while (thread_stat >> stat_str) {
stats.push_back(stat_str);
if (stats.size() > PROC_STAT_POS_STIME)
leoparente marked this conversation as resolved.
Show resolved Hide resolved
break;
}
if(stats.size() < 10) {

if (stats.size() <= PROC_STAT_POS_STIME) {
return 0.0;
}

uint64_t thread_total_time = (stats[8] + stats[9]);
uint64_t thread_total_time = std::stoull(stats[PROC_STAT_POS_UTIME]) + std::stoull(stats[PROC_STAT_POS_STIME]);

uint64_t current_thread_time = thread_total_time - _last_thread_time;
_last_thread_time = thread_total_time;
Expand Down