Skip to content

Commit

Permalink
refactor add proc function
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavDhulipala committed Aug 18, 2024
1 parent 369384e commit b236431
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions wrappers/proctrac.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ def from_proc(cls, jobid: int, proc: psutil.Popen) -> "TraceInfo":
job_id=jobid,
)

def merge(self, trace_info: "TraceInfo"):
self.cpus += trace_info.cpus
self.threads += trace_info.threads
self.mem += trace_info.mem
self.read_bytes += trace_info.read_bytes
self.write_bytes += trace_info.write_bytes
def add_subproc(self, proc: psutil.Popen):
io_counters = proc.io_counters()
self.cpus += proc.cpu_percent(0.1)
self.threads += proc.num_threads()
self.mem += proc.memory_info().rss
self.read_bytes += io_counters.read_bytes
self.write_bytes += io_counters.write_bytes


class ProcWrapper:
Expand All @@ -73,8 +74,7 @@ def poll_info(self) -> Generator[TraceInfo, None, None]:
start = datetime.now()
for p in self.proc.children(True):
try:
child_trace = TraceInfo.from_proc(self.jobid, p)
trace.merge(child_trace)
trace.add_subproc(p)
except psutil.Error as e:
print(f"failed to poll child process with error {e}")
continue
Expand Down

0 comments on commit b236431

Please sign in to comment.