Skip to content

Commit

Permalink
still more diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi Delbruck authored and Tobi Delbruck committed Jun 8, 2019
1 parent a3e772d commit 649d0e1
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/net/sf/jaer/util/SubclassFinder.java
Expand Up @@ -46,7 +46,7 @@ public class SubclassFinder {
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes)); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
className2subclassListFileNameMap = (HashMap<String, String>) in.readObject(); className2subclassListFileNameMap = (HashMap<String, String>) in.readObject();
in.close(); in.close();
log.info("loaded SubclassFinder cache existing filename hashmap from preferences. Key is "+ className2subclassListFileNameMap); log.info("loaded SubclassFinder cache existing filename hashmap from preferences. Key is " + className2subclassListFileNameMap);
} else { } else {
log.info("no existing SubclassFinder cache filename hashmap to load, must scan classpath to find subclasses"); log.info("no existing SubclassFinder cache filename hashmap to load, must scan classpath to find subclasses");
} }
Expand Down Expand Up @@ -155,6 +155,7 @@ public SubclassFinderWorker(Class clazz, DefaultListModel<ClassNameWithDescripti
*/ */
@Override @Override
protected ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> doInBackground() throws Exception { protected ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> doInBackground() throws Exception {
long startTime = System.currentTimeMillis();
setProgress(0); setProgress(0);
String superClassName = clazz.getName(); String superClassName = clazz.getName();
ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> classes = new ArrayList<>(300); ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> classes = new ArrayList<>(300);
Expand All @@ -163,17 +164,17 @@ protected ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> doInBackground
return classes; return classes;
} }
// see if cache should be used // see if cache should be used
if (useCacheIfAvailable && className2subclassListFileNameMap != null ) { if (useCacheIfAvailable && className2subclassListFileNameMap != null) {
String cachefilename=className2subclassListFileNameMap.get(superClassName); String cachefilename = className2subclassListFileNameMap.get(superClassName);
if(cachefilename==null){ if (cachefilename == null) {
log.info("no cache file found for "+superClassName); log.info("no cache file found for " + superClassName);
} }
File f = null; File f = null;
if(cachefilename!=null){ if (cachefilename != null) {
f=new File(cachefilename); f = new File(cachefilename);
} }
if (f != null && f.exists() && f.isFile() ) { if (f != null && f.exists() && f.isFile()) {
log.info("for super class " + superClassName + " found cache file " + f.getAbsolutePath()+"; reading subclasses from this file"); log.info("for super class " + superClassName + " found cache file " + f.getAbsolutePath() + "; reading subclasses from this file");
LineNumberReader is = new LineNumberReader(new FileReader(f)); LineNumberReader is = new LineNumberReader(new FileReader(f));
// count lines for progress // count lines for progress
while (is.skip(Long.MAX_VALUE) > 0) { while (is.skip(Long.MAX_VALUE) > 0) {
Expand All @@ -190,19 +191,22 @@ protected ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> doInBackground
final ClassNameWithDescriptionAndDevelopmentStatus myFoundClass = new ClassNameWithDescriptionAndDevelopmentStatus(c); final ClassNameWithDescriptionAndDevelopmentStatus myFoundClass = new ClassNameWithDescriptionAndDevelopmentStatus(c);
//sees if e.g. superclass AEChip can be cast from e.g. c=DVS128, i.e. can we do (AEChip)DVS128? //sees if e.g. superclass AEChip can be cast from e.g. c=DVS128, i.e. can we do (AEChip)DVS128?
classes.add(myFoundClass); classes.add(myFoundClass);
int prog=(int) (100 * ((float) (linesReadCount++) / nLines)); int prog = (int) (100 * ((float) (linesReadCount++) / nLines));
if(prog>100) prog=100; if (prog > 100) {
prog = 100;
}
setProgress(prog); setProgress(prog);
publish(myFoundClass); publish(myFoundClass);
line=is.readLine(); line = is.readLine();
} }
log.info("Read "+classes.size()+" subclasses from "+cachefilename); long duration = System.currentTimeMillis() - startTime;
log.info("Read " + classes.size() + " subclasses from " + cachefilename + " in " + duration / 1000 + "s");
return classes; return classes;
}else{ } else {
log.info("Cache filename "+cachefilename+" does not lead to a readable file; will rescan entire classpath"); log.info("Cache filename " + cachefilename + " does not lead to a readable file; will rescan entire classpath");
} }
} }
log.info("no cache found for " + superClassName + "; now scanning entire classpath to build list of subclasses of "+superClassName); log.info("no cache found for " + superClassName + "; now scanning entire classpath to build list of subclasses of " + superClassName);
Class superClass = FastClassFinder.forName(superClassName); Class superClass = FastClassFinder.forName(superClassName);
List<String> allClasses = ListClasses.listClasses(); // expensive, must search all classpath and make big string array list List<String> allClasses = ListClasses.listClasses(); // expensive, must search all classpath and make big string array list
int n = ".class".length(); int n = ".class".length();
Expand Down Expand Up @@ -267,7 +271,7 @@ protected ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> doInBackground
ps.println(clz.getClassName()); ps.println(clz.getClassName());
} }
ps.close(); ps.close();
log.info("wrote "+classes.size()+" classes to cache file "+cacheFile.getAbsolutePath()); log.info("wrote " + classes.size() + " classes to cache file " + cacheFile.getAbsolutePath());
if (className2subclassListFileNameMap == null) { if (className2subclassListFileNameMap == null) {
className2subclassListFileNameMap = new HashMap<String, String>(); className2subclassListFileNameMap = new HashMap<String, String>();
} }
Expand All @@ -279,7 +283,9 @@ protected ArrayList<ClassNameWithDescriptionAndDevelopmentStatus> doInBackground
// Get the bytes of the serialized object // Get the bytes of the serialized object
byte[] buf = bos.toByteArray(); byte[] buf = bos.toByteArray();
prefs.putByteArray(SUBCLASS_FINDERFILENAME_HASH_MAP_PREFS_KEY, buf); prefs.putByteArray(SUBCLASS_FINDERFILENAME_HASH_MAP_PREFS_KEY, buf);
log.info("stored cache file name with preferences key "+SUBCLASS_FINDERFILENAME_HASH_MAP_PREFS_KEY); log.info("stored cache file name with preferences key " + SUBCLASS_FINDERFILENAME_HASH_MAP_PREFS_KEY);
long duration = System.currentTimeMillis() - startTime;
log.info("Scanned " + classes.size() + " subclasses in " + duration / 1000 + "s");


return classes; return classes;
} }
Expand Down

0 comments on commit 649d0e1

Please sign in to comment.