Wireshark 4.7.2
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
interface_statistics.h
Go to the documentation of this file.
1
12
13#ifndef INTERFACE_STATISTICS_H
14#define INTERFACE_STATISTICS_H
15
16#include <config.h>
17
19
20#include <QHash>
21#include <QList>
22#include <QObject>
23#include <QSet>
24#include <QString>
25#include <QStringList>
26#include <QThread>
27
49class InterfaceStatistics : public QObject
50{
51 Q_OBJECT
52
53public:
60 explicit InterfaceStatistics(QObject *parent = nullptr);
61
65 ~InterfaceStatistics() override;
66
74 QList<int> pointsFor(const QString &interfaceName) const;
75
83 QList<int> droppedPointsFor(const QString &interfaceName) const;
84
96 bool isActive(const QString &interfaceName) const;
97
103 unsigned rate(const QString &interfaceName) const;
104
106 int updateInterval() const;
107
109 int historyCapacity() const;
110
112 bool isRunning() const;
113
114public slots:
120 void start();
121
123 void stop();
124
131 void pauseSampling();
132
134 void resumeSampling();
135
140 void setUpdateInterval(int intervalMsec);
141
146 void setInterfaceFilter(const QStringList &interfaceNames);
147
156 void removeInterfaces(const QStringList &removedInterfaceNames);
157
167 void resetActivity();
168
174 void setHistoryCapacity(int maxEntries);
175
176signals:
179
188
190 /* Bridge signals to the worker (queued across the thread boundary). */
191 void startWorker();
192 void stopWorker();
193 void pauseWorker();
194 void resumeWorker();
195 void setWorkerInterval(int intervalMsec);
196 void setWorkerFilter(const QStringList &interfaceNames);
198
199private slots:
201 void onSampled(const InterfaceStatsSnapshot &snapshot);
202
204 void onWorkerFailed(int exitCode, const QString &message);
205
206private:
208 void appendCapped(QList<int> &buffer, int value) const;
209
211 void trimToCapacity(QList<int> &buffer) const;
212
214 void resetBaselines();
215
216 InterfaceStatsWorker *worker_;
217 QThread workerThread_;
218
219 QHash<QString, quint64> lastReceived_;
220 QHash<QString, quint64> lastDropped_;
221 QHash<QString, QList<int> > receivedHistory_;
222 QHash<QString, QList<int> > droppedHistory_;
223 QSet<QString> active_;
224
225 QStringList interfaceFilter_;
226 int historyCapacity_;
227 int updateIntervalMsec_;
228 bool running_;
229 bool paused_;
230 bool warned_no_interfaces_;
231};
232
233#endif // INTERFACE_STATISTICS_H
void setUpdateInterval(int intervalMsec)
Sets the sampling interval and forwards it to the worker.
Definition interface_statistics.cpp:190
void stop()
Stops sampling and tears down the dumpcap stream.
Definition interface_statistics.cpp:143
unsigned rate(const QString &interfaceName) const
Most recent received-packet delta for an interface.
Definition interface_statistics.cpp:103
int historyCapacity() const
Returns the per-interface history capacity, in entries.
Definition interface_statistics.cpp:116
bool isRunning() const
Returns true between start() and stop() (sampling requested).
Definition interface_statistics.cpp:121
void pauseSampling()
Temporarily suspends sampling (e.g. while a capture is active).
Definition interface_statistics.cpp:153
void start()
Begins sampling: opens the dumpcap statistics stream via the worker.
Definition interface_statistics.cpp:126
QList< int > pointsFor(const QString &interfaceName) const
Received-packet deltas for an interface, oldest to newest.
Definition interface_statistics.cpp:88
void statisticsUpdated()
Emitted after a worker snapshot has been folded into the history.
void resumeSampling()
Resumes sampling previously suspended with pauseSampling().
Definition interface_statistics.cpp:165
int updateInterval() const
Returns the current sampling interval, in milliseconds.
Definition interface_statistics.cpp:111
void resetActivity()
Re-evaluates interface activity, e.g. on a manual interface refresh.
Definition interface_statistics.cpp:222
void activityChanged()
Emitted when the set of active interfaces changes.
void removeInterfaces(const QStringList &removedInterfaceNames)
Drops all retained state for the given (vanished) interfaces.
Definition interface_statistics.cpp:205
InterfaceStatistics(QObject *parent=nullptr)
Constructs the facade and starts the worker thread (idle).
Definition interface_statistics.cpp:43
void setInterfaceFilter(const QStringList &interfaceNames)
Restricts which interfaces are sampled/emitted (empty = all).
Definition interface_statistics.cpp:199
void setHistoryCapacity(int maxEntries)
Sets the per-interface history capacity in entries.
Definition interface_statistics.cpp:232
QList< int > droppedPointsFor(const QString &interfaceName) const
Dropped-packet deltas for an interface, oldest to newest.
Definition interface_statistics.cpp:93
bool isActive(const QString &interfaceName) const
Whether an interface is currently considered active for sorting.
Definition interface_statistics.cpp:98
~InterfaceStatistics() override
Tears down the worker and its thread safely, then destroys.
Definition interface_statistics.cpp:75
Worker that runs a dumpcap "-S" statistics stream off the GUI thread.
Definition interface_stats_worker.h:81
QHash< QString, InterfaceStatsSample > InterfaceStatsSnapshot
A full set of per-interface counters keyed by interface name.
Definition interface_stats_worker.h:42
Sliding window buffer tracking per-stream burst and bandwidth statistics.
Definition mcast_stream.h:34