Ejemplo n.º 1
0
Archivo: save.c Proyecto: mbi/NitroHack
/* returns 1 if save successful */
int dosave0(boolean emergency)
{
	int fd;
	struct memfile mf = {NULL, 0, 0};
	boolean log_disabled = iflags.disable_log;

	fd = logfile;
	
	/* when  we leave via nh_exit, logging is disabled. It needs to be
	 * enabled briefly so that log_finish will update the log header. */
	iflags.disable_log = FALSE;
	log_finish(LS_SAVED);
	iflags.disable_log = log_disabled;
	vision_recalc(2);	/* shut down vision to prevent problems
				   in the event of an impossible() call */
	
	savegame(&mf);
	store_mf(fd, &mf);
	
	freedynamicdata();

	return TRUE;
}
Ejemplo n.º 2
0
void log_msg(int channel, const char* name)
{
    log_start(channel, name);
    log_finish();
}
int main(int argc, char **argv){
    Buffer_Set buffers;
    File_Data file;
    float *widths_data;
    float *wrap_ys;
    float font_height;
    float max_width;

    void *scratch;
    int scratch_size;
    
    Stats_Log log;
    
    int do_replay = 0;
    char *replay_filename = 0;
    
    if (argc < 2){
        printf("usage: buffer_test <filename> <message> [-h <.hst file>]\n");
        exit(1);
    }
    
    setup();
    
    for (int i = 3; i < argc; ++i){
        if (do_replay){
            replay_filename = argv[i];
            do_replay = 0;
        }
        if (strcmp(argv[i], "-h") == 0){
            if (replay_filename != 0){
                printf("found -h twice, ignoring duplicates\n");
            }
            else{
                do_replay = 1;
            }
        }
    }
    
    do_replay = (replay_filename != 0);
    
    memzero_4tech(buffers);
    
    log.max = 1 << 20;
    log.size = 0;
    log.out = (char*)malloc(log.max);

    log.sec_max = 32;
    log.sec_top = 0;
    log.sections = (Log_Section*)malloc(sizeof(Log_Section)*log.sec_max);

    log.error = 0;

    scratch_size = 1 << 20;
    scratch = malloc(scratch_size);
    
    file = get_file(argv[1]);
    if (!file.data) exit(1);
    widths_data = get_font_data("LiberationSans-Regular.ttf", &font_height);
    max_width = 500.f;
    
    log_begin_section(&log, litstr("which-test"));
    {
        log_write_str(&log, argv[1], (int)strlen(argv[1]));
        log_write_int(&log, file.size);
        log_write_str(&log, argv[2], (int)strlen(argv[2]));
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("file-open"));
    {
        Record_Statistics init_rec, starts_widths_rec, wraps_rec;
    
        initialization_test(&log, &buffers, file, reps, scratch, scratch_size, &init_rec);
        stream_check_test(&buffers, scratch, scratch_size);
    
        measure_starts_widths_test(&log, &buffers, reps, scratch, scratch_size,
                                   &starts_widths_rec, widths_data);
        measure_check_test(&buffers);

        wrap_ys = measure_wraps_test(&log, &buffers, reps, scratch, scratch_size,
                                     &wraps_rec, font_height, max_width);
    
        Time_Record expected_file_open;
        expected_file_open = init_rec.expected + starts_widths_rec.expected + wraps_rec.expected;
    
        printf("average file open:\n");
        print_record(expected_file_open);
        printf("\n");
        log_time_record(&log, litstr("average"), expected_file_open);
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("cursor-seek"));
    {
        Record_Statistics full_cursor;
        Time_Record full_cursor_average;

        log_begin_section(&log, litstr("to-pos"));
        {
            memzero_4tech(full_cursor_average);
            for (int i = 0; i < 5; ++i){
                silence_test();
                int pos = (file.size*i) / 5;
                full_cursor_test(&log, &buffers, pos,
                                 wrap_ys, widths_data, font_height, max_width,
                                 5, scratch, scratch_size, &full_cursor);
                full_cursor_average = full_cursor_average + full_cursor.expected;
            }
            full_cursor_average /= 5;
            printf("average cursor from position:\n");
            print_record(full_cursor_average);
            printf("\n");
            log_time_record(&log, litstr("average"), full_cursor_average);
        }
        log_end_section(&log);

        log_begin_section(&log, litstr("to-line-character"));
        {
            memzero_4tech(full_cursor_average);
            for (int i = 0; i < 5; ++i){
                silence_test();
                int line = (buffers.buffer.line_count*i) / 5;
                full_cursor_line_test(&log, &buffers, line, 20,
                                      wrap_ys, widths_data, font_height, max_width,
                                      5, scratch, scratch_size, &full_cursor);
                full_cursor_average = full_cursor_average + full_cursor.expected;
            }
            full_cursor_average /= 5;
            printf("average cursor from line & character:\n");
            print_record(full_cursor_average);
            printf("\n");
            log_time_record(&log, litstr("average"), full_cursor_average);
        }
        log_end_section(&log);

        log_begin_section(&log, litstr("to-unwrapped-x-y"));
        {
            memzero_4tech(full_cursor_average);
            for (int i = 0; i < 5; ++i){
                silence_test();
                float y = font_height * (buffers.buffer.line_count*i) / 4.f;
                full_cursor_xy_test(&log, &buffers, y, 37.f, 0,
                                    wrap_ys, widths_data, font_height, max_width,
                                    5, scratch, scratch_size, &full_cursor);
                full_cursor_average = full_cursor_average + full_cursor.expected;
            }
            full_cursor_average /= 5;
            printf("average cursor from line & character:\n");
            print_record(full_cursor_average);
            printf("\n");
            log_time_record(&log, litstr("average"), full_cursor_average);
        }
        log_end_section(&log);
        
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("word-seek"));
    {
        Record_Statistics word_seek;

        {
            char word[] = "not-going-to-find-this";
            int word_len = sizeof(word) - 1;
            
            word_seek_test(&log, &buffers, reps, 0, word, word_len, scratch, scratch_size, &word_seek);

        }

        {
            char word[] = "return";
            int word_len = sizeof(word) - 1;
            
            word_seek_test(&log, &buffers, reps, 1, word, word_len, scratch, scratch_size, &word_seek);
        
            printf("average normal word seek:\n");
            print_record(word_seek.expected);
            printf("\n");
        }
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("one-hundred-single-edits"));
    {
        Record_Statistics edits;
        insert_bottom_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
        insert_top_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
        delete_bottom_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
        delete_top_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
    }
    log_end_section(&log);
    
    File_Data replay_file = {};
    Replay replay;
    
    if (do_replay){
        replay_file = get_file(replay_filename);
        prepare_replay(replay_file, &replay);
    }

    if (replay_file.data){
        log_begin_section(&log, litstr("natural-edits"));
        {
            Record_Statistics edits;
            natural_edits_test(&log, &buffers, reps, widths_data, &replay,
                               scratch, scratch_size, &edits);
        }
        log_end_section(&log);
    }
    else{
        printf("skipped natural-edits test\n\n");
    }
    
    log_begin_section(&log, litstr("batch-edit"));
    {
        Buffer_Edit *batch;
        char *str_base;
        int batch_size, str_size;

        batch_size = 1000;
        str_size = 10000;
        batch = (Buffer_Edit*)malloc(sizeof(Buffer_Edit)*batch_size);
        str_base = (char*)malloc(str_size);

        int character_stride;
        character_stride = buffer_size(&buffers.buffer);
        if (character_stride < batch_size * 10){
            batch_size = character_stride / 10;
            character_stride = 10;
        }
        else{
            character_stride = (character_stride / batch_size);
        }

        int p, curs;
        curs = 0;
        p = 0;
        for (int i = 0; i < batch_size; ++i){
            Buffer_Edit edit;
            edit.start = p;
            edit.end = p+8;
            p += character_stride;
            
            edit.str_start = curs;
            if (i & 1){
                edit.len = 9;
                memcpy_4tech(str_base + curs, "123456789", 9);
                curs += 9;
            }
            else{
                edit.len = 7;
                memcpy_4tech(str_base + curs, "abcdefg", 7);
                curs += 7;
            }
            
            batch[i] = edit;
        }
        
        Record_Statistics batch_stats;
        batch_edit_test(&log, &buffers, reps, widths_data, batch, str_base, batch_size,
                        scratch, scratch_size, &batch_stats);
    }
    log_end_section(&log);
    
    log_finish(&log);
    
    return(0);
}
Ejemplo n.º 4
0
void print_stats(void)
{
	s4    i;
	float f;
	s4    sum;


	// DONE
	dolog("Number of JIT compiler calls: %6d", count_jit_calls);
	// DONE
	dolog("Number of compiled methods:   %6d", count_methods);

	// DONE
	dolog("Number of compiled basic blocks:               %6d",
		  count_basic_blocks);
	// DONE
	dolog("Number of max. basic blocks per method:        %6d",
		  count_max_basic_blocks);

	// DONE
	dolog("Number of compiled JavaVM instructions:        %6d",
		  count_javainstr);
	// DONE
	dolog("Number of max. JavaVM instructions per method: %6d",
		  count_max_javainstr);
	// PARTLY DONE
	dolog("Size of compiled JavaVM instructions:          %6d(%d)",
		  count_javacodesize, count_javacodesize - count_methods * 18);

	// DONE
	dolog("Size of compiled Exception Tables:      %d", count_javaexcsize);
	// XXX 4 byte instructions hardcoded oO. I guess this is no longer valid.
	dolog("Number of Machine-Instructions: %d", count_code_len >> 2);
	// DONE
	dolog("Number of Spills (write to memory) <all [i/l/a|flt|dbl]>: %d [%d|%d|%d]",
		count_spills_write_ila + count_spills_write_flt + count_spills_write_dbl,
		count_spills_write_ila, count_spills_write_flt, count_spills_write_dbl);
	// DONE
	dolog("Number of Spills (read from memory) <all [i/l/a|flt|dbl]>: %d [%d|%d|%d]",
		count_spills_read_ila + count_spills_read_flt + count_spills_read_dbl,
		count_spills_read_ila, count_spills_read_flt, count_spills_read_dbl);
	// NOT used?!
	dolog("Number of Activ    Pseudocommands: %6d", count_pcmd_activ);
	// NOT used?!
	dolog("Number of Drop     Pseudocommands: %6d", count_pcmd_drop);
	// DONE
	dolog("Number of Const    Pseudocommands: %6d (zero:%5d)",
		  count_pcmd_load, count_pcmd_zero);
	// NOT used?!
	dolog("Number of ConstAlu Pseudocommands: %6d (cmp: %5d, store:%5d)",
		  count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
	// NOT used?!
	dolog("Number of Move     Pseudocommands: %6d", count_pcmd_move);
	// DONE
	dolog("Number of Load     Pseudocommands: %6d", count_load_instruction);
	// DONE
	// count_pcmd_store_comb NOT used?!
	dolog("Number of Store    Pseudocommands: %6d (combined: %5d)",
		  count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
	// DONE
	dolog("Number of OP       Pseudocommands: %6d", count_pcmd_op);
	// DONE
	dolog("Number of DUP      Pseudocommands: %6d", count_dup_instruction);
	// DONE
	dolog("Number of Mem      Pseudocommands: %6d", count_pcmd_mem);
	// DONE
	dolog("Number of Method   Pseudocommands: %6d", count_pcmd_met);
	// DONE
	dolog("Number of Branch   Pseudocommands: %6d (rets:%5d, Xrets: %5d)",
		  count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
	// DONE
	log_println("                resolved branches: %6d", count_branches_resolved);
	// DONE
	log_println("              unresolved branches: %6d", count_branches_unresolved);
	// DONE
	dolog("Number of Table    Pseudocommands: %6d", count_pcmd_table);
	dolog("Number of Useful   Pseudocommands: %6d", count_pcmd_table +
		  count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
	// DONE
	dolog("Number of Null Pointer Checks:     %6d", count_check_null);
	// DONE
	dolog("Number of Array Bound Checks:      %6d", count_check_bound);
	// DONE
	dolog("Number of Try-Blocks: %d", count_tryblocks);

	// DONE
	dolog("Number of branch_emit (total, 8bit/16bit/32bit/64bit offset): %d, %d/%d/%d/%d",
		count_emit_branch,  count_emit_branch_8bit,  count_emit_branch_16bit,
							count_emit_branch_32bit, count_emit_branch_64bit);

	// DONE
	dolog("Maximal count of stack elements:   %d", count_max_new_stack);
	// DONE
	dolog("Upper bound of max stack elements: %d", count_upper_bound_new_stack);
	// DONE
	dolog("Distribution of stack sizes at block boundary");
	dolog("     0     1     2     3     4     5     6     7     8     9  >=10");
	dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
		  count_block_stack[0], count_block_stack[1], count_block_stack[2],
		  count_block_stack[3], count_block_stack[4], count_block_stack[5],
		  count_block_stack[6], count_block_stack[7], count_block_stack[8],
		  count_block_stack[9], count_block_stack[10]);
	// DONE
	dolog("Distribution of store stack depth");
	dolog("     0     1     2     3     4     5     6     7     8     9  >=10");
	dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
		  count_store_depth[0], count_store_depth[1], count_store_depth[2],
		  count_store_depth[3], count_store_depth[4], count_store_depth[5],
		  count_store_depth[6], count_store_depth[7], count_store_depth[8],
		  count_store_depth[9], count_store_depth[10]);
	dolog("Distribution of store creator chains first part");
	dolog("     0     1     2     3     4     5     6     7     8     9");
	// DONE
	dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
		  count_store_length[0], count_store_length[1], count_store_length[2],
		  count_store_length[3], count_store_length[4], count_store_length[5],
		  count_store_length[6], count_store_length[7], count_store_length[8],
		  count_store_length[9]);
	// DONE
	dolog("Distribution of store creator chains second part");
	dolog("    10    11    12    13    14    15    16    17    18    19  >=20");
	dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
		  count_store_length[10], count_store_length[11],
		  count_store_length[12], count_store_length[13],
		  count_store_length[14], count_store_length[15],
		  count_store_length[16], count_store_length[17],
		  count_store_length[18], count_store_length[19],
		  count_store_length[20]);
	// DONE
	dolog("Distribution of analysis iterations");
	dolog("     1     2     3     4   >=5");
	dolog("%6d%6d%6d%6d%6d",
		  count_analyse_iterations[0], count_analyse_iterations[1],
		  count_analyse_iterations[2], count_analyse_iterations[3],
		  count_analyse_iterations[4]);


	/* Distribution of basic blocks per method ********************************/

	// DONE
	log_println("Distribution of basic blocks per method:");
	log_println("   <=5  <=10  <=15  <=20  <=30  <=40  <=50  <=75   >75");

	log_start();
	for (i = 0; i <= 8; i++)
		log_print("%6d", count_method_bb_distribution[i]);
	log_finish();

	/* print ratio */

	f = (float) count_methods;

	log_start();
	for (i = 0; i <= 8; i++)
		log_print("%6.2f", (float) count_method_bb_distribution[i] / f);
	log_finish();

	/* print cumulated ratio */

	log_start();
	for (i = 0, sum = 0; i <= 8; i++) {
		sum += count_method_bb_distribution[i];
		log_print("%6.2f", (float) sum / f);
	}
	log_finish();


	/* Distribution of basic block sizes **************************************/

	// DONE
	log_println("Distribution of basic block sizes:");
	log_println("     0     1     2     3     4     5     6     7     8     9   <13   <15   <17   <19   <21   <26   <31   >30");

	/* print block sizes */

	log_start();
	for (i = 0; i <= 17; i++)
		log_print("%6d", count_block_size_distribution[i]);
	log_finish();

	/* print ratio */

	f = (float) count_basic_blocks;

	log_start();
	for (i = 0; i <= 17; i++)
		log_print("%6.2f", (float) count_block_size_distribution[i] / f);
	log_finish();

	/* print cumulated ratio */

	log_start();
	for (i = 0, sum = 0; i <= 17; i++) {
		sum += count_block_size_distribution[i];
		log_print("%6.2f", (float) sum / f);
	}
	log_finish();

	// DONE
	statistics_print_memory_usage();

	// DONE
	dolog("Number of class loads:    %6d", count_class_loads);
	// DONE
	dolog("Number of class inits:    %6d", count_class_inits);
	// DONE
	dolog("Number of loaded Methods: %6d\n", count_all_methods);

	// DONE
	dolog("Calls of utf_new:                 %6d", count_utf_new);
	// NOT used?!
	dolog("Calls of utf_new (element found): %6d\n", count_utf_new_found);


	/* LSRA statistics ********************************************************/

	// DONE
	dolog("Moves reg -> reg:     %6d", count_mov_reg_reg);
	// DONE
	dolog("Moves mem -> reg:     %6d", count_mov_mem_reg);
	// DONE
	dolog("Moves reg -> mem:     %6d", count_mov_reg_mem);
	// DONE
	dolog("Moves mem -> mem:     %6d", count_mov_mem_mem);

	// DONE
	dolog("Methods allocated by LSRA:         %6d",
		  count_methods_allocated_by_lsra);
	// DONE
	dolog("Conflicts between local Variables: %6d", count_locals_conflicts);
	// DONE
	dolog("Local Variables held in Memory:    %6d", count_locals_spilled);
	// DONE
	dolog("Local Variables held in Registers: %6d", count_locals_register);
	// DONE
	dolog("Stackslots held in Memory:         %6d", count_ss_spilled);
	// DONE
	dolog("Stackslots held in Registers:      %6d", count_ss_register);
	// not used!?
	dolog("Memory moves at BB Boundaries:     %6d", count_mem_move_bb);
	// DONE
	dolog("Number of interface slots:         %6d\n", count_interface_size);
	// DONE
	dolog("Number of Argument stack slots in register:  %6d",
		  count_argument_reg_ss);
	// DONE
	dolog("Number of Argument stack slots in memory:    %6d\n",
		  count_argument_mem_ss);
	// DONE
	dolog("Number of Methods kept in registers:         %6d\n",
		  count_method_in_register);


	/* instruction scheduler statistics ***************************************/

#if defined(USE_SCHEDULER)
	dolog("Instruction scheduler statistics:");
	dolog("Number of basic blocks:       %7d", count_schedule_basic_blocks);
	dolog("Number of nodes:              %7d", count_schedule_nodes);
	dolog("Number of leaders nodes:      %7d", count_schedule_leaders);
	dolog("Number of max. leaders nodes: %7d", count_schedule_max_leaders);
	dolog("Length of critical path:      %7d\n", count_schedule_critical_path);
#endif


	/* call statistics ********************************************************/

	dolog("Function call statistics:");
	// DONE
	dolog("Number of jni->CallXMethod function invokations: %ld",
		  count_jni_callXmethod_calls);
	// DONE
	dolog("Overall number of jni invokations:               %ld",
		  count_jni_calls);

	// DONE
	log_println("java-to-native calls:   %10ld", count_calls_java_to_native);
	// DONE
	log_println("native-to-java calls:   %10ld", count_calls_native_to_java);


	/* now print other statistics ********************************************/

#if defined(ENABLE_INTRP)
	print_dynamic_super_statistics();
#endif
}
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
	static struct option options[] = {
		{ "with-disputed",	no_argument,		NULL,	'D' },
		{ "hostname",		required_argument,	NULL,	'h' },
		{ "quiet",		no_argument,		NULL,	'q' },
		{ "log-format",		required_argument,	NULL,	'l' },
		{ "log-file",		required_argument,	NULL,	'f' },
		{ NULL }
	};
	const char *opt_hostname = NULL;
	const char *opt_log_format = NULL;
	const char *opt_log_file = NULL;
	int c;

	while ((c = getopt_long(argc, argv, "Dh:ql:f:", options, NULL)) != EOF) {
		switch (c) {
		case 'D':
			opt_flags |= RPF_DISPUTED;
			break;

		case 'h':
			opt_hostname = optarg;
			break;

		case 'q':
			opt_flags |= RPF_QUIET;
			break;

		case 'l':
			opt_log_format = optarg;
			break;

		case 'f':
			opt_log_file = optarg;
			break;

		default:
		usage:
			fprintf(stderr,
				"Usage:\n"
				"rpctest [-h hostname]\n");
			return 1;
		}
	}

	if (optind != argc)
		goto usage;

	if (opt_flags & RPF_QUIET)
		log_quiet();

	log_init(opt_log_format, "rpcunit", opt_log_file);
	if (!rpctest_init_nettypes())
		return 1;

	rpctest_verify_netpath_all();
	rpctest_verify_netconfig_all();
	rpctest_verify_sockets_all();
	rpctest_verify_pmap_all(opt_flags);
	rpctest_verify_rpcb_all(opt_flags);
	rpctest_verify_svc_register();
	rpctest_verify_clnt_funcs();

	log_finish();

	return num_fails != 0;
}