hprof_io.c

来自「一个小公司要求给写的很简单的任务管理系统。」· C语言 代码 · 共 1,979 行 · 第 1/4 页

C
1,979
字号
            (void)md_snprintf(linebuf, sizeof(linebuf), "Compiled method");        } else if (lineno == -3) {            (void)md_snprintf(linebuf, sizeof(linebuf), "Native method");        } else if (lineno == -1) {            (void)md_snprintf(linebuf, sizeof(linebuf), "Unknown line");        } else {            (void)md_snprintf(linebuf, sizeof(linebuf), "%d", lineno);        }	linebuf[sizeof(linebuf)-1] = 0;	class_name = signature_to_name(csig);	if ( mname == NULL ) {	    mname = "<Unknown Method>";	}	if ( sname == NULL ) {	    sname = "<Unknown Source>";	}        write_printf("\t%s.%s(%s:%s)\n", class_name, mname, sname, linebuf);	HPROF_FREE(class_name);        }}voidio_write_trace_footer(SerialNumber trace_serial_num,		SerialNumber thread_serial_num, jint n_frames){}#define CPU_SAMPLES_RECORD_NAME ("CPU SAMPLES")#define CPU_TIMES_RECORD_NAME ("CPU TIME (ms)")voidio_write_cpu_samples_header(jlong total_cost, jint n_items){    if (gdata->output_format == 'b') {        write_header(HPROF_CPU_SAMPLES, (n_items * (4 * 2)) + (4 * 2));        write_u4((jint)total_cost);        write_u4(n_items);    } else {        time_t t;	char *record_name;	if ( gdata->cpu_sampling ) {            record_name = CPU_SAMPLES_RECORD_NAME;	} else {	    record_name = CPU_TIMES_RECORD_NAME;	}        t = time(0);        write_printf("%s BEGIN (total = %d) %s", record_name,                     /*jlong*/(int)total_cost, ctime(&t));        if ( n_items > 0 ) {	    write_printf("rank   self  accum   count trace method\n");	}    }}voidio_write_cpu_samples_elem(jint index, double percent, double accum,		jint num_hits, jlong cost, SerialNumber trace_serial_num,		jint n_frames, char *csig, char *mname){    CHECK_TRACE_SERIAL_NO(trace_serial_num);    if (gdata->output_format == 'b') {        write_u4((jint)cost);        write_u4(trace_serial_num);    } else {        write_printf("%4u %5.2f%% %5.2f%% %7u %5u",                     index, percent, accum, num_hits,                     trace_serial_num);        if (n_frames > 0) {	    char * class_name;	    	    class_name = signature_to_name(csig);            write_printf(" %s.%s\n", class_name, mname);	    HPROF_FREE(class_name);            } else {            write_printf(" <empty trace>\n");        }    }}voidio_write_cpu_samples_footer(void){    if (gdata->output_format == 'b') {        not_implemented();    } else {	char *record_name;	if ( gdata->cpu_sampling ) {            record_name = CPU_SAMPLES_RECORD_NAME;	} else {	    record_name = CPU_TIMES_RECORD_NAME;	}	write_printf("%s END\n", record_name);    }}voidio_write_heap_summary(jlong total_live_bytes, jlong total_live_instances,		jlong total_alloced_bytes, jlong total_alloced_instances){    if (gdata->output_format == 'b') {        write_header(HPROF_HEAP_SUMMARY, 4 * 6);        write_u4((jint)total_live_bytes);        write_u4((jint)total_live_instances);        write_u8(total_alloced_bytes);        write_u8(total_alloced_instances);    }}voidio_write_oldprof_header(void){    if ( gdata->old_timing_format ) {        write_printf("count callee caller time\n");    }}voidio_write_oldprof_elem(jint num_hits, jint num_frames, char *csig_callee,	    char *mname_callee, char *msig_callee, char *csig_caller,	    char *mname_caller, char *msig_caller, jlong cost){    if ( gdata->old_timing_format ) {	char * class_name_callee;	char * class_name_caller;		class_name_callee = signature_to_name(csig_callee);	class_name_caller = signature_to_name(csig_caller);        write_printf("%d ", num_hits);        if (num_frames >= 1) {            write_printf("%s.%s%s ", class_name_callee,		 mname_callee,  msig_callee);        } else {            write_printf("%s ", "<unknown callee>");        }        if (num_frames > 1) {            write_printf("%s.%s%s ", class_name_caller,		 mname_caller,  msig_caller);        } else {            write_printf("%s ", "<unknown caller>");        }        write_printf("%d\n", (int)cost);	HPROF_FREE(class_name_callee);	HPROF_FREE(class_name_caller);    }}voidio_write_oldprof_footer(void){}voidio_write_monitor_header(jlong total_time){    if (gdata->output_format == 'b') {	not_implemented();    } else {        time_t t = time(0);                t = time(0);        write_printf("MONITOR TIME BEGIN (total = %u ms) %s",                                (int)total_time, ctime(&t));        if (total_time > 0) {            write_printf("rank   self  accum   count trace monitor\n");        }    }}voidio_write_monitor_elem(jint index, double percent, double accum,	    jint num_hits, SerialNumber trace_serial_num, char *sig){    CHECK_TRACE_SERIAL_NO(trace_serial_num);    if (gdata->output_format == 'b') {	not_implemented();    } else {        char *class_name;	        class_name = signature_to_name(sig);	write_printf("%4u %5.2f%% %5.2f%% %7u %5u %s (Java)\n",                     index, percent, accum, num_hits,                     trace_serial_num, class_name);	HPROF_FREE(class_name);        }}voidio_write_monitor_footer(void){    if (gdata->output_format == 'b') {	not_implemented();    } else {        write_printf("MONITOR TIME END\n");    }}voidio_write_monitor_sleep(jlong timeout, SerialNumber thread_serial_num){    if (gdata->output_format == 'b') {	not_implemented();    } else {	if ( thread_serial_num == 0 ) {	    write_printf("SLEEP: timeout=%d, <unknown thread>\n",			(int)timeout);	} else {            CHECK_THREAD_SERIAL_NO(thread_serial_num);	    write_printf("SLEEP: timeout=%d, thread %d\n",			(int)timeout, thread_serial_num);	}    }}voidio_write_monitor_wait(char *sig, jlong timeout, 		SerialNumber thread_serial_num){    if (gdata->output_format == 'b') {	not_implemented();    } else {	if ( thread_serial_num == 0 ) {	    write_printf("WAIT: MONITOR %s, timeout=%d, <unknown thread>\n",			sig, (int)timeout);	} else {            CHECK_THREAD_SERIAL_NO(thread_serial_num);	    write_printf("WAIT: MONITOR %s, timeout=%d, thread %d\n",			sig, (int)timeout, thread_serial_num);	}    }}voidio_write_monitor_waited(char *sig, jlong time_waited, 		SerialNumber thread_serial_num){    if (gdata->output_format == 'b') {	not_implemented();    } else {	if ( thread_serial_num == 0 ) {	    write_printf("WAITED: MONITOR %s, time_waited=%d, <unknown thread>\n",			sig, (int)time_waited);	} else {            CHECK_THREAD_SERIAL_NO(thread_serial_num);	    write_printf("WAITED: MONITOR %s, time_waited=%d, thread %d\n",			sig, (int)time_waited, thread_serial_num);	}    }}voidio_write_monitor_exit(char *sig, SerialNumber thread_serial_num){    if (gdata->output_format == 'b') {	not_implemented();    } else {	if ( thread_serial_num == 0 ) {	    write_printf("EXIT: MONITOR %s, <unknown thread>\n", sig);	} else {            CHECK_THREAD_SERIAL_NO(thread_serial_num);	    write_printf("EXIT: MONITOR %s, thread %d\n",			sig, thread_serial_num);	}    }}voidio_write_monitor_dump_header(void){    if (gdata->output_format == 'b') {	not_implemented();    } else {        write_printf("MONITOR DUMP BEGIN\n");    }}voidio_write_monitor_dump_thread_state(SerialNumber thread_serial_num, 		      SerialNumber trace_serial_num,                      jint threadState){    CHECK_THREAD_SERIAL_NO(thread_serial_num);    CHECK_TRACE_SERIAL_NO(trace_serial_num);    if (gdata->output_format == 'b') {	not_implemented();    } else {	char tstate[20];	tstate[0] = 0;	if (threadState & JVMTI_THREAD_STATE_SUSPENDED) {	    (void)strcat(tstate,"S|");	}	if (threadState & JVMTI_THREAD_STATE_INTERRUPTED) {	    (void)strcat(tstate,"intr|");	}	if (threadState & JVMTI_THREAD_STATE_IN_NATIVE) {	    (void)strcat(tstate,"native|");	}	if ( ! ( threadState & JVMTI_THREAD_STATE_ALIVE ) ) {	    if ( threadState & JVMTI_THREAD_STATE_TERMINATED ) {		(void)strcat(tstate,"ZO");	    } else {		(void)strcat(tstate,"NS");	    }	} else {	    if ( threadState & JVMTI_THREAD_STATE_SLEEPING ) {		(void)strcat(tstate,"SL");	    } else if ( threadState & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER ) {		(void)strcat(tstate,"MW");	    } else if ( threadState & JVMTI_THREAD_STATE_WAITING ) {		(void)strcat(tstate,"CW");	    } else if ( threadState & JVMTI_THREAD_STATE_RUNNABLE ) {		(void)strcat(tstate,"R");	    } else {		(void)strcat(tstate,"UN");	    }	}	write_printf("    THREAD %d, trace %d, status: %s\n",		     thread_serial_num, trace_serial_num, tstate);    }}voidio_write_monitor_dump_state(char *sig, SerialNumber thread_serial_num,		    jint entry_count,		    SerialNumber *waiters, jint waiter_count,		    SerialNumber *notify_waiters, jint notify_waiter_count){    if (gdata->output_format == 'b') {	not_implemented();    } else {	int i;        if ( thread_serial_num != 0 ) {            CHECK_THREAD_SERIAL_NO(thread_serial_num);	    write_printf("    MONITOR %s\n", sig);	    write_printf("\towner: thread %d, entry count: %d\n", 		thread_serial_num, entry_count);	} else {	    write_printf("    MONITOR %s unowned\n", sig);	}	write_printf("\twaiting to enter:");	for (i = 0; i < waiter_count; i++) {            write_thread_serial_number(waiters[i], 				(i != (waiter_count-1)));	}	write_printf("\n");	write_printf("\twaiting to be notified:");	for (i = 0; i < notify_waiter_count; i++) {            write_thread_serial_number(notify_waiters[i], 				(i != (notify_waiter_count-1)));	}	write_printf("\n");    }}voidio_write_monitor_dump_footer(void){    if (gdata->output_format == 'b') {	not_implemented();    } else {        write_printf("MONITOR DUMP END\n");    }}/* ----------------------------------------------------------------- *//* These functions write to a separate file */voidio_heap_header(jlong total_live_instances, jlong total_live_bytes){    if (gdata->output_format != 'b') {	time_t t;		t = time(0);	heap_printf("HEAP DUMP BEGIN (%u objects, %u bytes) %s",			/*jlong*/(int)total_live_instances, 			/*jlong*/(int)total_live_bytes, ctime(&t));    }}voidio_heap_root_thread_object(ObjectIndex thread_obj_id, 		SerialNumber thread_serial_num, SerialNumber trace_serial_num){    CHECK_THREAD_SERIAL_NO(thread_serial_num);    CHECK_TRACE_SERIAL_NO(trace_serial_num);    if (gdata->output_format == 'b') {	 heap_tag(HPROF_GC_ROOT_THREAD_OBJ);	 heap_id(thread_obj_id);	 heap_u4(thread_serial_num);	 heap_u4(trace_serial_num);    } else {	heap_printf("ROOT %x (kind=<thread>, id=%u, trace=%u)\n",		     thread_obj_id, thread_serial_num, trace_serial_num);    }}voidio_heap_root_unknown(ObjectIndex obj_id){    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_UNKNOWN);	heap_id(obj_id);    } else {	heap_printf("ROOT %x (kind=<unknown>)\n", obj_id);    }}voidio_heap_root_jni_global(ObjectIndex obj_id, SerialNumber gref_serial_num, 			 SerialNumber trace_serial_num){    CHECK_TRACE_SERIAL_NO(trace_serial_num);    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_JNI_GLOBAL);	heap_id(obj_id);	heap_id(gref_serial_num);    } else {	heap_printf("ROOT %x (kind=<JNI global ref>, "		     "id=%x, trace=%u)\n",		     obj_id, gref_serial_num, trace_serial_num);    }}voidio_heap_root_jni_local(ObjectIndex obj_id, SerialNumber thread_serial_num, 	jint frame_depth){    CHECK_THREAD_SERIAL_NO(thread_serial_num);    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_JNI_LOCAL);	heap_id(obj_id);	heap_u4(thread_serial_num);	heap_u4(frame_depth);    } else {	heap_printf("ROOT %x (kind=<JNI local ref>, "		     "thread=%u, frame=%d)\n",		     obj_id, thread_serial_num, frame_depth);    }}voidio_heap_root_system_class(ObjectIndex obj_id, char *sig, SerialNumber class_serial_num){    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_STICKY_CLASS);	heap_id(obj_id);    } else {	char *class_name;		class_name = signature_to_name(sig);	heap_printf("ROOT %x (kind=<system class>, name=%s)\n",		     obj_id, class_name);	HPROF_FREE(class_name);    }}voidio_heap_root_monitor(ObjectIndex obj_id){    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_MONITOR_USED);	heap_id(obj_id);    } else {	heap_printf("ROOT %x (kind=<busy monitor>)\n", obj_id);    }}voidio_heap_root_thread(ObjectIndex obj_id, SerialNumber thread_serial_num){    CHECK_THREAD_SERIAL_NO(thread_serial_num);    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_THREAD_BLOCK);	heap_id(obj_id);	heap_u4(thread_serial_num);    } else {	heap_printf("ROOT %x (kind=<thread block>, thread=%u)\n",		     obj_id, thread_serial_num);    }}voidio_heap_root_java_frame(ObjectIndex obj_id, SerialNumber thread_serial_num, 	jint frame_depth){    CHECK_THREAD_SERIAL_NO(thread_serial_num);    if (gdata->output_format == 'b') {	heap_tag(HPROF_GC_ROOT_JAVA_FRAME);	heap_id(obj_id);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?