使用python跟踪

时间:2017-10-11 14:37:30

标签: python-2.7 python-3.x trace

我正在运行一个脚本,我需要查看它触及的文件的哪些语句。所以,我正在使用Python的trace

此命令在linux终端上运行完美:/x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/nate/bin/ntest -noconsole NATE_HOSTS=/u/smoke/presub/tharnhosts/temp_remove/nikhilh NODES=p8020-5 /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/lib/pynacl/ontap/test/cluster_ha.thpy

在另一个cluster_ha_original.py脚本中我有这段代码:

import trace
cmd_to_run = '/x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/nate/bin/ntest -noconsole NATE_HOSTS=/u/smoke/presub/tharnhosts/temp_remove/nikhilh NODES=p8020-5 /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/lib/pynacl/ontap/test/cluster_ha.thpy'

tracer = trace.Trace(count=False, trace=True)

tracer.run(cmd_to_run)
r = tracer.results()
r.write_results(summary=True)

上面的cluster_ha_original.py文件应该给了我完整的跟踪,其中包括cluster_ha.thpy内部调用但我收到语法错误的文件,函数和语句:

[nikhilh@cycl02 test]$ python3 cluster_ha_original.py
--- modulename: trace, funcname: _unsettrace
trace.py(78):         sys.settrace(None)
Traceback (most recent call last):
  File "cluster_ha_original.py", line 6, in <module>
    tracer.run(cmd_to_run)
  File "/usr/software/lib/python3.2/trace.py", line 501, in run
    self.runctx(cmd, dict, dict)
  File "/usr/software/lib/python3.2/trace.py", line 509, in runctx
    exec(cmd, globals, locals)
  File "<string>", line 1
    /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/nate/bin/ntest -noconsole NATE_HOSTS=/u/smoke/presub/tharnhosts/temp_remove/nikhilh NODES=p8020-5 /x/eng/bbsvl/users/nikhilh/C4563855_4563855_1710110159/test/lib/pynacl/ontap/test/cluster_ha.thpy
    ^
SyntaxError: invalid syntax

有什么想法吗?

0 个答案:

没有答案