Skip to content

Commit

Permalink
Merge pull request #179 from asmacdo/bf-fix-sample-totals-math
Browse files Browse the repository at this point in the history
Fix operator precedence involving or and addition
  • Loading branch information
yarikoptic authored Sep 13, 2024
2 parents 9c449fa + ba3c2cf commit 2b12679
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ class Sample:
timestamp: str = "" # TS of last sample collected

def add_pid(self, pid: int, stats: ProcessStats) -> None:
self.total_rss = self.total_rss or 0 + stats.rss
self.total_vsz = self.total_vsz or 0 + stats.vsz
self.total_pmem = self.total_pmem or 0.0 + stats.pmem
self.total_pcpu = self.total_pcpu or 0.0 + stats.pcpu
self.total_rss = (self.total_rss or 0) + stats.rss
self.total_vsz = (self.total_vsz or 0) + stats.vsz
self.total_pmem = (self.total_pmem or 0.0) + stats.pmem
self.total_pcpu = (self.total_pcpu or 0.0) + stats.pcpu
self.stats[pid] = stats
self.timestamp = max(self.timestamp, stats.timestamp)

Expand Down
20 changes: 20 additions & 0 deletions test/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
cmd="cmd 1",
)

stat2 = ProcessStats(
pcpu=1.1,
pmem=1.1,
rss=11,
vsz=11,
timestamp="2024-06-11T10:13:23-04:00",
etime="00:02",
cmd="cmd 1",
)


def test_sample_max_initial_values_one_pid() -> None:
maxes = Sample()
Expand Down Expand Up @@ -113,6 +123,16 @@ def test_averages_three_samples() -> None:
assert averages.pcpu == (stat0.pcpu + (2 * stat1.pcpu)) / 3


def test_sample_totals() -> None:
sample = Sample()
sample.add_pid(1, stat2)
sample.add_pid(2, stat2)
assert sample.total_rss == stat2.rss * 2
assert sample.total_vsz == stat2.vsz * 2
assert sample.total_pmem == stat2.pmem * 2
assert sample.total_pcpu == stat2.pcpu * 2


@pytest.mark.parametrize(
"pcpu, pmem, rss, vsz, etime, cmd",
[
Expand Down

0 comments on commit 2b12679

Please sign in to comment.