bug 571319 (remove threading from talos) remove threading from talos (take 2) p=anodelman r=bhearsum
git-svn-id: svn://10.0.0.236/trunk@260785 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
# Contributor(s):
|
||||
# Annie Sullivan <annie.sullivan@gmail.com> (original author)
|
||||
# Ben Hearsum <bhearsum@wittydomain.com> (ported to linux)
|
||||
# Alice Nodelman <anodelman@mozilla.com> (removed threading)
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -43,7 +44,6 @@ import subprocess
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
|
||||
def GetPrivateBytes(pids):
|
||||
"""Calculate the amount of private, writeable memory allocated to a process.
|
||||
@@ -125,7 +125,7 @@ counterDict["RSS"] = GetResidentSize
|
||||
counterDict["% Processor Time"] = GetCpuTime
|
||||
counterDict["XRes"] = GetXRes
|
||||
|
||||
class CounterManager(threading.Thread):
|
||||
class CounterManager():
|
||||
"""This class manages the monitoring of a process with any number of
|
||||
counters.
|
||||
|
||||
@@ -143,18 +143,16 @@ class CounterManager(threading.Thread):
|
||||
"""
|
||||
self.allCounters = {}
|
||||
self.registeredCounters = {}
|
||||
self.process = process
|
||||
self.childProcess = childProcess
|
||||
self.runThread = False
|
||||
self.primaryPid = -1
|
||||
self.pidList = []
|
||||
self.ffprocess = ffprocess
|
||||
self.primaryPid = self.ffprocess.GetPidsByName(process)[-1]
|
||||
os.stat('/proc/%s' % self.primaryPid)
|
||||
|
||||
self._loadCounters()
|
||||
self.registerCounters(counters)
|
||||
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
def _loadCounters(self):
|
||||
"""Loads all of the counters defined in the counterDict"""
|
||||
for counter in counterDict.keys():
|
||||
@@ -185,27 +183,11 @@ class CounterManager(threading.Thread):
|
||||
def getCounterValue(self, counterName):
|
||||
"""Returns the last value of the counter 'counterName'"""
|
||||
try:
|
||||
if counterName is "% Processor Time":
|
||||
return self._getCounterAverage(counterName)
|
||||
else:
|
||||
return self.registeredCounters[counterName][1][-1]
|
||||
self.updatePidList()
|
||||
return self.registeredCounters[counterName][0](self.pidList)
|
||||
except:
|
||||
return None
|
||||
|
||||
def _getCounterAverage(self, counterName):
|
||||
"""Returns the average value of the counter 'counterName'"""
|
||||
try:
|
||||
total = 0
|
||||
for v in self.registeredCounters[counterName][1]:
|
||||
total += v
|
||||
return total / len(self.registeredCounters[counterName][1])
|
||||
except:
|
||||
return None
|
||||
|
||||
def getProcess(self):
|
||||
"""Returns the process currently associated with this CounterManager"""
|
||||
return self.process
|
||||
|
||||
def updatePidList(self):
|
||||
"""Updates the list of PIDs we're interested in"""
|
||||
try:
|
||||
@@ -217,42 +199,8 @@ class CounterManager(threading.Thread):
|
||||
except:
|
||||
print "WARNING: problem updating child PID's"
|
||||
|
||||
def startMonitor(self):
|
||||
"""Starts the monitoring process.
|
||||
Throws an exception if any error occurs
|
||||
"""
|
||||
# TODO: make this function less ugly
|
||||
try:
|
||||
# the last process is the useful one
|
||||
self.primaryPid = self.ffprocess.GetPidsByName(self.process)[-1]
|
||||
os.stat('/proc/%s' % self.primaryPid)
|
||||
self.runThread = True
|
||||
self.start()
|
||||
except:
|
||||
print 'WARNING: problem starting counter monitor'
|
||||
|
||||
def stopMonitor(self):
|
||||
"""Stops the monitor"""
|
||||
"""any final cleanup"""
|
||||
# TODO: should probably wait until we know run() is completely stopped
|
||||
# before setting self.pid to None. Use a lock?
|
||||
self.runThread = False
|
||||
|
||||
def run(self):
|
||||
"""Performs the actual monitoring of the process. Will keep running
|
||||
until stopMonitor() is called
|
||||
"""
|
||||
while self.runThread:
|
||||
self.updatePidList()
|
||||
for counter in self.registeredCounters.keys():
|
||||
# counter[0] is a function that gets the current value for
|
||||
# a counter
|
||||
# counter[1] is a list of recorded values
|
||||
try:
|
||||
self.registeredCounters[counter][1].append(
|
||||
self.registeredCounters[counter][0](self.pidList))
|
||||
except:
|
||||
# if a counter throws an exception, remove it
|
||||
#self.unregisterCounters([counter])
|
||||
print "Error in collecting counter: " + counter
|
||||
|
||||
time.sleep(self.pollInterval)
|
||||
return
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
# Annie Sullivan <annie.sullivan@gmail.com> (original author)
|
||||
# Ben Hearsum <bhearsum@wittydomain.com> (ported to linux)
|
||||
# Zach Lipton <zach@zachlipton.com> (Mac port)
|
||||
# Alice Nodelman <anodelman@mozilla.com> (removed threading)
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -43,7 +44,6 @@ __author__ = 'annie.sullivan@gmail.com (Annie Sullivan)'
|
||||
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
def GetProcessData(pid):
|
||||
@@ -84,7 +84,7 @@ counterDict["Private Bytes"] = GetPrivateBytes
|
||||
counterDict["RSS"] = GetResidentSize
|
||||
counterDict["% Processor Time"] = GetCpuTime
|
||||
|
||||
class CounterManager(threading.Thread):
|
||||
class CounterManager():
|
||||
"""This class manages the monitoring of a process with any number of
|
||||
counters.
|
||||
|
||||
@@ -93,8 +93,6 @@ class CounterManager(threading.Thread):
|
||||
Some examples are: CalcCPUTime, GetResidentSize, and GetPrivateBytes
|
||||
"""
|
||||
|
||||
pollInterval = .25
|
||||
|
||||
def __init__(self, ffprocess, process, counters=None):
|
||||
"""Args:
|
||||
counters: A list of counters to monitor. Any counters whose name does
|
||||
@@ -102,16 +100,13 @@ class CounterManager(threading.Thread):
|
||||
"""
|
||||
self.allCounters = {}
|
||||
self.registeredCounters = {}
|
||||
self.process = process
|
||||
self.runThread = False
|
||||
self.pid = -1
|
||||
self.ffprocess = ffprocess
|
||||
# the last process is the useful one
|
||||
self.pid = self.ffprocess.GetPidsByName(process)[-1]
|
||||
|
||||
self._loadCounters()
|
||||
self.registerCounters(counters)
|
||||
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
def _loadCounters(self):
|
||||
"""Loads all of the counters defined in the counterDict"""
|
||||
for counter in counterDict.keys():
|
||||
@@ -142,61 +137,11 @@ class CounterManager(threading.Thread):
|
||||
def getCounterValue(self, counterName):
|
||||
"""Returns the last value of the counter 'counterName'"""
|
||||
try:
|
||||
if counterName is "% Processor Time":
|
||||
return self._getCounterAverage(counterName)
|
||||
else:
|
||||
return self.registeredCounters[counterName][1][-1]
|
||||
return self.registeredCounters[counterName][0](self.pid)
|
||||
except:
|
||||
print "Error in collecting counter: " + counterName
|
||||
return None
|
||||
|
||||
def _getCounterAverage(self, counterName):
|
||||
"""Returns the average value of the counter 'counterName'"""
|
||||
try:
|
||||
total = 0
|
||||
for v in self.registeredCounters[counterName][1]:
|
||||
total += v
|
||||
return total / len(self.registeredCounters[counterName][1])
|
||||
except:
|
||||
return None
|
||||
|
||||
def getProcess(self):
|
||||
"""Returns the process currently associated with this CounterManager"""
|
||||
return self.process
|
||||
|
||||
def startMonitor(self):
|
||||
"""Starts the monitoring process.
|
||||
Throws an exception if any error occurs
|
||||
"""
|
||||
# TODO: make this function less ugly
|
||||
try:
|
||||
# the last process is the useful one
|
||||
self.pid = self.ffprocess.GetPidsByName(self.process)[-1]
|
||||
self.runThread = True
|
||||
self.start()
|
||||
except:
|
||||
print 'WARNING: problem starting counter monitor'
|
||||
|
||||
def stopMonitor(self):
|
||||
"""Stops the monitor"""
|
||||
# TODO: should probably wait until we know run() is completely stopped
|
||||
# before setting self.pid to None. Use a lock?
|
||||
self.runThread = False
|
||||
|
||||
def run(self):
|
||||
"""Performs the actual monitoring of the process. Will keep running
|
||||
until stopMonitor() is called
|
||||
"""
|
||||
while self.runThread:
|
||||
for counter in self.registeredCounters.keys():
|
||||
# counter[0] is a function that gets the current value for
|
||||
# a counter
|
||||
# counter[1] is a list of recorded values
|
||||
try:
|
||||
self.registeredCounters[counter][1].append(
|
||||
self.registeredCounters[counter][0](self.pid))
|
||||
except:
|
||||
# if a counter throws an exception, remove it
|
||||
#self.unregisterCounters([counter]) #don't remove, let it try and resolve on next cycle
|
||||
print "Error in collecting counter: " + counter
|
||||
|
||||
time.sleep(self.pollInterval)
|
||||
"""any final cleanup"""
|
||||
return
|
||||
|
||||
@@ -43,7 +43,6 @@ import win32pdhutil
|
||||
class CounterManager:
|
||||
|
||||
def __init__(self, ffprocess, process, counters=None, childProcess="plugin-container"):
|
||||
self.process = process
|
||||
self.ffprocess = ffprocess
|
||||
self.childProcess = childProcess
|
||||
self.registeredCounters = {}
|
||||
@@ -52,6 +51,27 @@ class CounterManager:
|
||||
# is closed
|
||||
win32pdh.EnumObjects(None, None, 0, 1)
|
||||
|
||||
# Add the counter path for the default process.
|
||||
for counter in self.registeredCounters:
|
||||
path = win32pdh.MakeCounterPath((None, 'process', process,
|
||||
None, -1, counter))
|
||||
hq = win32pdh.OpenQuery()
|
||||
try:
|
||||
hc = win32pdh.AddCounter(hq, path)
|
||||
except:
|
||||
win32pdh.CloseQuery(hq)
|
||||
#assume that this is a memory counter for the system, not a process counter
|
||||
path = win32pdh.MakeCounterPath((None, 'Memory', None, None, -1 , counter))
|
||||
hq = win32pdh.OpenQuery()
|
||||
try:
|
||||
hc = win32pdh.AddCounter(hq, path)
|
||||
except:
|
||||
win32pdh.CloseQuery(hq)
|
||||
|
||||
self.registeredCounters[counter] = [hq, [(hc, path)]]
|
||||
self.updateCounterPathsForChildProcesses(counter)
|
||||
|
||||
|
||||
def registerCounters(self, counters):
|
||||
# self.registeredCounters[counter][0] is a counter query handle
|
||||
# self.registeredCounters[counter][1] is a list of tuples, the first
|
||||
@@ -127,31 +147,6 @@ class CounterManager:
|
||||
def getProcess(self):
|
||||
return self.process
|
||||
|
||||
def startMonitor(self):
|
||||
# PDH might need to be "refreshed" if it has been queried while the browser
|
||||
# is closed
|
||||
win32pdh.EnumObjects(None, None, 0, 1)
|
||||
|
||||
# Add the counter path for the default process.
|
||||
for counter in self.registeredCounters:
|
||||
path = win32pdh.MakeCounterPath((None, 'process', self.process,
|
||||
None, -1, counter))
|
||||
hq = win32pdh.OpenQuery()
|
||||
try:
|
||||
hc = win32pdh.AddCounter(hq, path)
|
||||
except:
|
||||
win32pdh.CloseQuery(hq)
|
||||
#assume that this is a memory counter for the system, not a process counter
|
||||
path = win32pdh.MakeCounterPath((None, 'Memory', None, None, -1 , counter))
|
||||
hq = win32pdh.OpenQuery()
|
||||
try:
|
||||
hc = win32pdh.AddCounter(hq, path)
|
||||
except:
|
||||
win32pdh.CloseQuery(hq)
|
||||
|
||||
self.registeredCounters[counter] = [hq, [(hc, path)]]
|
||||
self.updateCounterPathsForChildProcesses(counter)
|
||||
|
||||
def stopMonitor(self):
|
||||
try:
|
||||
for counter in self.registeredCounters:
|
||||
|
||||
@@ -277,7 +277,6 @@ class TTest(object):
|
||||
#set up the counters for this test
|
||||
if counters:
|
||||
cm = self.cmanager.CounterManager(self._ffprocess, browser_config['process'], counters)
|
||||
cm.startMonitor()
|
||||
counter_results = {}
|
||||
for counter in counters:
|
||||
counter_results[counter] = []
|
||||
|
||||
Reference in New Issue
Block a user