Beispiel #1
0
                    else:
                        recv_families[fam] = 1

            else:
                stats["recv_errs"] += 1
                err_label = action[2][1]
                if err_label in recv_err_labels:
                    recv_err_labels[err_label] += 1
                else:
                    recv_err_labels[err_label] = 1

        elif action_name == "socket":
            # ('socket_syscall', (['PF_FILE'], ['SOCK_STREAM', 'SOCK_CLOEXEC', 'SOCK_NONBLOCK'], 0), (4, None))
            if action[2][0] != -1:
                sockets[action[2][0]] = action[1][0][0]

        elif action_name == "accept":
            # ('accept_syscall', (3,), (4, (['AF_INET'], 50383, '127.0.0.1', 16)))
            if action[2][0] != -1:
                accepts[action[2][0]] = action[2][1][0][0]


if __name__ == "__main__":
    if len(sys.argv) < 2 or len(sys.argv) > 3:
        raise Exception("Please provide: trace file [file_path]")

    fh = open(sys.argv[1], "r")
    actions = parser_strace_calls.parse_trace(fh)

    net_stat(actions)
    print_net_stats()
Beispiel #2
0
def generate_trace_bundle(trace_path, parser=None):
    if parser == None:
        # parser was not given. try to infer from the file extension.
        if trace_path.endswith(".strace"):
            parser = "strace"
        elif trace_path.endswith(".truss"):
            parser = "truss"
        elif trace_path.endswith(".dtrace"):
            parser = "dtrace"
        else:
            raise Exception("Could not infer parser from the file extension")

    # dtrace traces are parsed the exact same way as strace traces.
    if parser == "dtrace":
        parser = "strace"

    assert (parser in ["strace", "truss"])

    fh = open(trace_path, "r")

    # parse actions from file, using the correct parser
    actions = None
    if parser == "strace":
        actions = parser_strace_calls.parse_trace(fh)
    elif parser == "truss":
        actions = parser_truss_calls.parse_trace(fh)
    else:
        raise Exception("Unknown parser when attempting to parse trace.")

    fh.close()

    if DEBUG:
        for action in actions:
            print action

    # generate the initial file system needed by the model.
    generate_lind_fs.generate_fs(actions, trace_path)

    # pickle the trace
    pickle_name = "actions.pickle"
    pickle_file = open(pickle_name, 'w')
    cPickle.dump(actions, pickle_file)
    pickle_file.close()

    # Now we have everything we need, create the trace bundle which will include
    # the trace pickle and the lind fs files.

    # first find a name for the bundle archive.
    head, bundle_name = os.path.split(trace_path)

    # if the bundle_name already exists, append a number.
    temp_count = ''
    bundle_extension = ".trace_bundle"
    while os.path.exists(bundle_name + temp_count + bundle_extension):
        if temp_count == '':
            temp_count = '1'
        else:
            temp_count = str(int(temp_count) + 1)
    bundle_name += temp_count + bundle_extension

    # Create the bundle archive.
    tar = tarfile.open(bundle_name, "w")

    # add the original trace file.
    original_trace_name = "original_trace." + parser
    # let's copy it locally and rename it first.
    shutil.copyfile(trace_path, original_trace_name)
    tar.add(original_trace_name)

    # add the pickle file
    tar.add(pickle_name)

    # add the lind fs metadata file
    if not os.path.exists("lind.metadata"):
        raise Exception("Lind fs metadata file not found.")
    tar.add("lind.metadata")

    # add the lind fs data files
    for fname in os.listdir(os.getcwd()):
        if fname.startswith("linddata."):
            tar.add(fname)

    tar.close()

    # Finally, clean up all intermediate files
    os.remove(original_trace_name)
    os.remove(pickle_name)
    os.remove("lind.metadata")
    for fname in os.listdir(os.getcwd()):
        if fname.startswith("linddata."):
            os.remove(fname)
Beispiel #3
0
      else:
        stats["write_errs"] += 1
        err_label = action[2][1]
        if err_label in write_err_labels:
          write_err_labels[err_label] += 1
        else:
          write_err_labels[err_label] = 1

    # keep track of all the file paths.
    if action_name in actions_with_path:
      if action_name in syscall_count:
        syscall_count[action_name] += 1
      else:
        syscall_count[action_name] = 1

      path = action[1][0]
      if path not in file_paths:
        file_paths.append(path)



if __name__ == "__main__":
  if len(sys.argv) < 2 or len(sys.argv) > 3:
    raise Exception("Please provide: trace file [file_path]")
  
  fh = open(sys.argv[1], "r")
  actions = parser_strace_calls.parse_trace(fh)
  
  io_stat(actions)
  print_io_stats()
Beispiel #4
0
def generate_trace_bundle(trace_path, parser=None):
  if parser == None:
    # parser was not given. try to infer from the file extension.
    if trace_path.endswith(".strace"):
      parser = "strace"
    elif trace_path.endswith(".truss"):
      parser = "truss"
    elif trace_path.endswith(".dtrace"):
      parser = "dtrace"
    else:
      raise Exception("Could not infer parser from the file extension")
  
  # dtrace traces are parsed the exact same way as strace traces.
  if parser == "dtrace":
    parser = "strace"

  assert(parser in ["strace", "truss"])

  fh = open(trace_path, "r")
  
  # parse actions from file, using the correct parser
  actions = None
  if parser == "strace":
    actions = parser_strace_calls.parse_trace(fh)
  elif parser == "truss":
    actions = parser_truss_calls.parse_trace(fh)
  else:
    raise Exception("Unknown parser when attempting to parse trace.")
  
  fh.close()

  if DEBUG:
    for action in actions:
      print action

  # generate the initial file system needed by the model.
  generate_lind_fs.generate_fs(actions, trace_path)
  
  # pickle the trace
  pickle_name = "actions.pickle"
  pickle_file = open(pickle_name, 'w')
  cPickle.dump(actions, pickle_file)
  pickle_file.close()

  # Now we have everything we need, create the trace bundle which will include 
  # the trace pickle and the lind fs files.
  
  # first find a name for the bundle archive.
  head, bundle_name = os.path.split(trace_path)
  
  # if the bundle_name already exists, append a number.
  temp_count = ''
  bundle_extension = ".trace_bundle"
  while os.path.exists(bundle_name + temp_count + bundle_extension):
    if temp_count == '':
      temp_count = '1'
    else:
      temp_count = str(int(temp_count) + 1)
  bundle_name += temp_count + bundle_extension
  
  # Create the bundle archive.
  tar = tarfile.open(bundle_name, "w")
  
  # add the original trace file.
  original_trace_name = "original_trace." + parser
  # let's copy it locally and rename it first.
  shutil.copyfile(trace_path, original_trace_name)
  tar.add(original_trace_name)

  # add the pickle file
  tar.add(pickle_name)
  
  # add the lind fs metadata file
  if not os.path.exists("lind.metadata"):
    raise Exception("Lind fs metadata file not found.")
  tar.add("lind.metadata")
  
  # add the lind fs data files
  for fname in os.listdir(os.getcwd()):
    if fname.startswith("linddata."):
      tar.add(fname)
  
  tar.close()
  
  # Finally, clean up all intermediate files
  os.remove(original_trace_name)
  os.remove(pickle_name)
  os.remove("lind.metadata")
  for fname in os.listdir(os.getcwd()):
    if fname.startswith("linddata."):
      os.remove(fname)