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