Classes | Functions | Variables
SortModuleTimes Namespace Reference

Classes

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

Functions

def signed_sqrt (value)
 
def ParseTimeModuleLine (line)
 
def ParseTimeEventLine (line)
 
def OPEN (Path, mode='r')
 
def ParseInputFile (InputFilePath, AllStats, EventStats, options)
 
def CenterString (s, w, f=' ')
 
def LeftString (s, w, f=' ')
 
def RightString (s, w, f=' ')
 
def JustifyString (s, w, f=' ')
 

Variables

string Version = "%(prog)s 1.5"
 
string __doc__ = "Prints statistics of the module timings based on the information from the Timing service."
 
 Parser = argparse.ArgumentParser(description=__doc__)
 parse command line arguments More...
 
 PresentMode
 
 metavar
 
 nargs
 
 help
 
 dest
 
 action
 
 const
 
 type
 
 int
 
 default
 
 version
 
 options = Parser.parse_args()
 
 CheckDuplicates
 
 AllStats = JobStatsClass( )
 parse all inputs, collect the information More...
 
 EventStats = TimeModuleStatsClass\
 
 bTrackEntries
 
int nErrors = 0
 
 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.

649 def CenterString(s, w, f = ' '):
650  """Returns the string s centered in a width w, padded by f on both sides."""
651  leftFillerWidth = max(0, w - len(s)) / 2
652  return f * leftFillerWidth + s + f * (w - leftFillerWidth)
653 # CenterString()
654 
def CenterString(s, w, f=' ')
static int max(int a, int b)
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.

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

655 def LeftString(s, w, f = ' '):
656  """Returns the string s in a width w, padded by f on the right."""
657  return s + f * max(0, w - len(s))
658 
def LeftString(s, w, f=' ')
static int max(int a, int b)
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.

499 def OPEN(Path, mode = 'r'):
500  """Open a file (possibly a compressed one).
501 
502  Support for modes other than 'r' (read-only) are questionable.
503  """
504  if Path.endswith('.bz2'): return bz2.BZ2File(Path, mode)
505  if Path.endswith('.gz'): return gzip.GzipFile(Path, mode)
506  return open(Path, mode)
507 # OPEN()
508 
509 
def OPEN(Path, mode='r')
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.

510 def ParseInputFile(InputFilePath, AllStats, EventStats, options):
511  """Parses a log file.
512 
513  The art log file at InputFilePath is parsed.
514  The per-module statistics are added to the existing in AllStats (an instance
515  of JobStatsClass), creating new ones as needed. Similarly, per-event
516  statistics are added to EventStats (a TimeModuleStatsClass instance).
517 
518  options class can contain the following members:
519  - Permissive (default: false): do not bail out when a format error is found;
520  the entry is typically skipped. This often happens because the output line
521  of the timing information is interrupted by some other output.
522  - MaxEvents (default: all events): collect statistics for at most MaxEvents
523  events (always the first ones)
524  - CheckDuplicates (default: false): enables the single-event tracking, that
525  allows to check for duplicates
526 
527  It returns the number of errors encountered.
528  """
529  def CompleteEvent(CurrentEvent, EventStats, AllStats):
530  """Make sure that CurrentEvent is known to all stats."""
531  EventStats.complete(( CurrentEvent, ))
532  for ModuleStats in AllStats:
533  ModuleStats.complete(EventStats.getEvents())
534  # CompleteEvent()
535 
536 
537  LogFile = OPEN(InputFilePath, 'r')
538 
539  nErrors = 0
540  LastLine = None
541  CurrentEvent = None
542  for iLine, line in enumerate(LogFile):
543 
544  line = line.strip()
545  if line == LastLine: continue # duplicate line
546  LastLine = line
547 
548  if line.startswith("TimeModule> "):
549 
550  try:
551  TimeData = ParseTimeModuleLine(line)
552  except FormatError, e:
553  nErrors += 1
554  msg = "Format error on '%s'@%d" % (InputFilePath, iLine + 1)
555  try: msg += " (%s)" % str(e.data['type'])
556  except KeyError: pass
557  try: msg += ", for event " + str(e.data['event'])
558  except KeyError: pass
559  try: msg += ", module " + str(e.data['module'])
560  except KeyError: pass
561  print >>sys.stderr, msg
562  if not options.Permissive: raise
563  else: continue
564  # try ... except
565 
566  try:
567  ModuleStats = AllStats[TimeData.module]
568  except KeyError:
569  ModuleStats = TimeModuleStatsClass \
570  (TimeData.module, bTrackEntries=options.CheckDuplicates)
571  AllStats[TimeData.module] = ModuleStats
572  #
573 
574  ModuleStats.add(TimeData)
575  elif line.startswith("TimeEvent> "):
576  try:
577  TimeData = ParseTimeEventLine(line)
578  except FormatError, e:
579  nErrors += 1
580  msg = "Format error on '%s'@%d" % (InputFilePath, iLine + 1)
581  try: msg += " (%s)" % str(e.data['type'])
582  except KeyError: pass
583  try: msg += ", for event " + str(e.data['event'])
584  except KeyError: pass
585  try: msg += ", module " + str(e.data['module'])
586  except KeyError: pass
587  print >>sys.stderr, msg
588  if not options.Permissive: raise
589  else: continue
590  # try ... except
591 
592  EventStats.add(TimeData)
593  if (options.MaxEvents >= 0) \
594  and (EventStats.n() >= options.MaxEvents):
595  if CurrentEvent: CompleteEvent(CurrentEvent, EventStats, AllStats)
596  raise NoMoreInput
597  else:
598  TimeData = None
599  continue
600 
601  if (CurrentEvent != TimeData.eventKey):
602  if TimeData and CurrentEvent:
603  CompleteEvent(CurrentEvent, EventStats, AllStats)
604  CurrentEvent = TimeData.eventKey
605  # if
606  # for line in log file
607  if CurrentEvent: CompleteEvent(CurrentEvent, EventStats, AllStats)
608 
609  return nErrors
610 # ParseInputFile()
611 
612 
613 #
614 # output
615 #
616 
def OPEN(Path, mode='r')
def ParseTimeEventLine(line)
def ParseInputFile(InputFilePath, AllStats, EventStats, options)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def ParseTimeModuleLine(line)
static QCString str
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  """Parses a line to extract event timing information.
462 
463  The line must be known to contain event timing information.
464  The function returns a EntryDataClass including the timing information, or
465  raises a FormatError if the line has no valid format.
466 
467  Format 1 (20140226):
468 
469  TimeEvent> run: 1 subRun: 0 event: 10 0.231838
470  """
471  Tokens = line.split()
472 
473  EventKey = None
474  time = None
475  try:
476  EventKey = EventKeyClass((int(Tokens[2]), int(Tokens[4]), int(Tokens[6])))
477  time = float(Tokens[7])
478  except Exception, e:
479  raise FormatError(
480  "TimeEvent format not recognized: '%s' (%s)" % (line, str(e)),
481  type="Event", event=EventKey
482  )
483  # try ... except
484 
485  if (Tokens[0] != 'TimeEvent>') \
486  or (Tokens[1] != 'run:') \
487  or (Tokens[3] != 'subRun:') \
488  or (Tokens[5] != 'event:') \
489  or (len(Tokens) != 8) \
490  :
491  raise FormatError("TimeEvent format not recognized: '%s'" % line,
492  type="Event", event=EventKey)
493  # if
494 
495  return EntryDataClass(EventKey, time=time)
496 # ParseTimeEventLine()
497 
498 
def ParseTimeEventLine(line)
static QCString str
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  """Parses a line to extract module timing information.
418 
419  The line must be known to contain module timing information.
420  The function returns a EntryDataClass including the timing information, or
421  raises a FormatError if the line has no valid format.
422 
423  Format 1 (20140226):
424 
425  TimeModule> run: 1 subRun: 0 event: 10 beziertrackercc BezierTrackerModule 0.231838
426  """
427  Tokens = line.split()
428 
429  ModuleKey = None
430  EventKey = None
431  time = None
432 
433  # Format 1 parsing:
434  try:
435  EventKey = EventKeyClass((int(Tokens[2]), int(Tokens[4]), int(Tokens[6])))
436  ModuleKey = ModuleKeyClass((Tokens[7], Tokens[8]))
437  time=float(Tokens[9])
438  except Exception, e:
439  raise FormatError(
440  "TimeModule format not recognized: '%s' (%s)" % (line, str(e)),
441  type="Module", event=EventKey, module=ModuleKey
442  )
443  # try ... except
444 
445  # validation of Format 1
446  if (Tokens[0] != 'TimeModule>') \
447  or (Tokens[1] != 'run:') \
448  or (Tokens[3] != 'subRun:') \
449  or (Tokens[5] != 'event:') \
450  or (len(Tokens) != 10) \
451  :
452  raise FormatError \
453  ("TimeModule format not recognized: '%s'" % line, type="Module")
454  # if
455 
456  return EntryDataClass(EventKey, module=ModuleKey, time=time)
457 # ParseTimeModuleLine()
458 
459 
def ParseTimeModuleLine(line)
static QCString str
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.

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

Definition at line 38 of file SortModuleTimes.py.

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

Variable Documentation

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

Definition at line 33 of file SortModuleTimes.py.

SortModuleTimes.action

Definition at line 870 of file SortModuleTimes.py.

SortModuleTimes.AllStats = JobStatsClass( )

parse all inputs, collect the information

Definition at line 890 of file SortModuleTimes.py.

SortModuleTimes.bTrackEntries

Definition at line 893 of file SortModuleTimes.py.

SortModuleTimes.CheckDuplicates

Definition at line 883 of file SortModuleTimes.py.

SortModuleTimes.const

Definition at line 871 of file SortModuleTimes.py.

SortModuleTimes.default

Definition at line 874 of file SortModuleTimes.py.

SortModuleTimes.dest

Definition at line 870 of file SortModuleTimes.py.

SortModuleTimes.EventStats = TimeModuleStatsClass\

Definition at line 892 of file SortModuleTimes.py.

SortModuleTimes.help

Definition at line 867 of file SortModuleTimes.py.

SortModuleTimes.int

Definition at line 874 of file SortModuleTimes.py.

SortModuleTimes.metavar

Definition at line 866 of file SortModuleTimes.py.

SortModuleTimes.nargs

Definition at line 866 of file SortModuleTimes.py.

int SortModuleTimes.nErrors = 0

Definition at line 897 of file SortModuleTimes.py.

SortModuleTimes.options = Parser.parse_args()

Definition at line 880 of file SortModuleTimes.py.

SortModuleTimes.OutputTable = TabularAlignmentClass()

print the results

Definition at line 916 of file SortModuleTimes.py.

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

parse command line arguments

Definition at line 862 of file SortModuleTimes.py.

SortModuleTimes.PresentMode

Definition at line 863 of file SortModuleTimes.py.

SortModuleTimes.type

Definition at line 874 of file SortModuleTimes.py.

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

Definition at line 32 of file SortModuleTimes.py.

SortModuleTimes.version

Definition at line 878 of file SortModuleTimes.py.