Example #1
0
    def start(self, all_options, run_start_time=None):
        """Start tracking this pants run."""
        if self.run_info:
            raise AssertionError(
                "RunTracker.start must not be called multiple times.")

        # Initialize the run.

        info_dir = os.path.join(self.options.pants_workdir, self.options_scope)
        self.run_info_dir = os.path.join(info_dir, self.run_id)
        self.run_info = RunInfo(os.path.join(self.run_info_dir, "info"))
        self.run_info.add_basic_info(self.run_id, self._run_timestamp)
        self.run_info.add_info("cmd_line", self._cmd_line)
        if self.options.parent_build_id:
            self.run_info.add_info("parent_build_id",
                                   self.options.parent_build_id)

        # Create a 'latest' symlink, after we add_infos, so we're guaranteed that the file exists.
        link_to_latest = os.path.join(os.path.dirname(self.run_info_dir),
                                      "latest")

        relative_symlink(self.run_info_dir, link_to_latest)

        # Time spent in a workunit, including its children.
        self.cumulative_timings = AggregatedTimings(
            os.path.join(self.run_info_dir, "cumulative_timings"))

        # Time spent in a workunit, not including its children.
        self.self_timings = AggregatedTimings(
            os.path.join(self.run_info_dir, "self_timings"))
        # Daemon stats.
        self.pantsd_stats = PantsDaemonStats()

        self._all_options = all_options

        self.report = Report()

        # Set up the JsonReporter for V2 stats.
        if self._stats_version == 2:
            json_reporter_settings = JsonReporter.Settings(
                log_level=Report.INFO)
            self.json_reporter = JsonReporter(self, json_reporter_settings)
            self.report.add_reporter("json", self.json_reporter)

        self.report.open()

        # And create the workunit.
        self._main_root_workunit = WorkUnit(run_info_dir=self.run_info_dir,
                                            parent=None,
                                            name=RunTracker.DEFAULT_ROOT_NAME,
                                            cmd=None)
        self.register_thread(self._main_root_workunit)
        # Set the true start time in the case of e.g. the daemon.
        self._main_root_workunit.start(run_start_time)
        self.report.start_workunit(self._main_root_workunit)
Example #2
0
    def start(self, report, run_start_time=None):
        """Start tracking this pants run using the given Report.

    `RunTracker.initialize` must have been called first to create the run_info_dir and
    run_info. TODO: This lifecycle represents a delicate dance with the `Reporting.initialize`
    method, and portions of the `RunTracker` should likely move to `Reporting` instead.

    report: an instance of pants.reporting.Report.
    """
        if not self.run_info:
            raise AssertionError(
                'RunTracker.initialize must be called before RunTracker.start.'
            )

        self.report = report

        # Set up the JsonReporter for V2 stats.
        if self._stats_version == 2:
            json_reporter_settings = JsonReporter.Settings(
                log_level=Report.INFO)
            self.json_reporter = JsonReporter(self, json_reporter_settings)
            report.add_reporter('json', self.json_reporter)

        self.report.open()

        # And create the workunit.
        self._main_root_workunit = WorkUnit(run_info_dir=self.run_info_dir,
                                            parent=None,
                                            name=RunTracker.DEFAULT_ROOT_NAME,
                                            cmd=None)
        self.register_thread(self._main_root_workunit)
        # Set the true start time in the case of e.g. the daemon.
        self._main_root_workunit.start(run_start_time)
        self.report.start_workunit(self._main_root_workunit)

        # Log reporting details.
        url = self.run_info.get_info('report_url')
        if url:
            self.log(Report.INFO, f'See a report at: {url}')
        else:
            self.log(Report.INFO,
                     '(To run a reporting server: ./pants server)')
Example #3
0
  def test_nested_grandchild(self):
    expected = {
      'name': 'root',
      'id': 'root_id',
      'parent_name': '',
      'parent_id': '',
      'labels': [
        'IAMROOT'
      ],
      'cmd': '',
      'start_time': -5419800.0,
      'outputs': {},
      'children': [
        {
          'name': 'child1',
          'id': 'child1_id',
          'parent_name': 'root',
          'parent_id': 'root_id',
          'labels': [],
          'cmd': '',
          'start_time': 31564800.0,
          'outputs': {},
          'children': [
            {
              'name': 'grandchild',
              'id': 'grandchild_id',
              'parent_name': 'child1',
              'parent_id': 'child1_id',
              'labels': [
                'LABEL1'
              ],
              'cmd': '',
              'start_time': 479721600.0,
              'outputs': {},
              'children': [],
              'log_entries': [],
              'outcome': 'SUCCESS',
              'end_time': 479721610.0,
              'unaccounted_time': 0
            }
          ],
          'log_entries': [],
          'outcome': 'SUCCESS',
          'end_time': 31564810.0,
          'unaccounted_time': 0
        },
        {
          'name': 'child2',
          'id': 'child2_id',
          'parent_name': 'root',
          'parent_id': 'root_id',
          'labels': [],
          'cmd': '',
          'start_time': 684140400.0,
          'outputs': {},
          'children': [],
          'log_entries': [],
          'outcome': 'SUCCESS',
          'end_time': 684140410.0,
          'unaccounted_time': 0
        }
      ],
      'log_entries': [],
      'outcome': 'SUCCESS',
      'end_time': -5419790.0,
      'unaccounted_time': 0
    }

    reporter = JsonReporter(FakeRunTracker(),
      JsonReporter.Settings(log_level=Report.INFO))

    self._check_callbacks(expected, reporter)
Example #4
0
    def test_nested_grandchild(self):
        expected = {
            "name": "root",
            "id": "root_id",
            "parent_name": "",
            "parent_id": "",
            "labels": ["IAMROOT"],
            "cmd": "",
            "start_time": -5419800.0,
            "outputs": {},
            "children": [
                {
                    "name": "child1",
                    "id": "child1_id",
                    "parent_name": "root",
                    "parent_id": "root_id",
                    "labels": [],
                    "cmd": "",
                    "start_time": 31564800.0,
                    "outputs": {},
                    "children": [
                        {
                            "name": "grandchild",
                            "id": "grandchild_id",
                            "parent_name": "child1",
                            "parent_id": "child1_id",
                            "labels": ["LABEL1"],
                            "cmd": "",
                            "start_time": 479721600.0,
                            "outputs": {},
                            "children": [],
                            "log_entries": [],
                            "outcome": "SUCCESS",
                            "end_time": 479721610.0,
                            "unaccounted_time": 0,
                        }
                    ],
                    "log_entries": [],
                    "outcome": "SUCCESS",
                    "end_time": 31564810.0,
                    "unaccounted_time": 0,
                },
                {
                    "name": "child2",
                    "id": "child2_id",
                    "parent_name": "root",
                    "parent_id": "root_id",
                    "labels": [],
                    "cmd": "",
                    "start_time": 684140400.0,
                    "outputs": {},
                    "children": [],
                    "log_entries": [],
                    "outcome": "SUCCESS",
                    "end_time": 684140410.0,
                    "unaccounted_time": 0,
                },
            ],
            "log_entries": [],
            "outcome": "SUCCESS",
            "end_time": -5419790.0,
            "unaccounted_time": 0,
        }

        reporter = JsonReporter(FakeRunTracker(), JsonReporter.Settings(log_level=Report.INFO))

        self._check_callbacks(expected, reporter)