2 * @file opgprof_options.cpp
3 * Options for opgprof tool
5 * @remark Copyright 2003 OProfile authors
6 * @remark Read the file COPYING
9 * @author Philippe Elie
20 #include "opgprof_options.h"
21 #include "popt_options.h"
23 #include "profile_spec.h"
24 #include "arrange_profiles.h"
28 profile_classes classes;
29 inverted_profile image_profile;
32 string gmon_filename = "gmon.out";
34 // Ugly, for build only
35 demangle_type demangle;
41 popt::option options_array[] = {
42 popt::option(options::gmon_filename, "output-filename", 'o',
43 "output filename, defaults to gmon.out if not specified",
45 popt::option(options::threshold_opt, "threshold", 't',
46 "minimum percentage needed to produce output",
51 bool try_merge_profiles(profile_spec const & spec, bool exclude_dependent)
53 list<string> sample_files = spec.generate_file_list(exclude_dependent, false);
56 << "Matched sample files: " << sample_files.size() << endl;
57 copy(sample_files.begin(), sample_files.end(),
58 ostream_iterator<string>(cverb << vsfile, "\n"));
60 // opgprof merge all by default
61 merge_option merge_by;
66 merge_by.unitmask = true;
68 classes = arrange_profiles(sample_files, merge_by,
69 spec.extra_found_images);
71 cverb << vsfile << "profile_classes:\n" << classes << endl;
73 size_t nr_classes = classes.v.size();
75 list<inverted_profile> iprofiles = invert_profiles(classes);
77 if (nr_classes == 1 && iprofiles.size() == 1) {
78 image_profile = *(iprofiles.begin());
82 // come round for another try
83 if (exclude_dependent)
86 if (iprofiles.empty()) {
87 cerr << "error: no sample files found: profile specification "
88 "too strict ?" << endl;
92 if (nr_classes > 1 || iprofiles.size() > 1) {
93 cerr << "error: specify exactly one binary to process "
94 "and give an event: or count: specification if necessary"
102 } // anonymous namespace
105 void handle_options(options::spec const & spec)
107 if (spec.first.size()) {
108 cerr << "differential profiles not allowed" << endl;
112 profile_spec const pspec =
113 profile_spec::create(spec.common, options::image_path,
116 cverb << vsfile << "output filename: " << options::gmon_filename
119 // we do a first try with exclude-dependent if it fails we include
120 // dependent. First try should catch "opgrof /usr/bin/make" whilst
121 // the second catch "opgprof /lib/libc-2.2.5.so"
122 if (!try_merge_profiles(pspec, true))
123 try_merge_profiles(pspec, false);