Understanding CPU Seconds

consider the following example:

import hotshot
import hotshot.stats
import time

def test_sleep():
    time.sleep(1)

def main():
    prof = hotshot.Profile("lol.prof")
    prof.runcall(test_sleep)
    prof.close()

    stats = hotshot.stats.load("lol.prof")
    stats.sort_stats("time", "calls")
    stats.print_stats(20)

if __name__ == "__main__":
    main()

I got this conclusion:

debian:# python lol.py
         1 function calls in 1.000 CPU seconds

   Ordered by: internal time, call count

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    1.000    1.000    1.000    1.000 lol.py:6(test_sleep)
        0    0.000             0.000          profile:0(profiler)

I expect that I will have 0sec processor time and 1sec wall time.

I expect 1 processor to be second in the case of a busy cycle, not in the case of sleep.

Can someone explain why I get such results?

Thank!

+3
source share
1 answer

This sounds like a HotShot error - it does not receive processor time from the OS, the time taken for the wait time has expired (and, possibly, subtracting the I / O wait time, which in this case would be zero). If you follow time python lol.py, you will see that you are not waiting.

+1
source

Source: https://habr.com/ru/post/1786753/


All Articles