DevConsole: Fix broken procfs parser
This commit is contained in:
parent
2485e15030
commit
cc745f990f
@ -11,3 +11,4 @@ def plg_on_top_data_refresh(self, ppinfo):
|
|||||||
data = [ppinfo['pid'], ppinfo['name'], ppinfo['state_name']]
|
data = [ppinfo['pid'], ppinfo['name'], ppinfo['state_name']]
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import sys, os
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
import string
|
import string
|
||||||
|
|
||||||
class ProcInfo:
|
class ProcInfo:
|
||||||
@ -36,10 +38,12 @@ class ProcInfo:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Parsing data , check 'man 5 proc' for details
|
# Parsing data , check 'man 5 proc' for details
|
||||||
data = infile.read().split()
|
stat_data = infile.read()
|
||||||
|
|
||||||
infile.close()
|
infile.close()
|
||||||
|
|
||||||
|
process_name = self._get_process_name(stat_data)
|
||||||
|
data = self._get_safe_split(stat_data)
|
||||||
|
|
||||||
state_dic = {
|
state_dic = {
|
||||||
'R': 'Running',
|
'R': 'Running',
|
||||||
'S': 'Sleeping',
|
'S': 'Sleeping',
|
||||||
@ -48,27 +52,34 @@ class ProcInfo:
|
|||||||
'T': 'Traced/Stopped',
|
'T': 'Traced/Stopped',
|
||||||
'W': 'Paging'
|
'W': 'Paging'
|
||||||
}
|
}
|
||||||
|
|
||||||
# user and group owners
|
# user and group owners
|
||||||
pidstat = os.stat(pidfile)
|
pidstat = os.stat(pidfile)
|
||||||
|
|
||||||
info = {
|
info = {
|
||||||
'pid': int(data[0]), # Process ID
|
'pid': int(data[0]), # Process ID
|
||||||
'name': data[1].strip('()'), # Process name
|
'name': process_name,
|
||||||
'state': data[2], # Process State, ex: R|S|D|Z|T|W
|
'state': data[2], # Process State, ex: R|S|D|Z|T|W
|
||||||
'state_name': state_dic[data[2]], # Process State name, ex: Running, sleeping, Zombie, etc
|
'state_name': state_dic[data[2]], # Process State name, ex: Running, sleeping, Zombie, etc
|
||||||
'ppid': int(data[3]), # Parent process ID
|
'ppid': int(data[3]), # Parent process ID
|
||||||
'utime': int(data[13]), # Used jiffies in user mode
|
'utime': int(data[13]), # Used jiffies in user mode
|
||||||
'stime': int(data[14]), # Used jiffies in kernel mode
|
'stime': int(data[14]), # Used jiffies in kernel mode
|
||||||
'start_time': int(data[21]), # Process time from system boot (jiffies)
|
'start_time': int(data[21]), # Process time from system boot (jiffies)
|
||||||
'vsize': int(data[22]), # Virtual memory size used (bytes)
|
'vsize': int(data[22]), # Virtual memory size used (bytes)
|
||||||
'rss': int(data[23])*4, # Resident Set Size (bytes)
|
'rss': int(data[23])*4, # Resident Set Size (bytes)
|
||||||
'user_id': pidstat.st_uid, # process owner
|
'user_id': pidstat.st_uid, # process owner
|
||||||
'group_id': pidstat.st_gid # owner group
|
'group_id': pidstat.st_gid # owner group
|
||||||
}
|
}
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
# Return the process name
|
||||||
|
def _get_process_name(self, data):
|
||||||
|
m = re.search("\(.*\)", data)
|
||||||
|
return m.string[m.start()+1:m.end()-1]
|
||||||
|
|
||||||
|
def _get_safe_split(self, data):
|
||||||
|
new_data = re.sub("\(.*\)", '()', data)
|
||||||
|
return new_data.split()
|
||||||
|
|
||||||
# Returns the CPU usage expressed in Jiffies
|
# Returns the CPU usage expressed in Jiffies
|
||||||
def get_CPU_usage(self, cpu_hz, used_jiffies, start_time):
|
def get_CPU_usage(self, cpu_hz, used_jiffies, start_time):
|
||||||
|
@ -56,8 +56,8 @@ class ProcSmaps:
|
|||||||
mapping = Mapping (size, rss, shared_clean, shared_dirty, private_clean, private_dirty, permissions, name)
|
mapping = Mapping (size, rss, shared_clean, shared_dirty, private_clean, private_dirty, permissions, name)
|
||||||
self.mappings.append (mapping)
|
self.mappings.append (mapping)
|
||||||
|
|
||||||
num_lines -= 7
|
num_lines -= 8
|
||||||
line_idx += 7
|
line_idx += 8
|
||||||
|
|
||||||
# Parses a line of the form "foo: 42 kB" and returns an integer for the "42" field
|
# Parses a line of the form "foo: 42 kB" and returns an integer for the "42" field
|
||||||
def parse_smaps_size_line (self, line):
|
def parse_smaps_size_line (self, line):
|
||||||
|
Loading…
Reference in New Issue
Block a user