Skip to content

Commit

Permalink
Self-adding GMT Overhead to the monitored cgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneTR committed Nov 28, 2024
1 parent 5303a1d commit f1d3af8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions metric_providers/cpu/utilization/cgroup/system/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ def __init__(self, resolution, skip_check=False, cgroups: dict = None):
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check = skip_check,
)
self._cgroups = cgroups
if cgroups:
self._cgroups = cgroups.copy() # because it is a frozen dict, we need to copy
else:
self._cgroups = {}

# we also find the cgroup that the GMT process belongs to. It will be a user session
current_pid = os.getpid()
with open(f"/proc/{current_pid}/cgroup", 'r', encoding='utf-8') as file:
lines = file.readlines()
if found_cgroups := len(lines) != 1:
raise RuntimeError(f"Could not find GMT\'s own cgroup or found too many. Amount: {found_cgroups}")
cgroup_name = lines[0].split('/')[-1].strip()
self._cgroups[cgroup_name] = 'GMT Overhead'

def start_profiling(self, containers=None):
# we hook here into the mechanism that can supply container names to the parent function
Expand All @@ -25,8 +37,8 @@ def read_metrics(self, run_id, containers=None):
return df

df['detail_name'] = df.container_id
for container_id in containers:
df.loc[df.detail_name == container_id, 'detail_name'] = containers[container_id]['name']
for container_id in self._cgroups:
df.loc[df.detail_name == container_id, 'detail_name'] = self._cgroups[container_id]
df = df.drop('container_id', axis=1)

return df

0 comments on commit f1d3af8

Please sign in to comment.