Wireshark  4.3.0
The Wireshark network protocol analyzer
io_graph_dialog.h
Go to the documentation of this file.
1 
10 #ifndef IO_GRAPH_DIALOG_H
11 #define IO_GRAPH_DIALOG_H
12 
13 #include <config.h>
14 
15 #include "epan/epan_dissect.h"
16 #include "epan/prefs.h"
17 #include "ui/preference_utils.h"
18 
19 #include "ui/io_graph_item.h"
20 
21 #include "wireshark_dialog.h"
22 
23 #include <ui/qt/models/uat_model.h>
25 
26 #include <wsutil/str_util.h>
27 
28 #include <QPointer>
29 #include <QIcon>
30 #include <QMenu>
31 #include <QTextStream>
32 
33 #include <vector>
34 
35 class QRubberBand;
36 class QTimer;
37 class QAbstractButton;
38 
39 class QCPBars;
40 class QCPGraph;
41 class QCPItemTracer;
42 class QCustomPlot;
43 class QCPAxisTicker;
44 class QCPAxisTickerDateTime;
45 
46 // GTK+ set this to 100000 (NUM_IO_ITEMS) before raising it to unlimited
47 // in commit 524583298beb671f43e972476693866754d38a38.
48 // This is the maximum index returned from get_io_graph_index that will
49 // be added to the graph. Thus, for a minimum interval size of 1 μs no
50 // more than 33.55 s.
51 // Each io_graph_item_t is 88 bytes on a system with 64 bit time_t, so
52 // the max size we'll attempt to allocate for the array of items is 2.75 GiB
53 // (plus a tiny amount extra for the std::vector bookkeeping.)
54 // 2^25 = 16777216
55 const int max_io_items_ = 1 << 25;
56 
57 // XXX - Move to its own file?
58 class IOGraph : public QObject {
59 Q_OBJECT
60 public:
61  // COUNT_TYPE_* in gtk/io_graph.c
62  enum PlotStyles { psLine, psDotLine, psStepLine, psDotStepLine, psImpulse, psBar, psStackedBar, psDot, psSquare, psDiamond, psCross, psPlus, psCircle };
63 
64  explicit IOGraph(QCustomPlot *parent);
65  ~IOGraph();
66  QString configError() const { return config_err_; }
67  QString name() const { return name_; }
68  void setName(const QString &name);
69  QString filter() const { return filter_; }
70  bool setFilter(const QString &filter);
71  void applyCurrentColor();
72  bool visible() const { return visible_; }
73  void setVisible(bool visible);
74  bool needRetap() const { return need_retap_; }
75  void setNeedRetap(bool retap);
76  QRgb color() const;
77  void setColor(const QRgb color);
78  void setPlotStyle(int style);
79  QString valueUnitLabel() const;
80  format_size_units_e formatUnits() const;
81  void setValueUnits(int val_units);
82  QString valueUnitField() const { return vu_field_; }
83  void setValueUnitField(const QString &vu_field);
84  unsigned int movingAveragePeriod() const { return moving_avg_period_; }
85  void setInterval(int interval);
86  bool addToLegend();
87  bool removeFromLegend();
88  QCPGraph *graph() const { return graph_; }
89  QCPBars *bars() const { return bars_; }
90  double startOffset() const;
91  nstime_t startTime() const;
92  int packetFromTime(double ts) const;
93  bool hasItemToShow(int idx, double value) const;
94  double getItemValue(int idx, const capture_file *cap_file) const;
95  int maxInterval () const { return cur_idx_; }
96 
97  void clearAllData();
98 
99  unsigned int moving_avg_period_;
100  unsigned int y_axis_factor_;
101 
102 public slots:
103  void recalcGraphData(capture_file *cap_file);
104  void captureEvent(CaptureEvent e);
105  void reloadValueUnitField();
106 
107 signals:
108  void requestReplot();
109  void requestRecalc();
110  void requestRetap();
111 
112 private:
113  // Callbacks for register_tap_listener
114  static void tapReset(void *iog_ptr);
115  static tap_packet_status tapPacket(void *iog_ptr, packet_info *pinfo, epan_dissect_t *edt, const void *data, tap_flags_t flags);
116  static void tapDraw(void *iog_ptr);
117 
118  void removeTapListener();
119 
120  bool showsZero() const;
121 
122  template<class DataMap> double maxValueFromGraphData(const DataMap &map);
123  template<class DataMap> void scaleGraphData(DataMap &map, int scalar);
124 
125  QCustomPlot *parent_;
126  QString config_err_;
127  QString name_;
128  bool tap_registered_;
129  bool visible_;
130  bool need_retap_;
131  QCPGraph *graph_;
132  QCPBars *bars_;
133  QString filter_;
134  QString full_filter_; // Includes vu_field_ if used
135  QBrush color_;
136  io_graph_item_unit_t val_units_;
137  QString vu_field_;
138  int hf_index_;
139  int interval_;
140  nstime_t start_time_;
141 
142  // Cached data. We should be able to change the Y axis without retapping as
143  // much as is feasible.
144  std::vector<io_graph_item_t> items_;
145  int cur_idx_;
146 };
147 
148 namespace Ui {
149 class IOGraphDialog;
150 }
151 
153 {
154  Q_OBJECT
155 
156 public:
157  explicit IOGraphDialog(QWidget &parent, CaptureFile &cf, QString displayFilter = QString());
158  ~IOGraphDialog();
159 
160  enum UatColumns { colEnabled = 0, colName, colDFilter, colColor, colStyle, colYAxis, colYField, colSMAPeriod, colYAxisFactor, colMaxNum};
161 
162  void addGraph(bool checked, QString name, QString dfilter, QRgb color_idx, IOGraph::PlotStyles style,
163  io_graph_item_unit_t value_units, QString yfield, int moving_average, int yaxisfactor);
164  void addGraph(bool copy_from_current = false);
165  void addDefaultGraph(bool enabled, int idx = 0);
166  void syncGraphSettings(int row);
167 
168 public slots:
169  void scheduleReplot(bool now = false);
170  void scheduleRecalc(bool now = false);
171  void scheduleRetap(bool now = false);
172  void reloadFields();
173 
174 protected:
175  void keyPressEvent(QKeyEvent *event);
176  void reject();
177 
178 protected slots:
179  void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
180  void modelRowsReset();
181  void modelRowsInserted(const QModelIndex &parent, int first, int last);
182  void modelRowsRemoved(const QModelIndex &parent, int first, int last);
183  void modelRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow);
184 
185 signals:
186  void goToPacket(int packet_num);
187  void recalcGraphData(capture_file *cap_file);
188  void intervalChanged(int interval);
189  void reloadValueUnitFields();
190 
191 private:
192  Ui::IOGraphDialog *ui;
193 
194  //Model and delegate were chosen over UatFrame because add/remove/copy
195  //buttons would need realignment (UatFrame has its own)
196  QPointer<UatModel> uat_model_;
197  UatDelegate *uat_delegate_;
198 
199  // XXX - This needs to stay synced with UAT index
200  QVector<IOGraph*> ioGraphs_;
201 
202  QString hint_err_;
203  QCPGraph *base_graph_;
204  QCPItemTracer *tracer_;
205  uint32_t packet_num_;
206  nstime_t start_time_;
207  bool mouse_drags_;
208  QRubberBand *rubber_band_;
209  QPoint rb_origin_;
210  QMenu ctx_menu_;
211  QTimer *stat_timer_;
212  bool need_replot_; // Light weight: tell QCP to replot existing data
213  bool need_recalc_; // Medium weight: recalculate values, then replot
214  bool need_retap_; // Heavy weight: re-read packet data
215  bool auto_axes_;
216  int precision_;
217 
218  QSharedPointer<QCPAxisTicker> number_ticker_;
219  QSharedPointer<QCPAxisTickerDateTime> datetime_ticker_;
220 
221 
222 // void fillGraph();
223  void zoomAxes(bool in);
224  void zoomXAxis(bool in);
225  void zoomYAxis(bool in);
226  void panAxes(int x_pixels, int y_pixels);
227  void toggleTracerStyle(bool force_default = false);
228  void getGraphInfo();
229  void updateHint();
230  void updateLegend();
231  QRectF getZoomRanges(QRect zoom_rect);
232  void createIOGraph(int currentRow);
233  void loadProfileGraphs();
234  void makeCsv(QTextStream &stream) const;
235  bool saveCsv(const QString &file_name) const;
236  IOGraph *currentActiveGraph() const;
237  bool graphIsEnabled(int row) const;
238 
239 private slots:
240  static void applyChanges();
241 
242  void copyFromProfile(QString filename);
243  void updateWidgets();
244  void showContextMenu(const QPoint &pos);
245  void graphClicked(QMouseEvent *event);
246  void mouseMoved(QMouseEvent *event);
247  void mouseReleased(QMouseEvent *event);
248  void selectedFrameChanged(QList<int> frames);
249 
250  void resetAxes();
251  void updateStatistics(void);
252  void copyAsCsvClicked();
253 
254  void on_intervalComboBox_currentIndexChanged(int index);
255  void on_todCheckBox_toggled(bool checked);
256  void on_graphUat_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
257 
258  void on_logCheckBox_toggled(bool checked);
259  void on_automaticUpdateCheckBox_toggled(bool checked);
260  void on_enableLegendCheckBox_toggled(bool checked);
261  void on_newToolButton_clicked();
262  void on_deleteToolButton_clicked();
263  void on_copyToolButton_clicked();
264  void on_clearToolButton_clicked();
265  void on_moveUpwardsToolButton_clicked();
266  void on_moveDownwardsToolButton_clicked();
267  void on_dragRadioButton_toggled(bool checked);
268  void on_zoomRadioButton_toggled(bool checked);
269  void on_actionReset_triggered();
270  void on_actionZoomIn_triggered();
271  void on_actionZoomInX_triggered();
272  void on_actionZoomInY_triggered();
273  void on_actionZoomOut_triggered();
274  void on_actionZoomOutX_triggered();
275  void on_actionZoomOutY_triggered();
276  void on_actionMoveUp10_triggered();
277  void on_actionMoveLeft10_triggered();
278  void on_actionMoveRight10_triggered();
279  void on_actionMoveDown10_triggered();
280  void on_actionMoveUp1_triggered();
281  void on_actionMoveLeft1_triggered();
282  void on_actionMoveRight1_triggered();
283  void on_actionMoveDown1_triggered();
284  void on_actionGoToPacket_triggered();
285  void on_actionDragZoom_triggered();
286  void on_actionToggleTimeOrigin_triggered();
287  void on_actionCrosshairs_triggered();
288  void on_buttonBox_helpRequested();
289  void on_buttonBox_accepted();
290  void buttonBoxClicked(QAbstractButton *button);
291 };
292 
293 #endif // IO_GRAPH_DIALOG_H
Definition: capture_event.h:21
Definition: capture_file.h:21
Definition: io_graph_dialog.h:153
Definition: io_graph_dialog.h:58
Definition: uat_delegate.h:24
Definition: wireshark_dialog.h:35
format_size_units_e
Definition: str_util.h:231
Definition: cfile.h:67
Definition: packet_info.h:44
Definition: epan_dissect.h:28
Definition: nstime.h:26
Definition: stream.c:41
tap_packet_status
Definition: tap.h:25