Skip to content

Commit

Permalink
Merge branch 'fix-procstat-token-count' into 'master'
Browse files Browse the repository at this point in the history
Account for tasks exiting while reading statistics

See merge request 774_03/becommon/libbiomeval!19
  • Loading branch information
Wayne Salamon committed May 21, 2024
2 parents 0a0db61 + 893a16d commit 94378d1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/libbiomeval/be_process_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ internalGetTasksStats(pid_t pid)
* Iterate through all /proc/<pid>/task/<tid>/stat files.
*/
float ticksPerSec = (float)sysconf(_SC_CLK_TCK);
if (ticksPerSec == -1) {
if (ticksPerSec <= 0) {
throw BE::Error::StrategyError(
"Could not obtain system clock-ticks/sec value");
}
Expand All @@ -255,16 +255,21 @@ internalGetTasksStats(pid_t pid)
throw BE::Error::StrategyError(
"Could not open " + tstatPath + ".");
}

std::string line{};
if (!std::getline(ifs, line)) {
/* Task likely exited while reading */
continue;
}
/*
* Tokenize the line using the space character.
* ID is first field, user time is the 14th field,
* system time is the 15th field.
*/
std::vector<std::string> tokens{};
std::string token{};
while (std::getline(ifs, token, ' ')) {
tokens.push_back(token);
}
const auto tokens = BE::Text::split(line, ' ', false);
if (tokens.size() < 15)
continue;

/*
* Add the stats for this task to the set of stats.
*/
Expand Down

0 comments on commit 94378d1

Please sign in to comment.