Skip to content

Commit

Permalink
Make CodanRunner progress monitor work a bit better
Browse files Browse the repository at this point in the history
The progress monitor didn't show which file was being analyzed properly.

Also, the work units didn't seem to be counted in a good way because the
progress bar would stay stuck at like 1%. The fix in this commit for that is
not perfect as it gives equal weight to all resources on a same level until
further split into sub monitors. It still works quite a bit better without
requiring more heavy changes.

Also fix usage of deprecated SubProgressMonitor.
  • Loading branch information
MarkZ3 committed Apr 27, 2024
1 parent f0ae450 commit 34a7a2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.core;singleton:=true
Bundle-Version: 4.2.100.qualifier
Bundle-Version: 4.2.200.qualifier
Bundle-Activator: org.eclipse.cdt.codan.core.CodanCorePlugin
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osgi.util.NLS;

/**
Expand Down Expand Up @@ -75,51 +75,53 @@ private static void processResource(IResource resource, Object model, CheckerLau
}
}
int numChildren = children == null ? 0 : children.length;
int childWeight = 10;
// System.err.println("processing " + resource);
monitor.beginTask(NLS.bind(Messages.CodanRunner_Code_analysis_on, resource.getFullPath().toString()),
checkers * (1 + numChildren * childWeight));
int work = children == null ? checkers : numChildren;
SubMonitor subMonitor = SubMonitor.convert(monitor, work);
subMonitor.subTask(NLS.bind(Messages.CodanRunner_Code_analysis_on, resource.getFullPath().toString()));
try {
CheckersTimeStats.getInstance().checkerStart(CheckersTimeStats.ALL);
ICheckerInvocationContext context = new CheckerInvocationContext(resource);
try {
for (IChecker checker : chegistry) {
if (monitor.isCanceled())
return;
if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) {
synchronized (checker) {
try {
checker.before(resource);
CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName());
if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) {
((IRunnableInEditorChecker) checker).processModel(model, context);
} else {
checker.processResource(resource, context);
if (children == null) {
try {
for (IChecker checker : chegistry) {
if (subMonitor.isCanceled())
return;
if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) {
synchronized (checker) {
try {
checker.before(resource);
CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName());
if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) {
((IRunnableInEditorChecker) checker).processModel(model, context);
} else {
checker.processResource(resource, context);
}
} catch (OperationCanceledException e) {
return;
} catch (Throwable e) {
CodanCorePlugin.log(e);
} finally {
CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName());
checker.after(resource);
}
} catch (OperationCanceledException e) {
return;
} catch (Throwable e) {
CodanCorePlugin.log(e);
} finally {
CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName());
checker.after(resource);
}
}
subMonitor.worked(1);
}
monitor.worked(1);
} finally {
context.dispose();
CheckersTimeStats.getInstance().checkerStop(CheckersTimeStats.ALL);
//CheckersTimeStats.getInstance().printStats();
}
} finally {
context.dispose();
CheckersTimeStats.getInstance().checkerStop(CheckersTimeStats.ALL);
//CheckersTimeStats.getInstance().printStats();
}

if (children != null && (checkerLaunchMode == CheckerLaunchMode.RUN_ON_FULL_BUILD
|| checkerLaunchMode == CheckerLaunchMode.RUN_ON_DEMAND)) {
for (IResource child : children) {
if (monitor.isCanceled())
return;
processResource(child, null, checkerLaunchMode, new SubProgressMonitor(monitor, childWeight));
processResource(child, null, checkerLaunchMode, subMonitor.split(1));
}
}
} finally {
Expand Down

0 comments on commit 34a7a2c

Please sign in to comment.