DevConsole: New referenced memory usage field in Memphis (introduced in kernel 2.6.22)
This commit is contained in:
parent
a3efc1284f
commit
91f68897a6
@ -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)"]
|
|
||||||
}
|
|
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):
|
def plg_on_top_data_refresh(self, ppinfo):
|
||||||
|
smaps = get_data(self, ppinfo['pid'])
|
||||||
dirty_sizes = get_dirty(self, ppinfo['pid'])
|
|
||||||
|
|
||||||
# memhis need an array
|
# memphis need an array
|
||||||
return [dirty_sizes['private']]
|
return [smaps['private_dirty'], smaps['referenced']]
|
||||||
|
|
||||||
def get_dirty(pself, pid):
|
def get_data(pself, pid):
|
||||||
ProcAnalysis = pself.INTERNALS['Plg'].proc_analysis(pid)
|
ProcAnalysis = pself.INTERNALS['Plg'].proc_analysis(pid)
|
||||||
|
|
||||||
return ProcAnalysis.DirtyRSS()
|
return ProcAnalysis.SMaps()
|
@ -7,20 +7,22 @@ class Analysis:
|
|||||||
def __init__(self, pid):
|
def __init__(self, pid):
|
||||||
self.pid = pid
|
self.pid = pid
|
||||||
|
|
||||||
def DirtyRSS(self):
|
def SMaps(self):
|
||||||
smaps = proc_smaps.ProcSmaps(self.pid)
|
smaps = proc_smaps.ProcSmaps(self.pid)
|
||||||
dirty = []
|
private_dirty = 0
|
||||||
|
shared_dirty = 0
|
||||||
|
referenced = 0
|
||||||
|
|
||||||
private = 0
|
|
||||||
shared = 0
|
|
||||||
|
|
||||||
for map in smaps.mappings:
|
for map in smaps.mappings:
|
||||||
private += map.private_dirty
|
private_dirty += map.private_dirty
|
||||||
shared += map.shared_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):
|
def ApproxRealMemoryUsage(self):
|
||||||
maps = proc_smaps.ProcMaps(self.pid)
|
maps = proc_smaps.ProcMaps(self.pid)
|
||||||
|
@ -36,7 +36,8 @@ class ProcSmaps:
|
|||||||
# Shared_Dirty: 0 kB
|
# Shared_Dirty: 0 kB
|
||||||
# Private_Clean: 8 kB
|
# Private_Clean: 8 kB
|
||||||
# Private_Dirty: 0 kB
|
# Private_Dirty: 0 kB
|
||||||
|
# Referenced: 4 kb -> Introduced in kernel 2.6.22
|
||||||
|
|
||||||
while num_lines > 0:
|
while num_lines > 0:
|
||||||
fields = lines[line_idx].split (" ", 5)
|
fields = lines[line_idx].split (" ", 5)
|
||||||
if len (fields) == 6:
|
if len (fields) == 6:
|
||||||
@ -51,13 +52,20 @@ class ProcSmaps:
|
|||||||
shared_dirty = self.parse_smaps_size_line (lines[line_idx + 4])
|
shared_dirty = self.parse_smaps_size_line (lines[line_idx + 4])
|
||||||
private_clean = self.parse_smaps_size_line (lines[line_idx + 5])
|
private_clean = self.parse_smaps_size_line (lines[line_idx + 5])
|
||||||
private_dirty = self.parse_smaps_size_line (lines[line_idx + 6])
|
private_dirty = self.parse_smaps_size_line (lines[line_idx + 6])
|
||||||
|
referenced = self.parse_smaps_size_line (lines[line_idx + 7])
|
||||||
name = name.strip ()
|
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)
|
self.mappings.append (mapping)
|
||||||
|
|
||||||
num_lines -= 8
|
num_lines -= 8
|
||||||
line_idx += 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
|
# 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):
|
||||||
@ -66,13 +74,15 @@ class ProcSmaps:
|
|||||||
return int(fields[1])
|
return int(fields[1])
|
||||||
|
|
||||||
class Mapping:
|
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.size = size
|
||||||
self.rss = rss
|
self.rss = rss
|
||||||
self.shared_clean = shared_clean
|
self.shared_clean = shared_clean
|
||||||
self.shared_dirty = shared_dirty
|
self.shared_dirty = shared_dirty
|
||||||
self.private_clean = private_clean
|
self.private_clean = private_clean
|
||||||
self.private_dirty = private_dirty
|
self.private_dirty = private_dirty
|
||||||
|
self.referenced = referenced
|
||||||
self.permissions = permissions
|
self.permissions = permissions
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user