[英]Saving results of trace function in python
I'm trying to find out some logging information using 'trace' function provided by python using the following code.我正在尝试使用 python 使用以下代码提供的“跟踪”函数来查找一些日志记录信息。
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=False,
countfuncs = True,
count=False,
timing = True)
tracer.run('exec(script, variables, variables)')
# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True,coverdir='trace_vizier')
The trace results are getting printed in the terminal but the file where data is saved is not generated.跟踪结果正在终端中打印,但未生成保存数据的文件。
Could someone tell me why this is happening?有人能告诉我为什么会这样吗?
Note - https://docs.python.org/3/library/trace.html (Trace function)注意 - https://docs.python.org/3/library/trace.html (跟踪功能)
It appears that It has something to do with putting in-builts functions as command for the run method from Trace, and with the arguments countfuncs
and count
that the Trace constructor receives.似乎它与将内置函数作为来自 Trace 的 run 方法的命令有关,并且与 Trace 构造函数接收的参数
countfuncs
和count
有关。 Here is what I did:这是我所做的:
From the arguments the Trace constructor receives change countfuncs
and count
to countfuncs = False, count=True
. Trace 构造函数从参数接收更改
countfuncs
和count
到countfuncs = False, count=True
。 Next put exec(script, variables, variables)' inside a function of your own and pass it into the run method.接下来将 exec(script, variables, variables)' 放入您自己的函数中并将其传递给 run 方法。
An example:一个例子:
def test(x):
exec(x)
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=False,
countfuncs = False,
count=True,
timing = True)
x = 'print("asdf")'
tracer.run('test(x)')
# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True,coverdir='trace_vizier')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.