-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dedicated types for process stats *et alii*
- Loading branch information
Showing
2 changed files
with
132 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
from __future__ import annotations | ||
from collections import defaultdict | ||
from duct import Report | ||
|
||
ex0 = {"pid1": {"pcpu": 0.0}} | ||
ex1 = {"pid1": {"pcpu": 1.0}} | ||
ex2 = {"pid2": {"pcpu": 1.0}} | ||
ex2pids = {"pid1": {"pcpu": 0.0}, "pid2": {"pcpu": 0.0}} | ||
|
||
|
||
def test_update_max_resources_initial_values_one_pid() -> None: | ||
maxes: dict[str, dict[str, float]] = defaultdict(dict) | ||
Report.update_max_resources(maxes, ex0) | ||
assert maxes == ex0 | ||
|
||
|
||
def test_update_max_resources_max_values_one_pid() -> None: | ||
maxes: dict[str, dict[str, float]] = defaultdict(dict) | ||
Report.update_max_resources(maxes, ex0) | ||
Report.update_max_resources(maxes, ex1) | ||
assert maxes == ex1 | ||
|
||
|
||
def test_update_max_resources_initial_values_two_pids() -> None: | ||
maxes: dict[str, dict[str, float]] = defaultdict(dict) | ||
Report.update_max_resources(maxes, ex2pids) | ||
assert maxes == ex2pids | ||
|
||
|
||
def test_update_max_resources_max_update_values_two_pids() -> None: | ||
maxes: dict[str, dict[str, float]] = defaultdict(dict) | ||
Report.update_max_resources(maxes, ex2pids) | ||
Report.update_max_resources(maxes, ex1) | ||
Report.update_max_resources(maxes, ex2) | ||
assert maxes.keys() == ex2pids.keys() | ||
assert maxes != ex2pids | ||
assert maxes["pid1"] == ex1["pid1"] | ||
assert maxes["pid2"] == ex2["pid2"] | ||
from duct import ProcessStats, Sample | ||
|
||
stat0 = ProcessStats( | ||
pcpu=0.0, pmem=0, rss=0, vsz=0, timestamp="2024-06-11T10:09:37-04:00" | ||
) | ||
|
||
stat1 = ProcessStats( | ||
pcpu=1.0, pmem=0, rss=0, vsz=0, timestamp="2024-06-11T10:13:23-04:00" | ||
) | ||
|
||
|
||
def test_sample_max_initial_values_one_pid() -> None: | ||
maxes = Sample() | ||
ex0 = Sample() | ||
ex0.add(1, stat0) | ||
maxes = maxes.max(ex0) | ||
assert maxes.stats == {1: stat0} | ||
|
||
|
||
def test_sample_max_one_pid() -> None: | ||
maxes = Sample() | ||
maxes.add(1, stat0) | ||
ex1 = Sample() | ||
ex1.add(1, stat1) | ||
maxes = maxes.max(ex1) | ||
assert maxes.stats == {1: stat1} | ||
|
||
|
||
def test_sample_max_initial_values_two_pids() -> None: | ||
maxes = Sample() | ||
ex0 = Sample() | ||
ex0.add(1, stat0) | ||
ex0.add(2, stat0) | ||
maxes = maxes.max(ex0) | ||
assert maxes.stats == {1: stat0, 2: stat0} | ||
|
||
|
||
def test_sample_maxtwo_pids() -> None: | ||
maxes = Sample() | ||
maxes.add(1, stat0) | ||
maxes.add(2, stat0) | ||
ex1 = Sample() | ||
ex1.add(1, stat1) | ||
maxes = maxes.max(ex1) | ||
ex2 = Sample() | ||
ex2.add(2, stat1) | ||
maxes = maxes.max(ex2) | ||
assert maxes.stats == {1: stat1, 2: stat1} |