DevConsole: Fix broken procfs parser

master
Eduardo Silva 17 years ago
parent 2485e15030
commit cc745f990f

@ -11,3 +11,4 @@ def plg_on_top_data_refresh(self, ppinfo):
data = [ppinfo['pid'], ppinfo['name'], ppinfo['state_name']]
return data

@ -1,4 +1,6 @@
import sys, os
import os
import re
import sys
import string
class ProcInfo:
@ -36,10 +38,12 @@ class ProcInfo:
return None
# Parsing data , check 'man 5 proc' for details
data = infile.read().split()
stat_data = infile.read()
infile.close()
process_name = self._get_process_name(stat_data)
data = self._get_safe_split(stat_data)
state_dic = {
'R': 'Running',
'S': 'Sleeping',
@ -48,27 +52,34 @@ class ProcInfo:
'T': 'Traced/Stopped',
'W': 'Paging'
}
# user and group owners
pidstat = os.stat(pidfile)
info = {
'pid': int(data[0]), # Process ID
'name': data[1].strip('()'), # Process name
'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
'ppid': int(data[3]), # Parent process ID
'utime': int(data[13]), # Used jiffies in user mode
'stime': int(data[14]), # Used jiffies in kernel mode
'start_time': int(data[21]), # Process time from system boot (jiffies)
'vsize': int(data[22]), # Virtual memory size used (bytes)
'rss': int(data[23])*4, # Resident Set Size (bytes)
'pid': int(data[0]), # Process ID
'name': process_name,
'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
'ppid': int(data[3]), # Parent process ID
'utime': int(data[13]), # Used jiffies in user mode
'stime': int(data[14]), # Used jiffies in kernel mode
'start_time': int(data[21]), # Process time from system boot (jiffies)
'vsize': int(data[22]), # Virtual memory size used (bytes)
'rss': int(data[23])*4, # Resident Set Size (bytes)
'user_id': pidstat.st_uid, # process owner
'group_id': pidstat.st_gid # owner group
}
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
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)
self.mappings.append (mapping)
num_lines -= 7
line_idx += 7
num_lines -= 8
line_idx += 8
# Parses a line of the form "foo: 42 kB" and returns an integer for the "42" field
def parse_smaps_size_line (self, line):

Loading…
Cancel
Save