Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c6d86a5d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c6d86a5d
编写于
6月 18, 2012
作者:
タ
タコ焼き仮面
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make events not use date and time to determine parent_of. fixes #5932
上级
7fe0f27e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
42 addition
and
11 deletion
+42
-11
activesupport/lib/active_support/log_subscriber.rb
activesupport/lib/active_support/log_subscriber.rb
+27
-6
activesupport/lib/active_support/notifications/instrumenter.rb
...esupport/lib/active_support/notifications/instrumenter.rb
+12
-4
activesupport/test/notifications_test.rb
activesupport/test/notifications_test.rb
+3
-1
未找到文件。
activesupport/lib/active_support/log_subscriber.rb
浏览文件 @
c6d86a5d
...
...
@@ -61,7 +61,7 @@ def attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notificatio
@@flushable_loggers
=
nil
log_subscriber
.
public_methods
(
false
).
each
do
|
event
|
next
if
:call
==
event
next
if
%w{ start finish }
.
include?
(
event
.
to_s
)
notifier
.
subscribe
(
"
#{
event
}
.
#{
namespace
}
"
,
log_subscriber
)
end
...
...
@@ -86,14 +86,35 @@ def flush_all!
end
end
def
call
(
message
,
*
args
)
def
initialize
@event_stack
=
Hash
.
new
{
|
h
,
id
|
h
[
id
]
=
Hash
.
new
{
|
ids
,
name
|
ids
[
name
]
=
[]
}
}
super
end
def
start
(
name
,
id
,
payload
)
return
unless
logger
e
=
ActiveSupport
::
Notifications
::
Event
.
new
(
name
,
Time
.
now
,
nil
,
id
,
payload
)
parent
=
@event_stack
[
id
][
name
].
last
parent
<<
e
if
parent
@event_stack
[
id
][
name
].
push
e
end
def
finish
(
name
,
id
,
payload
)
return
unless
logger
method
=
message
.
split
(
'.'
).
first
finished
=
Time
.
now
event
=
@event_stack
[
id
][
name
].
pop
event
.
end
=
finished
method
=
name
.
split
(
'.'
).
first
begin
send
(
method
,
ActiveSupport
::
Notifications
::
Event
.
new
(
message
,
*
args
)
)
rescue
=>
e
logger
.
error
"Could not log
#{
messag
e
.
inspect
}
event.
#{
e
.
class
}
:
#{
e
.
message
}
#{
e
.
backtrace
}
"
send
(
method
,
event
)
rescue
Exception
=>
e
logger
.
error
"Could not log
#{
nam
e
.
inspect
}
event.
#{
e
.
class
}
:
#{
e
.
message
}
#{
e
.
backtrace
}
"
end
end
...
...
activesupport/lib/active_support/notifications/instrumenter.rb
浏览文件 @
c6d86a5d
...
...
@@ -31,7 +31,8 @@ def unique_id
end
class
Event
attr_reader
:name
,
:time
,
:end
,
:transaction_id
,
:payload
,
:duration
attr_reader
:name
,
:time
,
:transaction_id
,
:payload
,
:children
attr_accessor
:end
def
initialize
(
name
,
start
,
ending
,
transaction_id
,
payload
)
@name
=
name
...
...
@@ -39,12 +40,19 @@ def initialize(name, start, ending, transaction_id, payload)
@time
=
start
@transaction_id
=
transaction_id
@end
=
ending
@duration
=
1000.0
*
(
@end
-
@time
)
@children
=
[]
end
def
duration
1000.0
*
(
self
.
end
-
time
)
end
def
<<
(
event
)
@children
<<
event
end
def
parent_of?
(
event
)
start
=
(
time
-
event
.
time
)
*
1000
start
<=
0
&&
(
start
+
duration
>=
event
.
duration
)
@children
.
include?
event
end
end
end
...
...
activesupport/test/notifications_test.rb
浏览文件 @
c6d86a5d
...
...
@@ -221,13 +221,15 @@ def test_events_consumes_information_given_as_payload
assert_equal
Hash
[
:payload
=>
:bar
],
event
.
payload
end
def
test_event_is_parent_based_on_
time_frame
def
test_event_is_parent_based_on_
children
time
=
Time
.
utc
(
2009
,
01
,
01
,
0
,
0
,
1
)
parent
=
event
(
:foo
,
Time
.
utc
(
2009
),
Time
.
utc
(
2009
)
+
100
,
random_id
,
{})
child
=
event
(
:foo
,
time
,
time
+
10
,
random_id
,
{})
not_child
=
event
(
:foo
,
time
,
time
+
100
,
random_id
,
{})
parent
.
children
<<
child
assert
parent
.
parent_of?
(
child
)
assert
!
child
.
parent_of?
(
parent
)
assert
!
parent
.
parent_of?
(
not_child
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录