Просмотр исходного кода

Add VTune attach workaround

Allow pause and send JIT info on demande with --vtune-later
Yuxiao Mao 1 год назад
Родитель
Сommit
0cf8625d76
4 измененных файлов с 31 добавлено и 4 удалено
  1. 1 1
      src/hlmodule.h
  2. 8 1
      src/main.c
  3. 7 2
      src/module.c
  4. 15 0
      src/std/sys.c

+ 1 - 1
src/hlmodule.h

@@ -144,7 +144,7 @@ const char* hl_op_name( int op );
 
 typedef unsigned char h_bool;
 hl_module *hl_module_alloc( hl_code *code );
-int hl_module_init( hl_module *m, h_bool hot_reload );
+int hl_module_init( hl_module *m, h_bool hot_reload, h_bool vtune_later );
 h_bool hl_module_patch( hl_module *m, hl_code *code );
 void hl_module_free( hl_module *m );
 h_bool hl_module_debug( hl_module *m, int port, h_bool wait );

+ 8 - 1
src/main.c

@@ -145,6 +145,7 @@ int main(int argc, pchar *argv[]) {
 	bool debug_wait = false;
 	bool hot_reload = false;
 	int profile_count = -1;
+	bool vtune_later = false;
 	main_context ctx;
 	bool isExc = false;
 	int first_boot_arg = -1;
@@ -176,6 +177,12 @@ int main(int argc, pchar *argv[]) {
 			profile_count = ptoi(*argv++);
 			continue;
 		}
+#ifdef HL_VTUNE
+		if( pcompare(arg,PSTR("--vtune-later")) == 0 ) {
+			vtune_later = true;
+			continue;
+		}
+#endif
 		if( *arg == '-' || *arg == '+' ) {
 			if( first_boot_arg < 0 ) first_boot_arg = argc + 1;
 			// skip value
@@ -214,7 +221,7 @@ int main(int argc, pchar *argv[]) {
 	ctx.m = hl_module_alloc(ctx.code);
 	if( ctx.m == NULL )
 		return 2;
-	if( !hl_module_init(ctx.m,hot_reload) )
+	if( !hl_module_init(ctx.m,hot_reload,vtune_later) )
 		return 3;
 	if( hot_reload ) {
 		ctx.file_time = pfiletime(ctx.file);

+ 7 - 2
src/module.c

@@ -629,7 +629,8 @@ static void hl_module_add( hl_module *m ) {
 	free(old_modules);
 }
 
-int hl_module_init( hl_module *m, h_bool hot_reload ) {
+void hl_setup_vtune( void *vtune_init, void *m );
+int hl_module_init( hl_module *m, h_bool hot_reload, h_bool vtune_later ) {
 	int i;
 	jit_ctx *ctx;
 	// expand globals
@@ -682,7 +683,11 @@ int hl_module_init( hl_module *m, h_bool hot_reload ) {
 	}
 
 #	ifdef HL_VTUNE
-	hl_module_init_vtune(m);
+	if( !vtune_later ) {
+		hl_module_init_vtune(m);
+	} else {
+		hl_setup_vtune(hl_module_init_vtune, m);
+	}
 #	endif
 	hl_module_add(m);
 	hl_setup_exception(module_resolve_symbol, module_capture_stack);

+ 15 - 0
src/std/sys.c

@@ -182,6 +182,20 @@ HL_PRIM void hl_sys_exit( int code ) {
 	exit(code);
 }
 
+static void *f_vtune_init = NULL;
+static void *g_vtune_module = NULL;
+HL_PRIM void hl_setup_vtune( void *vtune_init, void *m ) {
+	f_vtune_init = vtune_init;
+	g_vtune_module = m;
+}
+
+HL_PRIM void hl_sys_vtune_init() {
+	if( f_vtune_init ) {
+		getchar();
+		((void(*)(void*))f_vtune_init)(g_vtune_module);
+	}
+}
+
 #ifdef HL_DEBUG_REPRO
 static double CURT = 0;
 #endif
@@ -730,5 +744,6 @@ DEFINE_PRIM(_ARR, sys_args, _NO_ARG);
 DEFINE_PRIM(_I32, sys_getpid, _NO_ARG);
 DEFINE_PRIM(_BOOL, sys_check_reload, _BYTES);
 DEFINE_PRIM(_VOID, sys_profile_event, _I32 _BYTES _I32);
+DEFINE_PRIM(_VOID, sys_vtune_init, _NO_ARG);
 DEFINE_PRIM(_I32, sys_set_flags, _I32);
 DEFINE_PRIM(_BOOL, sys_has_debugger, _NO_ARG);