Skip to content

Commit

Permalink
Add support for v1 cgroups
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday committed Oct 7, 2024
1 parent e9611dc commit 32070aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
46 changes: 25 additions & 21 deletions system/jlib/jdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ SystemProcessInfo SystemProcessInfo::operator - (const SystemProcessInfo & rhs)
result.numThreads = numThreads - rhs.numThreads;
result.numPeriods = numPeriods - rhs.numPeriods;
result.numThrottledPeriods = numThrottledPeriods - rhs.numThrottledPeriods;
result.timeThrottledUs = timeThrottledUs - rhs.timeThrottledUs;
result.timeThrottledNs = timeThrottledNs - rhs.timeThrottledNs;
return result;
}

Expand Down Expand Up @@ -1156,28 +1156,32 @@ bool SystemInfo::update(unsigned flags)
const char * cgroup = queryCGroup();
if (cgroup)
{
VStringBuffer filename("/sys/fs/cgroup/%s/cpu.stat", cgroup);
if (loadBinaryFile(contents, filename.str(), false))
auto processLine = [this](size_t len, const char * ln)
{
auto processLine = [this](size_t len, const char * ln)
switch (*ln)
{
switch (*ln)
{
case 'n':
if (strncmp(ln, "nr_periods ", 11) == 0)
numPeriods = strtod(ln+11, nullptr);
else if (strncmp(ln, "nr_throttled ", 13) == 0)
numThrottledPeriods = strtod(ln+13, nullptr);
break;
case 't':
if (strncmp(ln, "throttled_usec ", 15) == 0)
timeThrottledUs = strtod(ln+15, nullptr);
break;
}
};
case 'n':
if (strncmp(ln, "nr_periods ", 11) == 0)
numPeriods = strtod(ln+11, nullptr);
else if (strncmp(ln, "nr_throttled ", 13) == 0)
numThrottledPeriods = strtod(ln+13, nullptr);
break;
case 't':
if (strncmp(ln, "throttled_usec ", 15) == 0)
timeThrottledNs = strtod(ln+15, nullptr) * 1000;
else if (strncmp(ln, "throttled_time ", 15) == 0)
timeThrottledNs = strtod(ln+15, nullptr);
break;
}
};

//Version 2 of cgroups has the information in cgroup/<cgroup>
VStringBuffer filename("/sys/fs/cgroup/%s/cpu.stat", cgroup);
if (loadBinaryFile(contents, filename.str(), false))
processLines(contents, processLine);
//Version 1 has the information in cgroup/cpu
else if (loadBinaryFile(contents, "/sys/fs/cgroup/cpu/cpu.stat", false))
processLines(contents, processLine);
}
}

return true;
Expand Down Expand Up @@ -2584,8 +2588,8 @@ class CExtendedStats // Disk network and cpu stats
if (periods)
{
unsigned throttling = deltacpu.getNumThrottledPeriods() * 100 / periods;
__uint64 timeThrottledUs = deltacpu.getTimeThrottledUs();
out.appendf(" thr=%u%% thrus=%llu", throttling, timeThrottledUs);
__uint64 timeThrottledNs = deltacpu.getTimeThrottledNs();
out.appendf(" thr=%u%% thrns=%llu", throttling, timeThrottledNs);
}
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions system/jlib/jdebug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class jlib_decl SystemProcessInfo

__uint64 getNumPeriods() const { return numPeriods; }
__uint64 getNumThrottledPeriods() const { return numThrottledPeriods; }
__uint64 getTimeThrottledUs() const { return timeThrottledUs; }
__uint64 getTimeThrottledNs() const { return timeThrottledNs; }

__uint64 getTotal() const { return user + system + idle + iowait; }
protected:
Expand All @@ -467,7 +467,7 @@ class jlib_decl SystemProcessInfo
__uint64 numThreads = 0;
__uint64 numPeriods = 0;
__uint64 numThrottledPeriods = 0;
__uint64 timeThrottledUs = 0;
__uint64 timeThrottledNs = 0;
};

class jlib_decl ProcessInfo : public SystemProcessInfo
Expand Down

0 comments on commit 32070aa

Please sign in to comment.