Rework the console to use autoactivation, move it in services/

This commit is contained in:
Marco Pesenti Gritti
2007-01-08 18:06:59 +01:00
parent 764eee81e5
commit cae78d7041
54 changed files with 83 additions and 98 deletions
@@ -0,0 +1,6 @@
sugardir = $(pkgdatadir)/shell/console/interface/memphis/plugins/cpu
sugar_PYTHON = \
README \
__init__.py \
info.py
@@ -0,0 +1,2 @@
This plugin give support to draw the Virtual Memory Size
usage by the current tracing process.
@@ -0,0 +1,23 @@
import os
import info
INTERNALS = {
'PLGNAME': "cpu",
'TABNAME': None,
'AUTHOR': "Eduardo Silva",
'DESC': "Print CPU usage",
# Plugin API
'Plg': None, # Plugin object
'current_plg': None, # Current plugin object
'current_page': None, # Current page number
# Top process view requirements
'top_data': [int], # Top data types needed by memphis core plugin
'top_cols': ["%CPU "] # Column names
}
# Get CPU frequency
cpu_hz = os.sysconf(2)
pids_ujiffies = {}
@@ -0,0 +1,48 @@
###########################################################
# Main function:
# -----------------
# self: self plugin object
# mself: memphis object / principal class
# pinfo: row with information about current tracing process
############################################################
def plg_on_top_data_refresh(self, pinfo):
PI = self.INTERNALS['Plg'].proc
pid = pinfo['pid']
# Get JIFFIES CPU usage
used_jiffies = pinfo['utime'] + pinfo['stime']
last_ujiffies = get_pid_ujiffies(self, pid)
cpu_usage = PI.get_CPU_usage(self.cpu_hz, used_jiffies, pinfo['start_time'])
# Get PERCENT CPU usage
if last_ujiffies == 0.0:
pcpu = 0.0
set_pid_ujiffies(self, pid, cpu_usage['used_jiffies'])
data = [int(pcpu)]
return data
used_jiffies = cpu_usage['used_jiffies'] - last_ujiffies
# Available jiffies are
avail_jiffies = (500/1000.0)*self.cpu_hz # 500 = 0.5 second
pcpu = ((used_jiffies*100)/avail_jiffies)
set_pid_ujiffies(self, pid, cpu_usage['used_jiffies'])
data = [int(pcpu)]
return data
def get_pid_ujiffies(self, pid):
if pid in self.pids_ujiffies:
return self.pids_ujiffies[pid]
else:
set_pid_ujiffies(self, pid, 0)
return self.pids_ujiffies[pid]
def set_pid_ujiffies(self, pid, ujiffies):
self.pids_ujiffies[pid] = ujiffies