2023-03-28 05:36:28 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2023 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _STREAM_TIMING
|
|
|
|
#define _STREAM_TIMING
|
|
|
|
|
2023-03-31 06:25:03 -05:00
|
|
|
#include "../common/sign.h"
|
|
|
|
|
2023-03-28 05:36:28 -05:00
|
|
|
#include <QHash>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
class StreamTiming : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool recordTxTime(uint portId, uint guid, uint ttagId,
|
2023-03-31 06:25:03 -05:00
|
|
|
const struct timespec ×tamp);
|
2023-03-28 05:36:28 -05:00
|
|
|
bool recordRxTime(uint portId, uint guid, uint ttagId,
|
2023-03-31 06:25:03 -05:00
|
|
|
const struct timespec ×tamp);
|
2023-03-28 05:36:28 -05:00
|
|
|
|
|
|
|
bool recordTxTime(uint portId, uint guid, uint ttagId,
|
2023-03-31 06:25:03 -05:00
|
|
|
const struct timeval ×tamp);
|
2023-03-28 05:36:28 -05:00
|
|
|
bool recordRxTime(uint portId, uint guid, uint ttagId,
|
2023-03-31 06:25:03 -05:00
|
|
|
const struct timeval ×tamp);
|
|
|
|
|
|
|
|
quint64 delay(uint portId, uint guid);
|
|
|
|
void clear(uint portId, uint guid = SignProtocol::kInvalidGuid);
|
2023-03-28 05:36:28 -05:00
|
|
|
|
|
|
|
static StreamTiming* instance();
|
|
|
|
|
|
|
|
private:
|
2023-04-27 00:39:31 -05:00
|
|
|
StreamTiming(QObject *parent=nullptr);
|
|
|
|
|
2023-03-28 05:36:28 -05:00
|
|
|
int processRecords();
|
|
|
|
int deleteStaleRecords();
|
|
|
|
|
|
|
|
quint32 makeKey(uint guid, uint ttagId) {
|
2023-04-04 02:52:18 -05:00
|
|
|
return guid << 8 | (ttagId & 0xFF);
|
2023-03-28 05:36:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: use only time intervals, not absolute time
|
|
|
|
quint64 timespecToNsecs(const struct timespec &interval) {
|
|
|
|
return interval.tv_nsec + interval.tv_sec*1e9;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TtagData {
|
|
|
|
struct timespec timeStamp; // nanosec resolution
|
|
|
|
uint portId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Timing {
|
|
|
|
struct timespec sumDelays; // nanosec resolution
|
|
|
|
uint countDelays;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-04-04 02:52:18 -05:00
|
|
|
// XXX: TxRxKey = guid (24 bit MSB) + ttagid (8 bit LSB)
|
2023-03-28 05:36:28 -05:00
|
|
|
// TODO: encode tx port in in packet and use as part of key
|
2023-03-31 06:25:03 -05:00
|
|
|
typedef quint32 TxRxKey;
|
|
|
|
QHash<TxRxKey, TtagData> txHash_;
|
|
|
|
QHash<TxRxKey, TtagData> rxHash_;
|
2023-03-28 05:36:28 -05:00
|
|
|
QMutex txHashLock_;
|
|
|
|
QMutex rxHashLock_;
|
2023-03-31 06:25:03 -05:00
|
|
|
|
|
|
|
typedef uint PortIdKey;
|
|
|
|
typedef uint GuidKey;
|
|
|
|
typedef QHash<GuidKey, Timing> PortTiming;
|
|
|
|
QHash<PortIdKey, PortTiming*> timing_;
|
2023-04-27 00:45:26 -05:00
|
|
|
QMutex timingLock_;
|
2023-03-28 05:36:28 -05:00
|
|
|
|
|
|
|
QTimer *timer_; // Periodic timer to process tx/rx records
|
|
|
|
QTimer *gcTimer_; // Garbage collection for stale tx records
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|