hprof_init.c

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

C
1,986
字号
"\n""Obsolete Options\n""----------------\n""gc_okay=y|n\n"#ifdef DEBUG"\n""DEBUG Option           Description                    Default\n""------------           -----------                    -------\n""primfields=y|n         include primitive field values y\n""primarrays=y|n         include primitive array values y\n""debugflags=MASK        Various debug flags            0\n""                        0x01   Report refs in and of unprepared classes\n""logflags=MASK          Logging to stderr              0\n""                        " TO_STR(LOG_DUMP_MISC)    " Misc logging\n""                        " TO_STR(LOG_DUMP_LISTS)   " Dump out the tables\n""                        " TO_STR(LOG_CHECK_BINARY) " Verify & dump format=b\n""coredump=y|n           Core dump on fatal             n\n""errorexit=y|n          Exit on any error              n\n""pause=y|n              Pause on onload & echo PID     n\n""debug=y|n              Turn on all debug checking     n\n""X=MASK                 Internal use only              0\n""\n""Environment Variables\n""---------------------\n""_JAVA_HPROF_OPTIONS\n""    Options can be added externally via this environment variable.\n""    Anything contained in it will get a comma prepended to it (if needed),\n""    then it will be added to the end of the options supplied via the\n""    " XRUN " or " AGENTLIB " command line option.\n"#endif"\n""Examples\n""--------\n""  - Get sample cpu information every 20 millisec, with a stack depth of 3:\n""      java " AGENTLIB "=cpu=samples,interval=20,depth=3 classname\n""  - Get heap usage information based on the allocation sites:\n""      java " AGENTLIB "=heap=sites classname\n"#ifdef DEBUG"  - Using the external option addition with csh, log details on all runs:\n""      setenv _JAVA_HPROF_OPTIONS \"logflags=0xC\"\n""      java " AGENTLIB "=cpu=samples classname\n""    is the same as:\n""      java " AGENTLIB "=cpu=samples,logflags=0xC classname\n"#endif"\n""Notes\n""-----\n""  - The option format=b cannot be used with monitor=y.\n""  - The option format=b cannot be used with cpu=old|times.\n""  - Use of the " XRUN " interface can still be used, e.g.\n""       java " XRUN ":[help]|[<option>=<value>, ...]\n""    will behave exactly the same as:\n""       java " AGENTLIB "=[help]|[<option>=<value>, ...]\n"    #ifdef DEBUG"  - The debug options and environment variables are available with both java\n""    and java_g versions.\n"#endif"\n""Warnings\n""--------\n""  - This is demonstration code for the JVMTI interface and use of BCI,\n""    it is not an official product or formal part of the JDK.\n""  - The " XRUN " interface will be removed in a future release.\n""  - The option format=b is considered experimental, this format may change\n""    in a future release.\n"    #ifdef DEBUG"  - The obsolete options may be completely removed in a future release.\n""  - The debug options and environment variables are not considered public\n""    interfaces and can change or be removed with any type of update of\n""    " AGENTNAME ", including patches.\n"#endif        );}static voidoption_error(char *description){    char errmsg[FILENAME_MAX+80];    (void)md_snprintf(errmsg, sizeof(errmsg),	   "%s option error: %s (%s)", AGENTNAME, description, gdata->options);    errmsg[sizeof(errmsg)-1] = 0;    HPROF_ERROR(JNI_FALSE, errmsg);    error_exit_process(1);}static void parse_options(char *command_line_options){    int file_or_net_option_seen = JNI_FALSE;    char *all_options;    char *extra_options;    char *options;    char *default_filename;    int   ulen;        if (command_line_options == 0)        command_line_options = "";        if ((strcmp(command_line_options, "help")) == 0) {        print_usage();        error_exit_process(0);    }    extra_options = getenv("_JAVA_HPROF_OPTIONS");    if ( extra_options == NULL ) {	extra_options = "";    }    all_options = HPROF_MALLOC((int)strlen(command_line_options) + 			        (int)strlen(extra_options) + 2);    gdata->options = all_options;    (void)strcpy(all_options, command_line_options);    if ( extra_options[0] != 0 ) {	if ( all_options[0] != 0 ) {	    (void)strcat(all_options, ",");        }	(void)strcat(all_options, extra_options);    }    options = all_options;    LOG2("parse_options()", all_options);        while (*options) {        char option[16];        char suboption[FILENAME_MAX+1];        char *endptr;        if (!get_tok(&options, option, (int)sizeof(option), '=')) {            option_error("general syntax error parsing options");        }        if (strcmp(option, "file") == 0) {            if ( file_or_net_option_seen  ) {                option_error("file or net options should only appear once");            }            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing file=filename");            }            gdata->utf8_output_filename = HPROF_MALLOC((int)strlen(suboption)+1);            (void)strcpy(gdata->utf8_output_filename, suboption);            file_or_net_option_seen = JNI_TRUE;        } else if (strcmp(option, "net") == 0) {            char port_number[16];            if (file_or_net_option_seen ) {                option_error("file or net options should only appear once");	    }	    if (!get_tok(&options, suboption, (int)sizeof(suboption), ':')) {                option_error("net option missing ':'");	    }	    if (!get_tok(&options, port_number, (int)sizeof(port_number), ',')) {                option_error("net option missing port");            }            gdata->net_hostname = HPROF_MALLOC((int)strlen(suboption)+1);            (void)strcpy(gdata->net_hostname, suboption);            gdata->net_port = (int)strtol(port_number, NULL, 10);            file_or_net_option_seen = JNI_TRUE;        } else if (strcmp(option, "format") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing format=a|b");            }            if (strcmp(suboption, "a") == 0) {                gdata->output_format = 'a';            } else if (strcmp(suboption, "b") == 0) {                gdata->output_format = 'b';            } else {                option_error("format option value must be a|b");            }        } else if (strcmp(option, "depth") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing depth=DECIMAL");            }            gdata->max_trace_depth = (int)strtol(suboption, &endptr, 10);            if ((endptr != NULL && *endptr != 0) || gdata->max_trace_depth < 0) {                option_error("depth option value must be decimal and >= 0");            }            gdata->prof_trace_depth = gdata->max_trace_depth;        } else if (strcmp(option, "interval") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing interval=DECIMAL");            }            gdata->sample_interval = (int)strtol(suboption, &endptr, 10);            if ((endptr != NULL && *endptr != 0) || gdata->sample_interval <= 0) {                option_error("interval option value must be decimal and > 0");            }        } else if (strcmp(option, "cutoff") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing cutoff=DOUBLE");            }            gdata->cutoff_point = strtod(suboption, &endptr);            if ((endptr != NULL && *endptr != 0) || gdata->cutoff_point < 0) {                option_error("cutoff option value must be floating point and >= 0");            }        } else if (strcmp(option, "cpu") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing cpu=y|samples|times|old");            }            if ((strcmp(suboption, "samples") == 0) ||                (strcmp(suboption, "y") == 0)) {                gdata->cpu_sampling = JNI_TRUE;            } else if (strcmp(suboption, "times") == 0) {                gdata->cpu_timing = JNI_TRUE;                gdata->old_timing_format = JNI_FALSE;            } else if (strcmp(suboption, "old") == 0) {                gdata->cpu_timing = JNI_TRUE;                gdata->old_timing_format = JNI_TRUE;            } else {                option_error("cpu option value must be y|samples|times|old");            }        } else if (strcmp(option, "heap") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("syntax error parsing heap=dump|sites|all");            }            if (strcmp(suboption, "dump") == 0) {                gdata->heap_dump = JNI_TRUE;            } else if (strcmp(suboption, "sites") == 0) {                gdata->alloc_sites = JNI_TRUE;            } else if (strcmp(suboption, "all") == 0) {                gdata->heap_dump = JNI_TRUE;                gdata->alloc_sites = JNI_TRUE;            } else {                option_error("heap option value must be dump|sites|all");            }        } else if( strcmp(option,"lineno") == 0) {            if ( !setBinarySwitch(&options, &(gdata->lineno_in_traces)) ) {                option_error("lineno option value must be y|n");            }        } else if( strcmp(option,"thread") == 0) {            if ( !setBinarySwitch(&options, &(gdata->thread_in_traces)) ) {                option_error("thread option value must be y|n");            }        } else if( strcmp(option,"doe") == 0) {            if ( !setBinarySwitch(&options, &(gdata->dump_on_exit)) ) {                option_error("doe option value must be y|n");            }        } else if( strcmp(option,"msa") == 0) {            if ( !setBinarySwitch(&options, &(gdata->micro_state_accounting)) ) {                option_error("msa option value must be y|n");            }        } else if( strcmp(option,"force") == 0) {            if ( !setBinarySwitch(&options, &(gdata->force_output)) ) {                option_error("force option value must be y|n");            }        } else if( strcmp(option,"verbose") == 0) {            if ( !setBinarySwitch(&options, &(gdata->verbose)) ) {                option_error("verbose option value must be y|n");            }        } else if( strcmp(option,"primfields") == 0) {            if ( !setBinarySwitch(&options, &(gdata->primfields)) ) {                option_error("primfields option value must be y|n");            }        } else if( strcmp(option,"primarrays") == 0) {            if ( !setBinarySwitch(&options, &(gdata->primarrays)) ) {                option_error("primarrays option value must be y|n");            }        } else if( strcmp(option,"monitor") == 0) {            if ( !setBinarySwitch(&options, &(gdata->monitor_tracing)) ) {                option_error("monitor option value must be y|n");            }        } else if( strcmp(option,"gc_okay") == 0) {            if ( !setBinarySwitch(&options, &(gdata->gc_okay)) ) {                option_error("gc_okay option value must be y|n");            }        } else if (strcmp(option, "logflags") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("logflags option value must be numeric");            }            gdata->logflags = (int)strtol(suboption, NULL, 0);        } else if (strcmp(option, "debugflags") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("debugflags option value must be numeric");            }            gdata->debugflags = (int)strtol(suboption, NULL, 0);        } else if (strcmp(option, "coredump") == 0) {            if ( !setBinarySwitch(&options, &(gdata->coredump)) ) {                option_error("coredump option value must be y|n");            }        } else if (strcmp(option, "exitpause") == 0) {	    option_error("The exitpause option was removed, use -XX:OnError='cmd %%p'");        } else if (strcmp(option, "errorexit") == 0) {            if ( !setBinarySwitch(&options, &(gdata->errorexit)) ) {                option_error("errorexit option value must be y|n");            }        } else if (strcmp(option, "pause") == 0) {            if ( !setBinarySwitch(&options, &(gdata->pause)) ) {                option_error("pause option value must be y|n");            }        } else if (strcmp(option, "debug") == 0) {            if ( !setBinarySwitch(&options, &(gdata->debug)) ) {                option_error("debug option value must be y|n");            }        } else if (strcmp(option, "precrash") == 0) {	    option_error("The precrash option was removed, use -XX:OnError='precrash -p %%p'");        } else if (strcmp(option, "X") == 0) {            if (!get_tok(&options, suboption, (int)sizeof(suboption), ',')) {                option_error("X option value must be numeric");            }            gdata->experiment = (int)strtol(suboption, NULL, 0);        } else {	    char errmsg[80];	    (void)strcpy(errmsg, "Unknown option: ");	    (void)strcat(errmsg, option);	    option_error(errmsg);        }    }       if (gdata->output_format == 'b') {        if (gdata->cpu_timing) {            option_error("cpu=times|old is not supported with format=b");        }        if (gdata->monitor_tracing) {            option_error("monitor=y is not supported with format=b");        }    }                if (gdata->old_timing_format) {        gdata->prof_trace_depth = 2;    }    if (gdata->output_format == 'b') {	default_filename = DEFAULT_OUTPUTFILE;    } else {        default_filename = DEFAULT_OUTPUTFILE DEFAULT_TXT_SUFFIX;    }        if (!file_or_net_option_seen) {	gdata->utf8_output_filename = HPROF_MALLOC((int)strlen(default_filename)+1);	(void)strcpy(gdata->utf8_output_filename, default_filename);    }    if ( gdata->utf8_output_filename != NULL ) {	/* UTF-8 to platform encoding (fill in gdata->output_filename) */	ulen = (int)strlen(gdata->utf8_output_filename);	gdata->output_filename = (char*)HPROF_MALLOC(ulen*3+3);#ifdef SKIP_NPT	(void)strcpy(gdata->output_filename, gdata->utf8_output_filename);#else	(void)(gdata->npt->utf8ToPlatform)	      (gdata->npt->utf, (jbyte*)gdata->utf8_output_filename, ulen, 	       gdata->output_filename, ulen*3+3);#endif    }    /* By default we turn on gdata->alloc_sites and gdata->heap_dump */    if (     !gdata->cpu_timing &&              !gdata->cpu_sampling &&              !gdata->monitor_tracing &&              !gdata->alloc_sites &&              !gdata->heap_dump) {        gdata->heap_dump = JNI_TRUE;        gdata->alloc_sites = JNI_TRUE;    }    if ( gdata->alloc_sites || gdata->heap_dump ) {	gdata->obj_watch = JNI_TRUE;    }    if ( gdata->obj_watch || gdata->cpu_timing ) {        gdata->bci = JNI_TRUE;    }    /* Create files & sockets needed */    if (gdata->heap_dump) {	char *base;	int   len;	/* Get a fast tempfile for the heap information */	base = gdata->output_filename;	if ( base==NULL ) {	    base = default_filename;	}	len = (int)strlen(base);	gdata->heapfilename = HPROF_MALLOC(len + 5);	(void)strcpy(gdata->heapfilename, base);	(void)strcat(gdata->heapfilename, ".TMP");	make_unique_filename(&(gdata->heapfilename));	(void)remove(gdata->heapfilename);	if (gdata->output_format == 'b') {	    if ( gdata->logflags & LOG_CHECK_BINARY ) {		char * check_suffix;		check_suffix = ".check" DEFAULT_TXT_SUFFIX;		gdata->checkfilename = 		    HPROF_MALLOC((int)strlen(default_filename)+				(int)strlen(check_suffix)+1);		(void)strcpy(gdata->checkfilename, default_filename);		(void)strcat(gdata->checkfilename, check_suffix);		(void)remove(gdata->checkfilename);	        gdata->check_fd = md_creat(gdata->checkfilename);	    }

⌨️ 快捷键说明

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