From: John L. <mov...@us...> - 2001-09-06 18:13:31
|
Update of /cvsroot/oprofile/oprofile/pp In directory usw-pr-cvs1:/tmp/cvs-serv22397/pp Modified Files: op_to_source opf_container.cpp opf_filter.cpp oprof_convert.c oprofpp.c Log Message: philippe's cleanup, and several fixes from me. Index: op_to_source =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/op_to_source,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- op_to_source 2001/09/01 02:03:34 1.5 +++ op_to_source 2001/09/06 18:13:28 1.6 @@ -101,9 +101,6 @@ shift done -# PHE FIXME : this checking need to be remade with the new samples files naming -# scheme - # Check than enough option has been given. if [ "$object_file" == "" -a "$sample_file" == "" ]; then echo "You need to give at least an object-file or a sample-file" @@ -116,12 +113,15 @@ exit 1 fi -# PHE FIXME: bogus here is case of passing sample_filename without the #x -# prefix. Should be rewrite perhaps. -#if [ "$sample_file" != "" -a ! -f "$sample_file" ]; then -# echo "sample file $sample_file does not exist" -# exit 1 -#fi +if [ "$object_file" == "" -a "$do_to_asm" == "true" ]; then + echo "you must give an object filename if assembly output is required" + exit 1 +fi + +# we don't check existence of sample file because oprofpp can use it +# as a base filename. FIXME: we need to make the check here to avoid breaking +# the pipe used to generate the report, else if sample file do not exist we +# get an ugly message error if [ "$sample_file" != "" ]; then oprofpp_option="$oprofpp_option -f $sample_file" Index: opf_container.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/opf_container.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- opf_container.cpp 2001/09/01 02:03:34 1.4 +++ opf_container.cpp 2001/09/06 18:13:28 1.5 @@ -25,6 +25,11 @@ #include "opf_filter.h" +namespace { + // FIXME ! + uint op_nr_counters = 2; +} + //--------------------------------------------------------------------------- // Functors used as predicate for vma comparison. struct less_sample_entry_by_vma { Index: opf_filter.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/opf_filter.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- opf_filter.cpp 2001/09/01 02:03:34 1.4 +++ opf_filter.cpp 2001/09/06 18:13:28 1.5 @@ -45,6 +45,8 @@ double do_ratio(size_t a, size_t total); +// FIXME: must change this +uint op_nr_counters = 2; } //--------------------------------------------------------------------------- Index: oprof_convert.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/oprof_convert.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- oprof_convert.c 2001/09/01 02:03:34 1.9 +++ oprof_convert.c 2001/09/06 18:13:28 1.10 @@ -235,26 +235,13 @@ goto err1; } - /* PHE FIXME: same issue in opd_proc.c with more comments */ -#if 0 - /* ugly: mmap needs than fd size is sufficient. */ - if (lseek(out_fd, size - 1, SEEK_SET) == -1) { - fprintf(stderr, "oprofiled: seek failed for \"%s\". %s\n", out_filename, strerror(errno)); - goto err2; - } - - /* PHE FIXME: this unsparse the file by one memory page - * size at the end file :( An another way to grow a file ? */ - if (write(out_fd, "", 1) != 1) { - perror("oprof_convert: cannot grow sample file. "); + /* truncate to grow the file is ok on linux, and probably ok + * in POSIX. I am unsure than don't touch the last page + * and unsparse a little what the samples file */ + if (ftruncate(out_fd, size) == -1) { + fprintf(stderr, "oprof_convert: ftruncate failed for \"%s\". %s\n", out_filename, strerror(errno)); goto err2; } -#else - if (ftruncate(out_fd, size) == -1) { - fprintf(stderr, "oprof_convert: ftruncate failed for \"%s\". %s\n", out_filename, strerror(errno)); - goto err2; - } -#endif footer = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, out_fd, 0); Index: oprofpp.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/oprofpp.c,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- oprofpp.c 2001/09/01 02:03:34 1.37 +++ oprofpp.c 2001/09/06 18:13:28 1.38 @@ -29,6 +29,7 @@ static int showvers; static int verbose; +static uint op_nr_counters = 2; static char const *samplefile; static char *basedir="/var/opd"; @@ -56,6 +57,8 @@ static int ctr = -1; static u32 sect_offset; +static int accumulate_samples(u32 counter[OP_MAX_COUNTERS], int index); + static struct poptOption options[] = { { "samples-file", 'f', POPT_ARG_STRING, &samplefile, 0, "image sample file", "file", }, { "image-file", 'i', POPT_ARG_STRING, &imagefile, 0, "image file", "file", }, @@ -186,16 +189,16 @@ } if (ctr != counter) { - /* PHE FIXME documentation of this behavior */ /* a --counter=x have priority on the # suffixe of filename */ if (ctr != -1 && counter != -1) { /* conflict between #%d and --ctr option */ fprintf(stderr, "oprofpp: conflict between %s filename counter nr and --ctr %d option, using --ctr option %d\n", file_ctr_str, ctr, ctr); + counter = ctr; } - } - counter = ctr; + if (ctr == -1) + ctr = counter; if (ctr == -1) { /* list_all_symbols_details always output all counter and do @@ -216,7 +219,7 @@ if (file_ctr_str) file_ctr_str[0] = '\0'; - if (ctr != -1 && (ctr < 0 || ctr >= op_nr_counters)) { + if (ctr != -1 && (ctr < 0 || ctr >= (int)op_nr_counters)) { ctr = 0; fprintf(stderr, "oprofpp: invalid counter number, using %d\n", ctr); @@ -284,6 +287,7 @@ char **matching; time_t newmtime; bfd *ibfd; + uint i; file = (char *)imagefile; @@ -338,9 +342,18 @@ if (!imagefile) free(file); - /* PHE FIXME: this is broken, should search for a opended sample file - * */ - if (footer[ctr == -1 ? 0 : ctr]->is_kernel) { + for (i = 0; i < op_nr_counters; ++i) { + if (footer[i]) + break; + } + + /* should never happens */ + if (i == op_nr_counters) { + fprintf(stderr,"oprofpp: open_image_file() no samples file open for %s.\n", file); + exit(EXIT_FAILURE); + } + + if (footer[i]->is_kernel) { asection *sect; sect = bfd_get_section_by_name(ibfd, ".text"); @@ -503,13 +516,11 @@ { struct opp_count *ca= (struct opp_count *)a; struct opp_count *cb= (struct opp_count *)b; - - /* PHE FIXME: I think it is correct... */ - int counter = ctr == -1 ? 0 : ctr; - if (ca->count[counter] < cb->count[counter]) + /* note than ctr must be sanitized before calling qsort */ + if (ca->count[ctr] < cb->count[ctr]) return -1; - return (ca->count[counter] > cb->count[counter]); + return (ca->count[ctr] > cb->count[ctr]); } /** @@ -524,9 +535,10 @@ struct opp_count *scounts; u32 start, end; uint tot[OP_MAX_COUNTERS],i,j; - int found_samples, k; + int found_samples; + uint k; - for (i = 0 ; i < op_nr_counters ; ++i) { + for (i = 0; i < op_nr_counters; ++i) { tot[i] = 0; } @@ -547,24 +559,24 @@ } for (j = start; j < end; j++) { - /* PHE FIXME too imbrication level */ - for (k = 0 ; k < op_nr_counters ; ++k) { - if (samples[k] && samples[k][j].count) { - verbprintf("Adding %u 0-samples for symbol $%s$ at pos j 0x%x\n", - samples[k][j].count, syms[i]->name, j); - scounts[i].count[k] += samples[k][j].count; - tot[k] += samples[k][j].count; - } - } + accumulate_samples(scounts[i].count, j); + } + + for (k = 0 ; k < op_nr_counters ; ++k) { + tot[k] += scounts[i].count[k]; } } + if (ctr == -1 || samples[ctr] == NULL) { + fprintf(stderr, " oprofpp: invalid counter %d before sort by count\n", ctr); + exit(EXIT_FAILURE); + } + qsort(scounts, num, sizeof(struct opp_count), countcomp); for (i=0; i < num; i++) { printf_symbol(scounts[i].sym->name); - /* PHE FIXME too imbrication level */ found_samples = 0; for (k = 0; k < op_nr_counters ; ++k) { if (scounts[i].count[k]) { @@ -593,7 +605,7 @@ { u32 start, end; u32 i, j; - int k; + uint k; for (i=0; i < num; i++) { if (streq(syms[i]->name, symbol)) @@ -762,24 +774,20 @@ /** * accumulate_samples - lookup and output linenr info from a vma address * in a given section to standard output. - * @counter: where to accumulate the samples, can be %NULL + * @counter: where to accumulate the samples * @index: index number of the samples. - * - * if @counter != %NULL accumulate samples count in @counter - * else just return 0/1 if they exist samples at @index * - * return non-zero if samples has been found + * return 0 if no samples has been found else return 1 */ static int accumulate_samples(u32 counter[OP_MAX_COUNTERS], int index) { - int k; + uint k; int found_samples = 0; for (k = 0; k < op_nr_counters; ++k) { if (samples[k] && samples[k][index].count) { found_samples = 1; - if (counter) - counter[k] += samples[k][index].count; + counter[k] += samples[k][index].count; } } @@ -803,7 +811,7 @@ for (i = 0 ; i < num ; ++i) { u32 counter[OP_MAX_COUNTERS]; - int k; + uint k; int found_samples; get_symbol_range(syms[i], (i == num-1) ? NULL : syms[i+1], @@ -1035,7 +1043,7 @@ { bfd *ibfd; asymbol **syms; - int i, j; + uint i, j; fd_t fd[OP_MAX_COUNTERS]; size_t size[OP_MAX_COUNTERS]; uint num; @@ -1043,6 +1051,8 @@ get_options(argc, argv); + // FIXME: we must discover op_nr_counters from cpu_type of sample + // file or something for (i = 0; i < op_nr_counters ; ++i) { fd[i] = -1; size[i] = 0; @@ -1051,10 +1061,11 @@ } for (i = 0; i < op_nr_counters ; ++i) { - if (ctr == -1 || ctr == i) - /* PHE FIXME: in some case we can pass 0 as can_fail - * to get better error message */ - fd[i] = open_samples_file(i, &size[i], 1); + if (ctr == -1 || ctr == (int)i) + /* if ctr == i, this means than we open only one + * samples file so don't allow opening failure to get + * a more precise error message */ + fd[i] = open_samples_file(i, &size[i], ctr != (int)i); } for (i = 0; i < op_nr_counters ; ++i) { @@ -1111,8 +1122,12 @@ exit(EXIT_FAILURE); } - printf("Cpu speed was (MHz estimation) : %f\n", - footer[ctr == -1 ? 0 : ctr]->cpu_speed); + for (i = 0; i < op_nr_counters ; ++i) { + if (fd[i] != -1) + break; + } + + printf("Cpu speed was (MHz estimation) : %f\n", footer[i]->cpu_speed); if (list_symbols) { do_list_symbols(syms, num); |