forked from cory/tildefriends
		
	Log during -t=bench every database access from the main thread.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4498 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										19
									
								
								src/ssb.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/ssb.c
									
									
									
									
									
								
							| @@ -234,6 +234,8 @@ typedef struct _tf_ssb_t | ||||
|  | ||||
| 	tf_ssb_store_queue_t store_queue; | ||||
| 	int ref_count; | ||||
|  | ||||
| 	uv_thread_t thread_self; | ||||
| } tf_ssb_t; | ||||
|  | ||||
| typedef struct _tf_ssb_connection_message_request_t | ||||
| @@ -2155,9 +2157,20 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path | ||||
| 	return ssb; | ||||
| } | ||||
|  | ||||
| static void _tf_ssb_assert_not_main_thread(tf_ssb_t* ssb) | ||||
| { | ||||
| 	if (uv_thread_self() == ssb->thread_self) | ||||
| 	{ | ||||
| 		const char* bt = tf_util_backtrace_string(); | ||||
| 		tf_printf("Acquiring DB from the main thread:\n%s\n", bt); | ||||
| 		tf_free((void*)bt); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| sqlite3* tf_ssb_acquire_db_reader(tf_ssb_t* ssb) | ||||
| { | ||||
| 	tf_trace_begin(ssb->trace, "db_reader"); | ||||
| 	_tf_ssb_assert_not_main_thread(ssb); | ||||
| 	sqlite3* db = NULL; | ||||
| 	uv_mutex_lock(&ssb->db_readers_lock); | ||||
| 	if (ssb->db_readers_count) | ||||
| @@ -2194,6 +2207,7 @@ void tf_ssb_release_db_reader(tf_ssb_t* ssb, sqlite3* db) | ||||
| sqlite3* tf_ssb_acquire_db_writer(tf_ssb_t* ssb) | ||||
| { | ||||
| 	tf_trace_begin(ssb->trace, "db_writer"); | ||||
| 	_tf_ssb_assert_not_main_thread(ssb); | ||||
| 	uv_mutex_lock(&ssb->db_writer_lock); | ||||
| 	sqlite3* writer = ssb->db_writer; | ||||
| 	assert(writer); | ||||
| @@ -3627,3 +3641,8 @@ void tf_ssb_unref(tf_ssb_t* ssb) | ||||
| { | ||||
| 	ssb->ref_count--; | ||||
| } | ||||
|  | ||||
| void tf_ssb_set_main_thread(tf_ssb_t* ssb) | ||||
| { | ||||
| 	ssb->thread_self = uv_thread_self(); | ||||
| } | ||||
|   | ||||
| @@ -210,3 +210,5 @@ tf_ssb_store_queue_t* tf_ssb_get_store_queue(tf_ssb_t* ssb); | ||||
|  | ||||
| void tf_ssb_ref(tf_ssb_t* ssb); | ||||
| void tf_ssb_unref(tf_ssb_t* ssb); | ||||
|  | ||||
| void tf_ssb_set_main_thread(tf_ssb_t* ssb); | ||||
|   | ||||
| @@ -638,6 +638,9 @@ void tf_ssb_test_bench(const tf_test_options_t* options) | ||||
| 	uint8_t id0bin[k_id_bin_len]; | ||||
| 	tf_ssb_id_str_to_bin(id0bin, id0); | ||||
|  | ||||
| 	tf_ssb_set_main_thread(ssb0); | ||||
| 	tf_ssb_set_main_thread(ssb1); | ||||
|  | ||||
| 	uv_idle_t idle0 = { .data = ssb0 }; | ||||
| 	uv_idle_init(&loop, &idle0); | ||||
| 	uv_idle_start(&idle0, _ssb_test_idle); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user