Skip to content

Commit

Permalink
fix ETA computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cornul11 committed Feb 13, 2024
1 parent ceceed8 commit c2afcab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void run() throws Exception {
int port = System.getenv("PORT") != null ? Integer.parseInt(System.getenv("PORT")) : 8080;
// Create a Server instance.
Server server = new Server(port);
System.out.println("Server started on port " + port);

// Create a ServerConnector to accept connections from clients.
Connector connector = new ServerConnector(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void printIgnoredUberJars() {
logger.info("Inserted library information of " + insertedUberJars + " uber JARs");
}

public void setProcessedJars(int processedJars) {
this.processedJars.set(processedJars);
}

public int processJarFile(Path jarFilePath) {
JarHandler jarHandler = new JarHandler(jarFilePath, ignoredUberJars, insertedLibraries, config);
List<ClassFileInfo> signatures = jarHandler.extractSignatures();
Expand Down Expand Up @@ -98,24 +102,24 @@ private List<Signature> getSignaturesToInsert(List<ClassFileInfo> signatures,

private void calculateAndLogElapsedTime() {
int processed = processedJars.incrementAndGet();
long elapsedTimeMillis = System.currentTimeMillis() - startTime;
long currentTime = System.currentTimeMillis();
long elapsedTimeMillis = currentTime - startTime;
double elapsedTimeSec = elapsedTimeMillis / 1000.0;
double timePerJarSec = elapsedTimeSec / processed;
double timePerJarSec = processed > 0 ? elapsedTimeSec / processed : 0;

int remainingJars = totalJars - processed;
double etaSec = remainingJars * timePerJarSec;
double etaSec = remainingJars > 0 ? remainingJars * timePerJarSec : 0;

int etaMin = (int) (etaSec / 60);
int etaSecs = (int) (etaSec % 60);

int etaHour = etaMin / 60;
int etaMins = etaMin % 60;

int etaDays = etaHour / 24;
int etaHours = etaHour % 24;

logger.info(String.format("Done processing %d/%d JARs, progress: \u001B[94m%d%%\u001B[0m, ETA: %d days, %d hours, %d minutes and %d seconds",
processed, totalJars, (processed * 100 / totalJars), etaDays, etaHours, etaMins, etaSecs));

}
public void printStats() {
// TODO: investigate why the number of unique hashes is not constant for a constant given set of JARs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public void processFilesFromPathListFile(String pathToFileWithPaths, String last
ExecutorService executor = Executors.newFixedThreadPool(numConsumerThreads);
try {
List<String> allPaths = Files.readAllLines(Paths.get(pathToFileWithPaths));
logger.info("Found " + allPaths.size() + " files from file: " + pathToFileWithPaths);

logger.info("Processing " + allPaths.size() + " files from file: " + pathToFileWithPaths);
// Calculate the number of paths to skip
int skipCount = (lastVisitedPath != null) ? allPaths.indexOf(lastVisitedPath.toString()) + 1 : 0;

// due to the concurrent nature of the app, it is difficult to pinpoint to last processed file,
// thus, this needs a more robust and resilient methodology
Expand All @@ -98,6 +100,9 @@ public void processFilesFromPathListFile(String pathToFileWithPaths, String last
.dropWhile(path -> (lastVisitedPath != null) && !path.equals(lastVisitedPath))
.collect(Collectors.toList());

logger.info("Processing " + pathsToProcess.size() + " files, skipping " + skipCount + " files.");

fileAnalyzer.setProcessedJars(skipCount);
pathsToProcess.stream().forEach(path -> executor.submit(new JarFromPathProcessor(path, fileAnalyzer)));


Expand Down

0 comments on commit c2afcab

Please sign in to comment.