Other method to read .profile file is using command “cprofilev -f test_func.profile”

cprofilev -f test_func.profile

Run above command in terminal and view stats in browser on http://127.0.0.1:4000

Advantage of this method is you can easily sort records ,just by one click on column name.

4. Profile web2py application

Create a empty text file in a directory and then pass this text file as argument to web2py. All profiling data will be stored in this file.
For example :
Create lcm.txt in ‘/home/gaurav/temp/lcm/” directory. Now run web2py server using following command with command line argument -F (profiler filename)

python web2py.py -p 8000 -a g0987 -F /home/gaurav/temp/lcm/lcm.txt

Note: For some web2py version , we have to provide directory using -f (not -F) option and data will be written in that directory in the form of .profile files. We can read these files using above mentioned methods.

Now open application from browser and open pages you want to profile.Then stop web2py server. This will write profiling data to lcm.txt. Data in text file will be in readable format , no need of pstats module to read data.

The post Time profiling in python using cProfile appeared first on Gaurav Vichare.