Jelajahi Sumber

libobs/media-io: Profile audio/video_thread

Palana 10 tahun lalu
induk
melakukan
c6140b4756
2 mengubah file dengan 22 tambahan dan 0 penghapusan
  1. 11 0
      libobs/media-io/audio-io.c
  2. 11 0
      libobs/media-io/video-io.c

+ 11 - 0
libobs/media-io/audio-io.c

@@ -22,10 +22,13 @@
 #include "../util/darray.h"
 #include "../util/circlebuf.h"
 #include "../util/platform.h"
+#include "../util/profiler.h"
 
 #include "audio-io.h"
 #include "audio-resampler.h"
 
+extern profiler_name_store_t *obs_get_profiler_name_store(void);
+
 /* #define DEBUG_AUDIO */
 
 #define nop() do {int invalid = 0;} while(0)
@@ -402,9 +405,14 @@ static void *audio_thread(void *param)
 
 	os_set_thread_name("audio-io: audio thread");
 
+	const char *audio_thread_name =
+		profile_store_name(obs_get_profiler_name_store(),
+				"audio_thread(%s)", audio->info.name);
+	
 	while (os_event_try(audio->stop_event) == EAGAIN) {
 		os_sleep_ms(AUDIO_WAIT_TIME);
 
+		profile_start(audio_thread_name);
 		pthread_mutex_lock(&audio->line_mutex);
 
 		audio_time = os_gettime_ns() - buffer_time;
@@ -412,6 +420,9 @@ static void *audio_thread(void *param)
 		prev_time  = audio_time;
 
 		pthread_mutex_unlock(&audio->line_mutex);
+		profile_end(audio_thread_name);
+
+		profile_reenable_thread();
 	}
 
 	return NULL;

+ 11 - 0
libobs/media-io/video-io.c

@@ -18,6 +18,7 @@
 #include <assert.h>
 #include "../util/bmem.h"
 #include "../util/platform.h"
+#include "../util/profiler.h"
 #include "../util/threading.h"
 #include "../util/darray.h"
 
@@ -26,6 +27,8 @@
 #include "video-frame.h"
 #include "video-scaler.h"
 
+extern profiler_name_store_t *obs_get_profiler_name_store(void);
+
 #define MAX_CONVERT_BUFFERS 3
 #define MAX_CACHE_SIZE 16
 
@@ -162,16 +165,24 @@ static void *video_thread(void *param)
 
 	os_set_thread_name("video-io: video thread");
 
+	const char *video_thread_name =
+		profile_store_name(obs_get_profiler_name_store(),
+				"video_thread(%s)", video->info.name);
+
 	while (os_sem_wait(video->update_semaphore) == 0) {
 		if (video->stop)
 			break;
 
+		profile_start(video_thread_name);
 		while (!video->stop && !video_output_cur_frame(video)) {
 			video->total_frames++;
 			video->skipped_frames++;
 		}
 
 		video->total_frames++;
+		profile_end(video_thread_name);
+
+		profile_reenable_thread();
 	}
 
 	return NULL;