Show buffer statistics

This commit is contained in:
Antti Seppälä 2007-10-09 17:58:17 +00:00
parent 784b64f5c0
commit dd530a1931
6 changed files with 74 additions and 15 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.62 2007/10/09 16:37:16 rahrenbe Exp $ * $Id: device.c,v 1.63 2007/10/09 17:58:17 ajhseppa Exp $
*/ */
#include "config.h" #include "config.h"
@ -97,19 +97,19 @@ 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 usage: %d%%\n", return cString::sprintf("IPTV device #%d (CardIndex: %d)\n%s\n%s\nTSBuffer: %s\nStreamBuffer: %s\n",
deviceIndex, CardIndex(), pIptvStreamer ? deviceIndex, CardIndex(), pIptvStreamer ?
*pIptvStreamer->GetInformation() : "", *pIptvStreamer->GetInformation() : "",
pIptvStreamer ? *pIptvStreamer->GetStatistic() : "", pIptvStreamer ? *pIptvStreamer->cIptvStreamerStatistics::GetStatistic() : "",
((MEGABYTE(IptvConfig.GetTsBufferSize()) - tsBuffer->Free()) / *cIptvBufferStatistics::GetStatistic(),
MEGABYTE(IptvConfig.GetTsBufferSize()))); 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"); cString info("Most active pids:\n");
info = cString::sprintf("%s%s", *info, *GetStatistic()); info = cString::sprintf("%s%s", *info, *cIptvDeviceStatistics::GetStatistic());
return info; return info;
} }
@ -365,7 +365,8 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
isPacketDelivered = true; isPacketDelivered = true;
Data = p; Data = p;
// Update statistics // Update statistics
AddStatistic(Count, ts_pid(p), payload(p)); cIptvDeviceStatistics::AddStatistic(TS_SIZE, 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.29 2007/10/09 16:37:16 rahrenbe Exp $ * $Id: device.h,v 1.30 2007/10/09 17:58:17 ajhseppa 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 { class cIptvDevice : public cDevice, public cIptvDeviceStatistics, public cIptvBufferStatistics {
// static ones // static ones
public: public:
static unsigned int deviceCount; static unsigned int deviceCount;

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.15 2007/10/08 23:51:58 rahrenbe Exp $ * $Id: statistics.c,v 1.16 2007/10/09 17:58:17 ajhseppa Exp $
*/ */
#include <limits.h> #include <limits.h>
@ -173,3 +173,42 @@ void cIptvStreamerStatistics::AddStatistic(long Bytes)
cMutexLock MutexLock(&mutex); cMutexLock MutexLock(&mutex);
dataBytes += Bytes; dataBytes += Bytes;
} }
// Buffer statistic class
cIptvBufferStatistics::cIptvBufferStatistics()
: freeSpace(0),
usedSpace(0),
timer(),
mutex()
{
debug("cIptvBufferStatistics::cIptvBufferStatistics()\n");
}
cIptvBufferStatistics::~cIptvBufferStatistics()
{
debug("cIptvBufferStatistics::~cIptvBufferStatistics()\n");
}
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));
if (!IptvConfig.GetUseBytes()) {
freeKilos *= 8;
usedKilos *= 8;
}
cString info = cString::sprintf("%ld/%ld k%s (%2.1f%%)", usedKilos, freeKilos, IptvConfig.GetUseBytes() ? "B" : "bit", percentage);
return info;
}
void cIptvBufferStatistics::AddStatistic(long used, long free)
{
//debug("cIptvBufferStatistics::AddStatistic(Bytes=%ld)\n", Bytes);
cMutexLock MutexLock(&mutex);
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.7 2007/10/08 16:24:48 rahrenbe Exp $ * $Id: statistics.h,v 1.8 2007/10/09 17:58:17 ajhseppa Exp $
*/ */
#ifndef __IPTV_STATISTICS_H #ifndef __IPTV_STATISTICS_H
@ -70,5 +70,22 @@ private:
cMutex mutex; cMutex mutex;
}; };
// Buffer statistics
class cIptvBufferStatistics : public cIptvStatisticIf {
public:
cIptvBufferStatistics();
virtual ~cIptvBufferStatistics();
cString GetStatistic();
protected:
void AddStatistic(long used, long free);
private:
long freeSpace;
long usedSpace;
cTimeMs timer;
cMutex mutex;
};
#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.19 2007/10/08 16:24:49 rahrenbe Exp $ * $Id: streamer.c,v 1.20 2007/10/09 17:58:17 ajhseppa Exp $
*/ */
#include <vdr/thread.h> #include <vdr/thread.h>
@ -37,12 +37,14 @@ 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) {
AddStatistic(length); cIptvStreamerStatistics::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.9 2007/10/07 22:54:09 rahrenbe Exp $ * $Id: streamer.h,v 1.10 2007/10/09 17:58:17 ajhseppa 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 { class cIptvStreamer : public cThread, public cIptvStreamerStatistics, public cIptvBufferStatistics {
private: private:
cRingBufferLinear* ringBuffer; cRingBufferLinear* ringBuffer;
cMutex* mutex; cMutex* mutex;