RecordEvent¶
- class paddle.profiler. RecordEvent ( name: str, event_type: TracerEventType = TracerEventType.UserDefined ) [源代码] ¶
用于用户自定义打点,记录某一段代码运行的时间。
参数¶
name (str) - 记录打点的名字。
event_type (TracerEventType,可选) - 可选参数,默认值为 TracerEventType.UserDefined。该参数预留为内部使用,最好不要指定该参数。
代码示例¶
import paddle
import paddle.profiler as profiler
# method1: using context manager
with profiler.RecordEvent("record_add"):
data1 = paddle.randn(shape=[3])
data2 = paddle.randn(shape=[3])
result = data1 + data2
# method2: call begin() and end()
record_event = profiler.RecordEvent("record_add")
record_event.begin()
data1 = paddle.randn(shape=[3])
data2 = paddle.randn(shape=[3])
result = data1 + data2
record_event.end()
注解
RecordEvent 只有在 性能分析器 处于 RECORD 状态才会生效。
方法¶
begin()¶
记录开始的时间。
代码示例
import paddle
import paddle.profiler as profiler
record_event = profiler.RecordEvent("record_sub")
record_event.begin()
data1 = paddle.randn(shape=[3])
data2 = paddle.randn(shape=[3])
result = data1 - data2
record_event.end()
end()¶
记录结束的时间。
代码示例
import paddle
import paddle.profiler as profiler
record_event = profiler.RecordEvent("record_mul")
record_event.begin()
data1 = paddle.randn(shape=[3])
data2 = paddle.randn(shape=[3])
result = data1 * data2
record_event.end()