477e3f40feab6de41122a0dda606ddab6be55599
[platform/upstream/oprofile.git] / gui / oprof_start.h
1 /**
2  * @file oprof_start.h
3  * The GUI start main class
4  *
5  * @remark Copyright 2002 OProfile authors
6  * @remark Read the file COPYING
7  *
8  * @author Philippe Elie
9  * @author John Levon
10  */
11
12 #ifndef OPROF_START_H
13 #define OPROF_START_H
14
15 #include <vector>
16 #include <map>
17 #include <set>
18
19 #include "config.h"
20
21 #include "ui/oprof_start.base.h"
22 #include "oprof_start_config.h"
23
24 #include "op_events.h"
25
26 #ifndef QT3_SUPPORT
27 #define Q3ListViewItem QListViewItem
28 #endif
29
30 class QIntValidator;
31 class QListViewItem;
32 class QTimerEvent;
33
34 /// a struct describing a particular event type
35 struct op_event_descr {
36         op_event_descr();
37
38         /// bit mask of allowed counters
39         uint counter_mask;
40         /// hardware event number
41         u32 val;
42         /// unit mask values if applicable
43         op_unit_mask const * unit;
44         /// name of event
45         std::string name;
46         /// description of event
47         std::string help_str;
48         /// minimum counter value
49         uint min_count;
50 };
51
52 class oprof_start : public oprof_start_base
53 {
54         Q_OBJECT
55
56 public:
57         oprof_start();
58
59 protected slots:
60         /// select the kernel image filename
61         void choose_kernel_filename();
62         /// flush profiler
63         void on_flush_profiler_data();
64         /// start profiler
65         void on_start_profiler();
66         /// stop profiler
67         void on_stop_profiler();
68         /// events selection change
69         void event_selected();
70         /// the mouse is over an event
71         void event_over(Q3ListViewItem *);
72         /// state of separate_kernel_cb changed
73         void on_separate_kernel_cb_changed(int);
74         /// reset sample files
75         void on_reset_sample_files();
76
77         /// close the dialog
78         void accept();
79
80         /// WM hide event
81         void closeEvent(QCloseEvent * e);
82
83         /// timer event
84         void timerEvent(QTimerEvent * e);
85
86 private:
87         /// the counter combo has been activated
88         void fill_events_listbox();
89
90         /// fill the event details and gui setup
91         void fill_events();
92
93         /// find an event description by name
94         op_event_descr const & locate_event(std::string const & name) const;
95
96         /// update config on user change
97         void record_selected_event_config();
98         /// update config and validate
99         bool record_config();
100
101         /// calculate unit mask for given event and unit mask part
102         void get_unit_mask_part(op_event_descr const & descr, uint num, bool selected, uint & mask);
103         /// calculate unit mask for given event
104         uint get_unit_mask(op_event_descr const & descr);
105         /// set the unit mask widgets for given event
106         void setup_unit_masks(op_event_descr const & descr);
107
108         /// return the maximum perf counter value for the current cpu type
109         uint max_perf_count() const;
110
111         /// show an event's settings
112         void display_event(op_event_descr const & descrp);
113
114         /// hide unit mask widgets
115         void hide_masks(void);
116
117         /// read the events set in daemonrc
118         void read_set_events();
119         /// use the default event
120         void setup_default_event();
121         /// load the extra config file
122         void load_config_file();
123         /// save the config
124         bool save_config();
125
126         /// redraw the event list by changing icon status
127         void draw_event_list();
128
129         /// return true if item is selectable or already selected
130         bool is_selectable_event(Q3ListViewItem * item);
131
132         /// try to alloc counters for the selected_events
133         bool alloc_selected_events() const;
134
135         /// validator for event count
136         QIntValidator* event_count_validator;
137
138         /// all available events for this hardware
139         std::vector<op_event_descr> v_events;
140
141         /// current event configs for each counter
142         typedef std::map<std::string, event_setting> event_setting_map;
143         event_setting_map event_cfgs;
144
145         /// The currently selected events. We must track this because
146         /// with multiple selection listbox QT doesn't allow to know
147         /// what is the last selected item. events_selected() update it
148         std::set<Q3ListViewItem *> selected_events;
149         Q3ListViewItem * current_event;
150
151         /// current config
152         config_setting config;
153
154         /// the expansion of "~" directory
155         std::string user_dir;
156
157         /// CPU type
158         op_cpu cpu_type;
159
160         /// CPU speed in MHz
161         double cpu_speed;
162
163         /// total number of available HW counters
164         uint op_nr_counters;
165
166         /// Total number of samples for this run
167         unsigned long total_nr_interrupts;
168 };
169
170 #endif // OPROF_START_H