Beispiel #1
0
 def get_background_root_workunit(self):
     if self._background_root_workunit is None:
         self._background_root_workunit = WorkUnit(run_tracker=self,
                                                   parent=None,
                                                   labels=[],
                                                   name='background',
                                                   cmd=None)
         self._background_root_workunit.start()
         self.report.start_workunit(self._background_root_workunit)
     return self._background_root_workunit
Beispiel #2
0
    def start(self, report):
        """Start tracking this pants run.

    report: an instance of pants.reporting.Report."""
        self.report = report
        self.report.open()

        self._main_root_workunit = WorkUnit(run_tracker=self,
                                            parent=None,
                                            labels=[],
                                            name=RunTracker.DEFAULT_ROOT_NAME,
                                            cmd=None)
        self.register_thread(self._main_root_workunit)
        self._main_root_workunit.start()
        self.report.start_workunit(self._main_root_workunit)
Beispiel #3
0
    def start(self, report):
        """Start tracking this pants run.

    report: an instance of pants.reporting.Report."""
        self.report = report
        self.report.open()

        self.root_workunit = WorkUnit(run_tracker=self,
                                      parent=None,
                                      labels=[],
                                      name='all',
                                      cmd=None)
        self.root_workunit.start()

        self.report.start_workunit(self.root_workunit)
        self._current_workunit = self.root_workunit
Beispiel #4
0
    def new_workunit(self, name, labels=list(), cmd='', parent=None):
        """Creates a (hierarchical) subunit of work for the purpose of timing and reporting.

    - name: A short name for this work. E.g., 'resolve', 'compile', 'scala', 'zinc'.
    - labels: An optional iterable of labels. The reporters can use this to decide how to
              display information about this work.
    - cmd: An optional longer string representing this work.
           E.g., the cmd line of a compiler invocation.
    - parent: If specified, the new workunit is created under this parent. Otherwise it's created
              under the current workunit for this thread. This allows threadpool work to nest
              under the workunit that submitted it, instead of under the thread's root workunit,
              which is fixed when the thread was created.

    Use like this:

    with context.new_workunit(name='compile', labels=[WorkUnit.GOAL]) as workunit:
      <do scoped work here>
      <set the outcome on workunit if necessary>

    Note that the outcome will automatically be set to failure if an exception is raised
    in a workunit, and to success otherwise, so usually you only need to set the
    outcome explicitly if you want to set it to warning.
    """
        enclosing_workunit = self._threadlocal.current_workunit
        current_workunit = WorkUnit(run_tracker=self,
                                    parent=parent or enclosing_workunit,
                                    name=name,
                                    labels=labels,
                                    cmd=cmd)
        self._threadlocal.current_workunit = current_workunit
        current_workunit.start()
        try:
            self.report.start_workunit(current_workunit)
            yield current_workunit
        except KeyboardInterrupt:
            current_workunit.set_outcome(WorkUnit.ABORTED)
            self._aborted = True
            raise
        except:
            current_workunit.set_outcome(WorkUnit.FAILURE)
            raise
        else:
            current_workunit.set_outcome(WorkUnit.SUCCESS)
        finally:
            self.report.end_workunit(current_workunit)
            current_workunit.end()
            self._threadlocal.current_workunit = enclosing_workunit
Beispiel #5
0
    def new_workunit(self, name, labels=list(), cmd=''):
        """Creates a (hierarchical) subunit of work for the purpose of timing and reporting.

    - name: A short name for this work. E.g., 'resolve', 'compile', 'scala', 'zinc'.
    - labels: An optional iterable of labels. The reporters can use this to decide how to
              display information about this work.
    - cmd: An optional longer string representing this work.
           E.g., the cmd line of a compiler invocation.

    Use like this:

    with context.new_workunit(name='compile', labels=[WorkUnit.GOAL]) as workunit:
      <do scoped work here>
      <set the outcome on workunit if necessary>

    Note that the outcome will automatically be set to failure if an exception is raised
    in a workunit, and to success otherwise, so usually you only need to set the
    outcome explicitly if you want to set it to warning.
    """
        self._current_workunit = WorkUnit(run_tracker=self,
                                          parent=self._current_workunit,
                                          name=name,
                                          labels=labels,
                                          cmd=cmd)
        self._current_workunit.start()
        try:
            self.report.start_workunit(self._current_workunit)
            yield self._current_workunit
        except KeyboardInterrupt:
            self._current_workunit.set_outcome(WorkUnit.ABORTED)
            raise
        except:
            self._current_workunit.set_outcome(WorkUnit.FAILURE)
            raise
        else:
            self._current_workunit.set_outcome(WorkUnit.SUCCESS)
        finally:
            self.report.end_workunit(self._current_workunit)
            self._current_workunit.end()
            self._current_workunit = self._current_workunit.parent