Search in sources :

Example 1 with ActionStartedEvent

use of com.google.devtools.build.lib.actions.ActionStartedEvent 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 ActionStartedEvent

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

the class ExperimentalStateTrackerTest method testAggregation.

@Test
public void testAggregation() throws Exception {
    // Assert that actions for the same test are aggregated so that an action afterwards
    // is still shown.
    ManualClock clock = new ManualClock();
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1234));
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 80);
    Label labelFooTest = Label.parseAbsolute("//foo/bar:footest");
    ConfiguredTarget targetFooTest = Mockito.mock(ConfiguredTarget.class);
    when(targetFooTest.getLabel()).thenReturn(labelFooTest);
    ActionOwner fooOwner = ActionOwner.create(labelFooTest, ImmutableList.<AspectDescriptor>of(), null, null, null, "abcdef", null);
    Label labelBarTest = Label.parseAbsolute("//baz:bartest");
    ConfiguredTarget targetBarTest = Mockito.mock(ConfiguredTarget.class);
    when(targetBarTest.getLabel()).thenReturn(labelBarTest);
    TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class);
    when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetFooTest, targetBarTest));
    ActionOwner barOwner = ActionOwner.create(labelBarTest, ImmutableList.<AspectDescriptor>of(), null, null, null, "fedcba", null);
    stateTracker.testFilteringComplete(filteringComplete);
    // First produce 10 actions for footest...
    for (int i = 0; i < 10; i++) {
        clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
        Action action = mockAction("Testing foo, shard " + i, "testlog_foo_" + i);
        when(action.getOwner()).thenReturn(fooOwner);
        stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
    }
    // ...then produce 10 actions for bartest...
    for (int i = 0; i < 10; i++) {
        clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
        Action action = mockAction("Testing bar, shard " + i, "testlog_bar_" + i);
        when(action.getOwner()).thenReturn(barOwner);
        stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
    }
    // ...and finally a completely unrelated action
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("Other action", "other/action"), clock.nanoTime()));
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Progress bar should contain ':footest', but was:\n" + output, output.contains(":footest"));
    assertTrue("Progress bar should contain ':bartest', but was:\n" + output, output.contains(":bartest"));
    assertTrue("Progress bar should contain 'Other action', but was:\n" + output, output.contains("Other action"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) Action(com.google.devtools.build.lib.actions.Action) Label(com.google.devtools.build.lib.cmdline.Label) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TestFilteringCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 3 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method testOldestActionVisible.

@Test
public void testOldestActionVisible() throws IOException {
    // The earliest-started action is always visible somehow in the progress bar
    // and its short version.
    String messageOld = "Running the first-started action";
    ManualClock clock = new ManualClock();
    clock.advanceMillis(120000);
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    stateTracker.actionStarted(new ActionStartedEvent(mockAction(messageOld, "bar/foo"), 123456789));
    for (int i = 0; i < 30; i++) {
        stateTracker.actionStarted(new ActionStartedEvent(mockAction("Other action " + i, "some/other/actions/number" + i), 123456790 + i));
    }
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Longest running action '" + messageOld + "' should be visible in output: " + output, output.contains(messageOld));
    terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
    true);
    output = terminalWriter.getTranscript();
    assertTrue("Longest running action '" + messageOld + "' should be visible in short output: " + output, output.contains(messageOld));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 4 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method runningActionTimeIndependent.

@Test
public void runningActionTimeIndependent() {
    ManualClock clock = new ManualClock();
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(123));
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("Some action", "foo"), clock.nanoTime()));
    assertTrue("Progress bar showing a running action should be time dependent", stateTracker.progressBarTimeDependent());
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) Test(org.junit.Test)

Example 5 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method testActionStrategyVisible.

@Test
public void testActionStrategyVisible() throws Exception {
    // verify that, if a strategy was reported for a shown action, it is visible
    // in the progress bar.
    String strategy = "verySpecialStrategy";
    String primaryOutput = "some/path/to/a/file";
    ManualClock clock = new ManualClock();
    Path path = outputBase.getRelative(new PathFragment(primaryOutput));
    Artifact artifact = new Artifact(path, Root.asSourceRoot(path));
    ActionExecutionMetadata actionMetadata = Mockito.mock(ActionExecutionMetadata.class);
    when(actionMetadata.getOwner()).thenReturn(Mockito.mock(ActionOwner.class));
    when(actionMetadata.getPrimaryOutput()).thenReturn(artifact);
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("Some random action", primaryOutput), clock.nanoTime()));
    stateTracker.actionStatusMessage(ActionStatusMessage.runningStrategy(actionMetadata, strategy));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Output should mention strategy '" + strategy + "', but was: " + output, output.contains(strategy));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) Artifact(com.google.devtools.build.lib.actions.Artifact) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Aggregations

ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)11 ManualClock (com.google.devtools.build.lib.testutil.ManualClock)10 LoggingTerminalWriter (com.google.devtools.build.lib.util.io.LoggingTerminalWriter)9 Test (org.junit.Test)9 Action (com.google.devtools.build.lib.actions.Action)5 ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)3 Label (com.google.devtools.build.lib.cmdline.Label)3 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)2 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)2 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)1 ActionExecutionStatusReporter (com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 IOException (java.io.IOException)1