Skip to content

Commit

Permalink
First rush for the issue #1105. Bug with Process IO when Glances starts
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Jan 6, 2018
1 parent 92c9b2d commit fc7106c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Enhancements and new features:
* Remove graph export from Glances #1206
* Add a code of conduct for Glances project's participants #1211
* Context switches bottleneck identification #1212
* Take advantage of the PSUtil issue #1025 (Add process_iter(attrs, ad_value)) #1105

Bugs corrected:

Expand Down
60 changes: 60 additions & 0 deletions glances/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def pid_max(self):
return int(f.read())
except (OSError, IOError):
return None
else:
return None

@property
def max_processes(self):
Expand Down Expand Up @@ -414,6 +416,64 @@ def update(self):
# Update the maximum process ID (pid) number
self.processcount['pid_max'] = self.pid_max

# Only work whith PsUtil
mandatories_attr = ['cmdline', 'cpu_percent', 'cpu_times',
'io_counters', 'memory_info', 'memory_percent',
'name', 'nice', 'pid',
'ppid', 'status', 'username']
self.processlist = [p.info for p in sorted(psutil.process_iter(attrs=mandatories_attr,
ad_value=None),
key=lambda p: p.info['cpu_percent'])]

# Add metadata
for proc in self.processlist:
proc['time_since_update'] = time_since_update
# Status
proc['status'] = str(proc['status'])[:1].upper()
# Process IO
# procstat['io_counters'] is a list:
# [read_bytes, write_bytes, read_bytes_old, write_bytes_old, io_tag]
# If io_tag = 0 > Access denied (display "?")
# If io_tag = 1 > No access denied (display the IO rate)
# Availability: all platforms except macOS and Illumos/Solaris
if proc['io_counters'] is not None:
proc_io = proc['io_counters']
io_new = [proc_io.read_bytes, proc_io.write_bytes]
# For IO rate computation
# Append saved IO r/w bytes
try:
proc['io_counters'] = io_new + self.io_old[proc['pid']]
except KeyError:
proc['io_counters'] = io_new + [0, 0]
# then save the IO r/w bytes
self.io_old[proc['pid']] = io_new
io_tag = 1
else:
proc['io_counters'] = [0, 0] + [0, 0]
io_tag = 0

# Append the IO tag (for display)
proc['io_counters'] += [io_tag]

def update_OLD(self):
"""Update the processes stats."""
# Reset the stats
self.processlist = []
self.reset_processcount()

# Do not process if disable tag is set
if self.disable_tag:
return

# Get the time since last update
time_since_update = getTimeSinceLastUpdate('process_disk')

# Reset the max dict
self.reset_max_values()

# Update the maximum process ID (pid) number
self.processcount['pid_max'] = self.pid_max

# Build an internal dict with only mandatories stats (sort keys)
processdict = {}
excluded_processes = set()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
psutil==5.2.2
psutil==5.4.2

0 comments on commit fc7106c

Please sign in to comment.