Wireshark 4.7.2
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
interface_stats_worker.h
Go to the documentation of this file.
1
12
13#ifndef INTERFACE_STATS_WORKER_H
14#define INTERFACE_STATS_WORKER_H
15
16#include <config.h>
17
18#include <wsutil/processes.h> /* for ws_process_id */
19
20#include <QHash>
21#include <QMetaType>
22#include <QObject>
23#include <QString>
24#include <QStringList>
25
26class QTimer;
27
36{
37 quint64 receivedPackets = 0;
38 quint64 droppedPackets = 0;
39};
40
42typedef QHash<QString, InterfaceStatsSample> InterfaceStatsSnapshot;
43
44Q_DECLARE_METATYPE(InterfaceStatsSample)
45Q_DECLARE_METATYPE(InterfaceStatsSnapshot)
46
47
80class InterfaceStatsWorker : public QObject
81{
82 Q_OBJECT
83
84public:
90 explicit InterfaceStatsWorker(QObject *parent = nullptr);
91
95 ~InterfaceStatsWorker() override;
96
103 int updateInterval() const;
104
105public slots:
112 void start();
113
119 void stop();
120
130 void setInterfaceFilter(const QStringList &interfaceNames);
131
136 void setUpdateInterval(int intervalMsec);
137
145 void pause();
146
152 void resume();
153
154signals:
156 void started();
157
159 void stopped();
160
166 void failed(int exitCode, const QString &errorMessage);
167
172 void sampled(const InterfaceStatsSnapshot &snapshot);
173
174private slots:
176 void poll();
177
178private:
183 bool openStream();
184
186 void closeStream();
187
189 void armTimer();
190
192 void disarmTimer();
193
195 void assertWorkerThread() const;
196
197 QStringList interfaceFilter_;
198 int updateIntervalMsec_;
199 QTimer *timer_;
200 int statFd_;
201 ws_process_id forkChild_;
202 bool paused_;
203};
204
205#endif // INTERFACE_STATS_WORKER_H
void setUpdateInterval(int intervalMsec)
Sets the pipe-drain/emit interval.
Definition interface_stats_worker.cpp:106
InterfaceStatsWorker(QObject *parent=nullptr)
Constructs an idle worker with the default update interval.
Definition interface_stats_worker.cpp:42
void failed(int exitCode, const QString &errorMessage)
Emitted when the stream could not be opened or has broken.
void resume()
Re-opens the stream previously suspended with pause().
Definition interface_stats_worker.cpp:136
void started()
Emitted once the dumpcap stream has been opened successfully.
void sampled(const InterfaceStatsSnapshot &snapshot)
Emitted each cycle in which new counters were read.
int updateInterval() const
Returns the current pipe-drain/emit interval, in milliseconds.
Definition interface_stats_worker.cpp:118
void stop()
Stops sampling and tears down the dumpcap stream and process.
Definition interface_stats_worker.cpp:87
void stopped()
Emitted after the stream and process have been torn down.
void setInterfaceFilter(const QStringList &interfaceNames)
Restricts which interfaces appear in emitted snapshots.
Definition interface_stats_worker.cpp:100
void start()
Opens the dumpcap statistics stream and begins periodic sampling.
Definition interface_stats_worker.cpp:70
void pause()
Tears down the dumpcap stream but remembers the configuration.
Definition interface_stats_worker.cpp:123
QHash< QString, InterfaceStatsSample > InterfaceStatsSnapshot
A full set of per-interface counters keyed by interface name.
Definition interface_stats_worker.h:42
Cumulative packet counters for a single interface, as reported by dumpcap's statistics stream.
Definition interface_stats_worker.h:36
quint64 droppedPackets
Definition interface_stats_worker.h:38
quint64 receivedPackets
Definition interface_stats_worker.h:37