remove example1, due to https://github.com/gaogaotiantian/viztracer/issues/81
This commit is contained in:
parent
e4de6ad3e9
commit
00ae03986a
|
@ -1,21 +1,35 @@
|
||||||
|
# same as example1, but without explicit viztracer calls
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import viztracer
|
|
||||||
import time
|
|
||||||
|
|
||||||
|
# if we don't run with gil_load, we just skip it
|
||||||
|
import gil_load
|
||||||
|
try:
|
||||||
|
gil_load.init()
|
||||||
|
gil_load.start()
|
||||||
|
use_gil_load = True
|
||||||
|
except RuntimeError:
|
||||||
|
use_gil_load = False
|
||||||
|
|
||||||
def run():
|
def some_computation():
|
||||||
total = 0
|
total = 0
|
||||||
for i in range(1_000_000):
|
for i in range(1_000_000):
|
||||||
total += i
|
total += i
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
|
||||||
with viztracer.VizTracer(output_file="example1.json"):
|
thread1 = threading.Thread(target=some_computation)
|
||||||
thread1 = threading.Thread(target=run)
|
thread2 = threading.Thread(target=some_computation)
|
||||||
thread2 = threading.Thread(target=run)
|
def main(args=None):
|
||||||
thread1.start()
|
thread1.start()
|
||||||
thread2.start()
|
thread2.start()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
for thread in [thread1, thread2]:
|
for thread in [thread1, thread2]:
|
||||||
thread.join()
|
thread.join()
|
||||||
|
if use_gil_load:
|
||||||
|
gil_load.stop()
|
||||||
|
stats = gil_load.get()
|
||||||
|
print(gil_load.format(stats))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# same as example1, but without explicit viztracer calls
|
# shows high gil load, but no wait
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
# if we don't run with gil_load, we just skip it
|
# if we don't run with gil_load, we just skip it
|
||||||
import gil_load
|
import gil_load
|
||||||
|
@ -11,25 +12,35 @@ try:
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
use_gil_load = False
|
use_gil_load = False
|
||||||
|
|
||||||
def some_computation():
|
|
||||||
|
N = 1024*1024*32
|
||||||
|
M = 4
|
||||||
|
x = np.arange(N, dtype='f8')
|
||||||
|
|
||||||
|
|
||||||
|
def some_numpy_computation():
|
||||||
total = 0
|
total = 0
|
||||||
for i in range(1_000_000):
|
for i in range(M):
|
||||||
total += i
|
total += x.sum()
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
|
||||||
thread1 = threading.Thread(target=some_computation)
|
thread1 = threading.Thread(target=some_numpy_computation)
|
||||||
thread2 = threading.Thread(target=some_computation)
|
thread2 = threading.Thread(target=some_numpy_computation)
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
thread1.start()
|
thread1.start()
|
||||||
thread2.start()
|
thread2.start()
|
||||||
time.sleep(0.2)
|
total = 0
|
||||||
|
for i in range(2_000_000):
|
||||||
|
total += i
|
||||||
for thread in [thread1, thread2]:
|
for thread in [thread1, thread2]:
|
||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
if use_gil_load:
|
if use_gil_load:
|
||||||
gil_load.stop()
|
gil_load.stop()
|
||||||
stats = gil_load.get()
|
stats = gil_load.get()
|
||||||
print(gil_load.format(stats))
|
print(gil_load.format(stats))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue