2007-10-05 21:00:44 +02:00
|
|
|
/*
|
|
|
|
* statistics.c: IPTV plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-10-07 21:06:33 +02:00
|
|
|
#include <limits.h>
|
|
|
|
|
2007-10-05 21:00:44 +02:00
|
|
|
#include "common.h"
|
2007-10-07 21:06:33 +02:00
|
|
|
#include "config.h"
|
2015-03-08 13:33:18 +01:00
|
|
|
#include "log.h"
|
|
|
|
#include "statistics.h"
|
2007-10-05 21:00:44 +02:00
|
|
|
|
2013-02-23 16:12:46 +01:00
|
|
|
// Section statistics class
|
2007-10-05 21:00:44 +02:00
|
|
|
cIptvSectionStatistics::cIptvSectionStatistics()
|
2013-02-23 14:31:11 +01:00
|
|
|
: filteredDataM(0),
|
|
|
|
numberOfCallsM(0),
|
|
|
|
timerM(),
|
|
|
|
mutexM()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvSectionStatistics::~cIptvSectionStatistics()
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
cString cIptvSectionStatistics::GetSectionStatistic()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
|
|
|
timerM.Set();
|
|
|
|
long bitrate = elapsed ? (long)(1000.0L * filteredDataM / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-09 01:51:58 +02:00
|
|
|
if (!IptvConfig.GetUseBytes())
|
|
|
|
bitrate *= 8;
|
|
|
|
// no trailing linefeed here!
|
2013-02-23 14:31:11 +01:00
|
|
|
cString s = cString::sprintf("%4ld (%4ld k%s/s)", numberOfCallsM, bitrate,
|
2013-02-23 01:03:27 +01:00
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit");
|
2013-02-23 14:31:11 +01:00
|
|
|
filteredDataM = numberOfCallsM = 0;
|
2013-02-23 01:03:27 +01:00
|
|
|
return s;
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
void cIptvSectionStatistics::AddSectionStatistic(long bytesP, long callsP)
|
2007-10-08 18:24:48 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%ld, %ld)", __PRETTY_FUNCTION__, bytesP, callsP);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
filteredDataM += bytesP;
|
|
|
|
numberOfCallsM += callsP;
|
2007-10-08 18:24:48 +02:00
|
|
|
}
|
|
|
|
|
2007-10-10 00:12:17 +02:00
|
|
|
// --- cIptvPidStatistics ----------------------------------------------------
|
2007-10-07 00:15:02 +02:00
|
|
|
|
2013-02-23 16:12:46 +01:00
|
|
|
// Device statistics class
|
2007-10-10 00:12:17 +02:00
|
|
|
cIptvPidStatistics::cIptvPidStatistics()
|
2013-02-23 14:31:11 +01:00
|
|
|
: timerM(),
|
|
|
|
mutexM()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2014-02-19 20:38:11 +01:00
|
|
|
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
|
|
|
|
for (int i = 0; i < numberOfElements; ++i) {
|
|
|
|
mostActivePidsM[i].pid = -1;
|
|
|
|
mostActivePidsM[i].dataAmount = 0L;
|
|
|
|
}
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2007-10-10 00:12:17 +02:00
|
|
|
cIptvPidStatistics::~cIptvPidStatistics()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
cString cIptvPidStatistics::GetPidStatistic()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-02-19 20:38:11 +01:00
|
|
|
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
|
2013-02-23 14:31:11 +01:00
|
|
|
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
|
|
|
timerM.Set();
|
2013-02-23 01:03:27 +01:00
|
|
|
cString s("Active pids:\n");
|
2014-02-19 20:38:11 +01:00
|
|
|
for (int i = 0; i < numberOfElements; ++i) {
|
|
|
|
if (mostActivePidsM[i].pid >= 0) {
|
|
|
|
long bitrate = elapsed ? (long)(1000.0L * mostActivePidsM[i].dataAmount / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-09 01:51:58 +02:00
|
|
|
if (!IptvConfig.GetUseBytes())
|
|
|
|
bitrate *= 8;
|
2013-02-23 01:03:27 +01:00
|
|
|
s = cString::sprintf("%sPid %d: %4d (%4ld k%s/s)\n", *s, i,
|
2013-02-23 14:31:11 +01:00
|
|
|
mostActivePidsM[i].pid, bitrate,
|
2013-02-23 01:03:27 +01:00
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit");
|
2007-10-09 01:51:58 +02:00
|
|
|
}
|
2007-10-08 00:54:09 +02:00
|
|
|
}
|
2014-02-19 20:38:11 +01:00
|
|
|
for (int i = 0; i < numberOfElements; ++i) {
|
|
|
|
mostActivePidsM[i].pid = -1;
|
|
|
|
mostActivePidsM[i].dataAmount = 0L;
|
|
|
|
}
|
2013-02-23 01:03:27 +01:00
|
|
|
return s;
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
int cIptvPidStatistics::SortPids(const void* data1P, const void* data2P)
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2013-02-23 14:31:11 +01:00
|
|
|
const pidStruct *comp1 = reinterpret_cast<const pidStruct*>(data1P);
|
|
|
|
const pidStruct *comp2 = reinterpret_cast<const pidStruct*>(data2P);
|
2014-02-19 20:38:11 +01:00
|
|
|
if (comp1->dataAmount > comp2->dataAmount)
|
2007-10-05 21:00:44 +02:00
|
|
|
return -1;
|
2014-02-19 20:38:11 +01:00
|
|
|
if (comp1->dataAmount < comp2->dataAmount)
|
2007-10-07 10:46:34 +02:00
|
|
|
return 1;
|
2007-10-05 21:00:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-19 20:38:11 +01:00
|
|
|
void cIptvPidStatistics::AddPidStatistic(int pidP, long payloadP)
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%d, %ld)", __PRETTY_FUNCTION__, pidP, payloadP);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
|
2007-10-05 21:00:44 +02:00
|
|
|
// If our statistic already is in the array, update it and quit
|
|
|
|
for (int i = 0; i < numberOfElements; ++i) {
|
2013-02-23 14:31:11 +01:00
|
|
|
if (mostActivePidsM[i].pid == pidP) {
|
2014-02-19 20:38:11 +01:00
|
|
|
mostActivePidsM[i].dataAmount += payloadP;
|
2007-10-07 00:15:02 +02:00
|
|
|
// Now re-sort the array and quit
|
2013-02-23 14:31:11 +01:00
|
|
|
qsort(mostActivePidsM, numberOfElements, sizeof(pidStruct), SortPids);
|
2007-10-07 00:15:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-10-05 21:00:44 +02:00
|
|
|
// Apparently our pid isn't in the array. Replace the last element with this
|
|
|
|
// one if new payload is greater
|
2014-02-19 20:38:11 +01:00
|
|
|
if (mostActivePidsM[numberOfElements - 1].dataAmount < payloadP) {
|
2013-02-23 14:31:11 +01:00
|
|
|
mostActivePidsM[numberOfElements - 1].pid = pidP;
|
2014-02-19 20:38:11 +01:00
|
|
|
mostActivePidsM[numberOfElements - 1].dataAmount = payloadP;
|
2007-10-06 00:30:14 +02:00
|
|
|
// Re-sort
|
2013-02-23 14:31:11 +01:00
|
|
|
qsort(mostActivePidsM, numberOfElements, sizeof(pidStruct), SortPids);
|
2007-10-06 00:30:14 +02:00
|
|
|
}
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2007-10-07 00:15:02 +02:00
|
|
|
// --- cIptvStreamerStatistics -----------------------------------------------
|
2007-10-05 21:00:44 +02:00
|
|
|
|
2013-02-23 16:12:46 +01:00
|
|
|
// Streamer statistics class
|
2007-10-05 21:00:44 +02:00
|
|
|
cIptvStreamerStatistics::cIptvStreamerStatistics()
|
2013-02-23 14:31:11 +01:00
|
|
|
: dataBytesM(0),
|
|
|
|
timerM(),
|
|
|
|
mutexM()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvStreamerStatistics::~cIptvStreamerStatistics()
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
cString cIptvStreamerStatistics::GetStreamerStatistic()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
|
|
|
timerM.Set();
|
|
|
|
long bitrate = elapsed ? (long)(1000.0L * dataBytesM / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-09 01:51:58 +02:00
|
|
|
if (!IptvConfig.GetUseBytes())
|
|
|
|
bitrate *= 8;
|
2013-02-23 01:03:27 +01:00
|
|
|
cString s = cString::sprintf("%ld k%s/s", bitrate, IptvConfig.GetUseBytes() ? "B" : "bit");
|
2013-02-23 14:31:11 +01:00
|
|
|
dataBytesM = 0;
|
2013-02-23 01:03:27 +01:00
|
|
|
return s;
|
2007-10-08 18:24:48 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
void cIptvStreamerStatistics::AddStreamerStatistic(long bytesP)
|
2007-10-08 18:24:48 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%ld)", __PRETTY_FUNCTION__, bytesP);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
dataBytesM += bytesP;
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
2007-10-09 19:58:17 +02:00
|
|
|
|
|
|
|
|
2013-02-23 16:12:46 +01:00
|
|
|
// Buffer statistics class
|
2007-10-09 19:58:17 +02:00
|
|
|
cIptvBufferStatistics::cIptvBufferStatistics()
|
2013-02-23 14:31:11 +01:00
|
|
|
: dataBytesM(0),
|
|
|
|
usedSpaceM(0),
|
|
|
|
timerM(),
|
|
|
|
mutexM()
|
2007-10-09 19:58:17 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-10-09 19:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvBufferStatistics::~cIptvBufferStatistics()
|
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug1("%s", __PRETTY_FUNCTION__);
|
2007-10-09 19:58:17 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
cString cIptvBufferStatistics::GetBufferStatistic()
|
2007-10-09 19:58:17 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s", __PRETTY_FUNCTION__);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
|
|
|
|
timerM.Set();
|
|
|
|
long bitrate = elapsed ? (long)(1000.0L * dataBytesM / KILOBYTE(1) / elapsed) : 0L;
|
2014-04-05 18:01:36 +02:00
|
|
|
long totalSpace = IPTV_BUFFER_SIZE;
|
2013-02-23 14:31:11 +01:00
|
|
|
float percentage = (float)((float)usedSpaceM / (float)totalSpace * 100.0);
|
2007-10-12 01:06:49 +02:00
|
|
|
long totalKilos = totalSpace / KILOBYTE(1);
|
2013-02-23 14:31:11 +01:00
|
|
|
long usedKilos = usedSpaceM / KILOBYTE(1);
|
2007-10-09 19:58:17 +02:00
|
|
|
if (!IptvConfig.GetUseBytes()) {
|
2007-10-10 00:12:17 +02:00
|
|
|
bitrate *= 8;
|
2007-10-12 01:06:49 +02:00
|
|
|
totalKilos *= 8;
|
2007-10-09 19:58:17 +02:00
|
|
|
usedKilos *= 8;
|
|
|
|
}
|
2013-02-23 01:03:27 +01:00
|
|
|
cString s = cString::sprintf("Buffer bitrate: %ld k%s/s\nBuffer usage: %ld/%ld k%s (%2.1f%%)\n", bitrate,
|
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit", usedKilos, totalKilos,
|
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit", percentage);
|
2013-02-23 14:31:11 +01:00
|
|
|
dataBytesM = 0;
|
|
|
|
usedSpaceM = 0;
|
2013-02-23 01:03:27 +01:00
|
|
|
return s;
|
2007-10-09 19:58:17 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 14:31:11 +01:00
|
|
|
void cIptvBufferStatistics::AddBufferStatistic(long bytesP, long usedP)
|
2007-10-09 19:58:17 +02:00
|
|
|
{
|
2015-03-08 13:33:18 +01:00
|
|
|
debug16("%s (%ld, %ld)", __PRETTY_FUNCTION__, bytesP, usedP);
|
2013-02-23 14:31:11 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
dataBytesM += bytesP;
|
|
|
|
if (usedP > usedSpaceM)
|
|
|
|
usedSpaceM = usedP;
|
2007-10-09 19:58:17 +02:00
|
|
|
}
|