|
1 | 1 | # how to use timeline tool to do profile
|
2 | 2 |
|
3 |
| -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. |
| 3 | +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. |
4 | 4 |
|
5 | 5 | ```python
|
6 |
| - with profiler.profiler('All', 'total', '/tmp/profile') as prof: |
7 |
| - for pass_id in range(pass_num): |
8 |
| - for batch_id, data in enumerate(train_reader()): |
9 |
| - exe.run(fluid.default_main_program(), |
10 |
| - feed=feeder.feed(data), |
11 |
| - fetch_list=[], |
12 |
| - use_program_cache=True) |
| 6 | + for pass_id in range(pass_num): |
| 7 | + for batch_id, data in enumerate(train_reader()): |
| 8 | + if pass_id == 0 and batch_id == 5: |
| 9 | + profiler.start_profiler("All") |
| 10 | + elif pass_id == 0 and batch_id == 10: |
| 11 | + profiler.stop_profiler("total", "/tmp/profile") |
| 12 | + exe.run(fluid.default_main_program(), |
| 13 | + feed=feeder.feed(data), |
| 14 | + fetch_list=[]) |
13 | 15 | ...
|
14 | 16 | ```
|
15 | 17 |
|
16 | 18 | 1. Run `python paddle/tools/timeline.py` to process `/tmp/profile`, it will generate another
|
17 | 19 | file `/tmp/timeline` by default. You can change the path by cmd parameter, please take a look at
|
18 | 20 | [timeline.py](https://github.com/PaddlePaddle/Paddle/blob/develop/tools/timeline.py) for details.
|
19 | 21 |
|
| 22 | +```python |
| 23 | +python Paddle/tools/timeline.py --profile_path=/tmp/profile --timeline_path=timeline |
| 24 | +``` |
| 25 | + |
20 | 26 | 1. Open chrome and visit <chrome://tracing/>, use `load` button to load the generated `timeline` file.
|
21 | 27 |
|
22 | 28 | 
|
|
0 commit comments