def perf_tcl_scan(dbpath): """Time scanning and loading some "real world" Tcl scripts into the CIDB. To run this time test: ciperf -f perf.db -t tcl_scan """ import which import codeintel import threading scripts = glob.glob(os.path.join(g_corpus_dir, "*.tcl")) if not scripts: raise Error("no scripts found for 'perf_tcl_scan'") finished = threading.Event() class MyManager(codeintel.Manager): scanned = [] def requestCompleted(self, request): self.scanned.append(request.path) if len(self.scanned) == len(scripts): finished.set() mgr = MyManager() mgr.initialize(dbpath) try: # Force a re-scan of our scripts. for script in scripts: r = ScanRequest(script, "Tcl", PRIORITY_OPEN, force=1) mgr.addRequest(r) finished.wait() # wait until done scanning finally: mgr.finalize()
def perf_setup_perl_completion(dbpath): """Setup for perl_completion(). This will ensure that your CIDB has the Perl files that "perl_completion" requires. """ import which import codeintel from codeintel.scheduler import PRIORITY_OPEN from codeintel import ScanRequest, CodeIntelError # Upgrade CIDB, if required, and initialize. # This should ensure that python.cix and perl.cix are loaded. mgr = codeintel.Manager(coreLanguages=["Python", "Perl"]) state, details = mgr.getCIDBUpgradeInfo(dbpath) if state == codeintel.CIDB_UPGRADE_NECESSARY: mgr.upgradeCIDB(dbpath) elif state == codeintel.CIDB_UPGRADE_NOT_POSSIBLE: raise Error("CIDB is not upgradable: %r" % dbpath) mgr.initialize(dbpath) try: # Scan in a test Perl script. script = os.path.join(g_corpus_dir, "GET.pl") # Gisle's GET Perl script r = ScanRequest(script, "Perl", PRIORITY_OPEN) mgr.addRequest(r) # let scheduler finish its scans time.sleep(2) while mgr._scheduler and mgr._scheduler.getNumRequests(): time.sleep(1) finally: mgr.finalize()
def perf_perl_scan(dbpath): """Time scanning and loading a "real world" Perl script into the CIDB. To run this time test: ciperf -f perf.db -t perl_scan """ import which import codeintel import threading # Gisle's HTTP Perl scripts (good real-world examples) plus some # Perl 5.8 stdlib modules. scripts = glob.glob(os.path.join(g_corpus_dir, "*.pl")) scripts += glob.glob(os.path.join(g_corpus_dir, "*.pm")) if not scripts: raise Error("no scripts found for 'perf_perl_scan'") finished = threading.Event() class MyManager(codeintel.Manager): scanned = [] def requestCompleted(self, request): self.scanned.append(request.path) if len(self.scanned) == len(scripts): finished.set() # Do NOT set Perl as a core language: don't want included re-scan to # confuse the results. mgr = MyManager() mgr.initialize(dbpath) try: # Force a re-scan of our scripts. for script in scripts: r = ScanRequest(script, "Perl", PRIORITY_OPEN, force=1) mgr.addRequest(r) finished.wait() # wait until done scanning finally: mgr.finalize()