Imported Upstream version 0.9.8
[platform/upstream/oprofile.git] / libpp / profile_spec.h
1 /**
2  * @file profile_spec.h
3  * Contains a PP profile specification
4  *
5  * @remark Copyright 2003 OProfile authors
6  * @remark Read the file COPYING
7  *
8  * @author Philippe Elie
9  */
10
11 #ifndef PROFILE_SPEC_H
12 #define PROFILE_SPEC_H
13
14 #include <map>
15 #include <vector>
16 #include <list>
17
18 #include "filename_spec.h"
19 #include "comma_list.h"
20 #include "locate_images.h"
21
22 /**
23  * Holds a parsed profile spec composed of tag:value pairs, as given in
24  * pp_interface documentation.
25  *
26  *  @internal implemented through a map of string, pointer to function member
27  *  indexed by tag_name.
28  */
29 class profile_spec
30 {
31 public:
32         /**
33          * @param args  a vector of non options strings
34          * @param extra extra image paths to search
35          *
36          * Factory returning a profile_spec instance storing all valid
37          * tag:value contained in args vector doing also alias
38          * substitution, non-valid tag:value options are considered
39          * as image:value
40          */
41         static profile_spec create(std::list<std::string> const & args,
42                                    std::vector<std::string> const & image_path,
43                                    std::string const & root_path);
44
45         /**
46          * @param exclude_dependent  whether to exclude dependent sub-images
47          * @param exclude_cg  whether to exclude call graph file
48          *
49          * Use the spec to generate the list of candidate sample files.
50          */
51         std::list<std::string>
52         generate_file_list(bool exclude_dependent, bool exclude_cg) const;
53
54         /**
55          * @param file_spec  the filename specification to check
56          *
57          * return true if filename match the spec. PP:3.24 internal loop
58          */
59         bool match(filename_spec const & file_spec) const;
60
61         /**
62          * return archive name
63          * returns an empty string if not using an archive.
64          */
65         std::string get_archive_path() const;
66
67 private:
68         profile_spec();
69
70         /**
71          * @param tag_value  a "tag:value" to interpret, all error throw an
72          * invalid_argument exception.
73          */
74         void parse(std::string const & tag_value);
75
76         /**
77          * @param image an image or a libray name given on command line
78          *
79          * Used for e.g. "opreport /bin/mybinary". We don't know yet
80          * if this is an application or a dependent image.
81          */
82         void set_image_or_lib_name(std::string const & image);
83
84         /**
85          * @param str  a "tag:value"
86          *
87          * return true if tag is a valid tag
88          */
89         bool is_valid_tag(std::string const & str);
90
91         /**
92          * implement tag parsing: PP:3.3 to 3.16
93          */
94         void parse_archive_path(std::string const &);
95         void parse_session(std::string const &);
96         void parse_session_exclude(std::string const &);
97         void parse_image(std::string const &);
98         void parse_image_exclude(std::string const &);
99         void parse_lib_image(std::string const &);
100         void parse_event(std::string const &);
101         void parse_count(std::string const &);
102         void parse_unitmask(std::string const &);
103         void parse_tid(std::string const &);
104         void parse_tgid(std::string const &);
105         void parse_cpu(std::string const &);
106
107         typedef void (profile_spec::*action_t)(std::string const &);
108         typedef std::map<std::string, action_t> parse_table_t;
109         parse_table_t parse_table;
110
111         /**
112          * @param tag_value  input "tag:value" string
113          * @param value  if success return the value part of tag_value
114          * helper for set/is_valid_tag public interface
115          *
116          * return null if tag is not valid, else return the pointer to member
117          * function to apply and the value in value parameter
118          */
119         action_t get_handler(std::string const & tag_value,
120                              std::string & value);
121
122         std::string archive_path;
123         std::string binary;
124         std::vector<std::string> session;
125         std::vector<std::string> session_exclude;
126         std::vector<std::string> image;
127         std::vector<std::string> image_exclude;
128         std::vector<std::string> lib_image;
129         comma_list<std::string> event;
130         comma_list<int> count;
131         comma_list<unsigned int> unitmask;
132         comma_list<pid_t> tid;
133         comma_list<pid_t> tgid;
134         comma_list<int> cpu;
135         // specified by user on command like opreport image1 image2 ...
136         std::vector<std::string> image_or_lib_image;
137
138 public: // FIXME
139         /// extra search path for images
140         extra_images extra_found_images;
141 };
142
143 #endif /* !PROFILE_SPEC_H */