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. * 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" #include "config.h"
@ -97,20 +97,17 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex)
cString cIptvDevice::GetGeneralInformation(void) cString cIptvDevice::GetGeneralInformation(void)
{ {
//debug("cIptvDevice::GetGeneralInformation(%d)\n", deviceIndex); //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 ? deviceIndex, CardIndex(), pIptvStreamer ?
*pIptvStreamer->GetInformation() : "", *pIptvStreamer->GetInformation() : "",
pIptvStreamer ? *pIptvStreamer->cIptvStreamerStatistics::GetStatistic() : "", pIptvStreamer ? *pIptvStreamer->GetStatistic() : "",
*cIptvBufferStatistics::GetStatistic(), *cIptvBufferStatistics::GetStatistic());
pIptvStreamer ? *pIptvStreamer->cIptvBufferStatistics::GetStatistic() : "");
} }
cString cIptvDevice::GetPidsInformation(void) cString cIptvDevice::GetPidsInformation(void)
{ {
//debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndex); //debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndex);
cString info("Most active pids:\n"); return cIptvPidStatistics::GetStatistic();
info = cString::sprintf("%s%s", *info, *cIptvDeviceStatistics::GetStatistic());
return info;
} }
cString cIptvDevice::GetFiltersInformation(void) cString cIptvDevice::GetFiltersInformation(void)
@ -348,6 +345,8 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
if (isPacketDelivered) { if (isPacketDelivered) {
tsBuffer->Del(TS_SIZE); tsBuffer->Del(TS_SIZE);
isPacketDelivered = false; isPacketDelivered = false;
// Update buffer statistics
cIptvBufferStatistics::AddStatistic(TS_SIZE, tsBuffer->Available(), tsBuffer->Free());
} }
uchar *p = tsBuffer->Get(Count); uchar *p = tsBuffer->Get(Count);
if (p && Count >= TS_SIZE) { if (p && Count >= TS_SIZE) {
@ -364,9 +363,8 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
} }
isPacketDelivered = true; isPacketDelivered = true;
Data = p; Data = p;
// Update statistics // Update pid statistics
cIptvDeviceStatistics::AddStatistic(TS_SIZE, ts_pid(p), payload(p)); cIptvPidStatistics::AddStatistic(ts_pid(p), payload(p));
cIptvBufferStatistics::AddStatistic(tsBuffer->Available(), tsBuffer->Free());
// Run the data through all filters // Run the data through all filters
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) { for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (secfilters[i]) if (secfilters[i])

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * 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 #ifndef __IPTV_DEVICE_H
@ -19,7 +19,7 @@
#include "sidscanner.h" #include "sidscanner.h"
#include "statistics.h" #include "statistics.h"
class cIptvDevice : public cDevice, public cIptvDeviceStatistics, public cIptvBufferStatistics { class cIptvDevice : public cDevice, public cIptvPidStatistics, public cIptvBufferStatistics {
// static ones // static ones
public: public:
static unsigned int deviceCount; 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. * 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> #include <getopt.h>
@ -201,10 +201,12 @@ const char **cPluginIptv::SVDRPHelpPages(void)
{ {
debug("cPluginIptv::SVDRPHelpPages()\n"); debug("cPluginIptv::SVDRPHelpPages()\n");
static const char *HelpPages[] = { static const char *HelpPages[] = {
"INFO [ <option> ]\n" "INFO [ <page> ]\n"
" Print IPTV device information and statistics.\n" " Print IPTV device information and statistics.\n"
" The data can be shown either in bits or bytes\n" " The output can be narrowed using optional \"page\""
" according the given option (bits=0; bytes=1).\n", " option: 1=general 2=pids 3=section filters.\n",
"MODE\n"
" Toggles between bit or byte information mode.\n",
NULL NULL
}; };
return HelpPages; 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); debug("cPluginIptv::SVDRPCommand(): Command=%s Option=%s\n", Command, Option);
if (strcasecmp(Command, "INFO") == 0) { if (strcasecmp(Command, "INFO") == 0) {
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex()); cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device) if (device) {
return device->GetInformation((atoi(Option) == 0)); 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 { else {
ReplyCode = 550; // Requested action not taken ReplyCode = 550; // Requested action not taken
return cString("IPTV information not available!"); 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; return NULL;
} }

View File

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

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * 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 #ifndef __IPTV_STATISTICS_H
@ -30,15 +30,15 @@ private:
cMutex mutex; cMutex mutex;
}; };
// Device statistics // Pid statistics
class cIptvDeviceStatistics : public cIptvStatisticIf { class cIptvPidStatistics : public cIptvStatisticIf {
public: public:
cIptvDeviceStatistics(); cIptvPidStatistics();
virtual ~cIptvDeviceStatistics(); virtual ~cIptvPidStatistics();
cString GetStatistic(); cString GetStatistic();
protected: protected:
void AddStatistic(long Bytes, u_short pid, long payload); void AddStatistic(u_short Pid, long Payload);
private: private:
struct pidStruct { struct pidStruct {
@ -46,7 +46,6 @@ private:
long DataAmount; long DataAmount;
}; };
pidStruct mostActivePids[IPTV_STATS_ACTIVE_PIDS_COUNT]; pidStruct mostActivePids[IPTV_STATS_ACTIVE_PIDS_COUNT];
long dataBytes;
cTimeMs timer; cTimeMs timer;
cMutex mutex; cMutex mutex;
@ -78,9 +77,10 @@ public:
cString GetStatistic(); cString GetStatistic();
protected: protected:
void AddStatistic(long used, long free); void AddStatistic(long Bytes, long Used, long Free);
private: private:
long dataBytes;
long freeSpace; long freeSpace;
long usedSpace; long usedSpace;
cTimeMs timer; cTimeMs timer;
@ -88,4 +88,3 @@ private:
}; };
#endif // __IPTV_STATISTICS_H #endif // __IPTV_STATISTICS_H

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * 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> #include <vdr/thread.h>
@ -37,14 +37,12 @@ void cIptvStreamer::Action(void)
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
int length = protocol->Read(&buffer); int length = protocol->Read(&buffer);
if (length >= 0) { if (length >= 0) {
cIptvStreamerStatistics::AddStatistic(length); AddStatistic(length);
mutex->Lock(); mutex->Lock();
int p = ringBuffer->Put(buffer, length); int p = ringBuffer->Put(buffer, length);
if (p != length && Running()) if (p != length && Running())
ringBuffer->ReportOverflow(length - p); ringBuffer->ReportOverflow(length - p);
mutex->Unlock(); mutex->Unlock();
cIptvBufferStatistics::AddStatistic(ringBuffer->Available(),
ringBuffer->Free());
} }
else else
cCondWait::SleepMs(100); // to reduce cpu load 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. * 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 #ifndef __IPTV_STREAMER_H
@ -17,7 +17,7 @@
#include "protocolif.h" #include "protocolif.h"
#include "statistics.h" #include "statistics.h"
class cIptvStreamer : public cThread, public cIptvStreamerStatistics, public cIptvBufferStatistics { class cIptvStreamer : public cThread, public cIptvStreamerStatistics {
private: private:
cRingBufferLinear* ringBuffer; cRingBufferLinear* ringBuffer;
cMutex* mutex; cMutex* mutex;