def extractTraceWithState(self, traceName, eventRange, traceNameOut = None):
    """
    Extract a portion of a trace including preceding state to form a new trace. The command collects events
    prior to the first extracted event from the trace to set up the same state in the new trace.
    
    @param traceName:     Name of the source trace
    @param eventRange:    Event range to extract
    @param traceNameOut:  Name under which the resulting trace is saved, or the original trace by default.
    """
    if not traceName in self.analyzer.traces:
      self.analyzer.fail("Trace not found: %s" % traceName)
      
    if traceNameOut is None:
      traceNameOut = traceName
      
    trace = self.analyzer.traces[traceName]
    firstEvent, lastEvent = self.analyzer.parseEventRange(trace, eventRange)
    trace = TraceOperations.extractWithState(self.analyzer.project, trace, firstEvent, lastEvent)
      
    self.analyzer.traces[traceNameOut] = trace
    
    self.reportInfo("%d events extracted from trace %s to trace %s." % (len(trace.events), traceName, traceNameOut))
    return trace
dataset/ETHPy150Open skyostil/tracy/src/analyzer/plugins/core/CorePlugin.py/CoreInteractivePlugin.extractTraceWithState/original