Free trial: Running Sciagraph

Let’s profile the following program:

import json, sys, time, os

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())
    l2 = deepcopy_list(l)
    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: 2.60 seconds

Running your program with profiling enabled

We can profile it by running it slightly differently. Remember to run inside a virtualenv (in this example, called test-env) with Sciagraph installed, see the previous step in the Getting Started guide.

(test-env) $ python -m sciagraph --output-path ./my-first-sciagraph --trial run example.py 5_000
All done, elapsed: 2.64 seconds
Successfully stored the Sciagraph profiling report.

The report was stored in my-first-sciagraph

Here’s what these options means:

  • The --output-path option sets the directory where the report will be stored.
  • The --trial runs Sciagraph in the free trial mode. In this mode, you are limited to profiling jobs for up to 60 seconds; any code that runs longer than that won’t be profiled. (To profile jobs of unlimited length, and store reports in the cloud for easier retrieval later, see the documentation for production setup.)

Once the program finishes, you should have now a HTML file you can open to view the report, at ./my-first-sciagraph/index.html.

Next: Understanding the output