@@ -115,11 +115,11 @@ void TestInference(const std::string& dirname,
115115#endif
116116 }
117117
118- // Enable the profiler
119- paddle::platform::EnableProfiler (state);
120-
121118 // 2. Initialize the inference_program and load parameters
122119 std::unique_ptr<paddle::framework::ProgramDesc> inference_program;
120+
121+ // Enable the profiler
122+ paddle::platform::EnableProfiler (state);
123123 {
124124 paddle::platform::RecordEvent record_event (
125125 " init_program" ,
@@ -143,6 +143,10 @@ void TestInference(const std::string& dirname,
143143 inference_program = paddle::inference::Load (executor, *scope, dirname);
144144 }
145145 }
146+ // Disable the profiler and print the timing information
147+ paddle::platform::DisableProfiler (paddle::platform::EventSortingKey::kDefault ,
148+ " load_program_profiler.txt" );
149+ paddle::platform::ResetProfiler ();
146150
147151 // 3. Get the feed_target_names and fetch_target_names
148152 const std::vector<std::string>& feed_target_names =
@@ -165,6 +169,12 @@ void TestInference(const std::string& dirname,
165169
166170 // 6. Run the inference program
167171 {
172+ // Ignore the profiling results of the first run
173+ executor.Run (*inference_program, scope, feed_targets, fetch_targets);
174+
175+ // Enable the profiler
176+ paddle::platform::EnableProfiler (state);
177+
168178 // Run repeat times to profile the performance
169179 for (int i = 0 ; i < repeat; ++i) {
170180 paddle::platform::RecordEvent record_event (
@@ -173,12 +183,13 @@ void TestInference(const std::string& dirname,
173183
174184 executor.Run (*inference_program, scope, feed_targets, fetch_targets);
175185 }
176- }
177186
178- // Disable the profiler and print the timing information
179- paddle::platform::DisableProfiler (paddle::platform::EventSortingKey::kDefault ,
180- " profiler.txt" );
181- paddle::platform::ResetProfiler ();
187+ // Disable the profiler and print the timing information
188+ paddle::platform::DisableProfiler (
189+ paddle::platform::EventSortingKey::kDefault ,
190+ " run_inference_profiler.txt" );
191+ paddle::platform::ResetProfiler ();
192+ }
182193
183194 delete scope;
184195}
0 commit comments