示例#1
0
def main():
    import profile
    import pstats

    if len(sys.argv[1:]):
        profile_it = 0
        reps_flag = 0
        profile_reps = 100
        for arg in sys.argv[1:]:
            if reps_flag:
                profile_reps = int(arg)
                reps_flag = 0
            elif arg == "-p" or arg == "--profile":
                profile_it = 1
            elif arg == "-r" or arg == "--reps":
                reps_flag = 1
            elif profile_it > 0:
                print "Profiling, " + str(profile_reps) + " repetitions..."
                page = page_factory.page(arg)
                profile.run('benchmark("' + arg + '", ' + str(profile_reps) + ")", "profile_stats")
                p = pstats.Stats("profile_stats")
                p.sort_stats("time").print_stats()
            else:
                print page_factory.page(URI(arg))
    else:
        profile()
示例#2
0
文件: HTML.py 项目: dnessorga/LDP
def main():
    import profile
    import pstats

    if len(sys.argv[1:]):
        profile_it = 0
        reps_flag = 0
        profile_reps = 100
        for arg in sys.argv[1:]:
            if reps_flag:
                profile_reps = int(arg)
                reps_flag = 0
            elif arg == '-p' or arg == '--profile':
                profile_it = 1
            elif arg == '-r' or arg == '--reps':
                reps_flag = 1
            elif profile_it > 0:
                print 'Profiling, ' + str(profile_reps) + ' repetitions...'
                page = page_factory.page(arg)
                profile.run(
                    'benchmark("' + arg + '", ' + str(profile_reps) + ')',
                    'profile_stats')
                p = pstats.Stats('profile_stats')
                p.sort_stats('time').print_stats()
            else:
                print page_factory.page(URI(arg))
    else:
        profile()
示例#3
0
def serve(app, **kw):
    _server = kw.pop("_server", create_server)  # test shim
    _quiet = kw.pop("_quiet", False)  # test shim
    _profile = kw.pop("_profile", False)  # test shim
    if not _quiet:  # pragma: no cover
        # idempotent if logging has already been set up
        logging.basicConfig()
    server = _server(app, **kw)
    if not _quiet:  # pragma: no cover
        server.print_listen("Serving on http://{}:{}")
    if _profile:  # pragma: no cover
        profile("server.run()", globals(), locals(), (), False)
    else:
        server.run()
示例#4
0
def serve(app, **kw):
    _server = kw.pop("_server", create_server)  # test shim
    _quiet = kw.pop("_quiet", False)  # test shim
    _profile = kw.pop("_profile", False)  # test shim
    if not _quiet:  # pragma: no cover
        # idempotent if logging has already been set up
        logging.basicConfig()
    server = _server(app, **kw)
    if not _quiet:  # pragma: no cover
        print("serving on http://%s:%s" % (server.effective_host, server.effective_port))
    if _profile:  # pragma: no cover
        profile("server.run()", globals(), locals(), (), False)
    else:
        server.run()
示例#5
0
def serve(app, **kw):
    _server = kw.pop('_server', create_server) # test shim
    _quiet = kw.pop('_quiet', False) # test shim
    _profile = kw.pop('_profile', False) # test shim
    if not _quiet: # pragma: no cover
        # idempotent if logging has already been set up
        logging.basicConfig()
    server = _server(app, **kw)
    if not _quiet: # pragma: no cover
        server.print_listen('Serving on http://{}:{}')
    if _profile: # pragma: no cover
        profile('server.run()', globals(), locals(), (), False)
    else:
        server.run()
示例#6
0
def serve(app, **kw):
    _server = kw.pop('_server', create_server)  # test shim
    _quiet = kw.pop('_quiet', False)  # test shim
    _profile = kw.pop('_profile', False)  # test shim
    if not _quiet:  # pragma: no cover
        # idempotent if logging has already been set up
        logging.basicConfig()
    server = _server(app, **kw)
    if not _quiet:  # pragma: no cover
        print('serving on http://%s:%s' %
              (server.effective_host, server.effective_port))
    if _profile:  # pragma: no cover
        profile('server.run()', globals(), locals(), (), False)
    else:
        server.run()
示例#7
0
def serve(app, **kw):
    _server = kw.pop('_server', WSGIServer) # test shim
    _quiet = kw.pop('_quiet', False) # test shim
    _profile = kw.pop('_profile', False) # test shim
    if not _quiet: # pragma: no cover
        # idempotent if logging has already been set up
        logging.basicConfig()
    server = _server(app, **kw)
    if not _quiet: # pragma: no cover
        print('serving on http://%s:%s' % (server.effective_host,
                                           server.effective_port))
    if _profile: # pragma: no cover
        profile('server.run()', globals(), locals(), (), False)
    else:
        server.run()
示例#8
0
def main(args=None, test=False):
    assert os.name == "posix", "This code makes Unix-specific assumptions"
    # if we hup, restart by making a new Supervisor()
    first = True
    while 1:
        options = ServerOptions()
        options.realize(args, doc=__doc__)
        options.first = first
        options.test = test
        if options.profile_options:
            sort_order, callers = options.profile_options
            profile('go(options)', globals(), locals(), sort_order, callers)
        else:
            go(options)
        if test or (options.mood < SupervisorStates.RESTARTING):
            break
        options.close_httpservers()
        options.close_logger()
        first = False
示例#9
0
def main(args=None, test=False):
    assert os.name == "posix", "This code makes Unix-specific assumptions"
    # if we hup, restart by making a new Supervisor()
    first = True
    while 1:
        options = ServerOptions()
        options.realize(args, doc=__doc__)
        options.first = first
        options.test = test
        if options.profile_options:
            sort_order, callers = options.profile_options
            profile('go(options)', globals(), locals(), sort_order, callers)
        else:
            go(options)
        if test or (options.mood < SupervisorStates.RESTARTING):
            break
        options.close_httpservers()
        options.close_logger()
        first = False
示例#10
0
def PSSM(seq, sc, residues, S):
    '''This function return a PSSM given a sequence, a substitution matrix, a list of possible residues or nucleotides and a multiple alignment'''
    f = profile(S, residues)
    M = []
    for i in range(len(seq)):
        a = seq[i]
        tmp = []
        for j in range(len(f)):
            acc = 0.0
            for b in residues:
                acc = acc + f[j].get(a, 0) * sc.get((a, b), 0)
            tmp.append(acc)
        M.append(tmp)
    return M
示例#11
0
def main(args=None, test=False):
    assert os.name == "posix", "This code makes Unix-specific assumptions"
    # if we hup, restart by making a new Supervisor()
    first = True
    # while 1:
    if 1:
        options = ServerOptions()
        # attribute_value = options.__dict__
        # for key,value in attribute_value.items():
        #     print(key,value)
        # __doc__ 该文件下
        options.realize(args, doc=__doc__)
        options.first = first
        options.test = test

        if options.profile_options:
            sort_order, callers = options.profile_options
            profile('go(options)', globals(), locals(), sort_order, callers)
        else:
            go(options)
        options.close_httpservers()
        options.close_logger()
        first = False
示例#12
0
  # setting profile.Profile.bias improves the performance measurement,
  # but you have to determine the correct value for your specific machine
  # first.
  # profile.Profile.bias = 0.0000106
  profile.run(what, 'profile')
  import pstats
  profile = pstats.Stats('profile')
  profile.strip_dirs().sort_stats('cumulative').print_stats(32)
  profile.strip_dirs().sort_stats('time').print_stats(20)

def main(start_state=None):
  puit.gamemaster = Gamemaster(start_state)
  puit.gamemaster.start()

if __name__ == '__main__':
  import getopt, sys
  options, args = getopt.getopt(sys.argv[1:], 'pt:', ['profile', 'test='])
  do_profile = False
  test = None
  for opt, arg in options:
    if opt in ('-p', '--profile'):
      do_profile = True
    elif opt in ('-t', '--test'):
      test = arg
  if do_profile:
    if test is None:
      profile('main()')
    else:
      profile('main(start_state="' + test + '")')
  else:
    main(start_state=test)
示例#13
0
    pr.dump_stats(filename)
    return result


def speed_test(uuid):
    try:
        print("Starting speed test")
        t0 = time.time()
        with SessionContext(commit = True) as session:
            # Load the article
            a = Article.load_from_uuid(uuid, session)
            if a is not None:
                # Parse it and store the updated version
                a.parse(session, verbose = True)
        t1 = time.time()
        print("Parsing finished in {0:.2f} seconds".format(t1 - t0))
    finally:
        Article.cleanup()


print("Welcome to speedtest")

Settings.read(os.path.join(basepath, "config/Reynir.conf"))
with Fast_Parser() as fp:
    pass

#speed_test("dbc585e4-736c-11e6-a2bb-04014c605401")
profile(speed_test, "dbc585e4-736c-11e6-a2bb-04014c605401")

print("speedtest done")
示例#14
0
##################################################
# for testing/debug performance only
# https://www.clips.uantwerpen.be/tutorials/python-performance-optimization
def profile(function, *args, **kwargs):
    """ Returns performance statistics (as a string) for the given function.
    """
    def _run():
        function(*args, **kwargs)

    import cProfile as profile
    import pstats
    import os
    import sys
    sys.modules['__main__'].__profile_run__ = _run
    id = function.__name__ + '()'
    profile.run('__profile_run__()', id)
    p = pstats.Stats(id)
    p.stream = open(id, 'w')
    p.sort_stats('time').print_stats(20)
    p.stream.close()
    s = open(id).read()
    os.remove(id)
    return s


###################################################

# Main()
if __name__ == '__main__':
    print(profile(Run))
示例#15
0
from random import randrange
import profile

def disjoin1(A, B, C):
    """Return True if there is no element common to all three lists."""
    for a in A:
        for b in B:
            for c in C:
                if a == b == c: # Common value found
                    return False
    return True


def disjoin2(A, B, C):
    for a in A:
        for b in B:
            if a == b: # only check C if A && B
                for c in C:
                    if a == c: # Common value found
                        return False
    return True


data_1 = [ randrange(0, 100) for k in range(0, 10 * 3)]
data_2 = [ randrange(0, 100) for k in range(0, 10 * 3)]
data_3 = [ randrange(0, 100) for k in range(0, 10 * 3)]

profile(disjoin1, )
示例#16
0
     return table[b]

from itertools import permutations
perm = permutations([1,2,3])
for i in list(perm):
    print i

import profile
def fib(n):
    if n==0:
        return 0
    elif n==1:
        return 1
    else:
        return fib(n-1) + fib(n-2)
fib = profile(fib)
fib(20)

x=[1,2,3,4]
y=reversed(x)
y.next()

def grep(pattern, dir):
    for f in dir:
        for line in open(f):
            if pattern in line:
                print line,

grep(".py","Downloads")

def update_windowT(
        source_path='',  #输入视频(raw)帧本地路径
        start_frameW='',
        end_frameW='',  # 以确定需要处理的video window
        segment_time='',
        knob_values='',  # 所有对应的knob的取值空间
        k='',  # top-k的k的值
        inputFps='',
        profile_time=None,
        golden_configration=None,  #作为ground truth的configration /   k个中选一个最佳为的次优ground truth(分析窗口的第一个段与剩余段的ground truth不同)
        configrationW=None,  #该 window的k个configration
        isLeader=None,
        cost=None,
        analyseConfigration=None,
        cover_thre=None,
        f1_thre=None,
        pipe=None,
        lock=None):

    i = 0
    configration = []  # 存储该profilewindow每个segment最佳的configration

    # 对leader video的profile window的第一个segment进行configration的全分析(取segment前一秒)
    # 返回top-k的configration
    start_frameP = start_frameW
    end_frameP = start_frameW + profile_time * inputFps
    if end_frameP > end_frameW:
        end_frameP = end_frameW

    #检查configrationW是否为空,一般不会执行
    if configrationW == None:
        configrationW = profile(source_path, start_frameP, end_frameP,
                                knob_values, k, golden_configration, cost,
                                inputFps, cover_thre, f1_thre)
        ####configrationW=[[2,[1280,720]],[5,[1280,960]],[15,[1280,720]],[2,[1280,960]],[5,[1280,720]]]

    if isLeader == 1:
        #第一个segment的最佳configration即为configrationW的第0个
        configration.append(configrationW[0])

        #segment的起始帧、结束帧
        start_frameS = start_frameW
        end_frameS = start_frameS + segment_time * int(inputFps)
        if end_frameS > end_frameW:
            end_frameS = end_frameW

        #获取configration中各knob的具体值
        if start_frameS % 4 > 2:
            frame_rate = 5
            image_W = 1200
            image_H = 720
        else:
            frame_rate = configrationW[0][0]
            image_W = configrationW[0][1][0]
            image_H = configrationW[0][1][1]
        #更新analyseConfigration
        lock.acquire()
        analyseConfigration[0] = frame_rate
        analyseConfigration[1][0] = image_W
        analyseConfigration[1][1] = image_H
        lock.release()
        #setAnalyseConfigration(frame_rate,image_W,image_H)
        print("\n第", start_frameS, "-", end_frameS, "帧的segment的configration:",
              frame_rate, image_W, image_H, "\n")

        #yolo_video(source_path,start_frameS,end_frameS,frame_rate,image_H,image_W,inputFps,pipe)

    #对profile window中从leader第二个/follower的第一个 segment开始的其余segment进行top-k中的configration的分析

    #对knob_values进行更新
    knob_valuesK = [None] * len(configrationW[0])
    #最佳的k个configration中包含的knob值
    i = 0
    while i < len(configrationW[0]):
        knob_valuesK[i] = []
        i = i + 1

    for conf in configrationW:

        i = 0
        while i < len(configrationW[0]):
            tag = 1
            for kn in knob_valuesK[i]:
                if conf[i] == kn:
                    tag = -1
                    break
            if tag == 1:
                knob_valuesK[i].append(conf[i])
            i = i + 1

    print("knob_valuesK", knob_valuesK)

    if isLeader == 1:
        start_frameP = start_frameW + segment_time * inputFps  # 第二个segment的开始帧
    else:
        start_frameP = start_frameW

    while start_frameP < end_frameW:

        k = 1  #top-k的值
        end_frameP = start_frameP + profile_time * inputFps  #取segmet前一秒
        if end_frameP > end_frameW:
            end_frameP = end_frameW
        space_configration = configrationW
        print("")
        print("start_frameP" + str(start_frameP) + ",end_frameP" +
              str(end_frameP))
        configrationS = profile(source_path, start_frameP, end_frameP,
                                knob_valuesK, k, golden_configration, cost,
                                inputFps, cover_thre, f1_thre,
                                space_configration, knob_values)

        ##########开始回传video
        #segment的起始帧、结束帧
        start_frameS = start_frameP
        end_frameS = start_frameS + segment_time * int(inputFps)
        if end_frameS > end_frameW:
            end_frameS = end_frameW

        #获取configration中各knob的具体值
        frame_rate = configrationS[0]
        image_W = configrationS[1][0]
        image_H = configrationS[1][1]
        print("\n第", start_frameS, "-", end_frameS, "帧的segment的configration:",
              frame_rate, image_W, image_H, "\n")

        #更新analyseConfigration
        lock.acquire()
        analyseConfigration[0] = frame_rate
        analyseConfigration[1][0] = image_W
        analyseConfigration[1][1] = image_H
        lock.release()
        #setAnalyseConfigration(frame_rate,image_W,image_H)
        #yolo_video(source_path,start_frameS,end_frameS,frame_rate,image_H,image_W,inputFps,pipe)
        ##################

        configration.append(configrationS)
        start_frameP = start_frameP + segment_time * inputFps

    print("")

    return configration
示例#18
0
    """Return list such that, for all j, A[j] equals average of S[0], ..., S[j]."""

    n = len(S)
    A = [0] * n # allocate space for results

    for j in range(n):
        A[j] = sum(S[0:j+1]) / (j+1) # record average
    return A


def prefix_average3(S):
    """Return list such that, for all j, A[j] equals average of S[0], ..., S[j]."""

    n = len(S)
    A = [0] * n
    total = 0

    for j in range(n):
        total += S[j]
        A[j] = total / (j+1)
    return A

data_1 = [ k for k in range(0, 10 ** 3)]
data_2 = [ k for k in range(0, 10 ** 4)]
data_3 = [ k for k in range(0, 10 ** 5)]

data_sets = [data_1, data_2, data_3]

profile(prefix_average1, data_sets)
profile(prefix_average2, data_sets)
profile(prefix_average3, data_sets)
示例#19
0
from random import randrange
import profile


def disjoin1(A, B, C):
    """Return True if there is no element common to all three lists."""
    for a in A:
        for b in B:
            for c in C:
                if a == b == c:  # Common value found
                    return False
    return True


def disjoin2(A, B, C):
    for a in A:
        for b in B:
            if a == b:  # only check C if A && B
                for c in C:
                    if a == c:  # Common value found
                        return False
    return True


data_1 = [randrange(0, 100) for k in range(0, 10 * 3)]
data_2 = [randrange(0, 100) for k in range(0, 10 * 3)]
data_3 = [randrange(0, 100) for k in range(0, 10 * 3)]

profile(disjoin1, )
cv2.imshow("shrink", shrink)  
cv2.imwrite("sample.jpg",shrink)

  
cv2.waitKey(0)  
'''
'''
configrationR=[30,[1280,720]]
golden_configration=[30,[1280,960]]
label_locationR=[[],[],['car',(233,2),(519,96)],['car',(242,3),(521,97)],['car',(244,1),(523,97)]]
label_locationG=[[],[],['car',(233,4),(519,129)],['car',(233,4),(519,129)],['car',(233,4),(519,129)]]

f1=eval_f1(label_locationR,label_locationG,configrationR,golden_configration)
print("f1=",f1)
'''
'''
start_frame=601
end_frame=630
pathIn = './test_videos/sample2.mp4'
knob_valuesK=[None]*2
knob_valuesK[0]=[1,2]
knob_valuesK[1]=[[640,480],[1280,720],[1280,960]]
golden_configration=[30,[1280,960]]
space_configration=[[1,[640,480],[1,[1280,720]],[2,[640,480]],[2,[1280,720]],[1,[1280,960]]]
a=[1,2,5,10,30]
b=[[640,480],[1280,720],[1280,960]]
profile(pathIn,start_frame,end_frame,knob_valuesK,1,[30,[1280,960]],space_configration,knob_values)
'''
'''
print("hello_image")
pathIn = './test_imgs/image001834.jpg'
示例#21
0
    pr.dump_stats(filename)
    return result


def speed_test(uuid):
    try:
        print("Starting speed test")
        t0 = time.time()
        with SessionContext(commit=True) as session:
            # Load the article
            a = Article.load_from_uuid(uuid, session)
            if a is not None:
                # Parse it and store the updated version
                a.parse(session, verbose=True)
        t1 = time.time()
        print("Parsing finished in {0:.2f} seconds".format(t1 - t0))
    finally:
        Article.cleanup()


print("Welcome to speedtest")

Settings.read(os.path.join(basepath, "config/Greynir.conf"))
with Fast_Parser() as fp:
    pass

#speed_test("dbc585e4-736c-11e6-a2bb-04014c605401")
profile(speed_test, "dbc585e4-736c-11e6-a2bb-04014c605401")

print("speedtest done")
示例#22
0
        home = os.path.abspath(user[5])
        
        pl = os.path.join(home, "example.png")
        pw = os.path.join(home, "example-pw.png")
        sh = os.path.join(home, "example-sh.png")

        m = draw()
        
        # profit
        
        m.save(pl)
        print "wrote combined layers to %s" % pl
        
        m.save(pw, "pinwin")
        print "wrote pinwin layer to %s" % pw
        
        m.save(sh, "shadow")
        print "wrote shadow layer to %s" % sh

    # hey look, code to run!
    
    parser = optparse.OptionParser()
    parser.add_option("-p", "--profile", action="store_true", help="run profiling stats", default=False)
    
    (opts, args) = parser.parse_args()

    if opts.profile :
        profile()
    else :
        run()
示例#23
0
文件: core.py 项目: dahrens/dgame
        _b = {}
        for name, config in self.cfg['image']['creatures'].iteritems():
            _b[name] = CreatureSheet(name, config, self.cfg['ui']['camera']['zoom_levels'])
        return _b


if __name__ == '__main__':
    def profile(function, *args, **kwargs):
        """ Returns performance statistics (as a string) for the given function."""
        def _run():
            function(*args, **kwargs)
        import cProfile as profile
        import pstats
        sys.modules['__main__'].__profile_run__ = _run
        identifier = function.__name__ + '()'
        profile.run('__profile_run__()', identifier)
        p = pstats.Stats(identifier)
        p.stream = open(identifier, 'w')
        p.sort_stats('time').print_stats(50)
        p.stream.close()
        s = open(identifier).read()
        os.remove(identifier)
        return s
    if DEBUG:
        logging.basicConfig(level = logging.DEBUG)
    if PROFILE:
        profile_result = profile(Launcher().run)
        print(profile_result)
    else:
        Launcher().run()
示例#24
0
from expMethod import expMethod
from expResult import expResult
import numpy as np
from scipy import interp
import decimal
import pylab as pl
from pylab import *
import random
from sklearn.metrics import roc_curve, auc
import sys
import pickle
import os,sys
import time

dataset = expDataset("", "")
#dataset.prefix_path = '../data/link_data'
#dataset.dataset_list = ['foursquare', 'twitter']

setting = expSetting()
method = expMethod()
result = expResult()

pro = profile(dataset, setting, method, result)
print "All Start"
start = time.clock()
pro.run_baseline()
elapsed = (time.clock() - start)
print("Time used:", elapsed)
print "All Finish"

示例#25
0
        except ImportError:
            import profile
        self.profile = profile.Profile()

    def __enter__(self):
        self.profile.enable()

    def __exit__(self, *a):
        self.profile.disable()
        self.profile.create_stats()
        import pstats
        stats = pstats.Stats(self.profile)
        stats.sort_stats('cumulative')
        stats.print_stats(.05)


def profile():
    from calibre.ptempfile import TemporaryDirectory
    path = sys.argv[-1]
    with TemporaryDirectory() as tdir, Profiler():
        return render(path,
                      tdir,
                      serialize_metadata=True,
                      extract_annotations=True,
                      virtualize_resources=False,
                      max_workers=1)


if __name__ == '__main__':
    profile()
def update_windowS(pathIn='',   #raw frame保存地址
                   start_frameW='',#视频分析窗口 起始帧
                   end_frameW='', #视频分析窗口 结束帧
                   segment_time='', #视频段的时间
                   knob_values='',  #全部的knob值   /   k个promising的configration包含的knob值
                   k='', #k个promising值  /  1个(promising中选出一个最佳的作为某个segment的configration)
                   fps='',   #输入视频流的帧率
                   profile_time=None,   #profile的时间(1s)
                   golden_configration=None,  #全分析时为golden configration。 
                   cost=None,   #由offline one-time生成的全部configration的cost值
                   ground_configration=None,   #k个中选一个最佳为次优的ground truth?
                   cover_thre=None,   #object覆盖度阈值
                   f1_thre=None,    #根据每帧分析的f1值,来确定该帧是否为准确帧
                   pipe=None,   #输出视频流的pipe
                   analyseConfigration=None,
                   lock=None
                   ): 


     #leader_pathIn=pathIn[0]    #多个视频
     #leader 的raw video本地保存路径
     leader_pathIn=pathIn
    
     #profile 部分的起始帧和结束帧
     start_frameP=start_frameW
     end_frameP=start_frameW+profile_time*fps
     if end_frameP>end_frameW:
         end_frameP=end_frameW
     
     #获取一个window的top k个最佳configration
     configrationW=profile(leader_pathIn,start_frameP,end_frameP,knob_values,k,
                           golden_configration,cost,fps,cover_thre,f1_thre) #leader topK

     #leader profile window中每个segment的configration
     isLeader=1
     

     #若输入视频流读取完毕,更新总帧数(更新视频的window结束帧)
     global frameCount
     if frameCount!=0 and end_frameW>frameCount:
          end_frameW=frameCount


     #获取window中每个segment的最佳(1个)configration
     #过渡:将不返回configration
     leader_configration=update_windowT(leader_pathIn,start_frameW,end_frameW,segment_time,knob_values,k,fps,profile_time,ground_configration,configrationW,isLeader,cost,analyseConfigration,cover_thre,f1_thre,pipe,lock)
     result_configration=[]
     result_configration.append(leader_configration)
     
     ##
     i=1
     isLeader=0

     #多个视频时需要获取followers的configration
     #while i<len(pathIn):
        #if start_frameW<total_frame[i]:
         # if end_frameW>total_frame[i]:  
            #end_frameW=total_frame[i]
        
          #follower_configration=update_windowT(pathIn[i],start_frameW,end_frameW,segment_time,knob_values,k,fps,profile_time,ground_configration,configrationW,isLeader,cost,cover_thre,f1_thre)
         # result_configration.append(follower_configration)
       # i=i+1
     ## 
        

     return result_configration