File: embedded.py

package info (click to toggle)
pprofile 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 512 kB
  • sloc: python: 2,928; sh: 41; makefile: 3
file content (26 lines) | stat: -rwxr-xr-x 460 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
import threading
import pprofile
import time
import sys

def func():
  # Busy loop, so context switches happen
  end = time.time() + 1
  while time.time() < end:
    pass

# Single-treaded run
prof = pprofile.Profile()
with prof:
  func()
prof.annotate(sys.stdout, __file__)

# Dual-threaded run
t1 = threading.Thread(target=func)
prof = pprofile.Profile()
with prof:
  t1.start()
  func()
  t1.join()
prof.annotate(sys.stdout, __file__)