Search in sources :

Example 6 with ProfilerTask

use of com.google.copybara.profiler.Profiler.ProfilerTask in project copybara by google.

the class GitHubApi method deleteReference.

public void deleteReference(String projectId, String ref) throws RepoException, ValidationException {
    checkArgument(ref.startsWith("refs/"), "References has to be complete references in the form of refs/heads/foo. But was: %s", ref);
    // There is no good reason for deleting master.
    checkArgument(!ref.equals("refs/heads/master"), "Copybara doesn't allow to delete master" + " branch for security reasons");
    try (ProfilerTask ignore = profiler.start("github_api_delete_reference")) {
        transport.delete(String.format("repos/%s/git/%s", projectId, ref));
    }
}
Also used : ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask)

Example 7 with ProfilerTask

use of com.google.copybara.profiler.Profiler.ProfilerTask in project copybara by google.

the class HgVisitorUtil method visitChanges.

/**
 * Visits Hg changes, up to the termination point specified by the visitor.
 */
static void visitChanges(HgRevision start, ChangesVisitor visitor, ChangeReader.Builder queryChanges, GeneralOptions generalOptions, String type, int visitChangePageSize) throws RepoException {
    Preconditions.checkNotNull(start);
    int offset = 0;
    boolean finished = false;
    try (ProfilerTask ignore = generalOptions.profiler().start(type + "/visit_changes")) {
        while (!finished) {
            ImmutableList<Change<HgRevision>> result;
            try (ProfilerTask ignore2 = generalOptions.profiler().start(String.format("hg_log_%d_%d", offset, visitChangePageSize))) {
                try {
                    result = queryChanges.setSkip(offset).setLimit(visitChangePageSize).build().run(start.getGlobalId()).reverse();
                } catch (ValidationException e) {
                    throw new RepoException(String.format("Error querying changes: %s", e.getMessage()), e.getCause());
                }
            }
            if (result.isEmpty()) {
                break;
            }
            offset += result.size();
            for (Change<HgRevision> current : result) {
                if (visitor.visit(current) == VisitResult.TERMINATE) {
                    finished = true;
                    break;
                }
            }
        }
    }
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) Change(com.google.copybara.Change) RepoException(com.google.copybara.exception.RepoException)

Example 8 with ProfilerTask

use of com.google.copybara.profiler.Profiler.ProfilerTask in project copybara by google.

the class ProfilerTest method testListenerLogging.

@Test
public void testListenerLogging() {
    // Keep a strong reference to the Logger we use to capture log records for the duration of the
    // test to avoid any potential race conditions with the weak referencing used by the JDK
    // 
    // TODO: This could be migrated to use the package level logger name, which would be less
    // fragile against code being moved around.
    Logger loggerUnderTest = Logger.getLogger(LogProfilerListener.class.getCanonicalName());
    TestLogHandler assertingHandler = new TestLogHandler();
    assertingHandler.setLevel(Level.FINE);
    loggerUnderTest.addHandler(assertingHandler);
    profiler = new Profiler(ticker);
    profiler.init(ImmutableList.of(new LogProfilerListener()));
    try (ProfilerTask ignore = profiler.start("testListenerLogging")) {
    // do something
    }
    LogRecord record = assertingHandler.getStoredLogRecords().get(0);
    assertThat(record.getMessage()).contains("testListenerLogging");
    assertThat(record.getSourceClassName()).contains(this.getClass().getName());
    loggerUnderTest.removeHandler(assertingHandler);
}
Also used : TestLogHandler(com.google.common.testing.TestLogHandler) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 9 with ProfilerTask

use of com.google.copybara.profiler.Profiler.ProfilerTask in project copybara by google.

the class ProfilerTest method reentrantTest.

@Test
public void reentrantTest() {
    try (ProfilerTask ignore = profiler.start("task1")) {
        try (ProfilerTask ignore2 = profiler.start("task2")) {
            profiler.simpleTask("task3", ticker.read(), ticker.read());
            profiler.simpleTask("task4", ticker.read(), ticker.read());
        }
        try (ProfilerTask ignore2 = profiler.start("task5")) {
            profiler.simpleTask("task6", ticker.read(), ticker.read());
            profiler.simpleTask("task7", ticker.read(), ticker.read());
        }
    }
    profiler.stop();
    assertThat(recordingCallback.events).isEqualTo(ImmutableList.of(new TaskWithType(EventType.START, new Task("//copybara", 0, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1", 1, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1/task2", 2, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1/task2/task3", 3, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task2/task3", 3, 4)), new TaskWithType(EventType.START, new Task("//copybara/task1/task2/task4", 5, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task2/task4", 5, 6)), new TaskWithType(EventType.END, new Task("//copybara/task1/task2", 2, 7)), new TaskWithType(EventType.START, new Task("//copybara/task1/task5", 8, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1/task5/task6", 9, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task5/task6", 9, 10)), new TaskWithType(EventType.START, new Task("//copybara/task1/task5/task7", 11, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task5/task7", 11, 12)), new TaskWithType(EventType.END, new Task("//copybara/task1/task5", 8, 13)), new TaskWithType(EventType.END, new Task("//copybara/task1", 1, 14)), new TaskWithType(EventType.END, new Task("//copybara", 0, 15))));
    // We don't record events once stopped.
    recordingCallback.events.clear();
    try (ProfilerTask ignore = profiler.start("bar")) {
        profiler.simpleTask("foo", 10, 20);
    }
    assertThat(recordingCallback.events).isEmpty();
}
Also used : ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) TaskWithType(com.google.copybara.testing.profiler.RecordingListener.TaskWithType) Test(org.junit.Test)

Example 10 with ProfilerTask

use of com.google.copybara.profiler.Profiler.ProfilerTask in project copybara by google.

the class ProfilerTest method multiThreadTest.

@Test
public void multiThreadTest() {
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    try (ProfilerTask ignore = profiler.start("task1")) {
        // Sequence the two invocations to have repetible tests
        CountDownLatch latch = new CountDownLatch(1);
        executorService.submit(() -> {
            try (ProfilerTask ignored = profiler.start("task2")) {
                profiler.simpleTask("task3", ticker.read(), ticker.read());
                profiler.simpleTask("task4", ticker.read(), ticker.read());
            }
            latch.countDown();
        });
        executorService.submit(() -> {
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
            try (ProfilerTask ignored = profiler.start("task5")) {
                profiler.simpleTask("task6", ticker.read(), ticker.read());
                profiler.simpleTask("task7", ticker.read(), ticker.read());
            }
        });
        MoreExecutors.shutdownAndAwaitTermination(executorService, 20, TimeUnit.SECONDS);
    }
    profiler.stop();
    assertThat(recordingCallback.events).containsExactly(new TaskWithType(EventType.START, new Task("//copybara", 0, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1", 1, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1/task2", 2, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1/task2/task3", 3, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task2/task3", 3, 4)), new TaskWithType(EventType.START, new Task("//copybara/task1/task2/task4", 5, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task2/task4", 5, 6)), new TaskWithType(EventType.END, new Task("//copybara/task1/task2", 2, 7)), new TaskWithType(EventType.START, new Task("//copybara/task1/task5", 8, -1)), new TaskWithType(EventType.START, new Task("//copybara/task1/task5/task6", 9, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task5/task6", 9, 10)), new TaskWithType(EventType.START, new Task("//copybara/task1/task5/task7", 11, -1)), new TaskWithType(EventType.END, new Task("//copybara/task1/task5/task7", 11, 12)), new TaskWithType(EventType.END, new Task("//copybara/task1/task5", 8, 13)), new TaskWithType(EventType.END, new Task("//copybara/task1", 1, 14)), new TaskWithType(EventType.END, new Task("//copybara", 0, 15)));
}
Also used : ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) TaskWithType(com.google.copybara.testing.profiler.RecordingListener.TaskWithType) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)29 ValidationException (com.google.copybara.exception.ValidationException)10 ImmutableList (com.google.common.collect.ImmutableList)8 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)8 RepoException (com.google.copybara.exception.RepoException)7 Test (org.junit.Test)6 Change (com.google.copybara.Change)5 Endpoint (com.google.copybara.Endpoint)5 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)5 SkylarkConsole (com.google.copybara.transform.SkylarkConsole)5 IOException (java.io.IOException)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Preconditions (com.google.common.base.Preconditions)4 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)4 Action (com.google.copybara.action.Action)4 ChangeMigrationFinishedEvent (com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent)4 Path (java.nio.file.Path)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)3 ImmutableListMultimap.toImmutableListMultimap (com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap)3