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));
}
}
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;
}
}
}
}
}
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);
}
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();
}
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)));
}
Aggregations