コード例 #1
0
def run_stratrunner(strategy, exchange, symbol, timeframe, volume, profile):
    strat_dir_str = "noobit_user.strategies"
    strat_file_path = f"{strat_dir_str}.{strategy}"
    strategy = import_module(strat_file_path)

    # in every strategy file the class needs to be called "Strategy"
    strat = strategy.Strategy(exchange=exchange,
                              symbol=symbol.upper(),
                              timeframe=timeframe,
                              volume=volume)

    runner = StratRunner(strats=[strat])

    if profile:
        print("Profiling code with Yappi")
        yappi.set_clock_type("WALL")
        with yappi.run():
            runner.run()
        # yappi.get_func_stats().print_all()
        stats = yappi.get_func_stats.sort(sort_type='totaltime',
                                          sort_order='desc')
        # returns all stats with sorting applied
        yappi.print_all(stats, sys.stdout, limit=10)
    else:
        runner.run()
コード例 #2
0
async def profiler_middleware(request, call_next):
    # Run the request
    with yappi.run():
        call_result = await call_next(request)

    # Generate ID for this request
    request_id = str(uuid.uuid1())

    # Save profile
    stats = yappi.get_func_stats()
    stats.save(f"{PROFILE_DIRECTORY}/{request_id}.prof", type="pstat")

    download_link = (
        f"{request.url.scheme}://{request.url.netloc}/profiles/{request_id}.prof"
    )

    # Save profile meta-info
    captured_profiles.append({
        "id": request_id,
        "timestamp": time.time(),
        "path": request.url.path,
        "download_link": download_link,
    })

    # Continue
    return call_result
コード例 #3
0
 def inner_run(self, *args, **options):
     signal.signal(signal.SIGUSR1, self.print)
     try:
         with yappi.run():
             return super().inner_run(*args, **options)
     finally:
         self.print()
コード例 #4
0
 def start(self):
     yappi.set_clock_type("WALL")
     if self.sync:
         yappi.start()
         context_manager = nullcontext()
     else:
         context_manager = yappi.run()
     return context_manager
コード例 #5
0
ファイル: test_functionality.py プロジェクト: nirs/yappi-1
    def test_run_recursive(self):
        def profiled():
            pass

        def not_profiled():
            pass

        yappi.clear_stats()
        try:
            with yappi.run():
                with yappi.run():
                    profiled()
                # Profiling stopped here
                not_profiled()
            stats = yappi.get_func_stats()
        finally:
            yappi.clear_stats()

        self.assertIsNotNone(utils.find_stat_by_name(stats, 'profiled'))
        self.assertIsNone(utils.find_stat_by_name(stats, 'not_profiled'))
コード例 #6
0
ファイル: test_functionality.py プロジェクト: sumerc/yappi
    def test_run_recursive(self):

        def profiled():
            pass

        def not_profiled():
            pass

        yappi.clear_stats()
        try:
            with yappi.run():
                with yappi.run():
                    profiled()
                # Profiling stopped here
                not_profiled()
            stats = yappi.get_func_stats()
        finally:
            yappi.clear_stats()

        self.assertIsNotNone(utils.find_stat_by_name(stats, 'profiled'))
        self.assertIsNone(utils.find_stat_by_name(stats, 'not_profiled'))
コード例 #7
0
ファイル: test_functionality.py プロジェクト: nirs/yappi-1
    def test_run(self):
        def profiled():
            pass

        yappi.clear_stats()
        try:
            with yappi.run():
                profiled()
            stats = yappi.get_func_stats()
        finally:
            yappi.clear_stats()

        self.assertIsNotNone(utils.find_stat_by_name(stats, 'profiled'))
コード例 #8
0
ファイル: test_functionality.py プロジェクト: sumerc/yappi
    def test_run(self):

        def profiled():
            pass

        yappi.clear_stats()
        try:
            with yappi.run():
                profiled()
            stats = yappi.get_func_stats()
        finally:
            yappi.clear_stats()

        self.assertIsNotNone(utils.find_stat_by_name(stats, 'profiled'))
コード例 #9
0
def main():
    args = parse_args()
    if args.packets_file:
        p_source = from_file(args)
    else:
        p_source = capture()

    if args.profile:
        import yappi
        yappi.set_clock_type("WALL")
        with yappi.run():
            run(args, p_source)
        stats = yappi.get_func_stats()
        stats.save('profile.prof', type='pstat')
    else:
        run(args, p_source)
コード例 #10
0
ファイル: basic.py プロジェクト: dmtrs/dependable

async def main() -> Tuple[uuid.UUID, uuid.UUID]:
    _id: uuid.UUID = await some_service()
    other_id: uuid.UUID = await some_service()
    return (_id, other_id)


@dependant
async def main_with_depends(
    *,
    _id: uuid.UUID = Depends(some_service),
    other_id: uuid.UUID = Depends(some_service),
) -> Tuple[uuid.UUID, uuid.UUID]:
    return (_id, other_id)


yappi.set_clock_type("cpu")
"""
with yappi.run():
    for i in range(5):
        asyncio.run(main())

yappi.get_func_stats().print_all()
"""
with yappi.run():
    for i in range(5):
        asyncio.run(main_with_depends())

yappi.get_func_stats().print_all()
コード例 #11
0
 def wrapper(*args, **kwargs):
     yappi.set_clock_type("WALL")
     with yappi.run():
         result = f(*args, **kwargs)
     _print_stats()
     return result