sumerc / yappi

Yet Another Python Profiler, but this time multithreading, asyncio and gevent aware.
MIT License
1.45k stars 73 forks source link

Can I format function names with print_all() ? #25

Closed euri10 closed 4 years ago

euri10 commented 4 years ago

This is a rather cosmetic issue, yet I'm running a logger.debug(yappi.get_func_stats({"tag": ctx_id}).print_all()) and find it difficult to read the output for the names (see below), is it possible to get a "nicer" output

I thought using a fmt kwarg and passingsomething like in https://docs.python.org/3/library/logging.html#logrecord-attributes would be awesome, at least it would feel natural

I currently have to use debug_print() to get a sense of those names but it would be awesome to be able to do a print_all(fmt=''%(filename)s %(funcName)s %(lineno)d") for instance

Clock type: WALL
Ordered by: totaltime, desc

name                                  ncall  tsub      ttot      tavg      
..ase.py:19 BenchMiddleware.__call__  1      0.000016  0.009153  0.009153
..arlette/middleware/base.py:36 coro  2      0.000000  0.009081  0.004540
./main.py:116 middleware              1      0.000017  0.009018  0.009018
..se.py:28 BenchMiddleware.call_next  2      0.006288  0.006426  0.003213
..py:47 ExceptionMiddleware.__call__  1      0.000009  0.006233  0.006233
../routing.py:578 APIRouter.__call__  1      0.000029  0.006224  0.006224
..e/routing.py:200 APIRoute.__call__  1      0.000015  0.006133  0.006133
..ckages/starlette/routing.py:38 app  1      0.000029  0.006118  0.006118
..ackages/fastapi/routing.py:100 app  1      0.000024  0.006025  0.006025
..ection.py:1400 Connection._execute  2      0.000035  0.004728  0.002364
..ction.py:1406 Connection.__execute  2      0.000027  0.004687  0.002344
..ion.py:1421 Connection._do_execute  2      0.002150  0.004648  0.002324
..py:137 circuits_json_in_postgresql  1      0.000034  0.003894  0.003894
..nection.py:443 Connection.fetchrow  1      0.000005  0.003417  0.003417`
sumerc commented 4 years ago

Yes, I might agree it might be better for some situations, but how about:

you do the formatting yourself:

for stat in yappi.get_func_stats():
    print("%.5s.%s:%d %d" % (stat.module, stat.name, stat.lineno, stat.ncall))

Not so hard, IMHO?

euri10 commented 4 years ago

Ha yes excellent ! Way better indeed, sorry I didnt realize you could access stat like that , it's very clean

Le lun. 2 déc. 2019 à 3:31 PM, Sümer Cip notifications@github.com a écrit :

Yes, I might agree it might be better for some situations, but how about:

you do the formatting yourself:

for stat in yappi.get_func_stats(): print("%.5s.%s:%d %d" % (stat.module, stat.name, stat.lineno, stat.ncall))

Not so hard, IMHO?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sumerc/yappi/issues/25?email_source=notifications&email_token=AAINSPSNW77ALRHG5LCTZI3QWUL37A5CNFSM4JTV6Y3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFTVOCQ#issuecomment-560420618, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAINSPS4VO6Q3MPRDJ7MWWTQWUL37ANCNFSM4JTV6Y3A .