Skip to content

Commit 791d23d

Browse files
committed
Handle divison by zero errors
1 parent dbb0dd1 commit 791d23d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

system/vm_stats/python_modules/vm_stats.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,14 @@ def get_delta(name):
9898
def get_vmeff(name):
9999
# get metrics
100100
[curr_metrics, last_metrics] = get_metrics()
101+
101102
try:
102-
delta = 100 * (float(curr_metrics['data']['pgsteal_normal']) - float(last_metrics['data']['pgsteal_normal'])) /(float(curr_metrics['data']['pgscan_kswapd_normal']) - float(last_metrics['data']['pgscan_kswapd_normal']))
103+
pgscan_diff = float(curr_metrics['data']['pgscan_kswapd_normal']) - float(last_metrics['data']['pgscan_kswapd_normal'])
104+
# To avoid division by 0 errors check whether pgscan is 0
105+
if pgscan_diff == 0:
106+
return 0.0
107+
108+
delta = 100 * (float(curr_metrics['data']['pgsteal_normal']) - float(last_metrics['data']['pgsteal_normal'])) / pgscan_diff
103109
if delta < 0:
104110
print name + " is less 0"
105111
delta = 0
@@ -108,7 +114,6 @@ def get_vmeff(name):
108114

109115
return delta
110116

111-
112117

113118
def create_desc(skel, prop):
114119
d = skel.copy()

0 commit comments

Comments
 (0)