Skip to content

Commit b3a0668

Browse files
author
GK
authored
Cgroup V2 statistic engine improvements (#68)
* In the statistics engine: for cgroup v2 use sum of 'file' and 'anon' for memory utilization stats
1 parent 8cfd509 commit b3a0668

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Then run:
219219

220220
```
221221
# install compiler tools & library dependencies with YUM:
222-
sudo dnf install -y gcc-c++ make gtest-devel fmt-devel google-benchmark-devel
222+
sudo dnf install -y gcc-c++ make gtest-devel fmt-devel benchmark-dev
223223
224224
# install dependencies with Conan:
225225
# (this part can be skipped if you are not interested in Prometheus support)

tools/common-code/cmonitor_statistics_engine.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import gzip
1515
from statistics import mean, median, mode, StatisticsError
1616

17+
1718
# =======================================================================================================
1819
# Helper classes
1920
# =======================================================================================================
@@ -102,16 +103,27 @@ def dump_cpu_stats(self, verbose) -> dict:
102103
def dump_cpu_throttle_stats(self, verbose) -> dict:
103104
return self.cpu_throttle.dump_json(verbose)
104105

105-
def insert_memory_stats(self, stats: dict, sample_index: int) -> None:
106-
if "stat.rss" in stats:
107-
self.memory.insert_stat(stats["stat.rss"])
108-
else:
109-
print(f"WARNING: The JSON file provided does not contain the 'stat.rss' measurement for sample #{sample_index}. Skipping this sample.")
110-
if "events.failcnt" in stats:
111-
self.memory_failcnt.insert_stat(stats["events.failcnt"])
106+
def insert_memory_stats(self, stats: dict, sample_index: int, cgroup_version: int) -> None:
107+
stat_labels = ["stat.rss"] if cgroup_version == 1 else ["stat.anon", "stat.file"]
108+
rss = 0
109+
all_stat_found = True
110+
for stat_label in stat_labels:
111+
if stat_label in stats:
112+
rss += stats[stat_label]
113+
else:
114+
print(
115+
f"WARNING: The JSON file provided does not contain the '{stat_label}' measurement for sample #{sample_index}. Skipping this sample."
116+
)
117+
all_stat_found = False
118+
if all_stat_found:
119+
self.memory.insert_stat(rss)
120+
121+
stat_label = "events.failcnt" if cgroup_version == 1 else "events.oom_kill"
122+
if stat_label in stats:
123+
self.memory_failcnt.insert_stat(stats[stat_label])
112124
else:
113125
print(
114-
f"WARNING: The JSON file provided does not contain the 'events.failcnt' measurement for sample #{sample_index}. Skipping this sample."
126+
f"WARNING: The JSON file provided does not contain the '{stat_label}' measurement for sample #{sample_index}. Skipping this sample."
115127
)
116128

117129
def dump_memory_stats(self, verbose) -> dict:
@@ -152,6 +164,13 @@ def process(self, json_data) -> bool:
152164
print("This tool requires at least 3 samples in the input JSON file. Aborting.")
153165
return False
154166

167+
cgroup_version = 1
168+
jheader = json_data["header"]
169+
if "cgroup_config" in jheader and "version" in jheader["cgroup_config"]:
170+
cgroup_version = int(jheader["cgroup_config"]["version"])
171+
else:
172+
print(f"WARNING: cgroup version not found in header using default value {cgroup_version}")
173+
155174
# skip sample 0 because it contains less statistics due to the differential logic that requires some
156175
# initialization sample for most of the stats
157176
first_sample = json_data["samples"][1]
@@ -183,7 +202,7 @@ def process(self, json_data) -> bool:
183202
if do_cpu_stats:
184203
self.cgroup_statistics.insert_cpu_stats(sample["cgroup_cpuacct_stats"], nsample)
185204
if do_memory_stats:
186-
self.cgroup_statistics.insert_memory_stats(sample["cgroup_memory_stats"], nsample)
205+
self.cgroup_statistics.insert_memory_stats(sample["cgroup_memory_stats"], nsample, cgroup_version)
187206

188207
self.num_samples_analyzed = len(samples_to_analyze)
189208
# self.cgroup_statistics.insert_io_stats(stats) # cgroup_blkio not yet available

0 commit comments

Comments
 (0)