Modify statistics to contain more intelligence.

This commit is contained in:
Antti Seppälä 2007-10-07 19:06:33 +00:00
parent 0887832b35
commit 0b965f0c76
10 changed files with 104 additions and 43 deletions

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: config.c,v 1.12 2007/10/06 00:02:50 rahrenbe Exp $
* $Id: config.c,v 1.13 2007/10/07 19:06:33 ajhseppa Exp $
*/
#include "common.h"
@ -16,7 +16,9 @@ cIptvConfig::cIptvConfig(void)
tsBufferSize(2),
tsBufferPrefillRatio(0),
sectionFiltering(1),
sidScanning(1)
sidScanning(1),
statsInKilos(1),
statsInBytes(1)
{
for (unsigned int i = 0; i < sizeof(disabledFilters); ++i)
disabledFilters[i] = -1;

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: config.h,v 1.10 2007/10/06 00:02:50 rahrenbe Exp $
* $Id: config.h,v 1.11 2007/10/07 19:06:33 ajhseppa Exp $
*/
#ifndef __IPTV_CONFIG_H
@ -20,6 +20,8 @@ protected:
unsigned int tsBufferPrefillRatio;
unsigned int sectionFiltering;
unsigned int sidScanning;
unsigned int statsInKilos;
unsigned int statsInBytes;
int disabledFilters[SECTION_FILTER_TABLE_SIZE];
public:
@ -29,12 +31,16 @@ public:
unsigned int GetTsBufferPrefillRatio(void) { return tsBufferPrefillRatio; }
unsigned int GetSectionFiltering(void) { return sectionFiltering; }
unsigned int GetSidScanning(void) { return sidScanning; }
unsigned int GetStatsInBytes(void) { return statsInBytes; }
unsigned int GetStatsInKilos(void) { return statsInKilos; }
unsigned int GetDisabledFiltersCount(void);
int GetDisabledFilters(unsigned int Index);
void SetTsBufferSize(unsigned int Size) { tsBufferSize = Size; }
void SetTsBufferPrefillRatio(unsigned int Ratio) { tsBufferPrefillRatio = Ratio; }
void SetSectionFiltering(unsigned int On) { sectionFiltering = On; }
void SetSidScanning(unsigned int On) { sidScanning = On; }
void SetStatsInBytes(unsigned int On) { statsInBytes = On; }
void SetStatsInKilos(unsigned int On) { statsInKilos = On; }
void SetDisabledFilters(unsigned int Index, int Number);
};

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.c,v 1.55 2007/10/07 10:13:45 ajhseppa Exp $
* $Id: device.c,v 1.56 2007/10/07 19:06:33 ajhseppa Exp $
*/
#include "common.h"
@ -96,11 +96,11 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex)
return NULL;
}
cString cIptvDevice::GetInformation(uint64_t elapsed, const char* unit, const int unitdivider)
cString cIptvDevice::GetInformation()
{
return cString::sprintf("Device:\n%s\nStreamer:\n%s\nSection Filter 0:\n%s", *GetStatistic(elapsed, unit, unitdivider),
pIptvStreamer ? *pIptvStreamer->GetStatistic(elapsed, unit, unitdivider) : "",
secfilters[0] ? *secfilters[0]->GetStatistic(elapsed, unit, unitdivider) : "");
return cString::sprintf("Device:\n%s\nStreamer:\n%s\nSection Filter 0:\n%s", *GetStatistic(),
pIptvStreamer ? *pIptvStreamer->GetStatistic() : "",
secfilters[0] ? *secfilters[0]->GetStatistic() : "");
}
cString cIptvDevice::GetChannelSettings(const char *Param, int *IpPort, cIptvProtocolIf* *Protocol)

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.h,v 1.26 2007/10/07 10:13:45 ajhseppa Exp $
* $Id: device.h,v 1.27 2007/10/07 19:06:33 ajhseppa Exp $
*/
#ifndef __IPTV_DEVICE_H
@ -48,7 +48,7 @@ private:
public:
cIptvDevice(unsigned int DeviceIndex);
virtual ~cIptvDevice();
cString GetInformation(uint64_t, const char* unit, const int unitdivider);
cString GetInformation();
// for channel parsing & buffering
private:

4
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.12 2007/10/07 10:13:45 ajhseppa Exp $
* $Id: iptv.c,v 1.13 2007/10/07 19:06:33 ajhseppa Exp $
*/
#include <getopt.h>
@ -210,7 +210,7 @@ cString cPluginIptv::SVDRPCommand(const char *Command, const char *Option, int &
if (strcasecmp(Command, "INFO") == 0) {
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device)
return device->GetInformation(0, "", 0);
return device->GetInformation();
else {
ReplyCode = 550; // Requested action not taken
return cString("IPTV information not available!");

20
setup.c
View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: setup.c,v 1.24 2007/10/07 15:13:48 rahrenbe Exp $
* $Id: setup.c,v 1.25 2007/10/07 19:06:33 ajhseppa Exp $
*/
#include <string.h>
@ -479,7 +479,7 @@ private:
};
cString text;
cTimeMs timeout;
void UpdateInfo(uint64_t elapsed, const char* unit, const int unitdivider);
void UpdateInfo();
public:
cIptvMenuInfo();
@ -491,18 +491,18 @@ public:
cIptvMenuInfo::cIptvMenuInfo()
:cOsdMenu(tr("IPTV Information")), text(""), timeout(INFO_TIMEOUT_MS)
{
UpdateInfo(0, "kbytes", 1024);
UpdateInfo();
}
cIptvMenuInfo::~cIptvMenuInfo()
{
}
void cIptvMenuInfo::UpdateInfo(uint64_t elapsed, const char* unit, const int unitdivider)
void cIptvMenuInfo::UpdateInfo()
{
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device)
text = device->GetInformation(elapsed, unit, unitdivider);
text = device->GetInformation();
else
text = cString(tr("IPTV information not available!"));
Display();
@ -540,7 +540,7 @@ eOSState cIptvMenuInfo::ProcessKey(eKeys Key)
switch (Key) {
case kOk: return osBack;
default: if (timeout.TimedOut())
UpdateInfo(INFO_TIMEOUT_MS, "kb/s", 1024);
UpdateInfo();
return osContinue;
}
}
@ -563,6 +563,8 @@ cIptvPluginSetup::cIptvPluginSetup()
disabledFilterIndexes[i] = IptvConfig.GetDisabledFilters(i);
disabledFilterNames[i] = tr(section_filter_table[i].description);
}
statsInKilos = IptvConfig.GetStatsInKilos();
statsInBytes = IptvConfig.GetStatsInBytes();
Setup();
SetHelp(trVDR("Channels"), NULL, NULL, trVDR("Button$Info"));
}
@ -582,6 +584,8 @@ void cIptvPluginSetup::Setup(void)
Add(new cMenuEditStraItem(tr("Disable filter"), &disabledFilterIndexes[i], SECTION_FILTER_TABLE_SIZE, disabledFilterNames));
}
}
Add(new cMenuEditBoolItem(tr("Show statistics in Kilos"), &statsInKilos));
Add(new cMenuEditBoolItem(tr("Show statistics in Bytes"), &statsInBytes));
SetCurrent(Get(current));
Display();
}
@ -648,12 +652,16 @@ void cIptvPluginSetup::Store(void)
SetupStore("TsBufferPrefill", tsBufferPrefill);
SetupStore("SectionFiltering", sectionFiltering);
SetupStore("SidScanning", sidScanning);
SetupStore("StatsInKilos", statsInKilos);
SetupStore("StatsInBytes", statsInBytes);
StoreFilters("DisabledFilters", disabledFilterIndexes);
// Update global config
IptvConfig.SetTsBufferSize(tsBufferSize);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefill);
IptvConfig.SetSectionFiltering(sectionFiltering);
IptvConfig.SetSidScanning(sidScanning);
IptvConfig.SetStatsInKilos(statsInKilos);
IptvConfig.SetStatsInBytes(statsInBytes);
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i)
IptvConfig.SetDisabledFilters(i, disabledFilterIndexes[i]);
}

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: setup.h,v 1.11 2007/10/06 20:57:53 rahrenbe Exp $
* $Id: setup.h,v 1.12 2007/10/07 19:06:33 ajhseppa Exp $
*/
#ifndef __IPTV_SETUP_H
@ -19,6 +19,8 @@ private:
int tsBufferPrefill;
int sectionFiltering;
int sidScanning;
int statsInKilos;
int statsInBytes;
int numDisabledFilters;
int disabledFilterIndexes[SECTION_FILTER_TABLE_SIZE];
const char *disabledFilterNames[SECTION_FILTER_TABLE_SIZE];

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: statisticif.h,v 1.3 2007/10/07 10:13:45 ajhseppa Exp $
* $Id: statisticif.h,v 1.4 2007/10/07 19:06:33 ajhseppa Exp $
*/
#ifndef __IPTV_STATISTICIF_H
@ -15,7 +15,7 @@ class cIptvStatisticIf {
public:
cIptvStatisticIf() {}
virtual ~cIptvStatisticIf() {}
virtual cString GetStatistic(uint64_t elapsed, const char* unit, const int unitdivider) = 0;
virtual cString GetStatistic() = 0;
private:
cIptvStatisticIf(const cIptvStatisticIf&);

View File

@ -3,16 +3,20 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: statistics.c,v 1.6 2007/10/07 10:13:45 ajhseppa Exp $
* $Id: statistics.c,v 1.7 2007/10/07 19:06:33 ajhseppa Exp $
*/
#include <limits.h>
#include "common.h"
#include "statistics.h"
#include "config.h"
// Section statistic class
cIptvSectionStatistics::cIptvSectionStatistics()
: filteredData(0),
numberOfCalls(0)
numberOfCalls(0),
timer()
{
//debug("cIptvSectionStatistics::cIptvSectionStatistics()\n");
}
@ -22,15 +26,25 @@ cIptvSectionStatistics::~cIptvSectionStatistics()
//debug("cIptvSectionStatistics::~cIptvSectionStatistics()\n");
}
cString cIptvSectionStatistics::GetStatistic(uint64_t elapsed, const char* unit, int unitdivider)
cString cIptvSectionStatistics::GetStatistic()
{
debug("cIptvSectionStatistics::GetStatistic()\n");
uint64_t elapsed = timer.Elapsed();
timer.Set();
// Prevent a divide-by-zero error
elapsed ? : elapsed = 1;
unitdivider ? : unitdivider = 1;
float divider = elapsed / 1000;
char unit[] = { ' ', 'B', '/', 's', '\0' };
if (IptvConfig.GetStatsInKilos()) {
divider *= KILOBYTE(1);
unit[0] = 'k';
}
if (!IptvConfig.GetStatsInBytes()) {
divider /= sizeof(unsigned short);
unit[1] = 'b';
}
long tmpFilteredData = filteredData;
long tmpNumberOfCalls = numberOfCalls;
float divider = unitdivider * elapsed / 1000;
filteredData = numberOfCalls = 0;
return cString::sprintf("Filtered data: %ld %s\nData packets passed: %ld\n", (long)(tmpFilteredData / divider), unit, tmpNumberOfCalls);
}
@ -39,7 +53,8 @@ cString cIptvSectionStatistics::GetStatistic(uint64_t elapsed, const char* unit,
// Device statistic class
cIptvDeviceStatistics::cIptvDeviceStatistics()
: dataBytes(0)
: dataBytes(0),
timer()
{
debug("cIptvDeviceStatistics::cIptvDeviceStatistics()\n");
memset(mostActivePids, '\0', sizeof(mostActivePids));
@ -50,24 +65,34 @@ cIptvDeviceStatistics::~cIptvDeviceStatistics()
debug("cIptvDeviceStatistics::~cIptvDeviceStatistics()\n");
}
cString cIptvDeviceStatistics::GetStatistic(uint64_t elapsed, const char* unit, int unitdivider)
cString cIptvDeviceStatistics::GetStatistic()
{
debug("cIptvDeviceStatistics::GetStatistic()\n");
pidStruct tmpMostActivePids[10];
long tmpDataBytes = dataBytes;
uint64_t elapsed = timer.Elapsed();
timer.Set();
// Prevent a divide-by-zero error
elapsed ? : elapsed = 1;
unitdivider ? : unitdivider = 1;
float divider = unitdivider * elapsed / 1000;
float divider = elapsed / 1000;
char unit[] = { ' ', 'B', '/', 's', '\0' };
if (IptvConfig.GetStatsInKilos()) {
divider *= KILOBYTE(1);
unit[0] = 'k';
}
if (!IptvConfig.GetStatsInBytes()) {
divider /= sizeof(unsigned short);
unit[1] = 'b';
}
dataBytes = 0;
memcpy(&tmpMostActivePids, &mostActivePids, sizeof(tmpMostActivePids));
memset(&mostActivePids, '\0', sizeof(mostActivePids));
return cString::sprintf("Stream data bytes: %ld %s\n"
" 1. Active Pid: %d %ld %s\n"
" 2. Active Pid: %d %ld %s\n"
" 3. Active Pid: %d %ld %s\n"
" 4. Active Pid: %d %ld %s\n"
" 5. Active Pid: %d %ld %s\n",
" 1. Active Pid: %d %ld %s\n"
" 2. Active Pid: %d %ld %s\n"
" 3. Active Pid: %d %ld %s\n"
" 4. Active Pid: %d %ld %s\n"
" 5. Active Pid: %d %ld %s\n",
(long)(tmpDataBytes / divider), unit,
tmpMostActivePids[0].pid, (long)(tmpMostActivePids[0].DataAmount / divider), unit,
tmpMostActivePids[1].pid, (long)(tmpMostActivePids[1].DataAmount / divider), unit,
@ -115,7 +140,8 @@ void cIptvDeviceStatistics::UpdateActivePids(u_short pid, long payload)
// Streamer statistic class
cIptvStreamerStatistics::cIptvStreamerStatistics()
: dataBytes(0)
: dataBytes(0),
timer()
{
debug("cIptvStreamerStatistics::cIptvStreamerStatistics()\n");
}
@ -125,13 +151,23 @@ cIptvStreamerStatistics::~cIptvStreamerStatistics()
debug("cIptvStreamerStatistics::~cIptvStreamerStatistics()\n");
}
cString cIptvStreamerStatistics::GetStatistic(uint64_t elapsed, const char* unit, int unitdivider)
cString cIptvStreamerStatistics::GetStatistic()
{
debug("cIptvStreamerStatistics::GetStatistic()\n");
uint64_t elapsed = timer.Elapsed();
timer.Set();
// Prevent a divide-by-zero error
elapsed ? : elapsed = 1;
unitdivider ? : unitdivider = 1;
float divider = unitdivider * elapsed / 1000;
float divider = elapsed / 1000;
char unit[] = { ' ', 'B', '/', 's', '\0' };
if (IptvConfig.GetStatsInKilos()) {
divider *= KILOBYTE(1);
unit[0] = 'k';
}
if (!IptvConfig.GetStatsInBytes()) {
divider /= sizeof(unsigned short);
unit[1] = 'b';
}
long tmpDataBytes = (long)(dataBytes / divider);
dataBytes = 0;
return cString::sprintf("Stream data bytes: %ld %s\n", tmpDataBytes, unit);

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: statistics.h,v 1.3 2007/10/07 10:13:45 ajhseppa Exp $
* $Id: statistics.h,v 1.4 2007/10/07 19:06:33 ajhseppa Exp $
*/
#ifndef __IPTV_STATISTICS_H
@ -26,7 +26,10 @@ public:
cIptvSectionStatistics();
virtual ~cIptvSectionStatistics();
cString GetStatistic(uint64_t elapsed, const char* unit, int unitdivider);
cString GetStatistic();
private:
cTimeMs timer;
};
// Device statistics
@ -38,13 +41,14 @@ public:
cIptvDeviceStatistics();
virtual ~cIptvDeviceStatistics();
cString GetStatistic(uint64_t elapsed, const char* unit, int unitdivider);
cString GetStatistic();
protected:
void UpdateActivePids(u_short pid, long payload);
private:
pidStruct mostActivePids[10];
cTimeMs timer;
};
// Streamer statistics
@ -56,7 +60,10 @@ public:
cIptvStreamerStatistics();
virtual ~cIptvStreamerStatistics();
cString GetStatistic(uint64_t elapsed, const char* unit, int unitdivider);
cString GetStatistic();
private:
cTimeMs timer;
};
#endif // __IPTV_STATISTICS_H