Running an Nsight Systems report python script independently

780 views Asked by At

I've tweaked a copy of one of the Nsight Systems report scripts (gpukernsum), and I now want to run it myself. So, I write:

./gpukernsum.py report.sqlite

This doesn't work; I get:

ERROR: Script 'gpukernsum.py' encountered an internal error.

$ ./gpukernsum.py report.sqlite
  File "./gpukernsum.py", line 40
    """
      ^
SyntaxError: invalid syntax

I know this is because f"""whatever""" is Python-3 syntax, so I change the script's hash-bang line from:

#!/usr/bin/env python

to:

#!/usr/bin/env python3

and now I get:

$ ./gpukernsum.py report.sqlite
Traceback (most recent call last):
  File "/path/to/./gpukernsum.py", line 7, in <module>
    import nsysstats
ModuleNotFoundError: No module named 'nsysstats'

So I added the relevant directory to the lookup path:

export PYTHONPATH="$PYTHONPATH:/opt/nvidia/nsight-systems/2022.1.1/host-linux-x64/python/lib"

and now I get:

$ ./gpukernsum.py report.sqlite
near "WITH": syntax error

... and I'm stuck. The relevant area of the code is:

    and not a percentage of the application wall or CPU execution time.
"""

    query_stub = """
WITH
    summary AS (
        SELECT
            coalesce({NAME_COL_NAME}, demangledName) AS nameId,

i.e. the "WITH" is part of a string literal which is an SQL query. So, what's the problem? Is Python complaining? Is sqlite complaining?

Note:

  • Nsight Systems 2022.1.1
  • CentOS 7
  • I'm using the original gpukernsum.py code - I have not made any changes to it (other than as described above).
  • My system has Python 3.9.1 for python3.
1

There are 1 answers

0
einpoklum On

A workaround answer:

Nsight Systems bundles its own version of Python, with lib and bin directories.

If you run your script with this specific version, having set PYTHONPATH as described in your question - then the script will work. It's what Nsight itself does, after all.