Search in sources :

Example 1 with ActionCompletionEvent

use of com.google.devtools.build.lib.actions.ActionCompletionEvent in project bazel by bazelbuild.

the class SkyframeActionExecutor method prepareScheduleExecuteAndCompleteAction.

/**
   * Prepare, schedule, execute, and then complete the action.
   * When this function is called, we know that this action needs to be executed.
   * This function will prepare for the action's execution (i.e. delete the outputs);
   * schedule its execution; execute the action;
   * and then do some post-execution processing to complete the action:
   * set the outputs readonly and executable, and insert the action results in the
   * action cache.
   *
   * @param action  The action to execute
   * @param context services in the scope of the action
   * @param actionStartTime time when we started the first phase of the action execution.
   * @throws ActionExecutionException if the execution of the specified action
   *   failed for any reason.
   * @throws InterruptedException if the thread was interrupted.
   */
private void prepareScheduleExecuteAndCompleteAction(Action action, ActionExecutionContext context, long actionStartTime) throws ActionExecutionException, InterruptedException {
    // Delete the metadataHandler's cache of the action's outputs, since they are being deleted.
    context.getMetadataHandler().discardOutputMetadata();
    // the action really does produce the outputs.
    try {
        action.prepare(context.getExecutor().getExecRoot());
        createOutputDirectories(action);
    } catch (IOException e) {
        reportError("failed to delete output files before executing action", e, action, null);
    }
    postEvent(new ActionStartedEvent(action, actionStartTime));
    ActionExecutionStatusReporter statusReporter = statusReporterRef.get();
    try {
        // Mark the current action as being prepared.
        statusReporter.updateStatus(ActionStatusMessage.preparingStrategy(action));
        boolean outputDumped = executeActionTask(action, context);
        completeAction(action, context.getMetadataHandler(), context.getFileOutErr(), outputDumped);
    } finally {
        statusReporter.remove(action);
        postEvent(new ActionCompletionEvent(actionStartTime, action));
    }
}
Also used : ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ActionExecutionStatusReporter(com.google.devtools.build.lib.actions.ActionExecutionStatusReporter) IOException(java.io.IOException) ActionCompletionEvent(com.google.devtools.build.lib.actions.ActionCompletionEvent)

Example 2 with ActionCompletionEvent

use of com.google.devtools.build.lib.actions.ActionCompletionEvent in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testCompletedActionNotShown.

@Test
public void testCompletedActionNotShown() throws IOException {
    // Completed actions should not be reported in the progress bar, nor in the
    // short progress bar.
    String messageFast = "Running quick action";
    String messageSlow = "Running slow action";
    ManualClock clock = new ManualClock();
    clock.advanceMillis(120000);
    Action fastAction = mockAction(messageFast, "foo/fast");
    Action slowAction = mockAction(messageSlow, "bar/slow");
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    stateTracker.actionStarted(new ActionStartedEvent(fastAction, 123456789));
    stateTracker.actionStarted(new ActionStartedEvent(slowAction, 123456999));
    stateTracker.actionCompletion(new ActionCompletionEvent(20, fastAction));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertFalse("Completed action '" + messageFast + "' should not be present in output: " + output, output.contains(messageFast));
    assertTrue("Only running action '" + messageSlow + "' should be present in output: " + output, output.contains(messageSlow));
    terminalWriter = new LoggingTerminalWriter();
    stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
    true);
    output = terminalWriter.getTranscript();
    assertFalse("Completed action '" + messageFast + "' should not be present in short output: " + output, output.contains(messageFast));
    assertTrue("Only running action '" + messageSlow + "' should be present in short output: " + output, output.contains(messageSlow));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) Action(com.google.devtools.build.lib.actions.Action) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ActionCompletionEvent(com.google.devtools.build.lib.actions.ActionCompletionEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Aggregations

ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 Action (com.google.devtools.build.lib.actions.Action)1 ActionExecutionStatusReporter (com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)1 ManualClock (com.google.devtools.build.lib.testutil.ManualClock)1 LoggingTerminalWriter (com.google.devtools.build.lib.util.io.LoggingTerminalWriter)1 IOException (java.io.IOException)1 Test (org.junit.Test)1