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