Search in sources :

Example 6 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method testSensibleShortening.

@Test
public void testSensibleShortening() throws Exception {
    // Verify that in the typical case, we shorten the progress message by shortening
    // the path implicit in it, that can also be extracted from the label. In particular,
    // the parts
    ManualClock clock = new ManualClock();
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 70);
    Action action = mockAction("Building some/very/very/long/path/for/some/library/directory/foo.jar (42 source files)", "/home/user/bazel/out/abcdef/some/very/very/long/path/for/some/library/directory/foo.jar");
    Label label = Label.parseAbsolute("//some/very/very/long/path/for/some/library/directory:libfoo");
    ActionOwner owner = ActionOwner.create(label, ImmutableList.<AspectDescriptor>of(), null, null, null, "fedcba", null);
    when(action.getOwner()).thenReturn(owner);
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(3));
    stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(5));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Progress bar should contain 'Building ', but was:\n" + output, output.contains("Building "));
    assertTrue("Progress bar should contain 'foo.jar (42 source files)', but was:\n" + output, output.contains("foo.jar (42 source files)"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) Action(com.google.devtools.build.lib.actions.Action) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) Label(com.google.devtools.build.lib.cmdline.Label) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 7 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method doTestOutputLength.

private void doTestOutputLength(boolean withTest, int actions) throws Exception {
    // If we target 70 characters, then there should be enough space to both,
    // keep the line limit, and show the local part of the running actions and
    // the passed test.
    ManualClock clock = new ManualClock();
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 70);
    Action foobuildAction = mockAction("Building //src/some/very/long/path/long/long/long/long/long/long/long/foo/foobuild.jar", "//src/some/very/long/path/long/long/long/long/long/long/long/foo:foobuild");
    Action bazbuildAction = mockAction("Building //src/some/very/long/path/long/long/long/long/long/long/long/baz/bazbuild.jar", "//src/some/very/long/path/long/long/long/long/long/long/long/baz:bazbuild");
    Label bartestLabel = Label.parseAbsolute("//src/another/very/long/long/path/long/long/long/long/long/long/long/long/bars:bartest");
    ConfiguredTarget bartestTarget = Mockito.mock(ConfiguredTarget.class);
    when(bartestTarget.getLabel()).thenReturn(bartestLabel);
    TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class);
    when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(bartestTarget));
    TestSummary testSummary = Mockito.mock(TestSummary.class);
    when(testSummary.getStatus()).thenReturn(BlazeTestStatus.PASSED);
    when(testSummary.getTarget()).thenReturn(bartestTarget);
    if (actions >= 1) {
        stateTracker.actionStarted(new ActionStartedEvent(foobuildAction, 123456789));
    }
    if (actions >= 2) {
        stateTracker.actionStarted(new ActionStartedEvent(bazbuildAction, 123456900));
    }
    if (withTest) {
        stateTracker.testFilteringComplete(filteringComplete);
        stateTracker.testSummary(testSummary);
    }
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Only lines with at most 70 chars should be present in the output:\n" + output, longestLine(output) <= 70);
    if (actions >= 1) {
        assertTrue("Running action 'foobuild' should be mentioned in output:\n" + output, output.contains("foobuild"));
    }
    if (actions >= 2) {
        assertTrue("Running action 'bazbuild' should be mentioned in output:\n" + output, output.contains("bazbuild"));
    }
    if (withTest) {
        assertTrue("Passed test ':bartest' should be mentioned in output:\n" + output, output.contains(":bartest"));
    }
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) 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)

Example 8 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 9 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method testActionVisible.

@Test
public void testActionVisible() throws IOException {
    // If there is only one action running, it should be visible
    // somewhere in the progress bar, and also the short version thereof.
    String message = "Building foo";
    ManualClock clock = new ManualClock();
    clock.advanceMillis(120000);
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    stateTracker.actionStarted(new ActionStartedEvent(mockAction(message, "bar/foo"), 123456789));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Action message '" + message + "' should be present in output: " + output, output.contains(message));
    terminalWriter = new LoggingTerminalWriter();
    stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
    true);
    output = terminalWriter.getTranscript();
    assertTrue("Action message '" + message + "' should be present in short output: " + output, output.contains(message));
}
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 10 with ActionStartedEvent

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

the class ExperimentalStateTrackerTest method testTimesShown.

@Test
public void testTimesShown() throws IOException {
    // For sufficiently long running actions, the time that has passed since their start is shown.
    // In the short version of the progress bar, this should be true at least for the oldest action.
    ManualClock clock = new ManualClock();
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(123));
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(2));
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("First action", "foo"), clock.nanoTime()));
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(7));
    stateTracker.actionStarted(new ActionStartedEvent(mockAction("Second action", "bar"), clock.nanoTime()));
    clock.advanceMillis(TimeUnit.SECONDS.toMillis(20));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Runtime of first action should be visible in output: " + output, output.contains("27s"));
    assertTrue("Runtime of second action should be visible in output: " + output, output.contains("20s"));
    terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
    true);
    output = terminalWriter.getTranscript();
    assertTrue("Runtime of first action should be visible in short output: " + output, output.contains("27s"));
}
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)

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