Ejemplo n.º 1
0
  def list_outputs(self, args, screen_info=None):
    """Command handler for inputs.

    Show inputs to a given node.

    Args:
      args: Command-line arguments, excluding the command prefix, as a list of
        str.
      screen_info: Optional dict input containing screen information such as
        cols.

    Returns:
      Output text lines as a RichTextLines object.
    """

    # Screen info not currently used by this handler. Include this line to
    # mute pylint.
    _ = screen_info
    # TODO(cais): Use screen info to format the output lines more prettily,
    # e.g., hanging indent of long node names.

    parsed = self._arg_parsers["list_outputs"].parse_args(args)

    output = self._list_inputs_or_outputs(
        parsed.recursive,
        parsed.node_name,
        parsed.depth,
        parsed.control,
        parsed.op_type,
        do_outputs=True)

    node_name = debug_data.get_node_name(parsed.node_name)
    _add_main_menu(output, node_name=node_name, enable_list_outputs=False)

    return output
Ejemplo n.º 2
0
  def print_source(self, args, screen_info=None):
    """Print the content of a source file."""
    del screen_info  # Unused.

    parsed = self._arg_parsers["print_source"].parse_args(args)

    source_annotation = source_utils.annotate_source(
        self._debug_dump,
        parsed.source_file_path,
        do_dumped_tensors=parsed.tensors,
        min_line=parsed.line_begin)

    with open(parsed.source_file_path, "rU") as f:
      source_text = f.read()

    source_lines = source_text.split("\n")
    num_lines = len(source_lines)
    line_num_width = int(np.ceil(np.log10(num_lines))) + 3

    labeled_source_lines = []
    if parsed.line_begin > 1:
      labeled_source_lines.append(
          RL("(... Omitted %d source lines ...)" % (parsed.line_begin - 1),
             "bold"))

    for i, line in enumerate(source_lines[parsed.line_begin - 1:]):
      annotated_line = RL("L%d" % (i + parsed.line_begin), "yellow")
      annotated_line += " " * (line_num_width - len(annotated_line))
      annotated_line += line
      labeled_source_lines.append(annotated_line)

      if i + parsed.line_begin in source_annotation:
        sorted_elements = sorted(source_annotation[i + parsed.line_begin])
        for k, element in enumerate(sorted_elements):
          if k >= parsed.max_elements_per_line:
            labeled_source_lines.append(
                "    (... Omitted %d of %d %s ...)" % (
                    len(sorted_elements) - parsed.max_elements_per_line,
                    len(sorted_elements),
                    "tensor(s)" if parsed.tensors else "op(s)"))
            break

          label = RL(" " * 4)
          if self._debug_dump.debug_watch_keys(
              debug_data.get_node_name(element)):
            attribute = debugger_cli_common.MenuItem("", "pt %s" % element)
          else:
            attribute = "blue"

          label += RL(element, attribute)
          labeled_source_lines.append(label)

    output = debugger_cli_common.rich_text_lines_from_rich_line_list(
        labeled_source_lines)
    _add_main_menu(output, node_name=None)
    return output
Ejemplo n.º 3
0
  def _prepare_cont_call_dump_path_and_run_options(self):
    """Prepare the dump path and RunOptions for next cont() call.

    Returns:
      dump_path: (str) Directory path to which the intermediate tensor will be
        dumped.
      run_options: (config_pb2.RunOptions) The RunOptions containing the tensor
        watch options for this graph.
    """
    run_options = config_pb2.RunOptions()
    dump_path = self._cont_call_dump_path()
    for element_name in self._closure_elements:
      if ":" in element_name:
        debug_utils.add_debug_tensor_watch(
            run_options,
            debug_data.get_node_name(element_name),
            output_slot=debug_data.get_output_slot(element_name),
            debug_urls=["file://" + dump_path])

    return dump_path, run_options
Ejemplo n.º 4
0
    def _prepare_cont_call_dump_path_and_run_options(self):
        """Prepare the dump path and RunOptions for next cont() call.

    Returns:
      dump_path: (str) Directory path to which the intermediate tensor will be
        dumped.
      run_options: (config_pb2.RunOptions) The RunOptions containing the tensor
        watch options for this graph.
    """
        run_options = config_pb2.RunOptions()
        dump_path = self._cont_call_dump_path()
        for element_name in self._closure_elements:
            if ":" in element_name:
                debug_utils.add_debug_tensor_watch(
                    run_options,
                    debug_data.get_node_name(element_name),
                    output_slot=debug_data.get_output_slot(element_name),
                    debug_urls=["file://" + dump_path])

        return dump_path, run_options
Ejemplo n.º 5
0
 def testParseNodeNameInputWorks(self):
   self.assertEqual("a", debug_data.get_node_name("a"))
   self.assertEqual(0, debug_data.get_output_slot("a"))
Ejemplo n.º 6
0
  def testParseTensorNameInputWorks(self):
    self.assertEqual("a", debug_data.get_node_name("a:0"))
    self.assertEqual(0, debug_data.get_output_slot("a:0"))

    self.assertEqual("_b", debug_data.get_node_name("_b:1"))
    self.assertEqual(1, debug_data.get_output_slot("_b:1"))
Ejemplo n.º 7
0
 def testParseNodeNameInputWorks(self):
   self.assertEqual("a", debug_data.get_node_name("a"))
   self.assertEqual(0, debug_data.get_output_slot("a"))
Ejemplo n.º 8
0
  def testParseTensorNameInputWorks(self):
    self.assertEqual("a", debug_data.get_node_name("a:0"))
    self.assertEqual(0, debug_data.get_output_slot("a:0"))

    self.assertEqual("_b", debug_data.get_node_name("_b:1"))
    self.assertEqual(1, debug_data.get_output_slot("_b:1"))