From: Philippe E. <ph...@us...> - 2002-03-06 21:52:21
|
Update of /cvsroot/oprofile/oprofile/pp In directory usw-pr-cvs1:/tmp/cvs-serv19974/oprofile/pp Modified Files: op_time.cpp oprofpp_util.cpp Log Message: pp and doc - fix op_time -l and missing binary file. This is made through two new options to op_time (preffered method) and ignoring non-existing binary file (but you get a warn in this case) Index: op_time.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/op_time.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- op_time.cpp 4 Mar 2002 00:12:43 -0000 1.22 +++ op_time.cpp 6 Mar 2002 21:52:17 -0000 1.23 @@ -32,6 +32,7 @@ #include "opf_filter.h" #include "../util/file_manip.h" +#include "../util/string_manip.h" #include "../util/op_popt.h" using std::string; @@ -78,6 +79,8 @@ static int show_image_name; static char * output_format; static const char * base_dir = "/var/opd/samples"; +static const char * path; +static const char * recursive_path; static OutSymbFlag output_format_flags; @@ -96,11 +99,55 @@ // FIXME: clarify this { "output-format", 't', POPT_ARG_STRING, &output_format, 0, "choose the output format", "output-format strings", }, + { "path", 'p', POPT_ARG_STRING, &path, 0, + "add path for retrieving image", "path_name[,path_name]", }, + { "recursive-path", 'P', POPT_ARG_STRING, &recursive_path, 0, + "add path for retrieving image recursively", "path_name[,path_name]", }, + { "output-format", 't', POPT_ARG_STRING, &output_format, 0, + "choose the output format", "output-format strings", }, { "version", 'v', POPT_ARG_NONE, &showvers, 0, "show version", NULL, }, POPT_AUTOHELP { NULL, 0, 0, NULL, 0, NULL, NULL, }, }; +/// associate filename with directory name where filename exist. Filled +/// through the -p/-P option to allow retrieving of image name when samples +/// file name contains an incorrect location for the image (such ram disk +/// module at boot time. We need a multimap to warn against ambiguity between +/// mutiple time found image name. +typedef multimap<string, string> alt_filename_t; +static alt_filename_t alternate_filename; + +/** + * add_to_alternate_filename - + * add all file name below path_name, optionnaly recursively, to the + * the set of alternative filename used to retrieve image name when + * a samples image name directory is not accurate + */ +void add_to_alternate_filename(const string & path_name, bool recursive) +{ + vector<string> path_names; + + separate_token(path_names, path_name, ','); + + vector<string>::iterator path; + for (path = path_names.begin() ; path != path_names.end() ; ++path) { + list<string> file_list; + create_file_list(file_list, path_name, "*", recursive); + list<string>::const_iterator it; + for (it = file_list.begin() ; it != file_list.end() ; ++it) { + typedef alt_filename_t::value_type value_t; + if (recursive) { + value_t value(basename(*it), dirname(*it)); + alternate_filename.insert(value); + } else { + value_t value(*it, *path); + alternate_filename.insert(value); + } + } + } +} + /** * get_options - process command line * @argc: program arg count @@ -149,6 +196,14 @@ output_format_flags = static_cast<OutSymbFlag>(output_format_flags | fl); } + if (path) { + add_to_alternate_filename(path, false); + } + + if (recursive_path) { + add_to_alternate_filename(recursive_path, true); + } + poptFreeContext(optcon); } @@ -170,7 +225,7 @@ * * return true if @filename */ -static bool samples_file_exist(const std::string & filename) +static bool file_exist(const std::string & filename) { ifstream in(filename.c_str()); @@ -212,7 +267,7 @@ // counter 1, so we must filter them. std::ostringstream s; s << string(base_dir) << "/" << *it << '#' << counter; - if (samples_file_exist(s.str()) == false) + if (file_exist(s.str()) == false) continue; image_name image(*it); @@ -342,7 +397,7 @@ } /* 3rd pass: we can output the result, during the output we optionnaly - * build the set of image_file which belongs to one application and + * build the set of image_name which belongs to one application and * display these results too */ /* this if else are only different by the type of iterator used, we @@ -393,6 +448,49 @@ } /** + * check_image_name - check than image_name belonging to samples_filename + * exist. If not it try to retrieve it through the alternate_filename + * location. + */ +string check_image_name(const string & image_name, + const string & samples_filename) +{ + if (file_exist(image_name)) + return image_name; + + typedef alt_filename_t::const_iterator it_t; + std::pair<it_t, it_t> p_it = + alternate_filename.equal_range(basename(image_name)); + + if (p_it.first == p_it.second) { + + static bool first_warn = true; + if (first_warn) { + cerr << "I can't locate some binary image file, all\n" + << "of this file(s) will be ignored in statistics" + << endl + << "Have you provided the right -p/-P option ?" + << endl; + first_warn = false; + } + + cerr << "warning: can't locate image file for samples files : " + << samples_filename << endl; + + return string(); + } + + if (std::distance(p_it.first, p_it.second) != 1) { + cerr << "the image name for samples files : " + << samples_filename << " is ambiguous\n" + << "so this file file will be ignored" << endl; + return string(); + } + + return p_it.first->second + '/' + p_it.first->first; +} + +/** * output_symbols_count - open each samples file to cumulate samples count * and display a sorted list of symbols and samples ratio * @files: the file list to treat. @@ -412,22 +510,31 @@ string samples_filename = string(base_dir) + "/" + filename; string lib_name; - string image_file = extract_app_name(filename, lib_name); + string image_name = extract_app_name(filename, lib_name); // if the samples file belongs to a shared lib we need to get // the right binary name if (lib_name.length()) - image_file = lib_name; + image_name = lib_name; - image_file = demangle_filename(image_file); + image_name = demangle_filename(image_name); - opp_samples_files samples_file(samples_filename, counter); + // if the image files does not exist try to retrieve it + image_name = check_image_name(image_name, samples_filename); - opp_bfd abfd(samples_file.header[samples_file.first_file], - samples_file.nr_samples, image_file); + // check_image_name have already warned the user if something + // feel bad. + if (file_exist(image_name)) { + opp_samples_files samples_file(samples_filename, + counter); - samples.add(samples_file, abfd, false, output_format_flags, - false, counter); + opp_bfd abfd(samples_file.header[samples_file.first_file], + samples_file.nr_samples, image_name); + + samples.add(samples_file, abfd, false, + output_format_flags, + false, counter); + } } // select the symbols Index: oprofpp_util.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/oprofpp_util.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- oprofpp_util.cpp 5 Mar 2002 20:23:56 -0000 1.34 +++ oprofpp_util.cpp 6 Mar 2002 21:52:17 -0000 1.35 @@ -859,7 +859,7 @@ { size_t sz_file = opd_get_fsize(filename.c_str(), 1); if (sz_file < sizeof(opd_header)) { - fprintf(stderr, "op_merge: sample file %s is not the right " + fprintf(stderr, "open_samples_file(): sample file %s is not the right " "size: got %d, expect at least %d\n", filename.c_str(), sz_file, sizeof(opd_header)); exit(EXIT_FAILURE); @@ -869,7 +869,7 @@ header = (opd_header*)mmap(0, sz_file, PROT_READ, MAP_PRIVATE, fd, 0); if (header == (void *)-1) { - fprintf(stderr, "op_merge: mmap of %s failed. %s\n", filename.c_str(), strerror(errno)); + fprintf(stderr, "open_samples_file(): mmap of %s failed. %s\n", filename.c_str(), strerror(errno)); exit(EXIT_FAILURE); } @@ -877,12 +877,12 @@ if (memcmp(header->magic, OPD_MAGIC, sizeof(header->magic))) { /* FIXME: is 4.4 ok : there is no zero terminator */ - fprintf(stderr, "op_merge: wrong magic %4.4s, expected %s.\n", header->magic, OPD_MAGIC); + fprintf(stderr, "open_samples_file(): wrong magic %4.4s, expected %s.\n", header->magic, OPD_MAGIC); exit(EXIT_FAILURE); } if (header->version != OPD_VERSION) { - fprintf(stderr, "op_merge: wrong version 0x%x, expected 0x%x.\n", header->version, OPD_VERSION); + fprintf(stderr, "open_samples_file(): wrong version 0x%x, expected 0x%x.\n", header->version, OPD_VERSION); exit(EXIT_FAILURE); } } @@ -1007,7 +1007,7 @@ { fd = open(filename.c_str(), O_RDONLY); if (fd == -1) { - fprintf(stderr, "op_merge: Opening %s failed. %s\n", filename.c_str(), strerror(errno)); + fprintf(stderr, "samples_files_t(): Opening %s failed. %s\n", filename.c_str(), strerror(errno)); exit(EXIT_FAILURE); } @@ -1043,7 +1043,7 @@ ::check_headers(header, rhs.header); if (size != rhs.size) { - fprintf(stderr, "op_merge: mapping file size " + fprintf(stderr, "check_headers(): mapping file size " "are different (%d, %d)\n", size, rhs.size); exit(EXIT_FAILURE); } |