All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions | Variables
SortModuleTimes Namespace Reference

Classes

class  Stats
 
class  EventKeyClass
 
class  ModuleKeyClass
 
class  EntryDataClass
 
class  TimeModuleStatsClass
 
class  JobStatsClass
 
class  FormatError
 
class  MaxItemLengthsClass
 
class  TabularAlignmentClass
 
class  NoMoreInput
 

Functions

def signed_sqrt
 
def ParseTimeModuleLine
 
def ParseTimeEventLine
 
def OPEN
 
def ParseInputFile
 
def CenterString
 
def LeftString
 
def RightString
 
def JustifyString
 

Variables

string Version = "%(prog)s 1.5"
 
string __doc__ = "Prints statistics of the module timings based on the information from the Timing service."
 
tuple Parser = argparse.ArgumentParser(description=__doc__)
 parse command line arguments More...
 
string help = "log file to be parsed"
 
string const = "EventTable"
 
string action = "store_false"
 
tuple options = Parser.parse_args()
 
tuple AllStats = JobStatsClass( )
 parse all inputs, collect the information More...
 
 EventStats = TimeModuleStatsClass\
 
int nErrors = 0
 
tuple OutputTable = TabularAlignmentClass()
 print the results More...
 

Function Documentation

def SortModuleTimes.CenterString (   s,
  w,
  f = ' ' 
)
Returns the string s centered in a width w, padded by f on both sides.

Definition at line 649 of file SortModuleTimes.py.

650 def CenterString(s, w, f = ' '):
651  """Returns the string s centered in a width w, padded by f on both sides."""
652  leftFillerWidth = max(0, w - len(s)) / 2
653  return f * leftFillerWidth + s + f * (w - leftFillerWidth)
654 # CenterString()
def SortModuleTimes.JustifyString (   s,
  w,
  f = ' ' 
)
Recomputes the spaces between the words in s so that they fill a width w.

The original spacing is lost. The string is split in words by str.split().
The character f is used to create the filling spaces between the words.
Note that the string can result longer than w if the content is too long.

Definition at line 663 of file SortModuleTimes.py.

664 def JustifyString(s, w, f = ' '):
665  """Recomputes the spaces between the words in s so that they fill a width w.
666 
667  The original spacing is lost. The string is split in words by str.split().
668  The character f is used to create the filling spaces between the words.
669  Note that the string can result longer than w if the content is too long.
670  """
671  assert len(f) == 1
672  tokens = s.split(f)
673  if len(tokens) <= 1: return CenterString(s, w, f=f)
674 
675  # example: 6 words, 7 spaces (in 5 spacers)
676  spaceSize = max(1., float(f - sum(map(len, tokens))) / (len(tokens) - 1))
677  # = 1.4
678  totalSpace = 0.
679  assignedSpace = 0
680  s = tokens[0]
681  for token in tokens[1:]:
682  totalSpace += spaceSize # 0 => 1.4 => 2.8 => 4.2 => 5.6 => 7.0
683  tokenSpace = int(totalSpace - assignedSpace) # int(1.4 1.8 2.2 1.6 2.0)
684  s += f * tokenSpace + token # spaces: 1 + 1 + 2 + 1 + 2
685  assignedSpace += tokenSpace # 0 => 1 => 2 => 4 => 5 => 7
686  # for
687  assert assignedSpace == w
688  return s
689 # JustifyString()
690 
def SortModuleTimes.LeftString (   s,
  w,
  f = ' ' 
)
Returns the string s in a width w, padded by f on the right.

Definition at line 655 of file SortModuleTimes.py.

656 def LeftString(s, w, f = ' '):
657  """Returns the string s in a width w, padded by f on the right."""
658  return s + f * max(0, w - len(s))
def SortModuleTimes.OPEN (   Path,
  mode = 'r' 
)
Open a file (possibly a compressed one).

Support for modes other than 'r' (read-only) are questionable.

Definition at line 499 of file SortModuleTimes.py.

500 def OPEN(Path, mode = 'r'):
501  """Open a file (possibly a compressed one).
502 
503  Support for modes other than 'r' (read-only) are questionable.
504  """
505  if Path.endswith('.bz2'): return bz2.BZ2File(Path, mode)
506  if Path.endswith('.gz'): return gzip.GzipFile(Path, mode)
507  return open(Path, mode)
508 # OPEN()
509 
def SortModuleTimes.ParseInputFile (   InputFilePath,
  AllStats,
  EventStats,
  options 
)
Parses a log file.

The art log file at InputFilePath is parsed.
The per-module statistics are added to the existing in AllStats (an instance
of JobStatsClass), creating new ones as needed. Similarly, per-event
statistics are added to EventStats (a TimeModuleStatsClass instance).

options class can contain the following members:
- Permissive (default: false): do not bail out when a format error is found;
  the entry is typically skipped. This often happens because the output line
  of the timing information is interrupted by some other output.
- MaxEvents (default: all events): collect statistics for at most MaxEvents
  events (always the first ones)
- CheckDuplicates (default: false): enables the single-event tracking, that
  allows to check for duplicates

It returns the number of errors encountered.

Definition at line 510 of file SortModuleTimes.py.

511 def ParseInputFile(InputFilePath, AllStats, EventStats, options):
512  """Parses a log file.
513 
514  The art log file at InputFilePath is parsed.
515  The per-module statistics are added to the existing in AllStats (an instance
516  of JobStatsClass), creating new ones as needed. Similarly, per-event
517  statistics are added to EventStats (a TimeModuleStatsClass instance).
518 
519  options class can contain the following members:
520  - Permissive (default: false): do not bail out when a format error is found;
521  the entry is typically skipped. This often happens because the output line
522  of the timing information is interrupted by some other output.
523  - MaxEvents (default: all events): collect statistics for at most MaxEvents
524  events (always the first ones)
525  - CheckDuplicates (default: false): enables the single-event tracking, that
526  allows to check for duplicates
527 
528  It returns the number of errors encountered.
529  """
530  def CompleteEvent(CurrentEvent, EventStats, AllStats):
531  """Make sure that CurrentEvent is known to all stats."""
532  EventStats.complete(( CurrentEvent, ))
533  for ModuleStats in AllStats:
534  ModuleStats.complete(EventStats.getEvents())
535  # CompleteEvent()
536 
537 
538  LogFile = OPEN(InputFilePath, 'r')
539 
540  nErrors = 0
541  LastLine = None
542  CurrentEvent = None
543  for iLine, line in enumerate(LogFile):
544 
545  line = line.strip()
546  if line == LastLine: continue # duplicate line
547  LastLine = line
548 
549  if line.startswith("TimeModule> "):
550 
551  try:
552  TimeData = ParseTimeModuleLine(line)
553  except FormatError, e:
554  nErrors += 1
555  msg = "Format error on '%s'@%d" % (InputFilePath, iLine + 1)
556  try: msg += " (%s)" % str(e.data['type'])
557  except KeyError: pass
558  try: msg += ", for event " + str(e.data['event'])
559  except KeyError: pass
560  try: msg += ", module " + str(e.data['module'])
561  except KeyError: pass
562  print >>sys.stderr, msg
563  if not options.Permissive: raise
564  else: continue
565  # try ... except
566 
567  try:
568  ModuleStats = AllStats[TimeData.module]
569  except KeyError:
570  ModuleStats = TimeModuleStatsClass \
571  (TimeData.module, bTrackEntries=options.CheckDuplicates)
572  AllStats[TimeData.module] = ModuleStats
573  #
574 
575  ModuleStats.add(TimeData)
576  elif line.startswith("TimeEvent> "):
577  try:
578  TimeData = ParseTimeEventLine(line)
579  except FormatError, e:
580  nErrors += 1
581  msg = "Format error on '%s'@%d" % (InputFilePath, iLine + 1)
582  try: msg += " (%s)" % str(e.data['type'])
583  except KeyError: pass
584  try: msg += ", for event " + str(e.data['event'])
585  except KeyError: pass
586  try: msg += ", module " + str(e.data['module'])
587  except KeyError: pass
588  print >>sys.stderr, msg
589  if not options.Permissive: raise
590  else: continue
591  # try ... except
592 
593  EventStats.add(TimeData)
594  if (options.MaxEvents >= 0) \
595  and (EventStats.n() >= options.MaxEvents):
596  if CurrentEvent: CompleteEvent(CurrentEvent, EventStats, AllStats)
597  raise NoMoreInput
598  else:
599  TimeData = None
600  continue
601 
602  if (CurrentEvent != TimeData.eventKey):
603  if TimeData and CurrentEvent:
604  CompleteEvent(CurrentEvent, EventStats, AllStats)
605  CurrentEvent = TimeData.eventKey
606  # if
607  # for line in log file
608  if CurrentEvent: CompleteEvent(CurrentEvent, EventStats, AllStats)
609 
610  return nErrors
611 # ParseInputFile()
612 
613 
614 #
615 # output
616 #
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def SortModuleTimes.ParseTimeEventLine (   line)
Parses a line to extract event timing information.

The line must be known to contain event timing information.
The function returns a EntryDataClass including the timing information, or
raises a FormatError if the line has no valid format.

Format 1 (20140226):

TimeEvent> run: 1 subRun: 0 event: 10 0.231838

Definition at line 460 of file SortModuleTimes.py.

461 def ParseTimeEventLine(line):
462  """Parses a line to extract event timing information.
463 
464  The line must be known to contain event timing information.
465  The function returns a EntryDataClass including the timing information, or
466  raises a FormatError if the line has no valid format.
467 
468  Format 1 (20140226):
469 
470  TimeEvent> run: 1 subRun: 0 event: 10 0.231838
471  """
472  Tokens = line.split()
473 
474  EventKey = None
475  time = None
476  try:
477  EventKey = EventKeyClass((int(Tokens[2]), int(Tokens[4]), int(Tokens[6])))
478  time = float(Tokens[7])
479  except Exception, e:
480  raise FormatError(
481  "TimeEvent format not recognized: '%s' (%s)" % (line, str(e)),
482  type="Event", event=EventKey
483  )
484  # try ... except
485 
486  if (Tokens[0] != 'TimeEvent>') \
487  or (Tokens[1] != 'run:') \
488  or (Tokens[3] != 'subRun:') \
489  or (Tokens[5] != 'event:') \
490  or (len(Tokens) != 8) \
491  :
492  raise FormatError("TimeEvent format not recognized: '%s'" % line,
493  type="Event", event=EventKey)
494  # if
495 
496  return EntryDataClass(EventKey, time=time)
497 # ParseTimeEventLine()
498 
def SortModuleTimes.ParseTimeModuleLine (   line)
Parses a line to extract module timing information.

The line must be known to contain module timing information.
The function returns a EntryDataClass including the timing information, or
raises a FormatError if the line has no valid format.

Format 1 (20140226):

TimeModule> run: 1 subRun: 0 event: 10 beziertrackercc BezierTrackerModule 0.231838

Definition at line 416 of file SortModuleTimes.py.

417 def ParseTimeModuleLine(line):
418  """Parses a line to extract module timing information.
419 
420  The line must be known to contain module timing information.
421  The function returns a EntryDataClass including the timing information, or
422  raises a FormatError if the line has no valid format.
423 
424  Format 1 (20140226):
425 
426  TimeModule> run: 1 subRun: 0 event: 10 beziertrackercc BezierTrackerModule 0.231838
427  """
428  Tokens = line.split()
429 
430  ModuleKey = None
431  EventKey = None
432  time = None
433 
434  # Format 1 parsing:
435  try:
436  EventKey = EventKeyClass((int(Tokens[2]), int(Tokens[4]), int(Tokens[6])))
437  ModuleKey = ModuleKeyClass((Tokens[7], Tokens[8]))
438  time=float(Tokens[9])
439  except Exception, e:
440  raise FormatError(
441  "TimeModule format not recognized: '%s' (%s)" % (line, str(e)),
442  type="Module", event=EventKey, module=ModuleKey
443  )
444  # try ... except
445 
446  # validation of Format 1
447  if (Tokens[0] != 'TimeModule>') \
448  or (Tokens[1] != 'run:') \
449  or (Tokens[3] != 'subRun:') \
450  or (Tokens[5] != 'event:') \
451  or (len(Tokens) != 10) \
452  :
453  raise FormatError \
454  ("TimeModule format not recognized: '%s'" % line, type="Module")
455  # if
456 
457  return EntryDataClass(EventKey, module=ModuleKey, time=time)
458 # ParseTimeModuleLine()
459 
def SortModuleTimes.RightString (   s,
  w,
  f = ' ' 
)
Returns the string s in a width w, padded by f on the left.

Definition at line 659 of file SortModuleTimes.py.

660 def RightString(s, w, f = ' '):
661  """Returns the string s in a width w, padded by f on the left."""
662  return f * max(0, w - len(s)) + s
def SortModuleTimes.signed_sqrt (   value)
Returns sign(x) * sqrt(abs(x))

Definition at line 38 of file SortModuleTimes.py.

38 
39 def signed_sqrt(value):
40  """Returns sign(x) * sqrt(abs(x))"""
41  if value >= 0.: return math.sqrt(value)
42  else: return -math.sqrt(-value)
43 # signed_sqrt()
44 

Variable Documentation

string SortModuleTimes.__doc__ = "Prints statistics of the module timings based on the information from the Timing service."

Definition at line 33 of file SortModuleTimes.py.

string SortModuleTimes.action = "store_false"

Definition at line 873 of file SortModuleTimes.py.

tuple SortModuleTimes.AllStats = JobStatsClass( )

parse all inputs, collect the information

Definition at line 890 of file SortModuleTimes.py.

string SortModuleTimes.const = "EventTable"

Definition at line 871 of file SortModuleTimes.py.

SortModuleTimes.EventStats = TimeModuleStatsClass\

Definition at line 892 of file SortModuleTimes.py.

string SortModuleTimes.help = "log file to be parsed"

Definition at line 867 of file SortModuleTimes.py.

int SortModuleTimes.nErrors = 0

Definition at line 897 of file SortModuleTimes.py.

tuple SortModuleTimes.options = Parser.parse_args()

Definition at line 880 of file SortModuleTimes.py.

tuple SortModuleTimes.OutputTable = TabularAlignmentClass()

print the results

Definition at line 916 of file SortModuleTimes.py.

tuple SortModuleTimes.Parser = argparse.ArgumentParser(description=__doc__)

parse command line arguments

Definition at line 862 of file SortModuleTimes.py.

string SortModuleTimes.Version = "%(prog)s 1.5"

Definition at line 32 of file SortModuleTimes.py.