Skip to content

Commit

Permalink
Fix undefined value issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxuan-ms committed Apr 9, 2024
1 parent 7326c11 commit 4f6af21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 21 additions & 1 deletion testplan/monitor/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

@dataclasses.dataclass
class ResourceData:
"""
Attributes of collecting resource data
"""

cpu_usage: float
memory_used: int
iops: float
Expand All @@ -34,17 +38,29 @@ class ResourceData:

@dataclasses.dataclass
class HostResourceData(ResourceData):
"""
Host level resource data
"""

disk_used: int


@dataclasses.dataclass
class ProcessResourceData(ResourceData):
"""
Process level resource data
"""

name: str
cmdline: str
pid: int


class HostResourceRow(NamedTuple):
"""
CSV file row structure of host level resource
"""

timestamp: float
cpu_usage: float
memory_used: int
Expand All @@ -55,6 +71,10 @@ class HostResourceRow(NamedTuple):


class ProcessResourceRow(NamedTuple):
"""
CSV file row structure of process level resource
"""

timestamp: float
pid: int
name: str
Expand Down Expand Up @@ -137,7 +157,7 @@ def collect_memory_usage(self) -> int:
@staticmethod
def _ensure_positive(num):
# Fix IO counter issue
return 0 if num < 0 else num
return max(num, 0)

def collect_host_data(self):
_disk_io = psutil.disk_io_counters()
Expand Down
8 changes: 4 additions & 4 deletions testplan/web_ui/testing/src/AssertionPane/ResourcePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ const TopUsageBanner = ({
fontWeight: "500",
cursor: "pointer",
};
const cpuDiv = _.isEmpty(maxCPU, true) ? null : (
const cpuDiv = _.isEmpty(maxCPU?.value, true) ? null : (
<div
style={itemStyle}
title={maxCPU.uid}
Expand All @@ -437,7 +437,7 @@ const TopUsageBanner = ({
</div>
);

const memDiv = _.isEmpty(maxMemory, true) ? null : (
const memDiv = _.isEmpty(maxMemory?.value, true) ? null : (
<div
style={itemStyle}
title={maxMemory.uid}
Expand All @@ -447,7 +447,7 @@ const TopUsageBanner = ({
</div>
);

const diskDiv = _.isEmpty(maxDisk, true) ? null : (
const diskDiv = _.isEmpty(maxDisk?.value, true) ? null : (
<div
style={itemStyle}
title={maxDisk.uid}
Expand All @@ -457,7 +457,7 @@ const TopUsageBanner = ({
</div>
);

const iopsDiv = _.isEmpty(maxIOPS, true) ? null : (
const iopsDiv = _.isEmpty(maxIOPS?.value, true) ? null : (
<div
style={itemStyle}
title={maxIOPS.uid}
Expand Down

0 comments on commit 4f6af21

Please sign in to comment.