1. Add `with profiler.profiler(...)` to the main training loop. After run, the code will generate a profile record file `/tmp/profile`. **Warning**: Please do not run too many batches when use profiler to record timeline information, for the profile record will grow with the batch number.
1. Add `profiler.start_profiler(...)`和`profiler.start_profiler(...)` to the main training loop. After run, the code will generate a profile record file `/tmp/profile`. **Warning**: Please do not run too many batches when use profiler to record timeline information, for the profile record will grow with the batch number.
```python
```python
with profiler.profiler('All', 'total', '/tmp/profile') as prof:
for pass_id in range(pass_num):
for pass_id in range(pass_num):
for batch_id, data in enumerate(train_reader()):
for batch_id, data in enumerate(train_reader()):
if pass_id == 0 and batch_id == 5:
exe.run(fluid.default_main_program(),
profiler.start_profiler("All")
feed=feeder.feed(data),
elif pass_id == 0 and batch_id == 10:
fetch_list=[],
profiler.stop_profiler("total", "/tmp/profile")
use_program_cache=True)
exe.run(fluid.default_main_program(),
feed=feeder.feed(data),
fetch_list=[])
...
...
```
```
...
@@ -17,6 +19,10 @@
...
@@ -17,6 +19,10 @@
file `/tmp/timeline` by default. You can change the path by cmd parameter, please take a look at
file `/tmp/timeline` by default. You can change the path by cmd parameter, please take a look at
[timeline.py](https://github.com/PaddlePaddle/Paddle/blob/develop/tools/timeline.py) for details.
[timeline.py](https://github.com/PaddlePaddle/Paddle/blob/develop/tools/timeline.py) for details.