def list_profile(self, args, screen_info=None):
    """Command handler for list_profile.

    List per-operation profile information.

    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_cols = 80
    if screen_info and "cols" in screen_info:
      screen_cols = screen_info["cols"]

    parsed = self._arg_parsers["list_profile"].parse_args(args)
    op_time_interval = (command_parser.parse_time_interval(parsed.op_time)
                        if parsed.op_time else None)
    exec_time_interval = (
        command_parser.parse_time_interval(parsed.execution_time)
        if parsed.execution_time else None)
    node_name_regex = (re.compile(parsed.node_name_filter)
                       if parsed.node_name_filter else None)
    file_path_regex = (re.compile(parsed.file_path_filter)
                       if parsed.file_path_filter else None)
    op_type_regex = (re.compile(parsed.op_type_filter)
                     if parsed.op_type_filter else None)

    output = debugger_cli_common.RichTextLines([""])
    device_name_regex = (re.compile(parsed.device_name_filter)
                         if parsed.device_name_filter else None)
    data_generator = self._get_profile_data_generator()
    device_count = len(self._run_metadata.step_stats.dev_stats)
    for index in range(device_count):
      device_stats = self._run_metadata.step_stats.dev_stats[index]
      if not device_name_regex or device_name_regex.match(device_stats.device):
        profile_data = [
            datum for datum in data_generator(device_stats)
            if _list_profile_filter(
                datum, node_name_regex, file_path_regex, op_type_regex,
                op_time_interval, exec_time_interval,
                min_lineno=parsed.min_lineno, max_lineno=parsed.max_lineno)]
        profile_data = sorted(
            profile_data,
            key=lambda datum: _list_profile_sort_key(datum, parsed.sort_by),
            reverse=parsed.reverse)
        output.extend(
            self._get_list_profile_lines(
                device_stats.device, index, device_count,
                profile_data, parsed.sort_by, parsed.reverse, parsed.time_unit,
                device_name_filter=parsed.device_name_filter,
                node_name_filter=parsed.node_name_filter,
                op_type_filter=parsed.op_type_filter,
                screen_cols=screen_cols))
    return output
Beispiel #2
0
  def list_profile(self, args, screen_info=None):
    """Command handler for list_profile.

    List per-operation profile information.

    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_cols = 80
    if screen_info and "cols" in screen_info:
      screen_cols = screen_info["cols"]

    parsed = self._arg_parsers["list_profile"].parse_args(args)
    op_time_interval = (command_parser.parse_time_interval(parsed.op_time)
                        if parsed.op_time else None)
    exec_time_interval = (
        command_parser.parse_time_interval(parsed.execution_time)
        if parsed.execution_time else None)
    node_name_regex = (re.compile(parsed.node_name_filter)
                       if parsed.node_name_filter else None)
    file_path_regex = (re.compile(parsed.file_path_filter)
                       if parsed.file_path_filter else None)
    op_type_regex = (re.compile(parsed.op_type_filter)
                     if parsed.op_type_filter else None)

    output = debugger_cli_common.RichTextLines([""])
    device_name_regex = (re.compile(parsed.device_name_filter)
                         if parsed.device_name_filter else None)
    data_generator = self._get_profile_data_generator()
    device_count = len(self._run_metadata.step_stats.dev_stats)
    for index in range(device_count):
      device_stats = self._run_metadata.step_stats.dev_stats[index]
      if not device_name_regex or device_name_regex.match(device_stats.device):
        profile_data = [
            datum for datum in data_generator(device_stats)
            if _list_profile_filter(
                datum, node_name_regex, file_path_regex, op_type_regex,
                op_time_interval, exec_time_interval,
                min_lineno=parsed.min_lineno, max_lineno=parsed.max_lineno)]
        profile_data = sorted(
            profile_data,
            key=lambda datum: _list_profile_sort_key(datum, parsed.sort_by),
            reverse=parsed.reverse)
        output.extend(
            self._get_list_profile_lines(
                device_stats.device, index, device_count,
                profile_data, parsed.sort_by, parsed.reverse, parsed.time_unit,
                device_name_filter=parsed.device_name_filter,
                node_name_filter=parsed.node_name_filter,
                op_type_filter=parsed.op_type_filter,
                screen_cols=screen_cols))
    return output
Beispiel #3
0
 def testParseTimeInterval(self):
   self.assertEqual(
       command_parser.Interval(10, True, 1e3, True),
       command_parser.parse_time_interval("[10us, 1ms]"))
   self.assertEqual(
       command_parser.Interval(10, False, 1e3, False),
       command_parser.parse_time_interval("(10us, 1ms)"))
   self.assertEqual(
       command_parser.Interval(10, False, 1e3, True),
       command_parser.parse_time_interval("(10us, 1ms]"))
   self.assertEqual(
       command_parser.Interval(10, True, 1e3, False),
       command_parser.parse_time_interval("[10us, 1ms)"))
   self.assertEqual(
       command_parser.Interval(0, False, 1e3, True),
       command_parser.parse_time_interval("<=1ms"))
   self.assertEqual(
       command_parser.Interval(1e3, True, float("inf"), False),
       command_parser.parse_time_interval(">=1ms"))
   self.assertEqual(
       command_parser.Interval(0, False, 1e3, False),
       command_parser.parse_time_interval("<1ms"))
   self.assertEqual(
       command_parser.Interval(1e3, False, float("inf"), False),
       command_parser.parse_time_interval(">1ms"))
 def testParseMemoryIntervalsWithInvalidValueStrings(self):
   with self.assertRaisesRegexp(ValueError, "Invalid value string after >= "):
     command_parser.parse_time_interval(">=wM")
   with self.assertRaisesRegexp(ValueError, "Invalid value string after > "):
     command_parser.parse_time_interval(">YM")
   with self.assertRaisesRegexp(ValueError, "Invalid value string after <= "):
     command_parser.parse_time_interval("<= _MB")
   with self.assertRaisesRegexp(ValueError, "Invalid value string after < "):
     command_parser.parse_time_interval("<-MB")
 def testParseTimeGreaterLessThanWithInvalidValueStrings(self):
   with self.assertRaisesRegexp(ValueError, "Invalid value string after >= "):
     command_parser.parse_time_interval(">=wms")
   with self.assertRaisesRegexp(ValueError, "Invalid value string after > "):
     command_parser.parse_time_interval(">Yms")
   with self.assertRaisesRegexp(ValueError, "Invalid value string after <= "):
     command_parser.parse_time_interval("<= _ms")
   with self.assertRaisesRegexp(ValueError, "Invalid value string after < "):
     command_parser.parse_time_interval("<-ms")
Beispiel #6
0
 def testParseMemoryIntervalsWithInvalidValueStrings(self):
   with self.assertRaisesRegex(ValueError, "Invalid value string after >= "):
     command_parser.parse_time_interval(">=wM")
   with self.assertRaisesRegex(ValueError, "Invalid value string after > "):
     command_parser.parse_time_interval(">YM")
   with self.assertRaisesRegex(ValueError, "Invalid value string after <= "):
     command_parser.parse_time_interval("<= _MB")
   with self.assertRaisesRegex(ValueError, "Invalid value string after < "):
     command_parser.parse_time_interval("<-MB")
Beispiel #7
0
 def testParseTimeIntervalsWithInvalidValueStrings(self):
   with self.assertRaisesRegex(ValueError, "Invalid first item in interval:"):
     command_parser.parse_time_interval("[wms, 10ms]")
   with self.assertRaisesRegex(ValueError, "Invalid second item in interval:"):
     command_parser.parse_time_interval("[ 0ms, _ms]")
   with self.assertRaisesRegex(ValueError, "Invalid first item in interval:"):
     command_parser.parse_time_interval("(xms, _ms]")
   with self.assertRaisesRegex(ValueError, "Invalid first item in interval:"):
     command_parser.parse_time_interval("((3ms, _ms)")
Beispiel #8
0
 def testParseTimeGreaterLessThanWithInvalidValueStrings(self):
   with self.assertRaisesRegex(ValueError, "Invalid value string after >= "):
     command_parser.parse_time_interval(">=wms")
   with self.assertRaisesRegex(ValueError, "Invalid value string after > "):
     command_parser.parse_time_interval(">Yms")
   with self.assertRaisesRegex(ValueError, "Invalid value string after <= "):
     command_parser.parse_time_interval("<= _ms")
   with self.assertRaisesRegex(ValueError, "Invalid value string after < "):
     command_parser.parse_time_interval("<-ms")
 def testParseTimeIntervalsWithInvalidValueStrings(self):
   with self.assertRaisesRegexp(ValueError, "Invalid first item in interval:"):
     command_parser.parse_time_interval("[wms, 10ms]")
   with self.assertRaisesRegexp(ValueError,
                                "Invalid second item in interval:"):
     command_parser.parse_time_interval("[ 0ms, _ms]")
   with self.assertRaisesRegexp(ValueError, "Invalid first item in interval:"):
     command_parser.parse_time_interval("(xms, _ms]")
   with self.assertRaisesRegexp(ValueError, "Invalid first item in interval:"):
     command_parser.parse_time_interval("((3ms, _ms)")
Beispiel #10
0
 def testInvalidTimeIntervalRaisesException(self):
   with self.assertRaisesRegex(
       ValueError, r"Invalid interval format: \[10us, 1ms. Valid formats are: "
       r"\[min, max\], \(min, max\), <max, >min"):
     command_parser.parse_time_interval("[10us, 1ms")
   with self.assertRaisesRegex(
       ValueError,
       r"Incorrect interval format: \[10us, 1ms, 2ms\]. Interval should "
       r"specify two values: \[min, max\] or \(min, max\)"):
     command_parser.parse_time_interval("[10us, 1ms, 2ms]")
   with self.assertRaisesRegex(
       ValueError,
       r"Invalid interval \[1s, 1ms\]. Start must be before end of interval."):
     command_parser.parse_time_interval("[1s, 1ms]")
Beispiel #11
0
 def testInvalidTimeIntervalRaisesException(self):
   with self.assertRaisesRegexp(
       ValueError,
       r"Invalid interval format: \[10us, 1ms. Valid formats are: "
       r"\[min, max\], \(min, max\), <max, >min"):
     command_parser.parse_time_interval("[10us, 1ms")
   with self.assertRaisesRegexp(
       ValueError,
       r"Incorrect interval format: \[10us, 1ms, 2ms\]. Interval should "
       r"specify two values: \[min, max\] or \(min, max\)"):
     command_parser.parse_time_interval("[10us, 1ms, 2ms]")
   with self.assertRaisesRegexp(
       ValueError,
       r"Invalid interval \[1s, 1ms\]. Start must be before end of interval."):
     command_parser.parse_time_interval("[1s, 1ms]")
Beispiel #12
0
 def testParseTimeInterval(self):
   self.assertEquals(
       command_parser.Interval(10, True, 1e3, True),
       command_parser.parse_time_interval("[10us, 1ms]"))
   self.assertEquals(
       command_parser.Interval(10, False, 1e3, False),
       command_parser.parse_time_interval("(10us, 1ms)"))
   self.assertEquals(
       command_parser.Interval(10, False, 1e3, True),
       command_parser.parse_time_interval("(10us, 1ms]"))
   self.assertEquals(
       command_parser.Interval(10, True, 1e3, False),
       command_parser.parse_time_interval("[10us, 1ms)"))
   self.assertEquals(command_parser.Interval(0, False, 1e3, True),
                     command_parser.parse_time_interval("<=1ms"))
   self.assertEquals(
       command_parser.Interval(1e3, True, float("inf"), False),
       command_parser.parse_time_interval(">=1ms"))
   self.assertEquals(command_parser.Interval(0, False, 1e3, False),
                     command_parser.parse_time_interval("<1ms"))
   self.assertEquals(
       command_parser.Interval(1e3, False, float("inf"), False),
       command_parser.parse_time_interval(">1ms"))