oparchive_options.cpp
Go to the documentation of this file.00001
00012 #include <vector>
00013 #include <list>
00014 #include <iostream>
00015 #include <algorithm>
00016 #include <iterator>
00017 #include <fstream>
00018 #include <string.h>
00019
00020 #include "op_config.h"
00021 #include "profile_spec.h"
00022 #include "arrange_profiles.h"
00023 #include "oparchive_options.h"
00024 #include "popt_options.h"
00025 #include "string_filter.h"
00026 #include "file_manip.h"
00027 #include "cverb.h"
00028
00029
00030 using namespace std;
00031
00032 profile_classes classes;
00033 list<string> sample_files;
00034
00035 namespace options {
00036 demangle_type demangle = dmt_normal;
00037 bool exclude_dependent;
00038 merge_option merge_by;
00039 string outdirectory;
00040 bool list_files;
00041 }
00042
00043
00044 namespace {
00045
00046 vector<string> mergespec;
00047
00048 popt::option options_array[] = {
00049 popt::option(options::outdirectory, "output-directory", 'o',
00050 "output to the given directory", "directory"),
00051 popt::option(options::exclude_dependent, "exclude-dependent", 'x',
00052 "exclude libs, kernel, and module samples for applications"),
00053 popt::option(options::list_files, "list-files", 'l',
00054 "just list the files necessary, don't produce the archive")
00055 };
00056
00057
00062 void check_options()
00063 {
00064 using namespace options;
00065
00066
00067 if (!list_files) {
00068 if (outdirectory.size() == 0) {
00069 cerr << "Requires --output-directory option." << endl;
00070 exit(EXIT_FAILURE);
00071 }
00072 string realpath = op_realpath(outdirectory);
00073 if (realpath == "/") {
00074 cerr << "Invalid --output-directory: /" << endl;
00075 exit(EXIT_FAILURE);
00076 }
00077 }
00078 }
00079
00080 }
00081
00082
00083 void handle_options(options::spec const & spec)
00084 {
00085 using namespace options;
00086
00087 if (spec.first.size()) {
00088 cerr << "differential profiles not allowed" << endl;
00089 exit(EXIT_FAILURE);
00090 }
00091
00092
00093
00094 merge_by.cpu = true;
00095 merge_by.lib = true;
00096 merge_by.tid = true;
00097 merge_by.tgid = true;
00098 merge_by.unitmask = true;
00099 check_options();
00100
00101 profile_spec const pspec =
00102 profile_spec::create(spec.common, image_path, root_path);
00103
00104 if (!was_session_dir_supplied())
00105 cerr << "Using " << op_samples_dir << " for session-dir" << endl;
00106
00107 sample_files = pspec.generate_file_list(exclude_dependent, false);
00108
00109 cverb << vsfile << "Matched sample files: " << sample_files.size()
00110 << endl;
00111 copy(sample_files.begin(), sample_files.end(),
00112 ostream_iterator<string>(cverb << vsfile, "\n"));
00113
00114 classes = arrange_profiles(sample_files, merge_by,
00115 pspec.extra_found_images);
00116
00117 cverb << vsfile << "profile_classes:\n" << classes << endl;
00118
00119 if (classes.v.empty()) {
00120 cerr << "error: no sample files found: profile specification "
00121 "too strict ?" << endl;
00122 exit(EXIT_FAILURE);
00123 }
00124
00125 if (strncmp(op_session_dir, "/var/lib/oprofile", strlen("/var/lib/oprofile")))
00126 cerr << "NOTE: The sample data in this archive is located at " << op_session_dir << endl
00127 << "instead of the standard location of /var/lib/oprofile. Hence, when using opreport" << endl
00128 << "and other post-processing tools on this archive, you must pass the following option:" << endl
00129 << "\t--session-dir=" << op_session_dir << endl;
00130 }