Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect indices retrieved from /proc/[PID]/statm #1188

Closed
donalm opened this issue Sep 13, 2022 · 0 comments
Closed

Incorrect indices retrieved from /proc/[PID]/statm #1188

donalm opened this issue Sep 13, 2022 · 0 comments

Comments

@donalm
Copy link
Contributor

donalm commented Sep 13, 2022

Note that _getStatFields returns a list with [None, None] as its first two values:

def _getStatFields(self, pidFilePath):
with open(pidFilePath, "r") as statFile:
return [None, None] + statFile.read().rsplit(")", 1)[-1].split()

So the following lines are running a regex against None, which results in a TypeError:

child_statm_fields = self._getStatFields(
rqd.rqconstants.PATH_PROC_PID_STATM.format(pid))
pids[pid]['statm_size'] = \
int(re.search(r"\d+", child_statm_fields[0]).group()) \
if re.search(r"\d+", child_statm_fields[0]) else -1
pids[pid]['statm_rss'] = \
int(re.search(r"\d+", child_statm_fields[1]).group()) \
if re.search(r"\d+", child_statm_fields[1]) else -1

Reviewing the output of man proc suggests that we do want the first two values returned by the /proc/[PID]/statm file:

       /proc/[pid]/statm
              Provides information about memory usage, measured in pages.  The columns are:

                  size       (1) total program size
                             (same as VmSize in /proc/[pid]/status)
                  resident   (2) resident set size
                             (same as VmRSS in /proc/[pid]/status)
                  share      (3) shared pages (i.e., backed by a file)
                  text       (4) text (code)
                  lib        (5) library (unused in Linux 2.6)
                  data       (6) data + stack
                  dt         (7) dirty pages (unused in Linux 2.6)

So the correct indices should be 2 and 3:

                    child_statm_fields = self._getStatFields(
                        rqd.rqconstants.PATH_PROC_PID_STATM.format(pid))
                    pids[pid]['statm_size'] = \
                        int(re.search(r"\d+", child_statm_fields[2]).group()) \
                        if re.search(r"\d+", child_statm_fields[2]) else -1
                    pids[pid]['statm_rss'] = \
                        int(re.search(r"\d+", child_statm_fields[3]).group()) \
                        if re.search(r"\d+", child_statm_fields[3]) else -1

fao @DiegoTavares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants