Beispiel #1
0
def get_profiler():
    global PROFILER
    if PROFILER is None:
        try:
            from line_profiler import LineProfiler
        except ImportError:
            raise ImportError("Need line-profiler installed to use "
                              "`--profile` option.")
        PROFILER = LineProfiler()
    return PROFILER
Beispiel #2
0
 def profiled_func(*args, **kwargs):
     profiler = LineProfiler()
     try:
         profiler.add_function(func)
         for f in follow:
             profiler.add_function(f)
         profiler.enable_by_count()
         return func(*args, **kwargs)
     finally:
         profiler.print_stats()
Beispiel #3
0
 def test_02_pic1_prof_v2(self):
     filename = '../scenes/102.png'
     # res = send_pic_file(filename)
     img = cv2.imread(filename, 1)
     pool = ThreadPool(4)
     lp = LineProfiler()
     lp_wrapper = lp(find_service.get_num_of_enemy_parallel2)
     res = lp_wrapper(img,pool)
     lp.print_stats()
     print(res)
Beispiel #4
0
 def DataReader_bin_test2(self):
     self.select_file(num=1)
     prf = LineProfiler()
     prf.add_function(self.read_bin_file_to_tx2)
     prf.runcall(self.read_bin_file_to_tx2,
                 start=3 * 10**7,
                 datapoints=10**6)
     prf.print_stats()
     print(len(self.x), math.log10((len(self.x))))
     self.plot_timecorse_of_move(show_it=1)
Beispiel #5
0
def lp_wrapper(f):
    lp = LineProfiler()
    g = lp(f)

    def wrapped(*argst, **kwt):
        result = g(*argst, **kwt)
        lp.print_stats()
        return result

    return wrapped
def cuda_motion_detection_test():
    dummy_event = "Event"
    image = np.random.randint(255, size=(900, 800, 3), dtype=np.uint8)

    lp = LineProfiler()
    lp_wrapper = lp(cuda_motion_detection)

    for i in range(1000):
        lp_wrapper(image)

    lp.print_stats()
Beispiel #7
0
def profile_on(fcn_names=None):
    if fcn_names and HAS_LINE_PROFILER:
        pr = LineProfiler()
        for fcn_name in fcn_names:
            pr.add_function(fcn_name)
        pr.enable()
        return pr

    pr = cProfile.Profile()
    pr.enable()
    return pr
Beispiel #8
0
def profile_line_runtime(func, *args, **kwargs):
    """
    Profile the runtime for individual lines in a given func
    """
    from line_profiler import LineProfiler

    lp = LineProfiler()
    lp_wrapper = lp(func)
    lp_wrapper(*args, **kwargs)

    return lp.print_stats()
Beispiel #9
0
    def wrapper(self, f, *args, **kwargs):
        prof = LineProfiler()
        prof.add_function(f)

        rtn = prof.runcall(f, *args, **kwargs)
        with StringIO() as f:
            prof.print_stats(stream=f)
            msg = "line_profiler result\n{}".format(f.getvalue())
            self.logger.debug(msg)

        return rtn
def resolve_profiler_function():
    from vengeance import print_runtime

    if is_running_debug():
        return print_runtime

    try:
        from line_profiler import LineProfiler
        return LineProfiler()
    except ImportError:
        return print_runtime
Beispiel #11
0
def timetest(func, *para):
    p = LineProfiler()
    p.add_function(func)
    p.enable_by_count()

    p_wrapper = p(func)
    p_wrapper(*para)
    
    # Printing
    print(func(*para))
    p.print_stats()
Beispiel #12
0
    def test_enable_profile_all(self):
        lp = LineProfiler()

        lp.enable_profile_all()
        lp.enable()
        value = f(10)
        lp.disable()

        self.assertEqual(value, f(10))
        self.assertEqual(len(lp.code_map.keys()), 1)
        self.assertEqual(len(lp.code_map[f.__code__]), 2)
 def wrapper(*args, **kwargs):
     profiler = LineProfiler()
     profiler.add_function(fn)
     try:
         for f in follow:
             profiler.add_function(f)
         profiler.enable_by_count()
         return fn(*args, **kwargs)
     finally:
         profiler.print_stats(output_unit=1)
         profiler.dump_stats(report)
def run_profiling_by_line(func, kwargs):
    line_profiler = LineProfiler()
    functions = inspect.getmembers(inspect.getmodule(func), inspect.isfunction)
    function_instances = dict(functions).values()

    for function_instance in function_instances:
        if function_instance is not func:
            line_profiler.add_function(function_instance)

    line_profiler_wrapper = line_profiler(func)
    line_profiler_wrapper(**kwargs)
    line_profiler.print_stats()
Beispiel #15
0
 def login(self):
     time_start = time.time()
     lp = LineProfiler()
     self.comm = mydb.Commission()
     self.userinfo = [self.name.get(), self.v.get(), self.password.get()]
     lp_wrapper = lp(self.comm.login)
     lp_wrapper(self.userinfo)
     lp.print_stats()
     time_finish = time.time()
     print("login function over ,elapse", time_finish - time_start)
     #self.comm.login(self.userinfo)
     self.destroy()
Beispiel #16
0
def start_profiling():
    if (app.config['PROFILE'] and app.mongo_logger is not None):
        if (not hasattr(g, 'profiler') or g.profiler is None):
            setattr(g, 'profiler', LineProfiler())
            # print('Collecting function info')
            function_info = collect_module_functions(
                [node, routes, utils, models])
            for f in function_info:
                # print('Adding profile framework for function {0}'.format(f))
                g.profiler.add_function(f)
            app.mongo_logger.db.profiling.create_index('path', unique=True)
        g.profiler.enable()
Beispiel #17
0
 def profiled_func(*args, **kwargs):
     try:
         profiler = LineProfiler()
         profiler.add_function(func)
         for f in follow:
             if isinstance(f, six.string_types):
                 f = to_function(f)
             profiler.add_function(f)
         profiler.enable_by_count()
         return func(*args, **kwargs)
     finally:
         profiler.print_stats()
Beispiel #18
0
def raytracer_main():
    profiler = 0
    if profiler == 0:
        raytracer_main2()
    elif profiler == 1:
        from line_profiler import LineProfiler
        profile = LineProfiler(_sample_light_sources2,
                               _FaceTextureCache.get_face_texture)
        profile.runctx('raytracer_main2()', globals(), locals())
        profile.print_stats()
    else:
        import cProfile
        cProfile.runctx('raytracer_main2()', globals(), locals(), 'stats5')
def motion_detection_test():
    dummy_event = "Event"
    motion_detector = MotionDetection(dummy_event, 500, 1)
    image = np.random.randint(255, size=(900, 800, 3), dtype=np.uint8)
    umat_image = cv2.UMat(image)

    lp = LineProfiler()
    lp_wrapper = lp(motion_detector.detect)

    for i in range(1000):
        lp_wrapper(umat_image)

    lp.print_stats()
Beispiel #20
0
 def wrapper(*args, **kwargs):
     if not hasattr(wrapper, 'cnt'):
         wrapper.cnt = 1
     else:
         wrapper.cnt += 1
     if not (max_cnt >= 0 and wrapper.cnt > max_cnt) and not sys._getframe().f_back.f_code.co_name == func.__name__:
         prof = LineProfiler()
         try:
             return prof(func)(*args, **kwargs)
         finally:
             prof.print_stats()
     else:
         return func(*args, **kwargs)
Beispiel #21
0
    def wrap(self, *args, **kw):

        # profile function and call function
        if self.profile:
            lp = LineProfiler()
            lp_wrapper = lp(f)
            result = lp_wrapper(self, *args, **kw)
            lp.print_stats()
        else:
            result = f(self, *args, **kw)

        # return function's result
        return result
Beispiel #22
0
def lineProfiling():
    A = Atrium(hexagonal = False, tTot = 10**3, nu_parallel = 1, nu_trans = 0.13)
    
    lp = LineProfiler()
    lp_wrapper = lp(A.cmpFull)
    lp.add_function(A.cmpTimestep)
    lp.add_function(A.pacemakerExcite)
    lp.add_function(A.restCells)
    lp.add_function(A.cellExcite)
    lp_wrapper()
    lp.print_stats()
    
    return A
Beispiel #23
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     self.profiler = cProfile.Profile()
     args = (request, ) + view_args
     if DJ_PROFILE_USE_LINE_PROFILER:
         self.line_profiler = LineProfiler()
         self._unwrap_closure_and_profile(view_func)
         self.line_profiler.enable_by_count()
         out = self.profiler.runcall(view_func, *args, **view_kwargs)
         self.line_profiler.disable_by_count()
     else:
         self.line_profiler = None
         out = self.profiler.runcall(view_func, *args, **view_kwargs)
     return out
Beispiel #24
0
def lineProfiling():
    A = Atrium()

    lp = LineProfiler()
    lp_wrapper = lp(A.cmpFull)
    lp.add_function(A.cmpTimestep)
    lp.add_function(A.pacemakerExcite)
    lp.add_function(A.restCells)
    lp.add_function(A.cellExcite)
    lp_wrapper()
    lp.print_stats()

    return A
Beispiel #25
0
        def timed(*args, **kw):
            if mode == 'disabled':
                return f(*args, **kw)
            elif mode == 'timing':
                ts = timer()
                if cupy:
                    start_gpu.record()
                result = f(*args, **kw)
                if cupy:
                    end_gpu.record()
                    end_gpu.synchronize()

                te = timer()

                if key == '':
                    if not filename:
                        _filename = inspect.stack()[1].filename.split('/')[-1]
                    else:
                        _filename = filename
                    _key = _filename + '.' + f.__name__
                    if classname:
                        _key = classname + '.' + _key
                else:
                    _key = key
                # key = filename
                if (_key not in times):
                    times[_key] = []
                    if exclude:
                        excluded.append(_key)
                if cupy:
                    elapsed_time = cupy.cuda.get_elapsed_time(
                        start_gpu, end_gpu)
                else:
                    elapsed_time = (te - ts) * 1000
                times[_key].append(elapsed_time)
                if 'lib_time' not in times:
                    times['lib_time'] = []
                times['lib_time'].append((timer() - te) * 1000)

                return result
            elif mode == 'line_profiler':
                from line_profiler import LineProfiler
                global lp
                if not lp:
                    lp = LineProfiler()
                lp_wrapper = lp(f)
                result = lp_wrapper(*args, **kw)
                return result
            else:
                raise RuntimeError(
                    '[timing.py:timeit] mode: %s not available' % mode)
Beispiel #26
0
    def test_function_decorator(self):
        profile = LineProfiler()
        f_wrapped = profile(f)
        self.assertEqual(f_wrapped.__name__, 'f')

        self.assertEqual(profile.enable_count, 0)
        value = f_wrapped(10)
        self.assertEqual(profile.enable_count, 0)
        self.assertEqual(value, f(10))

        timings = profile.code_map[f.__code__]
        self.assertEqual(len(timings), 2)
        for timing in timings.values():
            self.assertEqual(timing.nhits, 1)
Beispiel #27
0
 def profiled_func(*args, **kwargs):
     try:
         profiler = LineProfiler()
         profiler.add_function(func)
         if follow_all_methods:
             cls = args[0]  # class instance
             _add_all_class_methods(profiler, cls,
                                    except_=func.__name__)
         for f in follow:
             _add_function_or_classmethod(profiler, f, args)
         profiler.enable_by_count()
         return func(*args, **kwargs)
     finally:
         profiler.print_stats()
Beispiel #28
0
def create_line_profile(*args):
    line_profiler = LineProfiler()
    line_profiler.enable_by_count()

    for klass in args:
        for attr in dir(klass):
            func = getattr(klass, attr)
            condition = (not inspect.isfunction(func),
                         not inspect.ismethod(func))
            if all(condition):
                continue
            line_profiler.add_function(func)

    return line_profiler
Beispiel #29
0
def line(
        cls_runner: tp.Type[Perf],
        pattern_func: str,
        ) -> None:
    runner = cls_runner()
    for name in runner.iter_function_names(pattern_func):
        f = getattr(runner, name)
        profiler = LineProfiler()
        if not runner.meta:
            raise NotImplementedError('must define runner.meta')
        profiler.add_function(runner.meta[name].line_target)
        profiler.enable()
        f()
        profiler.disable()
        profiler.print_stats()
Beispiel #30
0
def process(cell_id):
    if strtobool(get_param(DbName.COMMON, 'profile')[0]):
        print('cell id : {}'.format(cell_id))
        pr = LineProfiler()
        rtg = RdfToGcnf(cell_id)
        pr.add_function(rtg.create_gcn_file)
        pr.enable()
        rtg.create_gcn_file()
        pr.disable()
        pr.print_stats()
        del rtg
    else:
        rtg = RdfToGcnf(cell_id)
        rtg.create_gcn_file()
        del rtg