Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
78b30d32
提交
78b30d32
authored
1月 23, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added slow_call vs. fast_call functionality to profile_linker
上级
3d5651e3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
36 行增加
和
13 行删除
+36
-13
compile.py
compile.py
+36
-13
没有找到文件。
compile.py
浏览文件 @
78b30d32
...
...
@@ -10,30 +10,50 @@ from copy import copy
class
profile_linker
:
def
__init__
(
self
,
env
):
self
.
order
=
env
.
toposort
()
# print "digraph unix { size = '6,6'; node [color = lightblue2; style = filled];"
# for op in self.order:
# for input in op.inputs:
# if input.owner:
# print input.owner.__class__.__name__ + str(abs(id(input.owner))), " -> ", op.__class__.__name__ + str(abs(id(op))), ";"
self
.
thunks
=
[
op
.
_perform
for
op
in
self
.
order
]
self
.
n_calls
=
0
self
.
n_thunks
=
0
self
.
times
=
[
0.0
for
op
in
self
.
order
]
#TODO: popen2("dot -Tpng | display") and actually make the graph window pop up
def
print_for_dot
(
self
):
print
"digraph unix { size = '6,6'; node [color = lightblue2; style = filled];"
for
op
in
self
.
order
:
for
input
in
op
.
inputs
:
if
input
.
owner
:
print
input
.
owner
.
__class__
.
__name__
+
str
(
abs
(
id
(
input
.
owner
))),
" -> "
,
op
.
__class__
.
__name__
+
str
(
abs
(
id
(
op
))),
";"
def
__call__
(
self
):
def
slow_call
(
self
):
"""Run the program, timing each thunk. """
for
i
,
thunk
in
enumerate
(
self
.
thunks
):
start_time
=
time
.
time
()
thunk
()
self
.
times
[
i
]
+=
time
.
time
()
-
start_time
self
.
n_thunks
+=
1
self
.
n_calls
+=
1
def
fast_call
(
self
):
"""Run the program, but only time the entire loop."""
start_time
=
time
.
time
()
for
th
in
self
.
thunks
:
th
()
self
.
n_thunks
+=
len
(
self
.
thunks
)
self
.
n_calls
+=
1
self
.
times
[
0
]
+=
time
.
time
()
-
start_time
def
dump
(
self
):
__call__
=
slow_call
def
dump
(
self
,
proportion
=
True
):
"""Print statistics accumulated so far."""
total_time
=
sum
(
self
.
times
)
print
self
.
n_calls
,
'calls took'
,
total_time
,
'seconds'
print
self
.
n_calls
,
'calls took'
,
total_time
,
'seconds to evaluate'
,
print
self
.
n_thunks
,
'thunks'
print
'Proportion of CPU per op'
for
op
,
t
in
zip
(
self
.
order
,
self
.
times
):
s_op
=
str
(
op
)
.
split
()[
0
][
1
:]
print
"
%-35
s
%4.5
f"
%
(
s_op
,
t
/
total_time
)
if
0
:
print
'Proportion of CPU per op'
for
op
,
t
in
zip
(
self
.
order
,
self
.
times
):
s_op
=
str
(
op
)
.
split
()[
0
][
1
:]
print
"
%-35
s
%4.5
f"
%
(
s_op
,
t
/
total_time
)
print
'Proportion of CPU per op class'
dct
=
{}
...
...
@@ -41,7 +61,10 @@ class profile_linker:
s_op
=
str
(
op
)
.
split
()[
0
][
1
:]
dct
[
s_op
]
=
dct
.
get
(
s_op
,
0.0
)
+
t
for
t
,
s_op
in
reversed
(
sorted
([(
t
,
op
)
for
op
,
t
in
dct
.
items
()])):
print
"
%-35
s
%4.5
f"
%
(
s_op
,
t
/
total_time
)
if
proportion
:
print
"
%-35
s
%4.5
f"
%
(
s_op
,
t
/
total_time
)
else
:
print
"
%-35
s
%4.5
f"
%
(
s_op
,
t
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论