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