intel / intel/gprofiler

--log-usage support in exe mode

Open
#227 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
826
Forks
79
PR merge metrics
No merged PRs in 30d

Description

`--log-usage` lets us track the CPU & memory usage of gProfiler. It does so by reading cgroups files for the cgroup gProfiler runs in. See https://github.com/Granulate/gprofiler/blob/89fcf8e271706029bedd486b2b35727e92058086/gprofiler/usage_loggers.py for how it's currently done.

This works in containers, as we can just use the cgroup files of the container.
In "executable" mode, however, we don't run in separate cgroups, so measuring the existing cgroups will not yield the correct result.

If we move ourselves into a child cgroup of the current one, we can then track that new one.

Note: we sometimes run in semi-containers, such as Databricks / Dataflow / Fargate, where we're an executable but we're on low privileges so I don't know if we can create new cgroups. We need to handle this case as well (that is, do not fail hard if we fail to move cgroups)

Resources:
* [cgroups memory controller](https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt) and specifically `usage_in_bytes`.
* [cgroups cpuacct controller](https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt)
* Moving cgroups - new process in cgrouup with [cgexec](https://linux.die.net/man/1/cgexec)
* Moving cgroups - [existing process in cgroup](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-moving_a_process_to_a_control_group) - this is probably what we should use; not `cgclassify` but "manually" writing our PID to the `tasks` file of a new cgroup.
* [Creating cgroups](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-creating_cgroups)

Cgroups are per-thread actually. So we should move our thread to a new cgroup as early as possible (before other threads/processes are spawned), and make sure it's really the only thread in the process once we do so.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.