1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Make CodanRunner progress monitor work a bit better (#768)

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.
This commit is contained in:
Marc-Andre Laperle 2024-05-17 12:56:16 -04:00 committed by GitHub
parent 3062cdc8d8
commit 0b7c2d9960
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 31 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.core;singleton:=true 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-Activator: org.eclipse.cdt.codan.core.CodanCorePlugin
Bundle-Vendor: %Bundle-Vendor Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.runtime, Require-Bundle: org.eclipse.core.runtime,

View file

@ -24,7 +24,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
/** /**
@ -75,43 +75,45 @@ public class CodanRunner {
} }
} }
int numChildren = children == null ? 0 : children.length; int numChildren = children == null ? 0 : children.length;
int childWeight = 10;
// System.err.println("processing " + resource); // System.err.println("processing " + resource);
monitor.beginTask(NLS.bind(Messages.CodanRunner_Code_analysis_on, resource.getFullPath().toString()), int work = children == null ? checkers : numChildren;
checkers * (1 + numChildren * childWeight)); SubMonitor subMonitor = SubMonitor.convert(monitor, work);
subMonitor.subTask(NLS.bind(Messages.CodanRunner_Code_analysis_on, resource.getFullPath().toString()));
try { try {
CheckersTimeStats.getInstance().checkerStart(CheckersTimeStats.ALL); CheckersTimeStats.getInstance().checkerStart(CheckersTimeStats.ALL);
ICheckerInvocationContext context = new CheckerInvocationContext(resource); ICheckerInvocationContext context = new CheckerInvocationContext(resource);
try { if (children == null) {
for (IChecker checker : chegistry) { try {
if (monitor.isCanceled()) for (IChecker checker : chegistry) {
return; if (subMonitor.isCanceled())
if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) { return;
synchronized (checker) { if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) {
try { synchronized (checker) {
checker.before(resource); try {
CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName()); checker.before(resource);
if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) { CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName());
((IRunnableInEditorChecker) checker).processModel(model, context); if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) {
} else { ((IRunnableInEditorChecker) checker).processModel(model, context);
checker.processResource(resource, 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 if (children != null && (checkerLaunchMode == CheckerLaunchMode.RUN_ON_FULL_BUILD
@ -119,7 +121,7 @@ public class CodanRunner {
for (IResource child : children) { for (IResource child : children) {
if (monitor.isCanceled()) if (monitor.isCanceled())
return; return;
processResource(child, null, checkerLaunchMode, new SubProgressMonitor(monitor, childWeight)); processResource(child, null, checkerLaunchMode, subMonitor.split(1));
} }
} }
} finally { } finally {