示例#1
0
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()
示例#2
0
def perf_cidb_size(dbpath):
    """Scan current Perl lib into a new CIDB and dump size information.
    
    The CIDB path selected with the "-f" option is ignored. Run this test
    with:
        ciperf -n 1 -r cidb_size
    """
    if sys.platform == "win32":
        clock = time.clock  # time.clock is best on Windows
    else:
        clock = time.time  # time.time is best on non-Win platforms

    results = []
    dbpath = "perf_cidb_size.db"
    if os.path.exists(dbpath):
        os.remove(dbpath)
        time.sleep(1)

    import which
    perl = which.which("perl")
    perllib = os.path.join(os.path.dirname(os.path.dirname(perl)), "lib")

    mgr = codeintel.Manager()
    mgr.initialize(dbpath)
    starttime = time.time()
    try:
        print "load directory '%s'" % perllib
        mgr.batchUpdateRequest("directory", perllib, "Perl")
        mgr.batchUpdateStart()
        mgr.batchUpdateWait()
        errors = mgr.batchUpdateGetErrors()
    finally:
        mgr.finalize()
    endtime = time.time()
    results.append({
        "dname": perllib,
        "seconds": endtime - starttime,
        "dbsize": os.stat(dbpath).st_size
    })
    print "Results:"
    for res in results:
        print res["dname"] + ':'
        seconds = res["seconds"]
        h, m, s = seconds / 3600.0, seconds / 60.0, seconds % 60.0
        print "\tTime: %02dh%02dm%02.1fs" % (h, m, s)
        print "\tSize: %.2f KB" % (res["dbsize"] / 1024.0)
示例#3
0
def perf_python_completion(dbpath):
    """Get some Python completions.
    
    To run this time test:
        ciperf -f perf.db -r setup_python_completion
        ciperf -f perf.db -t python_completion
    """
    import which
    import codeintel

    mgr = codeintel.Manager(coreLanguages=["Python", "Perl"])
    mgr.initialize(dbpath)
    try:
        script = os.path.join(g_corpus_dir, "cidb.py")
        line = 227  # in the time_query() function
        content = open(script, 'r').read()

        # Do a few Python completions in this file.
        for i in range(5):
            completions = mgr.getCallTips("Python",
                                          script,
                                          line,
                                          "os.chmod",
                                          content=content)
            completions = mgr.getMembers("Python",
                                         script,
                                         line,
                                         "os",
                                         content=content)
            completions = mgr.getMembers("Python",
                                         script,
                                         line,
                                         "timer",
                                         content=content)
            completions = mgr.getMembers("Python",
                                         script,
                                         line,
                                         "t",
                                         content=content)
            completions = mgr.getCallTips("Python",
                                          script,
                                          line,
                                          "timeit.Timer",
                                          content=content)
            completions = mgr.getCallTips("Python",
                                          script,
                                          line,
                                          "t.timeit",
                                          content=content)

        # Do similar in a big file.
        script = os.path.join(g_corpus_dir, "cb.py")
        line = 566  # in a CBRootNode method
        content = open(script, 'r').read()

        for i in range(5):
            completions = mgr.getCallTips("Python",
                                          script,
                                          line,
                                          "os.chmod",
                                          content=content)
            completions = mgr.getMembers("Python",
                                         script,
                                         line,
                                         "os",
                                         content=content)
            completions = mgr.getMembers("Python",
                                         script,
                                         line,
                                         "self",
                                         content=content)
            completions = mgr.getCallTips("Python",
                                          script,
                                          line,
                                          "self.addModule",
                                          content=content)
            completions = mgr.getCallTips("Python",
                                          script,
                                          line,
                                          "self.generateRows",
                                          content=content)
    finally:
        mgr.finalize()
示例#4
0
def perf_perl_completion(dbpath):
    """Get some Perl completions.
    
    To run this time test:
        ciperf -f perf.db -r setup_perl_completion
        ciperf -f perf.db -t perl_completion
    """
    import which
    import codeintel
    mgr = codeintel.Manager(coreLanguages=["Python", "Perl"])
    mgr.initialize(dbpath)
    try:
        # Gisle's GET Perl script (a good real-world example)
        # - lets "edit" on line 309, after the $ua var is set.
        script = os.path.join(g_corpus_dir,
                              "GET.pl")  # Gisle's GET Perl script
        line = 313
        content = open(script, 'r').read()

        if 0:
            #completions = mgr.getCallTips("Perl", script, line, "chmod", content=content)
            #completions = mgr.getCallTips("Perl", script, line, "LWP", content=content)
            #completions = mgr.getMembers("Perl", script, line, "LWP", content=content)
            #completions = mgr.getMembers("Perl", script, line, "LWP::UserAgent", content=content)
            #completions = mgr.getCallTips("Perl", script, line, "$ua.mirror", content=content)
            completions = mgr.getMembers("Perl",
                                         script,
                                         line,
                                         "$ua",
                                         content=content)
            #completions = mgr.getCallTips("Perl", script, line, "$ua", content=content)
        else:
            for i in range(5):
                # Do a few Perl completions in this file.
                completions = mgr.getCallTips("Perl",
                                              script,
                                              line,
                                              "chmod",
                                              content=content)
                completions = mgr.getCallTips("Perl",
                                              script,
                                              line,
                                              "LWP",
                                              content=content)
                completions = mgr.getMembers("Perl",
                                             script,
                                             line,
                                             "LWP",
                                             content=content)
                completions = mgr.getMembers("Perl",
                                             script,
                                             line,
                                             "LWP::UserAgent",
                                             content=content)
                completions = mgr.getCallTips("Perl",
                                              script,
                                              line,
                                              "$ua.mirror",
                                              content=content)
                completions = mgr.getMembers("Perl",
                                             script,
                                             line,
                                             "$ua",
                                             content=content)
                completions = mgr.getCallTips("Perl",
                                              script,
                                              line,
                                              "$ua",
                                              content=content)
    finally:
        mgr.finalize()