Ticket #6138: 134-release.19703.0116.recstats.cd.1.patch

File 134-release.19703.0116.recstats.cd.1.patch, 15.4 KB (added by anonymous, 12 years ago)

recorder stats patch

  • mythtv/libs/libmythtv/DeviceReadBuffer.cpp

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/DeviceReadBuffer.cpp release.19703.0116d/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
     
    196196    used     += len;
    197197    writePtr += len;
    198198    writePtr  = (writePtr == endPtr) ? buffer : writePtr;
    199 #if REPORT_RING_STATS
    200199    max_used = max(used, max_used);
     200#if REPORT_RING_STATS
    201201    avg_used = ((avg_used * avg_cnt) + used) / ++avg_cnt;
    202202#endif
    203203}
  • mythtv/libs/libmythtv/DeviceReadBuffer.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/DeviceReadBuffer.h release.19703.0116d/mythtv/libs/libmythtv/DeviceReadBuffer.h
     
    4040    void Reset(const QString &streamName, int streamfd);
    4141    void Stop(void);
    4242
     43    size_t GetMaxUsed() const { return max_used; };
     44
    4345    void SetRequestPause(bool request);
    4446    bool IsPaused(void) const;
    4547    bool WaitForUnpause(int timeout);
  • mythtv/libs/libmythtv/ThreadedFileWriter.cpp

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/ThreadedFileWriter.cpp release.19703.0116d/mythtv/libs/libmythtv/ThreadedFileWriter.cpp
     
    134134    rpos(0),                             wpos(0),
    135135    written(0),
    136136    // buffer
    137     buf(NULL),                           tfw_buf_size(0)
     137    buf(NULL),                           tfw_buf_size(0),
     138    tfw_highwater_mark(0)
    138139{
    139140}
    140141
     
    160161
    161162        tfw_buf_size = TFW_DEF_BUF_SIZE;
    162163        tfw_min_write_size = TFW_MIN_WRITE_SIZE;
     164        tfw_highwater_mark = 0;
    163165        pthread_create(&writer, NULL, boot_writer, this);
    164166        pthread_create(&syncer, NULL, boot_syncer, this);
    165167        return true;
     
    192194        delete [] buf;
    193195        buf = NULL;
    194196    }
     197
     198    VERBOSE(VB_GENERAL, LOC + QString("Buffer size = %1 KB hwm = %2 KB")
     199        .arg(tfw_buf_size / 1024).arg(tfw_highwater_mark/1024));
    195200}
    196201
    197202/** \fn ThreadedFileWriter::Write(const void*, uint)
     
    434439uint ThreadedFileWriter::BufUsed(void)
    435440{
    436441    QMutexLocker locker(&buflock);
    437     return (wpos >= rpos) ? wpos - rpos : tfw_buf_size - rpos + wpos;
     442    uint result = (wpos >= rpos) ? wpos - rpos : tfw_buf_size - rpos + wpos;
     443    if (result > tfw_highwater_mark)
     444        tfw_highwater_mark=result;
     445    return result;
    438446}
    439447
    440448/** \fn ThreadedFileWriter::BufFree(void)
  • mythtv/libs/libmythtv/ThreadedFileWriter.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/ThreadedFileWriter.h release.19703.0116d/mythtv/libs/libmythtv/ThreadedFileWriter.h
     
    5858    // buffer
    5959    char           *buf;
    6060    unsigned long   tfw_buf_size;
     61    unsigned long   tfw_highwater_mark;
    6162
    6263    // threads
    6364    pthread_t       writer;
  • mythtv/libs/libmythtv/dvbrecorder.cpp

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/dvbrecorder.cpp release.19703.0116d/mythtv/libs/libmythtv/dvbrecorder.cpp
     
    337337{
    338338    VERBOSE(VB_RECORD, LOC + "Close() fd("<<_stream_fd<<") -- begin");
    339339
     340    uint hwm = _stream_handler->GetMaxUsed();
     341    VERBOSE(VB_GENERAL,QString( LOC + "DVB Stats: pkts=%1 hwm=%2 KB Errors: trnsprt=%3 seq=%4")
     342            .arg(_total_packet_count)
     343            .arg(hwm/1024)
     344            .arg(_transport_error_count)
     345            .arg(_continuity_error_count));
     346
    340347    DVBStreamHandler::Return(_stream_handler);
    341348
    342349    VERBOSE(VB_RECORD, LOC + "Close() fd("<<_stream_fd<<") -- end");
     
    381388
    382389    _continuity_error_count = 0;
    383390    _stream_overflow_count = 0;
     391    _transport_error_count = 0;
     392    _bad_packet_count = 0;
     393    _total_packet_count = 0;
    384394
    385395    _request_recording = true;
    386396    _recording = true;
     
    524534                QString("PID 0x%1 discontinuity detected").arg(pid,0,16));
    525535        _continuity_error_count++;
    526536    }
     537    if (tspacket.TransportError())
     538    {
     539        _transport_error_count++;
     540    }
     541    _total_packet_count++;
    527542
    528543    // Sync recording start to first keyframe
    529544    if (_wait_for_keyframe_option && _first_keyframe < 0)
     
    558573                QString("PID 0x%1 discontinuity detected").arg(pid,0,16));
    559574        _continuity_error_count++;
    560575    }
     576    if (tspacket.TransportError())
     577    {
     578        _transport_error_count++;
     579    }
     580
     581    _total_packet_count++;
    561582
    562583    // Only create fake keyframe[s] if there are no audio/video streams
    563584    if (_input_pmt && _has_no_av)
  • mythtv/libs/libmythtv/dvbrecorder.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/dvbrecorder.h release.19703.0116d/mythtv/libs/libmythtv/dvbrecorder.h
     
    130130    mutable uint        _continuity_error_count;
    131131    mutable uint        _stream_overflow_count;
    132132    mutable uint        _bad_packet_count;
     133    mutable uint        _transport_error_count;
     134    mutable uint        _total_packet_count;
    133135
    134136    // Constants
    135137    static const int TSPACKETS_BETWEEN_PSIP_SYNC;
  • mythtv/libs/libmythtv/dvbstreamhandler.cpp

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/dvbstreamhandler.cpp release.19703.0116d/mythtv/libs/libmythtv/dvbstreamhandler.cpp
     
    9797    _dvbchannel(NULL),
    9898
    9999    _pid_lock(true),
    100     _listener_lock(true)
     100    _listener_lock(true),
     101    _max_used(0)
    101102{
    102103}
    103104
     
    196197    }
    197198}
    198199
     200uint DVBStreamHandler::GetMaxUsed(void)
     201{
     202    QMutexLocker locker(&_start_stop_lock);
     203    if (_device_read_buffer)
     204    {
     205       _max_used = _device_read_buffer->GetMaxUsed();
     206    }
     207    return _max_used;
     208}
     209
    199210void DVBStreamHandler::Stop(void)
    200211{
    201212    QMutexLocker locker(&_start_stop_lock);
     
    203214    if (IsRunning())
    204215    {
    205216        if (_device_read_buffer)
     217        {
    206218            _device_read_buffer->Stop();
     219            _max_used = _device_read_buffer->GetMaxUsed();
     220        }
    207221        SetRunning(false);
    208222        pthread_join(_reader_thread, NULL);
    209223    }
     
    243257        return;
    244258    bzero(buffer, buffer_size);
    245259
     260    VERBOSE(VB_GENERAL, QString(LOC + "HD Ringbuffer size = %1 KB").arg(buffer_size / 1024));
     261
    246262    int dvr_fd = open(_dvr_dev_path.ascii(), O_RDONLY | O_NONBLOCK);
    247263    if (dvr_fd < 0)
    248264    {
     
    348364        if (_device_read_buffer->IsRunning())
    349365            _device_read_buffer->Stop();
    350366
     367        _max_used=_device_read_buffer->GetMaxUsed();
     368
    351369        delete _device_read_buffer;
    352370        _device_read_buffer = NULL;
    353371    }
  • mythtv/libs/libmythtv/dvbstreamhandler.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/dvbstreamhandler.h release.19703.0116d/mythtv/libs/libmythtv/dvbstreamhandler.h
     
    7070    // ReaderPausedCB
    7171    virtual void ReaderPaused(int fd) { (void) fd; }
    7272
     73    uint GetMaxUsed();
     74
    7375  private:
    7476    DVBStreamHandler(uint);
    7577    ~DVBStreamHandler();
     
    118120    mutable QMutex          _listener_lock;
    119121    vector<MPEGStreamData*> _stream_data_list;
    120122
     123    uint _max_used;
     124
    121125    // for caching TS monitoring supported value.
    122126    static QMutex          _rec_supports_ts_monitoring_lock;
    123127    static QMap<uint,bool> _rec_supports_ts_monitoring;
  • mythtv/libs/libmythtv/hdhomerun/hdhomerun_video.c

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/hdhomerun/hdhomerun_video.c release.19703.0116d/mythtv/libs/libmythtv/hdhomerun/hdhomerun_video.c
     
    4949        volatile uint32_t network_error_count;
    5050        volatile uint32_t sequence_error_count;
    5151        volatile uint32_t overflow_error_count;
     52        volatile uint32_t buffer_highwater_mark;
    5253        volatile uint8_t sequence[0x2000];
    5354};
    5455
     
    286287                        head -= vs->buffer_size;
    287288                }
    288289
     290                /* update buffer_highwater_mark */
     291                /* head - where things will be inserted */
     292                /* tail - where things will be removed */
     293                size_t tail = vs->tail;
     294                uint32_t space_used;
     295                if (head > tail) {
     296                        space_used = head - tail;
     297                } else {
     298                        /* head < tail */
     299                        space_used = (head + vs->buffer_size) - tail;
     300                }
     301
     302                if (space_used > vs->buffer_highwater_mark) {
     303                        vs->buffer_highwater_mark = space_used;
     304                }
     305
    289306                /* Check for buffer overflow. */
    290307                if (head == vs->tail) {
    291308                        vs->overflow_error_count++;
     
    367384        vs->network_error_count = 0;
    368385        vs->sequence_error_count = 0;
    369386        vs->overflow_error_count = 0;
     387        vs->buffer_highwater_mark = 0;
    370388
    371389        pthread_mutex_unlock(&vs->lock);
    372390}
     
    376394        struct hdhomerun_video_stats_t stats;
    377395        hdhomerun_video_get_stats(vs, &stats);
    378396
    379         hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld\n",
     397        hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld hwm=%ld\n",
    380398                stats.packet_count, stats.network_error_count,
    381399                stats.transport_error_count, stats.sequence_error_count,
    382                 stats.overflow_error_count
     400                stats.overflow_error_count, stats.buffer_highwater_mark
    383401        );
    384402}
    385403
     
    394412        stats->transport_error_count = vs->transport_error_count;
    395413        stats->sequence_error_count = vs->sequence_error_count;
    396414        stats->overflow_error_count = vs->overflow_error_count;
     415        stats->buffer_highwater_mark = vs->buffer_highwater_mark;
    397416
    398417        pthread_mutex_unlock(&vs->lock);
    399418}
  • mythtv/libs/libmythtv/hdhomerun/hdhomerun_video.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/hdhomerun/hdhomerun_video.h release.19703.0116d/mythtv/libs/libmythtv/hdhomerun/hdhomerun_video.h
     
    4141        uint32_t transport_error_count;
    4242        uint32_t sequence_error_count;
    4343        uint32_t overflow_error_count;
     44        uint32_t buffer_highwater_mark;
    4445};
    4546
    4647#define TS_PACKET_SIZE 188
  • mythtv/libs/libmythtv/hdhrrecorder.cpp

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/hdhrrecorder.cpp release.19703.0116d/mythtv/libs/libmythtv/hdhrrecorder.cpp
     
    116116    memset(_continuity_counter, 0xff, sizeof(_continuity_counter));
    117117
    118118    _stream_handler = HDHRStreamHandler::Get(_channel->GetDeviceId(), _channel->GetTuner(), _channel->GetDevice());
     119    _stream_handler->GetStats(&_start_stats, false);
    119120
    120121    VERBOSE(VB_RECORD, LOC + "HDHR opened successfully");
    121122
     
    128129
    129130    if (IsOpen())
    130131    {
     132        hdhomerun_video_stats_t end_stats;
     133        _stream_handler->GetStats(&end_stats, true);
     134
     135        VERBOSE(VB_GENERAL,QString( LOC + "HDHR Stats: pkts=%1 hwm=%6 KB Errors: net=%2 trnsprt=%3 seq=%4 ovflow=%5")
     136               .arg(end_stats.packet_count          - _start_stats.packet_count)
     137               .arg(end_stats.network_error_count   - _start_stats.network_error_count)
     138               .arg(end_stats.transport_error_count - _start_stats.transport_error_count)
     139               .arg(end_stats.sequence_error_count  - _start_stats.sequence_error_count)
     140               .arg(end_stats.overflow_error_count  - _start_stats.overflow_error_count)
     141               .arg(end_stats.buffer_highwater_mark / 1024)); /* buffer_highwater_mark is absolute */
     142
    131143        HDHRStreamHandler::Return(_stream_handler);
    132144    }
    133145    else
  • mythtv/libs/libmythtv/hdhrrecorder.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/hdhrrecorder.h release.19703.0116d/mythtv/libs/libmythtv/hdhrrecorder.h
     
    9292    ProgramMapTable               *_input_pmt;
    9393    bool                           _has_no_av;
    9494
     95    hdhomerun_video_stats_t       _start_stats;
     96
    9597    unsigned char   _stream_id[0x1fff];
    9698    unsigned char   _pid_status[0x1fff];
    9799    unsigned char   _continuity_counter[0x1fff];
  • mythtv/libs/libmythtv/hdhrstreamhandler.cpp

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/hdhrstreamhandler.cpp release.19703.0116d/mythtv/libs/libmythtv/hdhrstreamhandler.cpp
     
    102102    _listener_lock(true),
    103103    _hdhr_lock(true)
    104104{
     105    memset(&_last_stats, 0, sizeof(_last_stats));
    105106}
    106107
    107108HDHRStreamHandler::~HDHRStreamHandler()
     
    286287    return (QString::null != TunerSet("target", "0.0.0.0:0"));
    287288}
    288289
     290void HDHRStreamHandler::GetStats(hdhomerun_video_stats_t* stats, bool use_cache) {
     291    QMutexLocker locker(&_hdhr_lock);
     292    if (_video_socket) {
     293        hdhomerun_video_get_stats(_video_socket, &_last_stats);
     294        memcpy(stats, &_last_stats, sizeof(hdhomerun_video_stats_t));
     295    } else if (use_cache) {
     296        memcpy(stats, &_last_stats, sizeof(hdhomerun_video_stats_t));
     297    } else {
     298        memset(stats, 0, sizeof(hdhomerun_video_stats_t));
     299    }
     300}
     301
    289302QString HDHRStreamHandler::GetTunerStatus() {
    290303    return TunerGet("status");
    291304}
     
    494507    hdhomerun_video_sock_t* tmp_video_socket;
    495508    {
    496509        QMutexLocker locker(&_hdhr_lock);
     510        hdhomerun_video_get_stats(_video_socket, &_last_stats);
    497511        tmp_video_socket = _video_socket;
    498512        _video_socket=NULL;
    499513    }
  • mythtv/libs/libmythtv/hdhrstreamhandler.h

    diff -r -u -N -X diff.exclude -x release.19703.0116c -x release.19703.0116d release.19703.0116c/mythtv/libs/libmythtv/hdhrstreamhandler.h release.19703.0116d/mythtv/libs/libmythtv/hdhrstreamhandler.h
     
    5050                          DTVSignalMonitor *sigmon,
    5151                          HDHRChannel       *dvbchan);
    5252
     53    void GetStats(hdhomerun_video_stats_t* stats, bool use_cache);
     54
    5355    // ReaderPausedCB
    5456    virtual void ReaderPaused(int fd) { (void) fd; }
    5557
     
    106108  private:
    107109    hdhomerun_control_sock_t  *_control_socket;
    108110    hdhomerun_video_sock_t    *_video_socket;
     111    hdhomerun_video_stats_t    _last_stats;
    109112    uint            _device_id;
    110113    uint            _device_ip;
    111114    uint            _tuner;