简体   繁体   中英

Python profile: How to get the time for each individual execution (no aggregation)

I am trying to debug a python based project that involves many repeated calls to the same set of functions. This code is part of an API.

However, over time the execution time for these functions increases linearly. I now need to find out what is causing this increase of total time a single request is taking to complete. Is there a way to profile python code and get the output for each execution of repeatedly called functions?

As an abstract example: Let's say function 1 involves calls to function 1, function 2, function 3. I call function 1 10,000 times and then notice that the execution of function 1 took initially 0.5 seconds but increases to 5 seconds at the 10,000 call to it. How can I figure out whether function 1, function 2 or function 3 is causing this increase?

You can use Linux perf tools if it is on Linux environment and check number of cycles for each function, number of instructions, L1 cache load, L1 cache miss and L2 cache load/miss and compare them one by one.

On the below example you can find the examples comparing different functions.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM