1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Added some statistics tweaks.

This commit is contained in:
Rolf Ahrenberg 2007-10-09 22:12:17 +00:00
parent 54cd27a8a9
commit c568bf973c
7 changed files with 84 additions and 79 deletions

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.c,v 1.64 2007/10/09 17:59:12 ajhseppa Exp $
* $Id: device.c,v 1.65 2007/10/09 22:12:17 rahrenbe Exp $
*/
#include "config.h"
@ -97,20 +97,17 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex)
cString cIptvDevice::GetGeneralInformation(void)
{
//debug("cIptvDevice::GetGeneralInformation(%d)\n", deviceIndex);
return cString::sprintf("IPTV device #%d (CardIndex: %d)\n%s\n%s\nTS Buffer: %s\nStream Buffer: %s\n",
return cString::sprintf("IPTV device #%d (CardIndex: %d)\n%s\n%s%s",
deviceIndex, CardIndex(), pIptvStreamer ?
*pIptvStreamer->GetInformation() : "",
pIptvStreamer ? *pIptvStreamer->cIptvStreamerStatistics::GetStatistic() : "",
*cIptvBufferStatistics::GetStatistic(),
pIptvStreamer ? *pIptvStreamer->cIptvBufferStatistics::GetStatistic() : "");
pIptvStreamer ? *pIptvStreamer->GetStatistic() : "",
*cIptvBufferStatistics::GetStatistic());
}
cString cIptvDevice::GetPidsInformation(void)
{
//debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndex);
cString info("Most active pids:\n");
info = cString::sprintf("%s%s", *info, *cIptvDeviceStatistics::GetStatistic());
return info;
return cIptvPidStatistics::GetStatistic();
}
cString cIptvDevice::GetFiltersInformation(void)
@ -348,6 +345,8 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
if (isPacketDelivered) {
tsBuffer->Del(TS_SIZE);
isPacketDelivered = false;
// Update buffer statistics
cIptvBufferStatistics::AddStatistic(TS_SIZE, tsBuffer->Available(), tsBuffer->Free());
}
uchar *p = tsBuffer->Get(Count);
if (p && Count >= TS_SIZE) {
@ -364,9 +363,8 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
}
isPacketDelivered = true;
Data = p;
// Update statistics
cIptvDeviceStatistics::AddStatistic(TS_SIZE, ts_pid(p), payload(p));
cIptvBufferStatistics::AddStatistic(tsBuffer->Available(), tsBuffer->Free());
// Update pid statistics
cIptvPidStatistics::AddStatistic(ts_pid(p), payload(p));
// Run the data through all filters
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (secfilters[i])

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.h,v 1.30 2007/10/09 17:58:17 ajhseppa Exp $
* $Id: device.h,v 1.31 2007/10/09 22:12:17 rahrenbe Exp $
*/
#ifndef __IPTV_DEVICE_H
@ -19,7 +19,7 @@
#include "sidscanner.h"
#include "statistics.h"
class cIptvDevice : public cDevice, public cIptvDeviceStatistics, public cIptvBufferStatistics {
class cIptvDevice : public cDevice, public cIptvPidStatistics, public cIptvBufferStatistics {
// static ones
public:
static unsigned int deviceCount;

26
iptv.c
View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: iptv.c,v 1.16 2007/10/09 16:37:16 rahrenbe Exp $
* $Id: iptv.c,v 1.17 2007/10/09 22:12:17 rahrenbe Exp $
*/
#include <getopt.h>
@ -201,10 +201,12 @@ const char **cPluginIptv::SVDRPHelpPages(void)
{
debug("cPluginIptv::SVDRPHelpPages()\n");
static const char *HelpPages[] = {
"INFO [ <option> ]\n"
"INFO [ <page> ]\n"
" Print IPTV device information and statistics.\n"
" The data can be shown either in bits or bytes\n"
" according the given option (bits=0; bytes=1).\n",
" The output can be narrowed using optional \"page\""
" option: 1=general 2=pids 3=section filters.\n",
"MODE\n"
" Toggles between bit or byte information mode.\n",
NULL
};
return HelpPages;
@ -215,13 +217,25 @@ cString cPluginIptv::SVDRPCommand(const char *Command, const char *Option, int &
debug("cPluginIptv::SVDRPCommand(): Command=%s Option=%s\n", Command, Option);
if (strcasecmp(Command, "INFO") == 0) {
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device)
return device->GetInformation((atoi(Option) == 0));
if (device) {
int page = IPTV_DEVICE_INFO_ALL;
if (Option) {
page = atoi(Option);
if ((page < IPTV_DEVICE_INFO_ALL) || (page > IPTV_DEVICE_INFO_FILTERS))
page = IPTV_DEVICE_INFO_ALL;
}
return device->GetInformation(page);
}
else {
ReplyCode = 550; // Requested action not taken
return cString("IPTV information not available!");
}
}
else if (strcasecmp(Command, "MODE") == 0) {
unsigned int mode = !IptvConfig.GetUseBytes();
IptvConfig.SetUseBytes(mode);
return cString::sprintf("IPTV information mode is: %s\n", mode ? "bytes" : "bits");
}
return NULL;
}

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: statistics.c,v 1.16 2007/10/09 17:58:17 ajhseppa Exp $
* $Id: statistics.c,v 1.17 2007/10/09 22:12:17 rahrenbe Exp $
*/
#include <limits.h>
@ -31,11 +31,9 @@ cString cIptvSectionStatistics::GetStatistic()
{
//debug("cIptvSectionStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
long bitrate = 0;
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
if (elapsed)
bitrate = (long)(1000.0 * filteredData / elapsed / KILOBYTE(1));
long bitrate = elapsed ? (long)((float)1000 / KILOBYTE(1) * filteredData / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
// no trailing linefeed here!
@ -53,39 +51,32 @@ void cIptvSectionStatistics::AddStatistic(long Bytes, long Calls)
numberOfCalls += Calls;
}
// --- cIptvDeviceStatistics -------------------------------------------------
// --- cIptvPidStatistics ----------------------------------------------------
// Device statistic class
cIptvDeviceStatistics::cIptvDeviceStatistics()
: dataBytes(0),
timer(),
cIptvPidStatistics::cIptvPidStatistics()
: timer(),
mutex()
{
debug("cIptvDeviceStatistics::cIptvDeviceStatistics()\n");
debug("cIptvPidStatistics::cIptvPidStatistics()\n");
memset(mostActivePids, '\0', sizeof(mostActivePids));
}
cIptvDeviceStatistics::~cIptvDeviceStatistics()
cIptvPidStatistics::~cIptvPidStatistics()
{
debug("cIptvDeviceStatistics::~cIptvDeviceStatistics()\n");
debug("cIptvPidStatistics::~cIptvPidStatistics()\n");
}
cString cIptvDeviceStatistics::GetStatistic()
cString cIptvPidStatistics::GetStatistic()
{
//debug("cIptvDeviceStatistics::GetStatistic()\n");
//debug("cIptvPidStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
long bitrate = 0L;
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
if (elapsed)
bitrate = (long)(1000.0 * dataBytes / elapsed / KILOBYTE(1));
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
cString info = cString::sprintf("Bitrate: %ld k%s/s\n", bitrate,
IptvConfig.GetUseBytes() ? "B" : "bit");
cString info("Active pids:\n");
for (unsigned int i = 0; i < IPTV_STATS_ACTIVE_PIDS_COUNT; ++i) {
if (mostActivePids[i].pid) {
bitrate = (long)(1000.0 * mostActivePids[i].DataAmount / elapsed / KILOBYTE(1));
long bitrate = elapsed ? (long)((float)1000 / KILOBYTE(1) * mostActivePids[i].DataAmount / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
info = cString::sprintf("%sPid %d: %4d (%4ld k%s/s)\n", *info, i,
@ -93,14 +84,13 @@ cString cIptvDeviceStatistics::GetStatistic()
IptvConfig.GetUseBytes() ? "B" : "bit");
}
}
dataBytes = 0;
memset(&mostActivePids, '\0', sizeof(mostActivePids));
return info;
}
int cIptvDeviceStatistics::SortPids(const void* data1, const void* data2)
int cIptvPidStatistics::SortPids(const void* data1, const void* data2)
{
//debug("cIptvDeviceStatistics::SortPids()\n");
//debug("cIptvPidStatistics::SortPids()\n");
pidStruct *comp1 = (pidStruct*)data1;
pidStruct *comp2 = (pidStruct*)data2;
if (comp1->DataAmount > comp2->DataAmount)
@ -110,16 +100,15 @@ int cIptvDeviceStatistics::SortPids(const void* data1, const void* data2)
return 0;
}
void cIptvDeviceStatistics::AddStatistic(long Bytes, u_short pid, long payload)
void cIptvPidStatistics::AddStatistic(u_short Pid, long Payload)
{
//debug("cIptvDeviceStatistics::AddStatistic(Bytes=%ld, pid=%ld, payload=%ld)\n", Bytes, pid, payload);
//debug("cIptvPidStatistics::AddStatistic(pid=%ld, payload=%ld)\n", Pid, Payload);
cMutexLock MutexLock(&mutex);
dataBytes += Bytes;
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) {
if (mostActivePids[i].pid == pid) {
mostActivePids[i].DataAmount += payload;
if (mostActivePids[i].pid == Pid) {
mostActivePids[i].DataAmount += Payload;
// Now re-sort the array and quit
qsort(&mostActivePids, numberOfElements, sizeof(pidStruct), SortPids);
return;
@ -127,9 +116,9 @@ void cIptvDeviceStatistics::AddStatistic(long Bytes, u_short pid, long payload)
}
// Apparently our pid isn't in the array. Replace the last element with this
// one if new payload is greater
if (mostActivePids[numberOfElements - 1].DataAmount < payload) {
mostActivePids[numberOfElements - 1].pid = pid;
mostActivePids[numberOfElements - 1].DataAmount = payload;
if (mostActivePids[numberOfElements - 1].DataAmount < Payload) {
mostActivePids[numberOfElements - 1].pid = Pid;
mostActivePids[numberOfElements - 1].DataAmount = Payload;
// Re-sort
qsort(&mostActivePids, numberOfElements, sizeof(pidStruct), SortPids);
}
@ -155,14 +144,12 @@ cString cIptvStreamerStatistics::GetStatistic()
{
//debug("cIptvStreamerStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
long bitrate = 0;
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
if (elapsed)
bitrate = (long)(1000.0 * dataBytes / elapsed / KILOBYTE(1));
long bitrate = elapsed ? (long)((float)1000 / KILOBYTE(1) * dataBytes / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
cString info = cString::sprintf("Streamer: %ld k%s/s\n", bitrate, IptvConfig.GetUseBytes() ? "B" : "bit");
cString info = cString::sprintf("Stream bitrate: %ld k%s/s\n", bitrate, IptvConfig.GetUseBytes() ? "B" : "bit");
dataBytes = 0;
return info;
}
@ -177,7 +164,8 @@ void cIptvStreamerStatistics::AddStatistic(long Bytes)
// Buffer statistic class
cIptvBufferStatistics::cIptvBufferStatistics()
: freeSpace(0),
: dataBytes(0),
freeSpace(0),
usedSpace(0),
timer(),
mutex()
@ -194,21 +182,29 @@ cString cIptvBufferStatistics::GetStatistic()
{
//debug("cIptvBufferStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
float percentage = (float)((1-(float)freeSpace / (float)(usedSpace + freeSpace)) * 100);
long usedKilos = (long)(usedSpace / KILOBYTE(1));
long freeKilos = (long)(freeSpace / KILOBYTE(1));
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
long bitrate = elapsed ? (long)((float)1000 / KILOBYTE(1) * dataBytes / elapsed) : 0L;
float percentage = (float)((1 - (float)freeSpace / (float)(usedSpace + freeSpace)) * 100);
long usedKilos = usedSpace / KILOBYTE(1);
long freeKilos = freeSpace / KILOBYTE(1);
if (!IptvConfig.GetUseBytes()) {
bitrate *= 8;
freeKilos *= 8;
usedKilos *= 8;
}
cString info = cString::sprintf("%ld/%ld k%s (%2.1f%%)", usedKilos, freeKilos, IptvConfig.GetUseBytes() ? "B" : "bit", percentage);
cString info = cString::sprintf("Buffer bitrate: %ld k%s/s\nBuffer usage: %ld/%ld k%s (%2.1f%%)\n", bitrate,
IptvConfig.GetUseBytes() ? "B" : "bit", usedKilos, freeKilos,
IptvConfig.GetUseBytes() ? "B" : "bit", percentage);
dataBytes = 0;
return info;
}
void cIptvBufferStatistics::AddStatistic(long used, long free)
void cIptvBufferStatistics::AddStatistic(long Bytes, long Used, long Free)
{
//debug("cIptvBufferStatistics::AddStatistic(Bytes=%ld)\n", Bytes);
//debug("cIptvBufferStatistics::AddStatistic(Bytes=%ld, Used=%ld, Free=%ld)\n", Bytes, Used, Free);
cMutexLock MutexLock(&mutex);
freeSpace = free;
usedSpace = used;
dataBytes += Bytes;
freeSpace = Free;
usedSpace = Used;
}

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: statistics.h,v 1.8 2007/10/09 17:58:17 ajhseppa Exp $
* $Id: statistics.h,v 1.9 2007/10/09 22:12:17 rahrenbe Exp $
*/
#ifndef __IPTV_STATISTICS_H
@ -30,15 +30,15 @@ private:
cMutex mutex;
};
// Device statistics
class cIptvDeviceStatistics : public cIptvStatisticIf {
// Pid statistics
class cIptvPidStatistics : public cIptvStatisticIf {
public:
cIptvDeviceStatistics();
virtual ~cIptvDeviceStatistics();
cIptvPidStatistics();
virtual ~cIptvPidStatistics();
cString GetStatistic();
protected:
void AddStatistic(long Bytes, u_short pid, long payload);
void AddStatistic(u_short Pid, long Payload);
private:
struct pidStruct {
@ -46,7 +46,6 @@ private:
long DataAmount;
};
pidStruct mostActivePids[IPTV_STATS_ACTIVE_PIDS_COUNT];
long dataBytes;
cTimeMs timer;
cMutex mutex;
@ -78,9 +77,10 @@ public:
cString GetStatistic();
protected:
void AddStatistic(long used, long free);
void AddStatistic(long Bytes, long Used, long Free);
private:
long dataBytes;
long freeSpace;
long usedSpace;
cTimeMs timer;
@ -88,4 +88,3 @@ private:
};
#endif // __IPTV_STATISTICS_H

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: streamer.c,v 1.20 2007/10/09 17:58:17 ajhseppa Exp $
* $Id: streamer.c,v 1.21 2007/10/09 22:12:17 rahrenbe Exp $
*/
#include <vdr/thread.h>
@ -37,14 +37,12 @@ void cIptvStreamer::Action(void)
unsigned char *buffer = NULL;
int length = protocol->Read(&buffer);
if (length >= 0) {
cIptvStreamerStatistics::AddStatistic(length);
AddStatistic(length);
mutex->Lock();
int p = ringBuffer->Put(buffer, length);
if (p != length && Running())
ringBuffer->ReportOverflow(length - p);
mutex->Unlock();
cIptvBufferStatistics::AddStatistic(ringBuffer->Available(),
ringBuffer->Free());
}
else
cCondWait::SleepMs(100); // to reduce cpu load

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: streamer.h,v 1.10 2007/10/09 17:58:17 ajhseppa Exp $
* $Id: streamer.h,v 1.11 2007/10/09 22:12:17 rahrenbe Exp $
*/
#ifndef __IPTV_STREAMER_H
@ -17,7 +17,7 @@
#include "protocolif.h"
#include "statistics.h"
class cIptvStreamer : public cThread, public cIptvStreamerStatistics, public cIptvBufferStatistics {
class cIptvStreamer : public cThread, public cIptvStreamerStatistics {
private:
cRingBufferLinear* ringBuffer;
cMutex* mutex;