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

Indexer: adds option to trace problems.

This commit is contained in:
Markus Schorn 2006-12-19 16:37:22 +00:00
parent b941080310
commit a5e988c391
2 changed files with 34 additions and 12 deletions

View file

@ -24,11 +24,14 @@ org.eclipse.cdt.core/debug/deltaprocessor=false
# Reports file type resolver activity # Reports file type resolver activity
org.eclipse.cdt.core/debug/typeresolver=false org.eclipse.cdt.core/debug/typeresolver=false
# Reports timings for PDOM
org.eclipse.cdt.core/debug/pdomtimings=false
# Reports sequence of files indexed # Reports sequence of files indexed
org.eclipse.cdt.core/debug/indexer=false org.eclipse.cdt.core/debug/indexer/activity=false
# Reports statistics for indexer
org.eclipse.cdt.core/debug/indexer/statistics=false
# Reports statistics for indexer
org.eclipse.cdt.core/debug/indexer/problems=false
# Code formatter debugging # Code formatter debugging
org.eclipse.cdt.core/debug/formatter=false org.eclipse.cdt.core/debug/formatter=false

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.pdom.indexer; package org.eclipse.cdt.internal.core.pdom.indexer;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -94,8 +95,9 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected Map/*<IIndexFileLocation, Object>*/ fContextMap = new HashMap/*<IIndexFileLocation, Object>*/(); protected Map/*<IIndexFileLocation, Object>*/ fContextMap = new HashMap/*<IIndexFileLocation, Object>*/();
protected volatile String fMessage; protected volatile String fMessage;
private boolean fTrace; private boolean fShowActivity;
private boolean fShowStatistics; private boolean fShowStatistics;
private boolean fShowProblems;
private int fResolutionTime; private int fResolutionTime;
private int fParsingTime; private int fParsingTime;
private int fAddToIndexTime; private int fAddToIndexTime;
@ -105,9 +107,10 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
private int fProblemBindingCount= 0; private int fProblemBindingCount= 0;
protected PDOMIndexerTask() { protected PDOMIndexerTask() {
fTrace= checkDebugOption("indexer", "true"); //$NON-NLS-1$//$NON-NLS-2$ fShowActivity= checkDebugOption("indexer/activity", "true"); //$NON-NLS-1$//$NON-NLS-2$
fShowStatistics= checkDebugOption("pdomtimings", "true"); //$NON-NLS-1$//$NON-NLS-2$ fShowStatistics= checkDebugOption("indexer/statistics", "true"); //$NON-NLS-1$//$NON-NLS-2$
} fShowProblems= checkDebugOption("indexer/problems", "true"); //$NON-NLS-1$//$NON-NLS-2$
}
private boolean checkDebugOption(String option, String value) { private boolean checkDebugOption(String option, String value) {
String trace = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/" + option); //$NON-NLS-1$ String trace = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/" + option); //$NON-NLS-1$
@ -224,7 +227,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
protected void parseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException { protected void parseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
IPath path= tu.getPath(); IPath path= tu.getPath();
try { try {
if (fTrace) { if (fShowActivity) {
System.out.println("Indexer: parsing " + path.toOSString()); //$NON-NLS-1$ System.out.println("Indexer: parsing " + path.toOSString()); //$NON-NLS-1$
} }
fMessage= MessageFormat.format(Messages.PDOMIndexerTask_parsingFileTask, fMessage= MessageFormat.format(Messages.PDOMIndexerTask_parsingFileTask,
@ -351,7 +354,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
final IBinding binding= name.resolveBinding(); final IBinding binding= name.resolveBinding();
if (fShowStatistics) { if (fShowStatistics) {
if (binding instanceof IProblemBinding) if (binding instanceof IProblemBinding)
fProblemBindingCount++; reportProblem((IProblemBinding) binding);
else if (name.isReference()) else if (name.isReference())
fReferenceCount++; fReferenceCount++;
else else
@ -373,7 +376,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
IIndexFileLocation path = orderedPaths[i]; IIndexFileLocation path = orderedPaths[i];
if (path != null) { if (path != null) {
if (fTrace) { if (fShowActivity) {
System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$ System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$
} }
IIndexFile file= addToIndex(index, path, symbolMap); IIndexFile file= addToIndex(index, path, symbolMap);
@ -399,6 +402,17 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
} }
} }
private void reportProblem(IProblemBinding problem) {
fProblemBindingCount++;
if (fShowProblems) {
String msg= "Indexer problem at "+ problem.getFileName() + ": " + problem.getLineNumber(); //$NON-NLS-1$//$NON-NLS-2$
String pmsg= problem.getMessage();
if (pmsg != null && pmsg.length() > 0)
msg+= "; " + problem.getMessage(); //$NON-NLS-1$
System.out.println(msg);
}
}
private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException { private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException {
LinkedHashSet/*<IIndexFileLocation>*/ orderedIncludes= new LinkedHashSet/*<IIndexFileLocation>*/(); LinkedHashSet/*<IIndexFileLocation>*/ orderedIncludes= new LinkedHashSet/*<IIndexFileLocation>*/();
ArrayList/*<IIndexFileLocation>*/ stack= new ArrayList/*<IIndexFileLocation>*/(); ArrayList/*<IIndexFileLocation>*/ stack= new ArrayList/*<IIndexFileLocation>*/();
@ -518,11 +532,16 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
+ (fParsingTime-fResolutionTime-fAddToIndexTime) + " parser, " //$NON-NLS-1$ + (fParsingTime-fResolutionTime-fAddToIndexTime) + " parser, " //$NON-NLS-1$
+ fResolutionTime + " resolution, " //$NON-NLS-1$ + fResolutionTime + " resolution, " //$NON-NLS-1$
+ fAddToIndexTime + " index update."); //$NON-NLS-1$ + fAddToIndexTime + " index update."); //$NON-NLS-1$
int sum= fDeclarationCount+fReferenceCount+fProblemBindingCount;
double problemPct= sum==0 ? 0.0 : (double) fProblemBindingCount / (double) sum;
NumberFormat nf= NumberFormat.getPercentInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
System.out.println(name + " Result: " //$NON-NLS-1$ System.out.println(name + " Result: " //$NON-NLS-1$
+ fDeclarationCount + " declarations, " //$NON-NLS-1$ + fDeclarationCount + " declarations, " //$NON-NLS-1$
+ fReferenceCount + " references, " //$NON-NLS-1$ + fReferenceCount + " references, " //$NON-NLS-1$
+ fErrorCount + " errors, " //$NON-NLS-1$ + fErrorCount + " errors, " //$NON-NLS-1$
+ fProblemBindingCount + " problems."); //$NON-NLS-1$ + fProblemBindingCount + "(" + nf.format(problemPct) + ") problems."); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }