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