示例#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
示例#2
0
class Trace:
    """
    <Purpose>
      This object represents an entire system call trace, which means that it 
      holds all the information extracted from a system call trace file created by
      an interposition utility such as the strace utility on Linux, the truss 
      utility on Solaris or the dtrace utility on BSD and OSX platforms.
    
    <Attributes>
      self.trace_path:
        The path to the file containing the traced system calls.
      
      self.tracing_utility:
        The detected tracing utility used to generate the trace file, e.g strace.
      
      self.parser:
        The parser to use in order to extract the information from the trace file.
        The choice of parser depends on the tracing utility used to generate the 
        trace file, i.e self.tracing_utility.
    
      self.syscalls:
        This variable holds all the parsed system calls. It is a list of Syscall
        objects returned by the parser.
    
      self.platform:
        The platform in which the trace is parsed on (sys.platform). This is
        especially useful when creating a trace bundle containing not only the
        parsed system calls but also a representation of all the files referenced
        in trace file.
    """

    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

        # - in bundle can store metadata what command / date / OS / etc the trace was
        # - gathered from.


    def _detect_tracing_utility(self):
        """
        <Purpose>
          Using the trace file given in self.trace_path figure out which tracing 
          utility was used to generate this trace file.
        
        <Arguments>
          None
        
        <Exceptions>
          None
        
        <Side Effects>
          None
        
        <Returns>
          tracing_utility:
            The name of the tracing utility used to generate the trace file.
        """

        # TODO: Unimplemented. return strace for now
        tracing_utility = "strace"

        return tracing_utility

    def __repr__(self):
        representation = "<Trace\nplatform=" + self.platform \
                       + "\ntrace_path=" + self.trace_path \
                       + "\ntracing_utility=" + self.tracing_utility \
                       + "\nparser=" + str(self.parser) \
                       + "\ntraced_syscalls=" + str(len(self.syscalls)) + ">"

        return representation