예제 #1
0
def create_graph_debug_info_def(operations):
    """Construct and returns a `GraphDebugInfo` protocol buffer.

  Args:
    operations: An iterable of op.Operation objects having _traceback members.

  Returns:
    GraphDebugInfo protocol buffer.

  Raises:
    TypeError: If the arguments are not of the correct proto buffer type.
  """
    # Creates an empty GraphDebugInfoDef proto.
    graph_debug_info_def = graph_debug_info_pb2.GraphDebugInfo()

    # Gets the file names and line numbers for the exported node names. Also
    # collects the unique file names.
    all_file_names = set()
    node_to_trace = {}
    for op in operations:
        # Gets the stack trace of the operation and then the file location.
        node_name = op.name
        node_to_trace[node_name] = error_interpolation.compute_useful_stack(op)
        for trace in node_to_trace[node_name]:
            all_file_names.add(trace[0])

    # Sets the `files` field in the GraphDebugInfo proto
    graph_debug_info_def.files.extend(all_file_names)

    # Builds a mapping between file names and index of the `files` field, so we
    # only store the indexes for the nodes in the GraphDebugInfo.
    file_to_index = dict([(y, x)
                          for x, y in enumerate(graph_debug_info_def.files)])

    # Creates the FileLineCol proto for each node and sets the value in the
    # GraphDebugInfo proto. We only store the file name index for each node to
    # save the storage space.
    for node_name, trace in node_to_trace.items():
        trace_def = graph_debug_info_def.traces[node_name]
        for file_name, line, func, code in trace:
            file_index = file_to_index[file_name]
            trace_def.file_line_cols.add(file_index=file_index,
                                         line=line,
                                         func=func,
                                         code=code)

    return graph_debug_info_def
예제 #2
0
def create_graph_debug_info_def(operations):
  """Construct and returns a `GraphDebugInfo` protocol buffer.

  Args:
    operations: An iterable of op.Operation objects having _traceback members.

  Returns:
    GraphDebugInfo protocol buffer.

  Raises:
    TypeError: If the arguments are not of the correct proto buffer type.
  """
  # Creates an empty GraphDebugInfoDef proto.
  graph_debug_info_def = graph_debug_info_pb2.GraphDebugInfo()

  # Gets the file names and line numbers for the exported node names. Also
  # collects the unique file names.
  all_file_names = set()
  node_to_trace = {}
  for op in operations:
    # Gets the stack trace of the operation and then the file location.
    node_name = op.name
    node_to_trace[node_name] = error_interpolation.compute_useful_stack(op)
    for trace in node_to_trace[node_name]:
      all_file_names.add(trace[0])

  # Sets the `files` field in the GraphDebugInfo proto
  graph_debug_info_def.files.extend(all_file_names)

  # Builds a mapping between file names and index of the `files` field, so we
  # only store the indexes for the nodes in the GraphDebugInfo.
  file_to_index = dict(
      [(y, x) for x, y in enumerate(graph_debug_info_def.files)])

  # Creates the FileLineCol proto for each node and sets the value in the
  # GraphDebugInfo proto. We only store the file name index for each node to
  # save the storage space.
  for node_name, trace in node_to_trace.items():
    trace_def = graph_debug_info_def.traces[node_name]
    for file_name, line, func, code in trace:
      file_index = file_to_index[file_name]
      trace_def.file_line_cols.add(
          file_index=file_index, line=line, func=func, code=code)

  return graph_debug_info_def