Skip to content

Commit

Permalink
Log a message with total sync time
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunnar Wagenknecht committed Feb 12, 2024
1 parent 9ec919e commit f70dc37
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.BAZEL_NATURE_ID;
import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.RESOURCE_FILTER_BAZEL_OUTPUT_SYMLINKS_ID;
import static com.salesforce.bazel.sdk.util.DurationUtil.humanReadableFormat;
import static java.lang.String.format;
import static java.nio.file.Files.isReadable;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -677,17 +678,25 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
}
}

// broadcast sync metrics
// broadcast & log sync metrics
var duration = Duration.between(start, Instant.now());
var projectsCount = targetProjects.size();
var targetsCount = targets.size();
getEventAdmin().postEvent(
new SyncFinishedEvent(
start,
duration,
"ok",
targetProjects.size(),
targets.size(),
projectsCount,
targetsCount,
workspace.getBazelProjectView().targetDiscoveryStrategy(),
workspace.getBazelProjectView().targetProvisioningStrategy()).build());
LOG.info(
"Synchronization of workspace '{}' finished successfully (duration {}, {} targets, {} projects)",
workspaceName,
humanReadableFormat(duration),
targetsCount,
projectsCount);

return Status.OK_STATUS;
} catch (OperationCanceledException e) {
Expand All @@ -712,5 +721,4 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.salesforce.bazel.sdk.command;

import static com.salesforce.bazel.sdk.util.DurationUtil.humanReadableFormat;
import static java.lang.String.format;
import static java.util.stream.Collectors.joining;
import static org.fusesource.jansi.Ansi.ansi;
Expand All @@ -12,23 +13,15 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

import com.salesforce.bazel.sdk.command.DefaultBazelCommandExecutor.PreparedCommandLine;
import com.salesforce.bazel.sdk.util.DurationUtil;

/**
* A version of {@link ProcessStreamsProvider} printing more information about the command execution.
*/
public abstract class VerboseProcessStreamsProvider extends ProcessStreamsProvider {

protected static String humanReadableFormat(Duration duration) {
return duration.truncatedTo(ChronoUnit.MILLIS)
.toString()
.substring(2)
.replaceAll("(\\d[HMS])(?!$)", "$1 ")
.toLowerCase();
}

private final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("EEE HH:mm:ss");

protected final BazelCommand<?> command;
Expand Down Expand Up @@ -92,7 +85,7 @@ public void executionFinished(int exitCode) {
ansi().a(ITALIC)
.a("Process finished in ")
.a(INTENSITY_BOLD)
.a(humanReadableFormat(executionTime))
.a(DurationUtil.humanReadableFormat(executionTime))
.reset()
.toString());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*-
* Copyright (c) 2024 Salesforce and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Salesforce - adapted from M2E, JDT or other Eclipse project
*/
package com.salesforce.bazel.sdk.util;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

/**
* Utility for {@link Duration}
*/
public class DurationUtil {

public static String humanReadableFormat(Duration duration) {
return duration.truncatedTo(ChronoUnit.MILLIS)
.toString()
.substring(2)
.replaceAll("(\\d[HMS])(?!$)", "$1 ")
.toLowerCase();
}

}

0 comments on commit f70dc37

Please sign in to comment.