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"
|
|
|
|
#include "statistics.h"
|
2007-10-07 21:06:33 +02:00
|
|
|
#include "config.h"
|
2007-10-05 21:00:44 +02:00
|
|
|
|
|
|
|
// Section statistic class
|
|
|
|
cIptvSectionStatistics::cIptvSectionStatistics()
|
2007-10-07 00:15:02 +02:00
|
|
|
: filteredData(0),
|
2007-10-07 21:06:33 +02:00
|
|
|
numberOfCalls(0),
|
2007-10-08 18:24:48 +02:00
|
|
|
timer(),
|
|
|
|
mutex()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2007-10-06 00:23:56 +02:00
|
|
|
//debug("cIptvSectionStatistics::cIptvSectionStatistics()\n");
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvSectionStatistics::~cIptvSectionStatistics()
|
|
|
|
{
|
2007-10-06 00:23:56 +02:00
|
|
|
//debug("cIptvSectionStatistics::~cIptvSectionStatistics()\n");
|
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
|
|
|
{
|
2007-10-08 00:54:09 +02:00
|
|
|
//debug("cIptvSectionStatistics::GetStatistic()\n");
|
2007-10-09 01:51:58 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
|
2007-10-07 21:06:33 +02:00
|
|
|
timer.Set();
|
2009-10-01 17:48:28 +02:00
|
|
|
long bitrate = elapsed ? (long)(1000.0L * filteredData / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-09 01:51:58 +02:00
|
|
|
if (!IptvConfig.GetUseBytes())
|
|
|
|
bitrate *= 8;
|
|
|
|
// no trailing linefeed here!
|
|
|
|
cString info = cString::sprintf("%4ld (%4ld k%s/s)", numberOfCalls, bitrate,
|
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit");
|
|
|
|
filteredData = numberOfCalls = 0;
|
2007-10-08 00:54:09 +02:00
|
|
|
return info;
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
void cIptvSectionStatistics::AddSectionStatistic(long Bytes, long Calls)
|
2007-10-08 18:24:48 +02:00
|
|
|
{
|
|
|
|
//debug("cIptvSectionStatistics::AddStatistic(Bytes=%ld, Calls=%ld)\n", Bytes, Calls);
|
2007-10-09 01:51:58 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2007-10-08 18:24:48 +02:00
|
|
|
filteredData += Bytes;
|
|
|
|
numberOfCalls += Calls;
|
|
|
|
}
|
|
|
|
|
2007-10-10 00:12:17 +02:00
|
|
|
// --- cIptvPidStatistics ----------------------------------------------------
|
2007-10-07 00:15:02 +02:00
|
|
|
|
2007-10-05 21:00:44 +02:00
|
|
|
// Device statistic class
|
2007-10-10 00:12:17 +02:00
|
|
|
cIptvPidStatistics::cIptvPidStatistics()
|
|
|
|
: timer(),
|
2007-10-08 18:24:48 +02:00
|
|
|
mutex()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2007-10-10 00:12:17 +02:00
|
|
|
debug("cIptvPidStatistics::cIptvPidStatistics()\n");
|
2007-10-05 21:00:44 +02:00
|
|
|
memset(mostActivePids, '\0', sizeof(mostActivePids));
|
|
|
|
}
|
|
|
|
|
2007-10-10 00:12:17 +02:00
|
|
|
cIptvPidStatistics::~cIptvPidStatistics()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2007-10-10 00:12:17 +02:00
|
|
|
debug("cIptvPidStatistics::~cIptvPidStatistics()\n");
|
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
|
|
|
{
|
2007-10-10 00:12:17 +02:00
|
|
|
//debug("cIptvPidStatistics::GetStatistic()\n");
|
2007-10-09 01:51:58 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
|
2007-10-07 21:06:33 +02:00
|
|
|
timer.Set();
|
2007-10-10 00:12:17 +02:00
|
|
|
cString info("Active pids:\n");
|
2007-10-08 00:54:09 +02:00
|
|
|
for (unsigned int i = 0; i < IPTV_STATS_ACTIVE_PIDS_COUNT; ++i) {
|
2007-10-09 01:51:58 +02:00
|
|
|
if (mostActivePids[i].pid) {
|
2009-10-01 17:48:28 +02:00
|
|
|
long bitrate = elapsed ? (long)(1000.0L * mostActivePids[i].DataAmount / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-09 01:51:58 +02:00
|
|
|
if (!IptvConfig.GetUseBytes())
|
|
|
|
bitrate *= 8;
|
|
|
|
info = cString::sprintf("%sPid %d: %4d (%4ld k%s/s)\n", *info, i,
|
|
|
|
mostActivePids[i].pid, bitrate,
|
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit");
|
|
|
|
}
|
2007-10-08 00:54:09 +02:00
|
|
|
}
|
2008-01-05 00:36:37 +01:00
|
|
|
memset(mostActivePids, '\0', sizeof(mostActivePids));
|
2007-10-08 00:54:09 +02:00
|
|
|
return info;
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2007-10-10 00:12:17 +02:00
|
|
|
int cIptvPidStatistics::SortPids(const void* data1, const void* data2)
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2007-10-10 00:12:17 +02:00
|
|
|
//debug("cIptvPidStatistics::SortPids()\n");
|
2007-10-05 21:00:44 +02:00
|
|
|
pidStruct *comp1 = (pidStruct*)data1;
|
|
|
|
pidStruct *comp2 = (pidStruct*)data2;
|
|
|
|
if (comp1->DataAmount > comp2->DataAmount)
|
|
|
|
return -1;
|
2007-10-07 10:46:34 +02:00
|
|
|
if (comp1->DataAmount < comp2->DataAmount)
|
|
|
|
return 1;
|
2007-10-05 21:00:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
void cIptvPidStatistics::AddPidStatistic(u_short Pid, long Payload)
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2007-10-10 00:12:17 +02:00
|
|
|
//debug("cIptvPidStatistics::AddStatistic(pid=%ld, payload=%ld)\n", Pid, Payload);
|
2007-10-09 01:51:58 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2007-10-05 21:00:44 +02:00
|
|
|
const int numberOfElements = sizeof(mostActivePids) / sizeof(pidStruct);
|
|
|
|
// If our statistic already is in the array, update it and quit
|
|
|
|
for (int i = 0; i < numberOfElements; ++i) {
|
2007-10-10 00:12:17 +02:00
|
|
|
if (mostActivePids[i].pid == Pid) {
|
|
|
|
mostActivePids[i].DataAmount += Payload;
|
2007-10-07 00:15:02 +02:00
|
|
|
// Now re-sort the array and quit
|
2008-01-05 00:36:37 +01:00
|
|
|
qsort(mostActivePids, 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
|
2007-10-10 00:12:17 +02:00
|
|
|
if (mostActivePids[numberOfElements - 1].DataAmount < Payload) {
|
|
|
|
mostActivePids[numberOfElements - 1].pid = Pid;
|
|
|
|
mostActivePids[numberOfElements - 1].DataAmount = Payload;
|
2007-10-06 00:30:14 +02:00
|
|
|
// Re-sort
|
2009-03-20 16:43:31 +01:00
|
|
|
qsort(mostActivePids, 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
|
|
|
|
|
|
|
// Streamer statistic class
|
|
|
|
cIptvStreamerStatistics::cIptvStreamerStatistics()
|
2007-10-07 21:06:33 +02:00
|
|
|
: dataBytes(0),
|
2007-10-08 18:24:48 +02:00
|
|
|
timer(),
|
|
|
|
mutex()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
|
|
|
debug("cIptvStreamerStatistics::cIptvStreamerStatistics()\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
cIptvStreamerStatistics::~cIptvStreamerStatistics()
|
|
|
|
{
|
|
|
|
debug("cIptvStreamerStatistics::~cIptvStreamerStatistics()\n");
|
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
cString cIptvStreamerStatistics::GetStreamerStatistic()
|
2007-10-05 21:00:44 +02:00
|
|
|
{
|
2007-10-08 00:54:09 +02:00
|
|
|
//debug("cIptvStreamerStatistics::GetStatistic()\n");
|
2007-10-09 01:51:58 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
|
2007-10-07 21:06:33 +02:00
|
|
|
timer.Set();
|
2009-10-01 17:48:28 +02:00
|
|
|
long bitrate = elapsed ? (long)(1000.0L * dataBytes / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-09 01:51:58 +02:00
|
|
|
if (!IptvConfig.GetUseBytes())
|
|
|
|
bitrate *= 8;
|
2007-10-10 00:12:17 +02:00
|
|
|
cString info = cString::sprintf("Stream bitrate: %ld k%s/s\n", bitrate, IptvConfig.GetUseBytes() ? "B" : "bit");
|
2007-10-09 01:51:58 +02:00
|
|
|
dataBytes = 0;
|
|
|
|
return info;
|
2007-10-08 18:24:48 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
void cIptvStreamerStatistics::AddStreamerStatistic(long Bytes)
|
2007-10-08 18:24:48 +02:00
|
|
|
{
|
|
|
|
//debug("cIptvStreamerStatistics::AddStatistic(Bytes=%ld)\n", Bytes);
|
2007-10-09 01:51:58 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2007-10-08 18:24:48 +02:00
|
|
|
dataBytes += Bytes;
|
2007-10-05 21:00:44 +02:00
|
|
|
}
|
2007-10-09 19:58:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Buffer statistic class
|
|
|
|
cIptvBufferStatistics::cIptvBufferStatistics()
|
2007-10-10 00:12:17 +02:00
|
|
|
: dataBytes(0),
|
2007-10-09 19:58:17 +02:00
|
|
|
usedSpace(0),
|
|
|
|
timer(),
|
|
|
|
mutex()
|
|
|
|
{
|
|
|
|
debug("cIptvBufferStatistics::cIptvBufferStatistics()\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
cIptvBufferStatistics::~cIptvBufferStatistics()
|
|
|
|
{
|
|
|
|
debug("cIptvBufferStatistics::~cIptvBufferStatistics()\n");
|
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
cString cIptvBufferStatistics::GetBufferStatistic()
|
2007-10-09 19:58:17 +02:00
|
|
|
{
|
|
|
|
//debug("cIptvBufferStatistics::GetStatistic()\n");
|
|
|
|
cMutexLock MutexLock(&mutex);
|
2007-10-10 00:12:17 +02:00
|
|
|
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
|
|
|
|
timer.Set();
|
2009-10-01 17:48:28 +02:00
|
|
|
long bitrate = elapsed ? (long)(1000.0L * dataBytes / KILOBYTE(1) / elapsed) : 0L;
|
2007-10-12 01:06:49 +02:00
|
|
|
long totalSpace = MEGABYTE(IptvConfig.GetTsBufferSize());
|
|
|
|
float percentage = (float)((float)usedSpace / (float)totalSpace * 100.0);
|
|
|
|
long totalKilos = totalSpace / KILOBYTE(1);
|
2007-10-10 00:12:17 +02:00
|
|
|
long usedKilos = usedSpace / 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;
|
|
|
|
}
|
2007-10-10 00:12:17 +02:00
|
|
|
cString info = cString::sprintf("Buffer bitrate: %ld k%s/s\nBuffer usage: %ld/%ld k%s (%2.1f%%)\n", bitrate,
|
2007-10-12 01:06:49 +02:00
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit", usedKilos, totalKilos,
|
2007-10-10 00:12:17 +02:00
|
|
|
IptvConfig.GetUseBytes() ? "B" : "bit", percentage);
|
|
|
|
dataBytes = 0;
|
2007-10-11 21:44:46 +02:00
|
|
|
usedSpace = 0;
|
2007-10-09 19:58:17 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2008-01-19 22:08:02 +01:00
|
|
|
void cIptvBufferStatistics::AddBufferStatistic(long Bytes, long Used)
|
2007-10-09 19:58:17 +02:00
|
|
|
{
|
2007-10-12 01:06:49 +02:00
|
|
|
//debug("cIptvBufferStatistics::AddStatistic(Bytes=%ld, Used=%ld)\n", Bytes, Used);
|
2007-10-09 19:58:17 +02:00
|
|
|
cMutexLock MutexLock(&mutex);
|
2007-10-10 00:12:17 +02:00
|
|
|
dataBytes += Bytes;
|
2007-10-12 01:06:49 +02:00
|
|
|
if (Used > usedSpace)
|
2007-10-11 21:44:46 +02:00
|
|
|
usedSpace = Used;
|
2007-10-09 19:58:17 +02:00
|
|
|
}
|