Bug fix and using regex to extract data

master
Steve L. Nyemba 8 years ago
parent ecd3dffbc6
commit 39df187e68

@ -129,14 +129,21 @@ class DetailProcess(Analysis):
def init (self,names): def init (self,names):
Analysis.init(self) Analysis.init(self)
self.names = names; self.names = names;
def split(self,name,stream):
pattern = " (\d+.{0,1}\d*)\x20*(\d+.{0,1}\d*)\x20*(\d+.{0,1}\d*)\x20".replace(":name",name)
g = re.match(pattern,stream)
if g :
return list(g.groups())+[name]
else:
return ''
def evaluate(self,name) : def evaluate(self,name) :
cmd = "ps -eo pmem,pcpu,vsize,comm|grep :app" cmd = "ps -eo pmem,pcpu,vsize,comm|grep -E \":app\""
handler = subprocess.Popen(cmd.replace(":app",name),shell=True,stdout=subprocess.PIPE) handler = subprocess.Popen(cmd.replace(":app",name),shell=True,stdout=subprocess.PIPE)
ostream = handler.communicate()[0].split('\n') ostream = handler.communicate()[0].split('\n')
ostream = [ row.split(' ') for row in ostream if row != '']
if len(ostream) == 0: ostream = [ self.split(name,row) for row in ostream if row != '']
if len(ostream) == 0:
ostream = [['0','0','0',name]] ostream = [['0','0','0',name]]
r = [] r = []
for row in ostream : for row in ostream :
@ -144,7 +151,7 @@ class DetailProcess(Analysis):
# Though the comm should only return the name as specified, # Though the comm should only return the name as specified,
# On OSX it has been observed that the fully qualified path is sometimes returned (go figure) # On OSX it has been observed that the fully qualified path is sometimes returned (go figure)
# #
row = [float(value) for value in row if value.strip() != '' and name not in value ] +[name] row = [float(value) for value in row if value.strip() != '' and name not in value ] +[re.sub('\$|^','',name)]
r.append(row) r.append(row)
return r return r
def format(self,row): def format(self,row):

Loading…
Cancel
Save