blob: 8c0988f7730f2bb2c0db3a5a0c5280bd875c9ebc [file] [log] [blame]
Upstreamcc2ee171970-01-12 13:46:40 +00001/**
2 * @file oparchive_options.cpp
3 * Options for oparchive tool
4 *
5 * @remark Copyright 2002, 2003, 2004 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author William Cohen
9 * @author Philippe Elie
10 */
11
12#include <vector>
13#include <list>
14#include <iostream>
15#include <algorithm>
16#include <iterator>
17#include <fstream>
18
19#include "profile_spec.h"
20#include "arrange_profiles.h"
21#include "oparchive_options.h"
22#include "popt_options.h"
23#include "string_filter.h"
24#include "file_manip.h"
25#include "cverb.h"
26
27
28using namespace std;
29
30profile_classes classes;
31list<string> sample_files;
32
33namespace options {
34 string archive_path;
35 bool exclude_dependent;
36 merge_option merge_by;
37 string outdirectory;
38}
39
40
41namespace {
42
43vector<string> mergespec;
44
45popt::option options_array[] = {
46 popt::option(options::outdirectory, "output-directory", 'o',
47 "output to the given directory", "directory"),
48 popt::option(options::exclude_dependent, "exclude-dependent", 'x',
49 "exclude libs, kernel, and module samples for applications")
50};
51
52
53/**
54 * check incompatible or meaningless options
55 *
56 */
57void check_options()
58{
59 using namespace options;
60
61 /* output directory is required */
62 if (outdirectory.size() == 0) {
63 cerr << "Requires --output-directory option." << endl;
64 exit(EXIT_FAILURE);
65 }
66}
67
68} // anonymous namespace
69
70
71void handle_options(options::spec const & spec)
72{
73 using namespace options;
74
75 if (spec.first.size()) {
76 cerr << "differential profiles not allowed" << endl;
77 exit(EXIT_FAILURE);
78 }
79
80 merge_by = handle_merge_option(mergespec, true, exclude_dependent);
81 check_options();
82
83 profile_spec const pspec =
84 profile_spec::create(spec.common, extra_found_images);
85
86 sample_files = pspec.generate_file_list(exclude_dependent, false);
87
88 archive_path = pspec.get_archive_path();
89 cverb << vsfile << "Archive: " << archive_path << endl;
90
91 cverb << vsfile << "Matched sample files: " << sample_files.size()
92 << endl;
93 copy(sample_files.begin(), sample_files.end(),
94 ostream_iterator<string>(cverb << vsfile, "\n"));
95
96 classes = arrange_profiles(sample_files, merge_by);
97
98 cverb << vsfile << "profile_classes:\n" << classes << endl;
99
100 if (classes.v.empty()) {
101 cerr << "error: no sample files found: profile specification "
102 "too strict ?" << endl;
103 exit(EXIT_FAILURE);
104 }
105}