Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions
MoinMoin.util.profile.Profiler Class Reference
Inheritance diagram for MoinMoin.util.profile.Profiler:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def addRequest
def sample

Public Attributes

 logfile
 requestsPerSample
 collect
 pid
 count
 requests
 data

Private Member Functions

def _setData
def _setMemory
def _log

Detailed Description

Profile memory usage

Profiler count requests and sample memory usage.

FIXME: We might want to save the profiler log in the profiled wiki
data dir, but the data dir is available only later in request. This
should be fixed by loading the config earlier.

Definition at line 43 of file profile.py.


Constructor & Destructor Documentation

def MoinMoin.util.profile.Profiler.__init__ (   self,
  name,
  requestsPerSample = 100,
  collect = 0 
)
Initialize a profiler

@param name: profiler name, used in the log file name
@param requestsPerSample: how many request to run between samples
@param collect: should call gc.collect() in each sample

Reimplemented in MoinMoin.util.profile.TwistedProfiler.

Definition at line 52 of file profile.py.

00052 
00053     def __init__(self, name, requestsPerSample=100, collect=0):
00054         """ Initialize a profiler
00055 
00056         @param name: profiler name, used in the log file name
00057         @param requestsPerSample: how many request to run between samples
00058         @param collect: should call gc.collect() in each sample
00059         """
00060         logname = '%s--%s.log' % (name, time.strftime('%Y-%m-%d--%H-%M'))
00061         self.logfile = file(logname, 'a')
00062         self.requestsPerSample = requestsPerSample
00063         self.collect = collect
00064         self.pid = os.getpid()
00065         self.count = 0 # count between somples
00066         self.requests = 0 # requests added
00067         self.data = {'collect': 'NA'} # Sample data


Member Function Documentation

def MoinMoin.util.profile.Profiler._log (   self) [private]
Format sample and write to log

Private method used by profilers.

Definition at line 124 of file profile.py.

00124 
00125     def _log(self):
00126         """ Format sample and write to log
00127 
00128         Private method used by profilers.
00129         """
00130         line = ('%(date)s req:%(requests)d mem:%(memory)sKB collect:%(collect)s '
00131                 'objects:%(objects)d garbage:%(garbage)d\n' % self.data)
00132         self.logfile.write(line)
00133         self.logfile.flush()
00134 

Here is the caller graph for this function:

def MoinMoin.util.profile.Profiler._setData (   self) [private]
Collect sample data into self.data

Private method used by profilers.

Definition at line 100 of file profile.py.

00100 
00101     def _setData(self):
00102         """ Collect sample data into self.data
00103 
00104         Private method used by profilers.
00105         """
00106         d = self.data
00107         d['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
00108         d['requests'] = self.requests
00109         if self.collect:
00110             d['collect'] = str(gc.collect())
00111         d['objects'] = len(gc.get_objects())
00112         d['garbage'] = len(gc.garbage)

Here is the caller graph for this function:

Get process memory usage

Private method used by profilers.

Uses ps call, maybe we should use procfs on Linux or maybe
getrusage system call (using the ctypes module).

Definition at line 113 of file profile.py.

00113 
00114     def _setMemory(self):
00115         """ Get process memory usage
00116 
00117         Private method used by profilers.
00118 
00119         Uses ps call, maybe we should use procfs on Linux or maybe
00120         getrusage system call (using the ctypes module).
00121         """
00122         lines = os.popen('/bin/ps -p %s -o rss' % self.pid).readlines()
00123         self.data['memory'] = lines[1].strip()

Here is the caller graph for this function:

Add a request to the profile

Call this for each page request.

WARNING: This is the most important call. if you don't call this
for each request - you will not have any profile data.

Invoke sample when self.count reach self.requestsPerSample.

Definition at line 68 of file profile.py.

00068 
00069     def addRequest(self):
00070         """ Add a request to the profile
00071 
00072         Call this for each page request.
00073 
00074         WARNING: This is the most important call. if you don't call this
00075         for each request - you will not have any profile data.
00076 
00077         Invoke sample when self.count reach self.requestsPerSample.
00078         """
00079         self.requests += 1
00080         self.count += 1
00081         if self.count == self.requestsPerSample:
00082             # Time for a sample
00083             self.count = 0
00084             self.sample()

Here is the call graph for this function:

Make a sample of memory usage and log it

You can call this to make samples between the samples done each
requestsPerSample, for example, at startup.

Invoke common methods for all profilers. Some profilers like
TwistedProfiler override this method.

Reimplemented in MoinMoin.util.profile.TwistedProfiler.

Definition at line 85 of file profile.py.

00085 
00086     def sample(self):
00087         """ Make a sample of memory usage and log it
00088 
00089         You can call this to make samples between the samples done each
00090         requestsPerSample, for example, at startup.
00091 
00092         Invoke common methods for all profilers. Some profilers like
00093         TwistedProfiler override this method.
00094         """
00095         self._setData()
00096         self._setMemory()
00097         self._log()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 62 of file profile.py.

Definition at line 64 of file profile.py.

Definition at line 66 of file profile.py.

Definition at line 60 of file profile.py.

Definition at line 63 of file profile.py.

Definition at line 65 of file profile.py.

Definition at line 61 of file profile.py.


The documentation for this class was generated from the following file: