Update of /cvsroot/oprofile/oprofile/libpp In directory sc8-pr-cvs1:/tmp/cvs-serv27085/libpp Modified Files: Tag: BRANCH_CALLGRAPH arrange_profiles.cpp count_array.cpp count_array.h filename_spec.cpp format_output.cpp locate_images.cpp locate_images.h name_storage.cpp op_header.cpp parse_filename.cpp profile.cpp profile.h profile_container.cpp profile_spec.cpp profile_spec.h symbol.h symbol_sort.cpp Log Message: merge from HEAD Index: arrange_profiles.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/arrange_profiles.cpp,v retrieving revision 1.12.2.2 retrieving revision 1.12.2.3 diff -u -p -d -r1.12.2.2 -r1.12.2.3 --- arrange_profiles.cpp 25 Oct 2003 20:54:22 -0000 1.12.2.2 +++ arrange_profiles.cpp 8 Nov 2003 16:17:39 -0000 1.12.2.3 @@ -71,7 +71,7 @@ void report_error(profile_classes const if (!i) { str += " and "; - str += tostr(classes.v.size() - 5); + str += op_lexical_cast<string>(classes.v.size() - 5); str += " more,"; } @@ -353,9 +353,15 @@ void add_profile(profile_class & pclass, int numeric_compare(string const & lhs, string const & rhs) { - // FIXME: do we need to handle "all" ?? - unsigned int lhsval = touint(lhs); - unsigned int rhsval = touint(rhs); + if (lhs == "all" && rhs == "all") + return 0; + // we choose an order arbitrarily + if (lhs == "all") + return 1; + if (rhs == "all") + return -1; + unsigned int lhsval = op_lexical_cast<unsigned int>(lhs); + unsigned int rhsval = op_lexical_cast<unsigned int>(rhs); if (lhsval == rhsval) return 0; if (lhsval < rhsval) Index: count_array.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/count_array.cpp,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -p -d -r1.2.2.2 -r1.2.2.3 --- count_array.cpp 14 Sep 2003 23:57:04 -0000 1.2.2.2 +++ count_array.cpp 8 Nov 2003 16:17:39 -0000 1.2.2.3 @@ -16,11 +16,6 @@ using namespace std; -count_array_t::count_array_t() -{ -} - - u32 count_array_t::operator[](size_type index) const { if (index >= container.size()) @@ -42,7 +37,8 @@ count_array_t & count_array_t::operator+ if (rhs.container.size() > container.size()) container.resize(rhs.container.size()); - for (size_type i = 0 ; i < min(container.size(), rhs.container.size()); ++i) + size_type min_size = min(container.size(), rhs.container.size()); + for (size_type i = 0 ; i < min_size; ++i) container[i] += rhs.container[i]; return *this; @@ -54,7 +50,8 @@ count_array_t & count_array_t::operator- if (rhs.container.size() > container.size()) container.resize(rhs.container.size()); - for (size_type i = 0 ; i < min(container.size(), rhs.container.size()); ++i) + size_type min_size = min(container.size(), rhs.container.size()); + for (size_type i = 0 ; i < min_size; ++i) container[i] -= rhs.container[i]; return *this; Index: count_array.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/count_array.h,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -p -d -r1.2.2.3 -r1.2.2.4 --- count_array.h 25 Oct 2003 20:54:22 -0000 1.2.2.3 +++ count_array.h 8 Nov 2003 16:17:39 -0000 1.2.2.4 @@ -23,9 +23,6 @@ */ class count_array_t { public: - /// all counts are intialized to zero - count_array_t(); - typedef std::vector<u32> container_type; typedef container_type::size_type size_type; Index: filename_spec.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/filename_spec.cpp,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -p -d -r1.2.2.1 -r1.2.2.2 --- filename_spec.cpp 14 Sep 2003 23:57:04 -0000 1.2.2.1 +++ filename_spec.cpp 8 Nov 2003 16:17:39 -0000 1.2.2.2 @@ -62,8 +62,8 @@ void filename_spec::set_sample_filename( image = parsed.image; lib_image = parsed.lib_image; event = parsed.event; - count = lexical_cast_no_ws<int>(parsed.count); - unitmask = lexical_cast_no_ws<unsigned int>(parsed.unitmask); + count = op_lexical_cast<int>(parsed.count); + unitmask = op_lexical_cast<unsigned int>(parsed.unitmask); tgid.set(parsed.tgid); tid.set(parsed.tid); cpu.set(parsed.cpu); Index: format_output.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/format_output.cpp,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -u -p -d -r1.3.2.3 -r1.3.2.4 --- format_output.cpp 25 Oct 2003 20:54:22 -0000 1.3.2.3 +++ format_output.cpp 8 Nov 2003 16:17:39 -0000 1.3.2.4 @@ -12,7 +12,6 @@ #include <sstream> #include <iomanip> -#include "file_manip.h" #include "string_manip.h" #include "format_output.h" @@ -124,7 +123,6 @@ size_t formatter::output_field(ostream & { if (!hide_immutable) { out << string(padding, ' '); - padding = 0; field_description const & field(format_map[fl]); string str = (this->*field.formatter)(datum); @@ -146,7 +144,6 @@ size_t formatter::output_header_field(os size_t padding) { out << string(padding, ' '); - padding = 0; field_description const & field(format_map[fl]); out << field.header_name; @@ -386,7 +383,7 @@ string formatter::format_percent(field_d double ratio = op_ratio(f.sample.counts[f.pclass], total_count[f.pclass]); - return format_double(ratio * 100, percent_int_width, + return ::format_percent(ratio * 100, percent_int_width, percent_fract_width); } @@ -398,7 +395,7 @@ string formatter::format_cumulated_perce double ratio = op_ratio(cumulated_percent[f.pclass], total_count[f.pclass]); - return format_double(ratio * 100, percent_int_width, + return ::format_percent(ratio * 100, percent_int_width, percent_fract_width); } @@ -409,7 +406,7 @@ string formatter::format_percent_details double ratio = op_ratio(f.sample.counts[f.pclass], total_count_details[f.pclass]); - return format_double(ratio * 100, percent_int_width, + return ::format_percent(ratio * 100, percent_int_width, percent_fract_width); } @@ -423,7 +420,7 @@ string formatter::format_cumulated_perce double ratio = op_ratio(cumulated_percent_details[f.pclass], total_count_details[f.pclass]); - return format_double(ratio * 100, percent_int_width, + return ::format_percent(ratio * 100, percent_int_width, percent_fract_width); } Index: locate_images.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/locate_images.cpp,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -p -d -r1.2.2.2 -r1.2.2.3 --- locate_images.cpp 25 Oct 2003 20:54:22 -0000 1.2.2.2 +++ locate_images.cpp 8 Nov 2003 16:17:40 -0000 1.2.2.3 @@ -32,7 +32,7 @@ void extra_images::populate(vector<strin list<string>::const_iterator lit = file_list.begin(); list<string>::const_iterator lend = file_list.end(); for (; lit != lend; ++lit) { - value_type v(basename(*lit), dirname(*lit)); + value_type v(op_basename(*lit), op_dirname(*lit)); images.insert(v); } } @@ -111,7 +111,7 @@ string const find_image_path(string cons return image_name; } - string const base = basename(image); + string const base = op_basename(image); vector<string> result = extra_images.find(base); Index: locate_images.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/locate_images.h,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -u -p -d -r1.3.2.2 -r1.3.2.3 --- locate_images.h 25 Oct 2003 20:54:22 -0000 1.3.2.2 +++ locate_images.h 8 Nov 2003 16:17:40 -0000 1.3.2.3 @@ -28,8 +28,6 @@ */ class extra_images { public: - extra_images() {} - /// add all filenames found in the given paths, recursively void populate(std::vector<std::string> const & paths); Index: name_storage.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/name_storage.cpp,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -p -d -r1.5 -r1.5.2.1 --- name_storage.cpp 8 Jun 2003 03:44:13 -0000 1.5 +++ name_storage.cpp 8 Nov 2003 16:17:40 -0000 1.5.2.1 @@ -27,7 +27,7 @@ string const & image_name_storage::basen { stored_name const & n = get(id); if (n.name_processed.empty()) { - n.name_processed = ::basename(n.name); + n.name_processed = op_basename(n.name); } return n.name_processed; } @@ -37,7 +37,7 @@ string const & debug_name_storage::basen { stored_name const & n = get(id); if (n.name_processed.empty()) { - n.name_processed = ::basename(n.name); + n.name_processed = op_basename(n.name); } return n.name_processed; } Index: op_header.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/op_header.cpp,v retrieving revision 1.3.2.7 retrieving revision 1.3.2.8 diff -u -p -d -r1.3.2.7 -r1.3.2.8 --- op_header.cpp 25 Oct 2003 20:54:22 -0000 1.3.2.7 +++ op_header.cpp 8 Nov 2003 16:17:40 -0000 1.3.2.8 @@ -21,7 +21,6 @@ #include "op_file.h" #include "op_header.h" #include "op_events.h" -//#include "stream_util.h" #include "string_manip.h" using namespace std; @@ -147,7 +146,7 @@ string const op_print_event(op_cpu cpu_t str += ")"; } - str += " count " + tostr(count); + str += " count " + op_lexical_cast<string>(count); return str; } Index: parse_filename.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/parse_filename.cpp,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -p -d -r1.1.2.1 -r1.1.2.2 --- parse_filename.cpp 14 Sep 2003 23:57:04 -0000 1.1.2.1 +++ parse_filename.cpp 8 Nov 2003 16:17:40 -0000 1.1.2.2 @@ -28,8 +28,7 @@ parsed_filename parse_event_spec(string size_type const nr_parts = 6; - parts_type parts; - separate_token(parts, event_spec, '.'); + parts_type parts = separate_token(event_spec, '.'); if (parts.size() != nr_parts) { throw invalid_argument("parse_event_spec(): bad event specification: " + event_spec); @@ -54,6 +53,7 @@ parsed_filename parse_event_spec(string return result; } + /** * @param component path component * @@ -61,11 +61,13 @@ parsed_filename parse_event_spec(string */ void remove_base_dir(vector<string> & path) { - while (!path.empty()) { - if (path[0] == "{root}" || path[0] == "{kern}") + vector<string>::iterator it; + for (it = path.begin(); it != path.end(); ++it) { + if (*it == "{root}" || *it == "{kern}") break; - path.erase(path.begin()); } + + path.erase(path.begin(), it); } } // anonymous namespace @@ -95,14 +97,14 @@ parsed_filename parse_filename(string co result.filename = filename; - vector<string> path; - separate_token(path, filename_spec, '/'); + vector<string> path = separate_token(filename_spec, '/'); remove_base_dir(path); // pp_interface PP:3.19 to PP:3.23 path must start either with {root} - // or {kern} and we must found at least 2 component - if (path.size() < 2 || (path[0] != "{root}" && path[0] != "{kern}")) { + // or {kern} and we must found at least 2 component, remove_base_dir() + // return an empty path if {root} or {kern} are not found + if (path.size() < 2) { throw invalid_argument("parse_filename() invalid filename: " + filename); } Index: profile.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/profile.cpp,v retrieving revision 1.6.2.6 retrieving revision 1.6.2.7 diff -u -p -d -r1.6.2.6 -r1.6.2.7 --- profile.cpp 25 Oct 2003 20:54:22 -0000 1.6.2.6 +++ profile.cpp 8 Nov 2003 16:17:40 -0000 1.6.2.7 @@ -33,11 +33,6 @@ profile_t::profile_t() } -profile_t::~profile_t() -{ -} - - // static member unsigned int profile_t::sample_count(string const & filename) { @@ -126,9 +121,9 @@ profile_t::samples_range(unsigned int st // if the image contains no symbol the vma range is [0 - filesize] // in this case we can't substract start_offset else we will underflow // and the iterator range will be empty. - if (start) { + if (start) start -= start_offset; - } + end -= start_offset; ordered_samples_t::const_iterator first = Index: profile.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/profile.h,v retrieving revision 1.7.2.4 retrieving revision 1.7.2.5 diff -u -p -d -r1.7.2.4 -r1.7.2.5 --- profile.h 25 Oct 2003 20:54:22 -0000 1.7.2.4 +++ profile.h 8 Nov 2003 16:17:40 -0000 1.7.2.5 @@ -19,7 +19,6 @@ #include "odb_hash.h" #include "op_types.h" -#include "op_hw_config.h" #include "utility.h" class opd_header; @@ -35,8 +34,6 @@ public: * profile_t - construct an empty profile_t object */ profile_t(); - - ~profile_t(); /// return the header of the last opened samples file opd_header const & get_header() const { Index: profile_container.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/profile_container.cpp,v retrieving revision 1.11.2.4 retrieving revision 1.11.2.5 diff -u -p -d -r1.11.2.4 -r1.11.2.5 --- profile_container.cpp 25 Oct 2003 20:54:22 -0000 1.11.2.4 +++ profile_container.cpp 8 Nov 2003 16:17:41 -0000 1.11.2.5 @@ -16,8 +16,6 @@ #include <algorithm> #include <numeric> -#include "string_filter.h" - #include "symbol.h" #include "op_header.h" #include "profile.h" Index: profile_spec.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/profile_spec.cpp,v retrieving revision 1.2.2.4 retrieving revision 1.2.2.5 diff -u -p -d -r1.2.2.4 -r1.2.2.5 --- profile_spec.cpp 25 Oct 2003 20:54:22 -0000 1.2.2.4 +++ profile_spec.cpp 8 Nov 2003 16:17:41 -0000 1.2.2.5 @@ -14,7 +14,6 @@ #include <iterator> #include <iostream> -#include "op_fileio.h" #include "file_manip.h" #include "op_config.h" #include "profile_spec.h" @@ -138,21 +137,21 @@ void profile_spec::parse_binary(string c void profile_spec::parse_session(string const & str) { normal_tag_set = true; - separate_token(session, str, ','); + session = separate_token(str, ','); } void profile_spec::parse_session_exclude(string const & str) { normal_tag_set = true; - separate_token(session_exclude, str, ','); + session_exclude = separate_token(str, ','); } void profile_spec::parse_image(string const & str) { normal_tag_set = true; - separate_token(image, str, ','); + image = separate_token(str, ','); fixup_image_spec(image, extra); } @@ -160,14 +159,14 @@ void profile_spec::parse_image(string co void profile_spec::parse_image_exclude(string const & str) { normal_tag_set = true; - separate_token(image_exclude, str, ','); + image_exclude = separate_token(str, ','); } void profile_spec::parse_lib_image(string const & str) { normal_tag_set = true; - separate_token(lib_image, str, ','); + lib_image = separate_token(str, ','); fixup_image_spec(image, extra); } @@ -175,42 +174,42 @@ void profile_spec::parse_lib_image(strin void profile_spec::parse_event(string const & str) { normal_tag_set = true; - event.set(str, false); + event.set(str); } void profile_spec::parse_count(string const & str) { normal_tag_set = true; - count.set(str, false); + count.set(str); } void profile_spec::parse_unitmask(string const & str) { normal_tag_set = true; - unitmask.set(str, false); + unitmask.set(str); } void profile_spec::parse_tid(string const & str) { normal_tag_set = true; - tid.set(str, false); + tid.set(str); } void profile_spec::parse_tgid(string const & str) { normal_tag_set = true; - tgid.set(str, false); + tgid.set(str); } void profile_spec::parse_cpu(string const & str) { normal_tag_set = true; - cpu.set(str, false); + cpu.set(str); } @@ -234,6 +233,29 @@ profile_spec::get_handler(string const & } +namespace { + +/// return true if the value from the profile spec may match the comma +/// list +template<typename T> +bool comma_match(comma_list<T> const & cl, generic_spec<T> const & value) +{ + // if the profile spec is "all" we match the sample file + if (!cl.is_set()) + return true; + + // an "all" sample file should never match specified profile + // spec values + if (!value.is_set()) + return false; + + // now match each profile spec value against the sample file + return cl.match(value.value()); +} + +} + + bool profile_spec::match(string const & filename) const { filename_spec spec(filename); @@ -298,52 +320,44 @@ bool profile_spec::match(string const & } } - if (!event.match(spec.event)) { + if (!event.match(spec.event)) return false; - } - if (!count.match(spec.count)) { + if (!count.match(spec.count)) return false; - } - if (!unitmask.match(spec.unitmask)) { + if (!unitmask.match(spec.unitmask)) return false; - } - if (!cpu.match(spec.cpu)) { + if (!comma_match(cpu, spec.cpu)) return false; - } - if (!tid.match(spec.tid)) { + if (!comma_match(tid, spec.tid)) return false; - } - if (!tgid.match(spec.tgid)) { + if (!comma_match(tgid, spec.tgid)) return false; - } return true; } -/* TODO */ -static bool substitute_alias(profile_spec & /*parser*/, - string const & /*arg*/) -{ - return false; -} - - profile_spec profile_spec::create(vector<string> const & args, extra_images const & extra) { profile_spec spec(extra); + set<string> tag_seen; for (size_t i = 0 ; i < args.size() ; ++i) { if (spec.is_valid_tag(args[i])) { + if (tag_seen.find(args[i]) != tag_seen.end()) { + throw op_runtime_error("tag specified " + "more than once: " + args[i]); + } + tag_seen.insert(args[i]); spec.parse(args[i]); - } else if (!substitute_alias(spec, args[i])) { - string file = op_follow_link(args[i]); + } else { + string file = follow_link(args[i]); file = relative_to_absolute_path(file); spec.set_image_or_lib_name(file); } @@ -405,11 +419,11 @@ list<string> profile_spec::generate_file if (sessions.empty()) { ostringstream os; - os << "No session given" << endl; - os << "included session was:" << endl; + os << "No session given\n" + << "included session was:\n"; copy(session.begin(), session.end(), ostream_iterator<string>(os, "\n")); - os << "excluded session was:" << endl; + os << "excluded session was:\n"; copy(session_exclude.begin(), session_exclude.end(), ostream_iterator<string>(os, "\n")); throw invalid_argument(os.str()); Index: profile_spec.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/profile_spec.h,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -p -d -r1.2.2.1 -r1.2.2.2 --- profile_spec.h 11 Aug 2003 21:18:40 -0000 1.2.2.1 +++ profile_spec.h 8 Nov 2003 16:17:41 -0000 1.2.2.2 @@ -15,7 +15,6 @@ #include <vector> #include <list> -#include "generic_spec.h" #include "filename_spec.h" #include "comma_list.h" Index: symbol.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/symbol.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -p -d -r1.1.2.1 -r1.1.2.2 --- symbol.h 11 Aug 2003 21:18:40 -0000 1.1.2.1 +++ symbol.h 8 Nov 2003 16:17:41 -0000 1.1.2.2 @@ -12,7 +12,6 @@ #ifndef SYMBOL_H #define SYMBOL_H -#include "config.h" #include "name_storage.h" #include "count_array.h" Index: symbol_sort.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libpp/symbol_sort.cpp,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -u -p -d -r1.3.2.3 -r1.3.2.4 --- symbol_sort.cpp 11 Aug 2003 21:18:40 -0000 1.3.2.3 +++ symbol_sort.cpp 8 Nov 2003 16:17:41 -0000 1.3.2.4 @@ -12,7 +12,6 @@ #include "symbol_sort.h" #include "symbol.h" #include "symbol_functors.h" -#include "file_manip.h" #include "name_storage.h" #include "op_exception.h" @@ -128,11 +127,10 @@ void sort_options::sort(symbol_collectio long_filenames = lf; std::vector<sort_order> sort_option(options); - for (sort_order cur = first; cur != last; ) { + for (sort_order cur = first; cur != last; cur = sort_order(cur + 1)) { if (find(sort_option.begin(), sort_option.end(), cur) == sort_option.end()) sort_option.push_back(cur); - cur = sort_order(cur + 1); } stable_sort(syms.begin(), syms.end(), |