use of com.google.copybara.profiler.Profiler in project copybara by google.
the class Feedback method run.
@Override
public void run(Path workdir, @Nullable String sourceRef) throws RepoException, ValidationException {
// TODO(danielromero): Handle correctly null sourceRefs
SkylarkConsole console = new SkylarkConsole(generalOptions.console());
Profiler profiler = generalOptions.profiler();
try (ProfilerTask ignore = profiler.start("run/" + name)) {
for (Action action : actions) {
try (ProfilerTask ignore2 = profiler.start(action.getName())) {
action.run(new FeedbackContext(origin, destination, sourceRef, console));
}
}
}
ValidationException.checkCondition(console.getErrorCount() == 0, "%d errors executing the feedback migration", console.getErrorCount());
}
use of com.google.copybara.profiler.Profiler in project copybara by google.
the class AbstractGitHubApiTest method setUpFamework.
@Before
public void setUpFamework() throws Exception {
MockitoAnnotations.initMocks(this);
profiler = new Profiler(Ticker.systemTicker());
profiler.init(ImmutableList.of(new LogProfilerListener()));
api = new GitHubApi(getTransport(), profiler);
}
use of com.google.copybara.profiler.Profiler in project copybara by google.
the class AbstractGithubApiTest method setUpFamework.
@Before
public void setUpFamework() throws Exception {
Profiler profiler = new Profiler(Ticker.systemTicker());
profiler.init(ImmutableList.of(new LogProfilerListener()));
api = new GithubApi(getTransport(), profiler);
}
use of com.google.copybara.profiler.Profiler in project copybara by google.
the class Workflow method run.
@Override
public void run(Path workdir, ImmutableList<String> sourceRefs) throws RepoException, IOException, ValidationException {
if (sourceRefs.size() > 1) {
throw new CommandLineException(String.format("Workflow does not support multiple source_ref arguments yet: %s", ImmutableList.copyOf(sourceRefs)));
}
@Nullable String sourceRef = sourceRefs.size() == 1 ? sourceRefs.get(0) : null;
validateFlags();
try (ProfilerTask ignore = profiler().start("run/" + name)) {
console.progress("Getting last revision: " + "Resolving " + ((sourceRef == null) ? "origin reference" : sourceRef));
O resolvedRef = generalOptions.repoTask("origin.resolve_source_ref", () -> origin.resolve(sourceRef));
logger.log(Level.INFO, String.format("Running Copybara for workflow '%s' and ref '%s': %s", name, resolvedRef.asString(), this.toString()));
logger.log(Level.INFO, String.format("Using working directory : %s", workdir));
ImmutableList.Builder<DestinationEffect> allEffects = ImmutableList.builder();
WorkflowRunHelper<O, D> helper = newRunHelper(workdir, resolvedRef, sourceRef, event -> {
allEffects.addAll(event.getDestinationEffects());
eventMonitors().dispatchEvent(m -> m.onChangeMigrationFinished(event));
});
try (ProfilerTask ignored = profiler().start(mode.toString().toLowerCase())) {
mode.run(helper);
} finally {
if (!getGeneralOptions().dryRunMode) {
try (ProfilerTask ignored = profiler().start("after_all_migration")) {
ImmutableList<DestinationEffect> effects = allEffects.build();
ImmutableList<DestinationEffect> resultEffects = runHooks(effects, getAfterAllMigrationActions(), // Only do this once for all the actions
memoized(c -> helper.getOriginReader().getFeedbackEndPoint(c)), // Only do this once for all the actions
memoized(c -> helper.getDestinationWriter().getFeedbackEndPoint(c)), resolvedRef);
if (effects.size() != resultEffects.size()) {
console.warn("Effects where created in after_all_migrations, but they are ignored.");
}
}
}
}
}
}
use of com.google.copybara.profiler.Profiler in project copybara by google.
the class Mirror method defaultMirror.
private void defaultMirror(GitRepository repo) throws RepoException, ValidationException {
List<String> fetchRefspecs = refspec.stream().map(r -> r.originToOrigin().toString()).collect(Collectors.toList());
generalOptions.console().progressFmt("Fetching from %s", origin);
Profiler profiler = generalOptions.profiler();
try (ProfilerTask ignore1 = profiler.start("fetch")) {
repo.fetch(origin, /*prune=*/
true, /*force=*/
true, fetchRefspecs, partialFetch);
}
if (generalOptions.dryRunMode) {
generalOptions.console().progressFmt("Skipping push to %s. You can check the" + " commits to push in: %s", destination, repo.getGitDir());
} else {
generalOptions.console().progressFmt("Pushing to %s", destination);
List<Refspec> pushRefspecs = mirrorOptions.forcePush || generalOptions.isForced() ? refspec.stream().map(Refspec::withAllowNoFastForward).collect(Collectors.toList()) : refspec;
try (ProfilerTask ignore1 = profiler.start("push")) {
repo.push().prune(prune).withRefspecs(destination, pushRefspecs).run();
} catch (NonFastForwardRepositoryException e) {
// multiple refs, and that mirrors, it is better to just fail and tell the user.
throw new ValidationException("Error pushing some refs because origin is behind:" + e.getMessage(), e);
}
}
}
Aggregations