int main(int argc, char *argv[]) { char *input_file = NULL; char *output_file = NULL; short int char_num; bool use_mono; if(argc != 4) /* Required argc is 4, for three mandatory arguments. */ usage_printx(argv[0]); else { if(!strcmp(argv[3],"-0")) use_mono = true; else if(!strcmp(argv[3],"-1")) use_mono = false; else usage_printx(argv[0]); } input_file = argv[1]; output_file = argv[2]; if(!freopen(input_file, "rt", stdin)) msg_printx(ERROR_OPENING_FILE, "Error: unable to open %s for reading.\n", input_file); if(!freopen(output_file, "wb", stdout)) msg_printx(ERROR_OPENING_FILE, "Error: unable to open %s for writing.\n", output_file); for(char_num = NUM_SYMBOLS; char_num; char_num--) { char *line = get_row(use_mono); if(use_mono) { do_symbol(FONT_WIDTH_MONO); } else { size_t len = strlen(line); int p = line[len - 1]; putchar(p == ' '? 0x08 : p-47); /* Put a backspace character or a decimal digit */ do_symbol(FONT_WIDTH_VAR); } } return 0; }
int main() { freopen("char_et.txt", "rt", stdin); freopen("char_et.mt", "wb", stdout); for(char_num=256; char_num; char_num--) { fseek(stdin, 8, SEEK_CUR); do_symbol(FONT_WIDTH_MONO); } freopen("char2_et.txt", "rt", stdin); freopen("char2_et.mt", "wb", stdout); for(char_num=256; char_num; char_num--) { fseek(stdin, 6, SEEK_CUR); ch = getchar(); putchar(ch==' '? 0x08 : ch-47); fseek(stdin, 3, SEEK_CUR); do_symbol(FONT_WIDTH_VAR); } return 0; }
int main(int argc, char ** argv) { int fp; const char * func = prof_func; FILE *kmap; int current_symbol_value , next_symbol_value, code_offset; char current_symbol[80] , next_symbol[80]; int has_read , j; long long total=0; off_t profile_size; unsigned long end_address=0; const char *fname = "/proc/profile"; int step; /* * We can read the profiling step from * /proc/profile directly, so we are not * compilation dependent */ char type; int found_function=0, just_found_function=0; /* * This is needed for ultra-low * resolution profiling. */ if (argc >= 2) func = argv[1]; if (argc >= 3) fname = argv[2]; fp = open(fname, O_RDONLY); if (fp < 0) { perror(fname); exit(1); } kmap = fopen("/System.map","r"); if (!kmap) { kmap = fopen("/usr/src/linux/System.map","r"); if (!kmap) { perror("System.map"); exit(1); } } /* * The size of /proc/profile is a very good sanity check, it should end * with _etext. If not the System.map is bolixed. */ { struct stat statbuf; fstat (fp, &statbuf); profile_size=statbuf.st_size; } fscanf(kmap, "%x %*s %s\n", ¤t_symbol_value, current_symbol); fscanf(kmap, "%x %c %s\n", &next_symbol_value, &type, next_symbol); /* * We expect the _stext symbol here. This is both necessary and a good * sanity check. */ if ( strcmp(current_symbol,"_stext") && strcmp(current_symbol,"_text") ) { fprintf(stderr, "expecting _text or _stext as first System.map symbol.\n%s", "(maybe stray undefined symbols in System.map?).\n"); exit(1); } code_offset=current_symbol_value; /* * Here we read the profiling step from /proc/profile. This is a good * sanity check as well. Nothing should go wrong after this. */ has_read = read (fp , &step , sizeof(step) ); if (has_read != (int)sizeof(int)) { perror("huh, couldnt read step from /proc/profile."); exit(1); } printf("// Step: %d, Profiling %s().\n\n",step, func); /* * Main read-analyze loop. */ for (;;) { unsigned long long tiempo = 0; unsigned int buffer [(next_symbol_value - current_symbol_value)/step]; if (!strcmp(func, current_symbol)) { found_function=1; just_found_function=1; } if (!strcmp("_etext", current_symbol)) end_address=next_symbol_value; if ((next_symbol_value/step) == (current_symbol_value/step)) { strcpy(current_symbol, next_symbol); fscanf(kmap, "%x %c %s\n", &next_symbol_value, &type, next_symbol); continue; } lseek (fp , sizeof(int)+ (current_symbol_value-code_offset)/step* sizeof(int) , SEEK_SET); has_read = read (fp , buffer , sizeof(buffer) ); if (just_found_function) { just_found_function=0; show_finegrained_function(has_read, buffer, step, current_symbol, current_symbol_value); } for ( j = 0 ; j < has_read/(int)sizeof(int) ; j++) tiempo += buffer[j]; if (tiempo != 0) { do_symbol(tiempo, current_symbol_value, current_symbol, type); total += tiempo; } if ((has_read < (next_symbol_value-current_symbol_value)/ step*(int)sizeof(int)) || next_symbol_value == current_symbol_value ) break; strcpy ( current_symbol , next_symbol ); current_symbol_value = next_symbol_value; fscanf(kmap , "%x %c %s\n" , &next_symbol_value , &type, next_symbol ); } show_symbols(total); if ( abs((int)(profile_size-sizeof(int))/sizeof(int)*step -(end_address-code_offset)) > (int)step) { fprintf(stderr,"\n// WARNING: wrong _etext symbol.\n"); fprintf(stderr,"// (wrong System.map?)\n"); exit(1); } if (!found_function) { fprintf(stderr,"\n// WARNING: Symbol '%s' not in System.map.\n", func); exit(1); } return(0); }