def _ProfileScope(self, profileScopeName): """ A context manager that measures the execution time between enter and exit and stores the elapsed time in the class' metrics dictionary. """ stopwatch = Tf.Stopwatch() collector = Trace.Collector() try: stopwatch.Start() collector.enabled = True collector.BeginEvent(profileScopeName) yield finally: collector.EndEvent(profileScopeName) collector.enabled = False stopwatch.Stop() elapsedTime = stopwatch.seconds self._profileScopeMetrics[profileScopeName] = elapsedTime Tf.Status('%s: %f' % (profileScopeName, elapsedTime)) traceFilePath = os.path.join(self._testDir, '%s.trace' % profileScopeName) Trace.Reporter.globalReporter.Report(traceFilePath) collector.Clear() Trace.Reporter.globalReporter.ClearTree()
def _ProfileScope(self, profileScopeName): """ A context manager that measures the execution time between enter and exit and stores the elapsed time in the class' metrics dictionary. """ stopwatch = Tf.Stopwatch() try: stopwatch.Start() yield finally: stopwatch.Stop() elapsedTime = stopwatch.seconds self._profileScopeMetrics[profileScopeName] = elapsedTime Tf.Status("%s: %f" % (profileScopeName, elapsedTime))
def __enter__(self): self._stopwatch = Tf.Stopwatch() self._stopwatch.Start() self.interval = 0 return self