cProfile for Python does not recognize Function name

The problem is that you imported send_email inside your method definition. I suggest you to use runctx: cProfile.runctx(‘send_email()’, None, locals()) From the official documentation: cProfile.runctx(command, globals, locals, filename=None) This function is similar to run(), with added arguments to supply the globals and locals dictionaries for the command string.

saving cProfile results to readable external file

Updated. You can get output of profiler using io.StringIO() and save it into file. Here is an example: import cProfile import pstats import io def my_func(): result = [] for i in range(10000): result.append(i) return result pr = cProfile.Profile() pr.enable() my_result = my_func() pr.disable() s = io.StringIO() ps = pstats.Stats(pr, stream=s).sort_stats(‘tottime’) ps.print_stats() with open(‘test.txt’, ‘w+’) … Read more

Python cProfile results: two numbers for ncalls

The smaller number is the number of ‘primitive’ or non-recursive calls. The larger number is the total number of invocations, including recursive calls. Since deepcopy is implemented recursively, it means that you called deepcopy directly 1724 times, but that it ended up calling itself ~383k times to copy sub-objects.

Can I run line_profiler over a pytest test?

Run pytest like this: python3 -m cProfile -o profile -m pytest You can even pass in optional arguments: python3 -m cProfile -o profile -m pytest tests/worker/test_tasks.py -s campaigns This will create a binary file called profile in your current directory. This can be analyzed with pstats: import pstats p = pstats.Stats(‘profile’) p.strip_dirs() p.sort_stats(‘cumtime’) p.print_stats(50) This … Read more

Using cProfile results with KCacheGrind

With cProfile you can also profile existing programs, without making any separate profiling script. Just run program with profiler python -m cProfile -o profile_data.pyprof script_to_profile.py and open profile data in kcachegrind with pyprof2calltree, whose -k switch automatically opens data in kcachegrind pyprof2calltree -i profile_data.pyprof -k For example profiling whole paster server and webapp would be … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)