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