mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Indexer: adds cache hits and misses to tracable indexer statistics.
This commit is contained in:
parent
6fa7029c9f
commit
fc81dd18e0
8 changed files with 100 additions and 6 deletions
|
@ -461,4 +461,26 @@ public class CIndex implements IIndex {
|
|||
return flatten(result);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCacheHits() {
|
||||
long result= 0;
|
||||
for (int i = 0; i < fFragments.length; i++) {
|
||||
result+= fFragments[i].getCacheHits();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public long getCacheMisses() {
|
||||
long result= 0;
|
||||
for (int i = 0; i < fFragments.length; i++) {
|
||||
result+= fFragments[i].getCacheMisses();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void resetCacheCounters() {
|
||||
for (int i = 0; i < fFragments.length; i++) {
|
||||
fFragments[i].resetCacheCounters();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,5 +172,20 @@ public interface IIndexFragment {
|
|||
* @throws CoreException
|
||||
* @see IIndexFragment#PROPERTY_FRAGMENT_ID
|
||||
*/
|
||||
public String getProperty(String propertyName) throws CoreException;
|
||||
public String getProperty(String propertyName) throws CoreException;
|
||||
|
||||
/**
|
||||
* Resets the counters for cache-hits and cache-misses.
|
||||
*/
|
||||
void resetCacheCounters();
|
||||
|
||||
/**
|
||||
* Returns cache hits since last reset of counters.
|
||||
*/
|
||||
long getCacheHits();
|
||||
|
||||
/**
|
||||
* Returns cache misses since last reset of counters.
|
||||
*/
|
||||
long getCacheMisses();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -58,4 +58,19 @@ public interface IWritableIndex extends IIndex {
|
|||
* Releases a write lock, reestablishing a certain amount of read locks.
|
||||
*/
|
||||
void releaseWriteLock(int establishReadLockCount);
|
||||
|
||||
/**
|
||||
* Resets the counters for cache-hits
|
||||
*/
|
||||
void resetCacheCounters();
|
||||
|
||||
/**
|
||||
* Returns cache hits since last reset of counters.
|
||||
*/
|
||||
long getCacheHits();
|
||||
|
||||
/**
|
||||
* Returns cache misses since last reset of counters.
|
||||
*/
|
||||
long getCacheMisses();
|
||||
}
|
||||
|
|
|
@ -693,5 +693,17 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
public void close() throws CoreException {
|
||||
fLinkageIDCache.clear();
|
||||
db.close();
|
||||
}
|
||||
|
||||
public long getCacheHits() {
|
||||
return db.getCacheHits();
|
||||
}
|
||||
|
||||
public long getCacheMisses() {
|
||||
return db.getCacheMisses();
|
||||
}
|
||||
|
||||
public void resetCacheCounters() {
|
||||
db.resetCacheCounters();
|
||||
}
|
||||
}
|
|
@ -66,6 +66,8 @@ public class Database {
|
|||
|
||||
private long malloced;
|
||||
private long freed;
|
||||
private long cacheHits;
|
||||
private long cacheMisses;
|
||||
private ChunkCache fCache;
|
||||
|
||||
// public for tests only, you shouldn't need these
|
||||
|
@ -164,6 +166,7 @@ public class Database {
|
|||
Chunk chunk = chunks[index];
|
||||
if (chunk != null && chunk.fWritable == fWritable) {
|
||||
chunk.fCacheHitFlag= true;
|
||||
cacheHits++;
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
@ -172,8 +175,12 @@ public class Database {
|
|||
synchronized(fCache) {
|
||||
chunk= chunks[index];
|
||||
if (chunk == null) {
|
||||
cacheMisses++;
|
||||
chunk = chunks[index] = new Chunk(this, index);
|
||||
}
|
||||
else {
|
||||
cacheHits++;
|
||||
}
|
||||
fCache.add(chunk, fWritable);
|
||||
return chunk;
|
||||
}
|
||||
|
@ -457,4 +464,16 @@ public class Database {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCacheCounters() {
|
||||
cacheHits= cacheMisses= 0;
|
||||
}
|
||||
|
||||
public long getCacheHits() {
|
||||
return cacheHits;
|
||||
}
|
||||
|
||||
public long getCacheMisses() {
|
||||
return cacheMisses;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
}
|
||||
}
|
||||
|
||||
protected void traceEnd(long start) {
|
||||
protected void traceEnd(long start, IWritableIndex index) {
|
||||
if (checkDebugOption(IPDOMIndexerTask.TRACE_STATISTICS, TRUE)) {
|
||||
IndexerProgress info= getProgressInformation();
|
||||
String name= getClass().getName();
|
||||
|
@ -300,7 +300,16 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
+ fStatistics.fReferenceCount + " references, " //$NON-NLS-1$
|
||||
+ fStatistics.fErrorCount + " errors, " //$NON-NLS-1$
|
||||
+ fStatistics.fProblemBindingCount + "(" + nf.format(problemPct) + ") problems."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
if (index != null) {
|
||||
long misses= index.getCacheMisses();
|
||||
long hits= index.getCacheHits();
|
||||
long tries= misses+hits;
|
||||
double missPct= tries==0 ? 0.0 : (double) misses / (double) tries;
|
||||
System.out.println(name + " Cache: " //$NON-NLS-1$
|
||||
+ hits + " hits, " //$NON-NLS-1$
|
||||
+ misses + "(" + nf.format(missPct)+ ") misses."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -100,11 +100,12 @@ class PDOMFastIndexerTask extends PDOMIndexerTask {
|
|||
CCorePlugin.log(e);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
traceEnd(start);
|
||||
traceEnd(start, index);
|
||||
}
|
||||
|
||||
private void setupIndexAndReaderFactory() throws CoreException {
|
||||
this.index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||
this.index.resetCacheCounters();
|
||||
this.fIflCache = new HashMap/*<String,IIndexFileLocation>*/();
|
||||
this.fCodeReaderFactory = new IndexBasedCodeReaderFactory(index, fIflCache);
|
||||
}
|
||||
|
|
|
@ -101,11 +101,12 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
|||
CCorePlugin.log(e);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
traceEnd(start);
|
||||
traceEnd(start, fIndex);
|
||||
}
|
||||
|
||||
private void setupIndex() throws CoreException {
|
||||
fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||
fIndex.resetCacheCounters();
|
||||
}
|
||||
|
||||
private void registerTUsInReaderFactory(Collection/*<ITranslationUnit>*/ sources)
|
||||
|
|
Loading…
Add table
Reference in a new issue