2323
2424#include < GLES2/gl2.h>
2525#include " absl/strings/string_view.h" // from @com_google_absl
26+ #include " absl/time/clock.h" // from @com_google_absl
2627#include " absl/types/span.h" // from @com_google_absl
2728#include " litert/c/litert_common.h"
2829#include " litert/cc/litert_compiled_model.h"
3233#include " litert/cc/litert_options.h"
3334#include " litert/samples/async_segmentation/image_processor.h"
3435#include " litert/samples/async_segmentation/image_utils.h"
36+ #include " litert/samples/async_segmentation/timing_utils.h"
3537
3638int main (int argc, char * argv[]) {
3739 if (argc != 4 ) {
@@ -85,6 +87,8 @@ int main(int argc, char* argv[]) {
8587
8688 // ================= PRE-PROCESSING =================
8789 // Load and preprocess the image
90+ ProfilingTimestamps profiling_timestamps;
91+ profiling_timestamps.load_image_start_time = absl::Now ();
8892 int width_orig = 0 , height_orig = 0 , channels_file = 0 , loaded_channels = 3 ;
8993 GLuint tex_id_orig = 0 ;
9094 auto img_data_cpu = ImageUtils::LoadImage (input_file, width_orig, height_orig,
@@ -93,6 +97,9 @@ int main(int argc, char* argv[]) {
9397 std::cerr << " Failed to load image file: " << input_file << std::endl;
9498 return 1 ;
9599 }
100+ profiling_timestamps.load_image_end_time =
101+ profiling_timestamps.e2e_start_time =
102+ profiling_timestamps.pre_process_start_time = absl::Now ();
96103 tex_id_orig = processor.CreateOpenGLTexture (img_data_cpu, width_orig,
97104 height_orig, loaded_channels);
98105 if (!tex_id_orig) {
@@ -129,9 +136,13 @@ int main(int argc, char* argv[]) {
129136 LITERT_ABORT_IF_ERROR (
130137 input_buffers[0 ].Write (absl::MakeConstSpan (preprocessed_buffer_data)));
131138
139+ profiling_timestamps.pre_process_end_time =
140+ profiling_timestamps.inference_start_time = absl::Now ();
132141 // ================= INFERENCE =================
133142 // Run inference
134143 LITERT_ABORT_IF_ERROR (compiled_model.Run (input_buffers, output_buffers));
144+ profiling_timestamps.inference_end_time =
145+ profiling_timestamps.post_process_start_time = absl::Now ();
135146
136147 // ================= POST-PROCESSING =================
137148 // Post-process the results
@@ -173,6 +184,9 @@ int main(int argc, char* argv[]) {
173184 return 1 ;
174185 }
175186
187+ profiling_timestamps.post_process_end_time =
188+ profiling_timestamps.e2e_end_time =
189+ profiling_timestamps.save_image_start_time = absl::Now ();
176190 // Save the output image
177191 std::vector<unsigned char > final_blended_uchar_data (out_blend_width *
178192 out_blend_height * 4 );
@@ -188,6 +202,9 @@ int main(int argc, char* argv[]) {
188202 std::cout << " Successfully saved final blended image to " << output_file
189203 << std::endl;
190204
205+ profiling_timestamps.save_image_end_time = absl::Now ();
206+ PrintTiming (profiling_timestamps);
207+
191208 processor.DeleteOpenGLTexture (tex_id_orig);
192209 processor.DeleteOpenGLBuffer (preprocessed_buffer_id);
193210 for (GLuint id : mask_buffer_ids) {
0 commit comments