All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
SortModuleTimes.TimeModuleStatsClass Class Reference
Inheritance diagram for SortModuleTimes.TimeModuleStatsClass:
SortModuleTimes.Stats

Public Member Functions

def __init__
 
def add
 
def complete
 
def getEvents
 
def getEntries
 
def nEntries
 
def nEvents
 
def hasEmptyData
 
def FormatStatsAsList
 
def FormatTimesAsList
 
- Public Member Functions inherited from SortModuleTimes.Stats
def __init__
 
def clear
 
def add
 
def n
 
def weights
 
def sum
 
def min
 
def max
 
def sumsq
 
def average
 
def sqaverage
 
def rms2
 
def rms
 
def stdev
 
def stdevp
 

Public Attributes

 key
 
 entries
 
- Public Attributes inherited from SortModuleTimes.Stats
 e_n
 
 e_w
 
 e_sum
 
 e_sumsq
 
 e_min
 
 e_max
 

Detailed Description

Collects statistics about execution time.

This class collects statistics about execution time of a module or the whole
event.
The timing information is added by add() function, with as argument an
instance of EntryDataClass.
Optionally, the object can keep track of all the entries separately.
The order of insertion of the events is also recorded.
By default, this does not happen and only statistics are stored.

The sample can be forcibly filled with empty entries. The idea is that one
event is added to the sample only when the information about its timing is
available. If we are tracking the event keys, we can check if we have all
the events and, if some event keys are missing, we can add an empty entry for
them so that we have the correct number of enrties in the sample.
This is achieved by a call to complete().
Note that to keep the order of the events the correct one one should check
if the previous event is present or not, and complete() with it, before
adding a new event. If the completion is performed after the new event is
added, the previous event will be added after the new one, when complete()
is actually called.

Definition at line 196 of file SortModuleTimes.py.

Constructor & Destructor Documentation

def SortModuleTimes.TimeModuleStatsClass.__init__ (   self,
  moduleKey,
  bTrackEntries = False 
)
Constructor: specifies the module we collect information about.

If the flag bTrackEntries is true, all the added events are stored singly.

Definition at line 219 of file SortModuleTimes.py.

220  def __init__(self, moduleKey, bTrackEntries = False):
221  """Constructor: specifies the module we collect information about.
222 
223  If the flag bTrackEntries is true, all the added events are stored singly.
224  """
225  Stats.__init__(self)
226  self.key = moduleKey
self.entries = OrderedDict() if bTrackEntries else None

Member Function Documentation

def SortModuleTimes.TimeModuleStatsClass.add (   self,
  data 
)
Adds a time to the sample.

The argument data is an instance of EntryDataClass, that includes both
event identification and timing information.
Its time() is used as the value of the statistic; if the entry has no time
(None), the event information is considered to be missing.

Definition at line 229 of file SortModuleTimes.py.

230  def add(self, data):
231  """Adds a time to the sample.
232 
233  The argument data is an instance of EntryDataClass, that includes both
234  event identification and timing information.
235  Its time() is used as the value of the statistic; if the entry has no time
236  (None), the event information is considered to be missing.
237  """
238  if self.entries is not None:
239  if data.eventKey in self.entries: return False
240  self.entries[data.eventKey] = data
241  # if
242  if not data.isMissing(): Stats.add(self, data.time())
return True
def SortModuleTimes.TimeModuleStatsClass.complete (   self,
  eventKeys 
)
Makes sure that an entry for each of the keys in eventKeys is present.

For event keys already known, nothing happens. For new event keys, an
empty entry is added at the end of the list, with no time information.
Note that the events are added at the bottom of the list, in the relative
order in eventKeys.

If we are not tracking the events, nothing happens ever.

Definition at line 245 of file SortModuleTimes.py.

246  def complete(self, eventKeys):
247  """Makes sure that an entry for each of the keys in eventKeys is present.
248 
249  For event keys already known, nothing happens. For new event keys, an
250  empty entry is added at the end of the list, with no time information.
251  Note that the events are added at the bottom of the list, in the relative
252  order in eventKeys.
253 
254  If we are not tracking the events, nothing happens ever.
255  """
256  if self.entries is None: return 0
257  if (len(self.entries) > 1): eventKeys = eventKeys[-1:]
258  res = 0
259  for eventKey in eventKeys:
260  if self.add(EntryDataClass(eventKey)): res += 1
return res
def SortModuleTimes.TimeModuleStatsClass.FormatStatsAsList (   self,
  format_ = None 
)
Prints the collected information into a list.

The list of strings includes a statistics ID (based on the key), an
average time, a relative RMS in percent, the total time and the recorded
the number of events with timing information and the timing extrema.

The format dictionary can contain format directives, for future use (no
format directive is currently supported).

Definition at line 291 of file SortModuleTimes.py.

292  def FormatStatsAsList(self, format_ = None):
293  """Prints the collected information into a list.
294 
295  The list of strings includes a statistics ID (based on the key), an
296  average time, a relative RMS in percent, the total time and the recorded
297  the number of events with timing information and the timing extrema.
298 
299  The format dictionary can contain format directives, for future use (no
300  format directive is currently supported).
301  """
302  if isinstance(self.key, basestring): name = str(self.key)
303  else: name = str(self.key)
304  if (self.n() == 0) or (self.sum() == 0.):
305  return [ name, "n/a" ]
306  RMS = self.rms() if (self.n() != 0) else 0.
307  return [
308  name,
309  "%g\"" % self.average(),
310  "(RMS %4.1f%%)" % (RMS / self.average() * 100.),
311  "total %g\"" % self.sum(), "(%d events:" % self.n(),
312  "%g" % self.min(), "- %g)" % self.max(),
]
def SortModuleTimes.TimeModuleStatsClass.FormatTimesAsList (   self,
  format_ = {} 
)
Prints the collected information into a list.

The list of strings includes a statistics ID (based on the key), and
a time entry for each of the events stored (with holes for the events
with missing time).
The format dictionary can contain format directives; the ones supported
so far are:
- 'max_events' (int): limit the number of events to the first max_events
  (by default, all the available entries are printed)
- 'format' (string, default: '%g'): the C-style formatting string for the
  numeric timings

Definition at line 315 of file SortModuleTimes.py.

316  def FormatTimesAsList(self, format_ = {}):
317  """Prints the collected information into a list.
318 
319  The list of strings includes a statistics ID (based on the key), and
320  a time entry for each of the events stored (with holes for the events
321  with missing time).
322  The format dictionary can contain format directives; the ones supported
323  so far are:
324  - 'max_events' (int): limit the number of events to the first max_events
325  (by default, all the available entries are printed)
326  - 'format' (string, default: '%g'): the C-style formatting string for the
327  numeric timings
328  """
329  if isinstance(self.key, basestring): name = str(self.key)
330  else: name = str(self.key)
331 
332  n = min(self.nEntries(), format_.get('max_events', self.nEntries()))
333  format_str = format_.get('format', '%g')
334  if not self.entries: return [ name, ] + [ "n/a", ] * n
335 
336  output = [ name, ]
337  for i, entry in enumerate(self.entries.values()):
338  if i >= n: break
339  if entry is None or entry.isMissing(): output.append("n/a")
340  else: output.append(format_str % entry.time())
341  # for
return output
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def SortModuleTimes.TimeModuleStatsClass.getEntries (   self)
Returns a list of the event statistics (if tracking the events).

Definition at line 268 of file SortModuleTimes.py.

269  def getEntries(self):
270  """Returns a list of the event statistics (if tracking the events)."""
return [] if self.entries is None else self.entries.values()
def SortModuleTimes.TimeModuleStatsClass.getEvents (   self)
Returns the list of known event keys (if tracking the events).

Definition at line 263 of file SortModuleTimes.py.

264  def getEvents(self):
265  """Returns the list of known event keys (if tracking the events)."""
return [] if self.entries is None else self.entries.keys()
def SortModuleTimes.TimeModuleStatsClass.hasEmptyData (   self)
Returns whethere there are entries without timing information.

Note: throws if not tracking events.

Definition at line 283 of file SortModuleTimes.py.

284  def hasEmptyData(self):
285  """Returns whethere there are entries without timing information.
286 
287  Note: throws if not tracking events.
288  """
return self.nEntries() > self.nEvents()
def SortModuleTimes.TimeModuleStatsClass.nEntries (   self)
Returns the number of recorded entries (throws if not tracking).

Definition at line 273 of file SortModuleTimes.py.

274  def nEntries(self):
275  """Returns the number of recorded entries (throws if not tracking)."""
return len(self.entries)
def SortModuleTimes.TimeModuleStatsClass.nEvents (   self)
Returns the number of valid entries (events with timing).

Definition at line 278 of file SortModuleTimes.py.

279  def nEvents(self):
280  """Returns the number of valid entries (events with timing)."""
return self.n()

Member Data Documentation

SortModuleTimes.TimeModuleStatsClass.entries

Definition at line 226 of file SortModuleTimes.py.

SortModuleTimes.TimeModuleStatsClass.key

Definition at line 225 of file SortModuleTimes.py.


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