Example #1
0
    def __init__(self, trace_path=None):
        """
        <Purpose>
          Creates a trace object containing all the information extracted from a 
          trace file.
        
        <Arguments>
          trace_path:
            The path to the trace file containing all needed information.
        
        <Exceptions>
          IOError:
            If no trace_path is given.
          
          IOError:
            If the trace_path given is not a file.
        
        <Side Effects>
          None
        
        <Returns>
          None
        """

        self.trace_path = trace_path

        # Were we given a trace path?
        if self.trace_path == None:
            raise IOError("A trace file is needed to initialize a Trace object")

        # does this file exist?
        if not os.path.exists(self.trace_path):
            raise IOError("Could not find trace file `" + self.trace_path + "`")

        # detect tracing utility used to generate the trace file. peek here to avoid
        # re-initializing the file.
        self.tracing_utility = self._detect_tracing_utility()

        # select parser according to the tracing utility.
        if self.tracing_utility == "strace":
            self.parser = StraceParser(self.trace_path)
        elif self.tracing_utility == "truss":
            self.parser = TrussParser(self.trace_path)
        else:
            raise Exception("Unknown parser when attempting to parse trace.")

        # parse system calls
        self.syscalls = self.parser.parse_trace()

        # get platform information
        self.platform = sys.platform