Skip to content

Commit

Permalink
Allow cmd abbreviation from ps
Browse files Browse the repository at this point in the history
This abbreviation happens at the kernel level, and ps surrounds it in
brackets to indicate that it has changed.
  • Loading branch information
asmacdo committed Sep 11, 2024
1 parent 5f60393 commit a8da083
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import math
import os
import re
import shutil
import socket
import subprocess
Expand Down Expand Up @@ -130,12 +131,17 @@ class ProcessStats:
cmd: str

def max(self, other: ProcessStats) -> ProcessStats:
cmd = self.cmd
if self.cmd != other.cmd:
lgr.critical("TEST!\n!!!!!!!!!\n!!!!!!!!\n!!!!!!!!!!\n!!!!!!!!!!!")
lgr.critical(f"self cmd:{self.cmd}")
lgr.critical(f"other cmd:{other.cmd}")
lgr.critical(f"self whole:{asdict(self)}")
lgr.critical(f"other whole:{asdict(other)}")
lgr.critical(

Check warning on line 136 in src/con_duct/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/con_duct/__main__.py#L136

Added line #L136 was not covered by tests
f"cmd has changed. Previous measurement was {self.cmd}, now {other.cmd}."
)
# Brackets indicate that the kernel has substituted an abbreviation.
surrounded_by_brackets = r"\[.*?\]"

Check warning on line 140 in src/con_duct/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/con_duct/__main__.py#L140

Added line #L140 was not covered by tests
if re.search(surrounded_by_brackets, self.cmd):
lgr.critical(f"using {other.cmd}.")
cmd = other.cmd
lgr.critical(f"using {self.cmd}.")
raise Exception()

Check warning on line 145 in src/con_duct/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/con_duct/__main__.py#L142-L145

Added lines #L142 - L145 were not covered by tests
return ProcessStats(
pcpu=max(self.pcpu, other.pcpu),
Expand All @@ -144,7 +150,7 @@ def max(self, other: ProcessStats) -> ProcessStats:
vsz=max(self.vsz, other.vsz),
timestamp=max(self.timestamp, other.timestamp),
etime=other.etime, # For the aggregate always take the latest
cmd=other.cmd,
cmd=cmd,
)

def __post_init__(self) -> None:
Expand Down Expand Up @@ -424,13 +430,9 @@ def collect_sample(self) -> Optional[Sample]:
)
for line in output.splitlines()[1:]:
if line:
pid, pcpu, pmem, rss_kib, vsz_kib, etime, stat, cmd = line.split(
maxsplit=7
pid, pcpu, pmem, rss_kib, vsz_kib, etime, cmd = line.split(
maxsplit=6,
)
if "Z" in stat: # Skip zombie processes
continue
if cmd.startswith("["):
cmd = cmd + stat
sample.add_pid(
int(pid),
ProcessStats(
Expand Down

0 comments on commit a8da083

Please sign in to comment.