mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Indexer: Minor improvement of progress reporting.
This commit is contained in:
parent
1d087b260f
commit
ae557bd281
5 changed files with 63 additions and 59 deletions
|
@ -16,6 +16,7 @@ public class IndexerProgress {
|
|||
public int fTotalSourcesEstimate;
|
||||
public int fCompletedHeaders;
|
||||
public int fCompletedSources;
|
||||
public int fTimeEstimate;
|
||||
public String fMonitorDetail;
|
||||
|
||||
public IndexerProgress() {
|
||||
|
@ -32,4 +33,8 @@ public class IndexerProgress {
|
|||
public int getRemainingSources() {
|
||||
return fTotalSourcesEstimate-fCompletedSources;
|
||||
}
|
||||
|
||||
public int getTimeEstimate() {
|
||||
return fTotalSourcesEstimate > 0 ? fTotalSourcesEstimate : fTimeEstimate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
|
@ -26,8 +25,9 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
*
|
||||
*/
|
||||
public class PDOMIndexerJob extends Job {
|
||||
private static final int PROGRESS_UPDATE_INTERVAL = 500;
|
||||
private static final int TOTAL_MONITOR_WORK = 1000;
|
||||
|
||||
private static final int TOTAL_MONITOR_WORK = 100000;
|
||||
private final PDOMManager pdomManager;
|
||||
private IPDOMIndexerTask currentTask;
|
||||
private boolean cancelledByManager= false;
|
||||
|
@ -42,8 +42,6 @@ public class PDOMIndexerJob extends Job {
|
|||
}
|
||||
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
fMonitor = monitor;
|
||||
String taskName = CCorePlugin.getResourceString("pdom.indexer.task"); //$NON-NLS-1$
|
||||
monitor.beginTask(taskName, TOTAL_MONITOR_WORK);
|
||||
|
@ -57,7 +55,6 @@ public class PDOMIndexerJob extends Job {
|
|||
public void setCanceled(boolean cancelled) {
|
||||
fMonitor.setCanceled(cancelled);
|
||||
}
|
||||
|
||||
};
|
||||
synchronized(taskMutex) {
|
||||
currentTask= null;
|
||||
|
@ -78,12 +75,6 @@ public class PDOMIndexerJob extends Job {
|
|||
}
|
||||
}
|
||||
while (currentTask != null);
|
||||
|
||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||
+ "/debug/pdomtimings"); //$NON-NLS-1$
|
||||
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
|
||||
System.out.println("PDOM Indexer Job Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
|
||||
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
|
@ -117,7 +108,7 @@ public class PDOMIndexerJob extends Job {
|
|||
while(!m.isCanceled() && !targetMonitor.isCanceled()) {
|
||||
currentTick= pdomManager.getMonitorMessage(targetMonitor, currentTick, TOTAL_MONITOR_WORK);
|
||||
try {
|
||||
Thread.sleep(350);
|
||||
Thread.sleep(PROGRESS_UPDATE_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
|
|
|
@ -368,11 +368,9 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
else {
|
||||
if (fCurrentTask != null) {
|
||||
IndexerProgress info= fCurrentTask.getProgressInformation();
|
||||
if (info != null) {
|
||||
fCompletedSources+= info.fCompletedSources;
|
||||
fCompletedHeaders+= info.fCompletedHeaders;
|
||||
}
|
||||
}
|
||||
result= fCurrentTask= (IPDOMIndexerTask)fTaskQueue.removeFirst();
|
||||
}
|
||||
}
|
||||
|
@ -601,7 +599,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
}
|
||||
|
||||
public boolean joinIndexer(int waitMaxMillis, IProgressMonitor monitor) {
|
||||
monitor.beginTask(Messages.PDOMManager_JoinIndexerTask, 1000);
|
||||
final int totalTicks = 1000;
|
||||
monitor.beginTask(Messages.PDOMManager_JoinIndexerTask, totalTicks);
|
||||
long limit= System.currentTimeMillis()+waitMaxMillis;
|
||||
try {
|
||||
int currentTicks= 0;
|
||||
|
@ -609,7 +608,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
if (monitor.isCanceled()) {
|
||||
return false;
|
||||
}
|
||||
currentTicks= getMonitorMessage(monitor, currentTicks, 1000);
|
||||
currentTicks= getMonitorMessage(monitor, currentTicks, totalTicks);
|
||||
synchronized(fTaskQueueMutex) {
|
||||
if (isIndexerIdle()) {
|
||||
return true;
|
||||
|
@ -643,33 +642,26 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
int remainingSources= 0;
|
||||
int completedSources= 0;
|
||||
int completedHeaders= 0;
|
||||
int unknown= 0;
|
||||
int totalEstimate= 0;
|
||||
String detail= null;
|
||||
IndexerProgress info;
|
||||
synchronized (fTaskQueueMutex) {
|
||||
completedHeaders= fCompletedHeaders;
|
||||
completedSources= fCompletedSources;
|
||||
totalEstimate= fCompletedHeaders+fCompletedSources;
|
||||
for (Iterator iter = fTaskQueue.iterator(); iter.hasNext();) {
|
||||
IPDOMIndexerTask task = (IPDOMIndexerTask) iter.next();
|
||||
info= task.getProgressInformation();
|
||||
if (info == null) {
|
||||
unknown++;
|
||||
}
|
||||
else {
|
||||
remainingSources+= info.getRemainingSources();
|
||||
}
|
||||
totalEstimate+= info.getTimeEstimate();
|
||||
}
|
||||
if (fCurrentTask != null) {
|
||||
info= fCurrentTask.getProgressInformation();
|
||||
if (info == null) {
|
||||
unknown++;
|
||||
}
|
||||
else {
|
||||
remainingSources+= info.getRemainingSources();
|
||||
completedHeaders+= info.fCompletedHeaders;
|
||||
completedSources+= info.fCompletedSources;
|
||||
detail= info.fMonitorDetail;
|
||||
}
|
||||
totalEstimate+= info.getTimeEstimate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -682,9 +674,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
}
|
||||
monitor.subTask(msg);
|
||||
|
||||
totalSources+= unknown*1000;
|
||||
if (completedSources > 0 && totalSources >= completedSources) {
|
||||
int newTick= completedSources*base/totalSources;
|
||||
if (completedSources > 0 && totalEstimate >= completedSources) {
|
||||
int newTick= completedSources*base/totalEstimate;
|
||||
if (newTick > currentTicks) {
|
||||
monitor.worked(newTick-currentTicks);
|
||||
return newTick;
|
||||
|
|
|
@ -25,18 +25,27 @@ import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
|||
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||
private static final String TRUE= String.valueOf(true);
|
||||
private static final ITranslationUnit[] NO_TUS = new ITranslationUnit[0];
|
||||
|
||||
private IPDOMIndexer fIndexer;
|
||||
private IPDOMIndexerTask fDelegate;
|
||||
private final IPDOMIndexer fIndexer;
|
||||
private final IndexerProgress fProgress;
|
||||
private volatile IPDOMIndexerTask fDelegate;
|
||||
|
||||
public PDOMRebuildTask(IPDOMIndexer indexer) {
|
||||
fIndexer= indexer;
|
||||
fProgress= createProgress(indexer.getProject().getElementName());
|
||||
}
|
||||
|
||||
private IndexerProgress createProgress(String prjName) {
|
||||
IndexerProgress progress= new IndexerProgress();
|
||||
progress.fTimeEstimate= 1000;
|
||||
progress.fMonitorDetail= NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask, prjName);
|
||||
return progress;
|
||||
}
|
||||
|
||||
public IPDOMIndexer getIndexer() {
|
||||
return fIndexer;
|
||||
|
@ -73,7 +82,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
|||
}
|
||||
}
|
||||
|
||||
private void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {
|
||||
private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {
|
||||
boolean allFiles= TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES));
|
||||
List list= new ArrayList();
|
||||
TranslationUnitCollector collector= new TranslationUnitCollector(list, allFiles, monitor);
|
||||
|
@ -83,8 +92,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
|||
}
|
||||
|
||||
|
||||
public IndexerProgress getProgressInformation() {
|
||||
return fDelegate != null ? fDelegate.getProgressInformation() : null;
|
||||
public synchronized IndexerProgress getProgressInformation() {
|
||||
return fDelegate != null ? fDelegate.getProgressInformation() : fProgress;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
@ -30,13 +31,16 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
|||
public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
|
||||
private static final String TRUE = String.valueOf(true);
|
||||
|
||||
private IPDOMIndexer fIndexer;
|
||||
private boolean fAllFiles;
|
||||
private IPDOMIndexerTask fDelegate;
|
||||
final private IPDOMIndexer fIndexer;
|
||||
final private boolean fAllFiles;
|
||||
final private IPDOMIndexerTask fDelegate;
|
||||
final private IndexerProgress fProgress;
|
||||
|
||||
public PDOMResourceDeltaTask(IPDOMIndexer indexer, ICElementDelta delta) throws CoreException {
|
||||
fIndexer= indexer;
|
||||
fProgress= new IndexerProgress();
|
||||
fAllFiles= TRUE.equals(getIndexer().getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES));
|
||||
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
||||
List a= new ArrayList();
|
||||
List c= new ArrayList();
|
||||
List r= new ArrayList();
|
||||
|
@ -48,6 +52,13 @@ public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
|
|||
ITranslationUnit[] ra= (ITranslationUnit[]) r.toArray(new ITranslationUnit[r.size()]);
|
||||
fDelegate= indexer.createTask(aa, ca, ra);
|
||||
}
|
||||
else {
|
||||
fDelegate= null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fDelegate= null;
|
||||
}
|
||||
}
|
||||
|
||||
private void processDelta(ICElementDelta delta, List added, List changed, List removed, IProgressMonitor pm) throws CoreException {
|
||||
|
@ -90,7 +101,6 @@ public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void collectSources(ICContainer container, Collection sources, IProgressMonitor pm) throws CoreException {
|
||||
|
@ -108,11 +118,10 @@ public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
|
|||
}
|
||||
|
||||
public IndexerProgress getProgressInformation() {
|
||||
return fDelegate == null ? null : fDelegate.getProgressInformation();
|
||||
return fDelegate != null ? fDelegate.getProgressInformation() : fProgress;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return fDelegate == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue