Skip to content

Commit

Permalink
Add debug and info logging for cgroup parsing in ProcessInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
iritb committed Jan 2, 2025
1 parent d561908 commit 0f9da62
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ProcessInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ int ProcessInfo::read_and_parse_cgroup(int pid) {
char *ptr = data.data();
char *end = ptr + nr;

Logger::Debug("Read /proc/%d/cgroup: %.*s", pid, nr, data.data());

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'int' does not match the argument type 'long'.

const char *containerd_prefix = "/containerd-";
const size_t containerd_prefix_len = strlen(containerd_prefix);
const char *docker_prefix = "/docker/";
Expand All @@ -409,6 +411,8 @@ int ProcessInfo::read_and_parse_cgroup(int pid) {
line_end = end;
}

Logger::Info("Processing line: %.*s", static_cast<int>(line_end - ptr), ptr);

// Check for containerd format
char *containerd_pos = strstr(ptr, containerd_prefix);
if (containerd_pos != nullptr && containerd_pos < line_end) {
Expand All @@ -430,11 +434,14 @@ int ProcessInfo::read_and_parse_cgroup(int pid) {
if (system_docker_pos != nullptr && system_docker_pos < line_end) {
_container_id = std::string(system_docker_pos + system_docker_prefix_len, 12); // Extract the first 12 characters of the container ID
Logger::Info("Read Container id (3) from cgroup for /proc/%d/cgroup: %s", pid, _container_id);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'char *' does not match the argument type 'basic_string<char, char_traits, allocator>'.
Logger::Warn("Read Container id (3) from cgroup for /proc/%d/cgroup: %s", pid, _container_id);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'char *' does not match the argument type 'basic_string<char, char_traits, allocator>'.
return 0;
}

ptr = line_end + 1;
}

Logger::Warn("No container ID found in /proc/%d/cgroup", pid);

return 1;
}
Expand All @@ -460,6 +467,8 @@ bool ProcessInfo::read(int pid) {
return false;
}

Logger::Info("Read cgroup for %d", pid);
Logger::Warn("Read cgroup for %d", pid);
pret = read_and_parse_cgroup(pid);
if (pret != 0) {
if (pret > 0) {
Expand Down

0 comments on commit 0f9da62

Please sign in to comment.