1 19 20 package org.netbeans.modules.masterfs.filebasedfs; 21 import java.util.Iterator ; 22 import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory; 23 24 28 public final class Statistics { 29 30 31 public static final Statistics.TimeConsumer REFRESH_FOLDER = 32 new Statistics.TimeConsumer("Folder refresh"); public static final Statistics.TimeConsumer REFRESH_FILE = 34 new Statistics.TimeConsumer("File refresh"); public static final Statistics.TimeConsumer REFRESH_FS = 36 new Statistics.TimeConsumer("FileSystem refresh"); public static final Statistics.TimeConsumer LISTENERS_CALLS = 38 new Statistics.TimeConsumer("Invocation of FileChangeListeners"); 40 41 private Statistics() {} 42 43 44 public static Statistics.StopWatch getStopWatch(Statistics.TimeConsumer consumer) { 45 return new Statistics.StopWatch(consumer); 46 } 47 48 public static int fileSystems() { 49 return FileBasedFileSystem.getSize(); 50 } 51 52 public static int fileNamings() { 53 return NamingFactory.getSize(); 54 } 55 56 public static int fileObjects() { 57 int retVal = 0; 58 Iterator it = FileBasedFileSystem.getInstances().iterator(); 59 for (int i = 0; it.hasNext(); i++) { 60 FileBasedFileSystem fbs = (FileBasedFileSystem)it.next(); 61 retVal += fileObjectsPerFileSystem(fbs); 62 } 63 64 return retVal; 65 } 66 67 public static int fileObjectsPerFileSystem(FileBasedFileSystem fbs) { 68 return fbs.getFactory().getSize(); 69 } 70 71 72 public static final class TimeConsumer { 73 private int elapsedTime; 74 private int numberOfCalls; 75 private final String description; 76 77 private TimeConsumer(final String description) { 78 this.description = description; 79 } 80 81 public int getConsumedTime() { 82 return elapsedTime; 83 } 84 85 public int getNumberOfCalls() { 86 return numberOfCalls; 87 } 88 89 public void reset() { 90 elapsedTime = 0; 91 numberOfCalls = 0; 92 } 93 94 public String toString() { 95 return description + ": " + numberOfCalls + " calls in " + elapsedTime + "ms"; 96 } 97 98 private void incrementNumerOfCalls() { 99 numberOfCalls++; 100 101 } 102 } 103 104 public static final class StopWatch { 105 private long startTime = 0; 106 private final Statistics.TimeConsumer activity; 107 108 109 110 private StopWatch(Statistics.TimeConsumer activity) { 111 this.activity = activity; 112 } 113 114 115 public void start() { 116 startTime = System.currentTimeMillis(); 117 } 118 119 public void stop() { 120 assert startTime != 0; 121 activity.elapsedTime += (System.currentTimeMillis() - startTime); 122 activity.incrementNumerOfCalls(); 123 startTime = 0; 124 } 125 } 126 } 127 128 | Popular Tags |