Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
commit
9c0df1c6c5
@ -130,15 +130,14 @@ class Data:
|
||||
treeview.set_model(self.store)
|
||||
|
||||
def _start_memphis(self, button):
|
||||
|
||||
# Update information every 1.5 second
|
||||
button.hide()
|
||||
self.interface.button_stop.show()
|
||||
self._running_status = True
|
||||
gobject.timeout_add(1500, self.load_data, self.treeview)
|
||||
self._gid = gobject.timeout_add(1500, self.load_data, self.treeview)
|
||||
|
||||
def _stop_memphis(self, button):
|
||||
|
||||
gobject.source_remove(self._gid)
|
||||
self._running_status = False
|
||||
button.hide()
|
||||
self.interface.button_start.show()
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = clean_size cpu dirty_size memphis_init
|
||||
SUBDIRS = clean_size cpu smaps memphis_init
|
||||
|
||||
sugardir = $(pkgdatadir)/services/console/interface/memphis/plugins
|
||||
sugar_PYTHON =
|
||||
|
@ -1,17 +0,0 @@
|
||||
|
||||
import info
|
||||
|
||||
|
||||
INTERNALS = {
|
||||
# Basic information
|
||||
'PLGNAME': "Dirty Size",
|
||||
'TABNAME': None, # No tabbed plugin
|
||||
'AUTHOR': "Eduardo Silva",
|
||||
'DESC': "Get dirty size memory usage",
|
||||
|
||||
# Plugin API
|
||||
'Plg': None, # Plugin object
|
||||
|
||||
'top_data': [int], # Top data types needed by memphis core plugin
|
||||
'top_cols': ["PDRSS (kb)"]
|
||||
}
|
@ -11,3 +11,4 @@ def plg_on_top_data_refresh(self, ppinfo):
|
||||
data = [ppinfo['pid'], ppinfo['name'], ppinfo['state_name']]
|
||||
|
||||
return data
|
||||
|
||||
|
17
services/console/interface/memphis/plugins/smaps/__init__.py
Normal file
17
services/console/interface/memphis/plugins/smaps/__init__.py
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
import info
|
||||
|
||||
|
||||
INTERNALS = {
|
||||
# Basic information
|
||||
'PLGNAME': "SMaps",
|
||||
'TABNAME': None, # No tabbed plugin
|
||||
'AUTHOR': "Eduardo Silva",
|
||||
'DESC': "Get dirty size and reference memory usage",
|
||||
|
||||
# Plugin API
|
||||
'Plg': None, # Plugin object
|
||||
|
||||
'top_data': [int, int], # Top data types needed by memphis core plugin
|
||||
'top_cols': ["PDRSS (kb)", "Referenced (kb)"]
|
||||
}
|
@ -8,13 +8,12 @@
|
||||
|
||||
|
||||
def plg_on_top_data_refresh(self, ppinfo):
|
||||
|
||||
dirty_sizes = get_dirty(self, ppinfo['pid'])
|
||||
smaps = get_data(self, ppinfo['pid'])
|
||||
|
||||
# memhis need an array
|
||||
return [dirty_sizes['private']]
|
||||
# memphis need an array
|
||||
return [smaps['private_dirty'], smaps['referenced']]
|
||||
|
||||
def get_dirty(pself, pid):
|
||||
def get_data(pself, pid):
|
||||
ProcAnalysis = pself.INTERNALS['Plg'].proc_analysis(pid)
|
||||
|
||||
return ProcAnalysis.DirtyRSS()
|
||||
return ProcAnalysis.SMaps()
|
@ -7,20 +7,22 @@ class Analysis:
|
||||
def __init__(self, pid):
|
||||
self.pid = pid
|
||||
|
||||
def DirtyRSS(self):
|
||||
def SMaps(self):
|
||||
smaps = proc_smaps.ProcSmaps(self.pid)
|
||||
dirty = []
|
||||
private_dirty = 0
|
||||
shared_dirty = 0
|
||||
referenced = 0
|
||||
|
||||
private = 0
|
||||
shared = 0
|
||||
|
||||
for map in smaps.mappings:
|
||||
private += map.private_dirty
|
||||
shared += map.shared_dirty
|
||||
private_dirty += map.private_dirty
|
||||
shared_dirty += map.shared_dirty
|
||||
referenced += map.referenced
|
||||
|
||||
dirty = {"private": int(private), "shared": int(shared)}
|
||||
smaps = {"private_dirty": int(private_dirty), \
|
||||
"shared_dirty": int(shared_dirty),\
|
||||
"referenced": int(referenced)}
|
||||
|
||||
return dirty
|
||||
return smaps
|
||||
|
||||
def ApproxRealMemoryUsage(self):
|
||||
maps = proc_smaps.ProcMaps(self.pid)
|
||||
|
@ -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):
|
||||
|
@ -36,7 +36,8 @@ class ProcSmaps:
|
||||
# Shared_Dirty: 0 kB
|
||||
# Private_Clean: 8 kB
|
||||
# Private_Dirty: 0 kB
|
||||
|
||||
# Referenced: 4 kb -> Introduced in kernel 2.6.22
|
||||
|
||||
while num_lines > 0:
|
||||
fields = lines[line_idx].split (" ", 5)
|
||||
if len (fields) == 6:
|
||||
@ -51,13 +52,20 @@ class ProcSmaps:
|
||||
shared_dirty = self.parse_smaps_size_line (lines[line_idx + 4])
|
||||
private_clean = self.parse_smaps_size_line (lines[line_idx + 5])
|
||||
private_dirty = self.parse_smaps_size_line (lines[line_idx + 6])
|
||||
referenced = self.parse_smaps_size_line (lines[line_idx + 7])
|
||||
name = name.strip ()
|
||||
|
||||
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, referenced, permissions, name)
|
||||
self.mappings.append (mapping)
|
||||
|
||||
num_lines -= 7
|
||||
line_idx += 7
|
||||
num_lines -= 8
|
||||
line_idx += 8
|
||||
|
||||
self._clear_reference(pid)
|
||||
|
||||
def _clear_reference(self, pid):
|
||||
os.system("echo 1 > /proc/%s/clear_refs" % pid)
|
||||
|
||||
# Parses a line of the form "foo: 42 kB" and returns an integer for the "42" field
|
||||
def parse_smaps_size_line (self, line):
|
||||
@ -66,13 +74,15 @@ class ProcSmaps:
|
||||
return int(fields[1])
|
||||
|
||||
class Mapping:
|
||||
def __init__ (self, size, rss, shared_clean, shared_dirty, private_clean, private_dirty, permissions, name):
|
||||
def __init__ (self, size, rss, shared_clean, shared_dirty, \
|
||||
private_clean, private_dirty, referenced, permissions, name):
|
||||
self.size = size
|
||||
self.rss = rss
|
||||
self.shared_clean = shared_clean
|
||||
self.shared_dirty = shared_dirty
|
||||
self.private_clean = private_clean
|
||||
self.private_dirty = private_dirty
|
||||
self.referenced = referenced
|
||||
self.permissions = permissions
|
||||
self.name = name
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user