Running Sciagraph
Getting started with Sciagraph:
Let’s profile the following program:
import json, sys, time, os
from threading import Thread
def deepcopy_list(l):
return [i[:] for i in l]
def main(length):
start = time.time()
l = []
for i in range(length):
l.append(list(range(i)))
with open("output.json", "w") as f:
s = json.dumps(l)
f.write(s)
f.flush()
os.fsync(f.fileno())
threads = [Thread(target=lambda: deepcopy_list(l)) for _ in range(3)]
for t in threads:
t.start()
for t in threads:
t.join()
print("All done, elapsed: {:.2f} seconds".format(time.time() - start))
main(int(sys.argv[1]))
Typically you’d run it like so:
(test-env) $ python example.py 5_000
All done, elapsed: 1.41 seconds
Make sure you have an access token
To use Sciagraph, you need to sign up for the free Hobbyist plan. Once you’re signed up, that URL will tell you the command you need to run to store the access token on disk.
Remember to run inside a virtualenv (in this example, called test-env
) with Sciagraph installed; see the previous step in the Getting Started guide.
The command to store the token will look something like this:
(test-env) $ python -m sciagraph.store_token ...
Profiling your program
To run your program under Sciagraph, you just need to run it slightly differently:
(test-env) $ python -m sciagraph run example.py 5_000
All done, elapsed: 1.37 seconds
Successfully stored the Sciagraph profiling report.
The report was stored in sciagraph-result/2023-04-17T17-25-09_998002
Once the program finishes, the report will be opened automatically in a browser, assuming you’re running in a GUI environment.
If not, you can view the report by opening the index.html
file in the reported directory.
Note: You can also profile your program automatically without changing the command-line, by setting the environment variable
SCIAGRAPH_MODE=process
. You can also profile multiple jobs in a single process, and more. See the more detailed usage documentation.