Ticket #1728: 07_fix_time_for_prune_and_do_not_readd_pruned_entries.patch

File 07_fix_time_for_prune_and_do_not_readd_pruned_entries.patch, 4.5 KB (added by Janne <janne-mythtv@…>, 14 years ago)

fixes patch 03... and adds features

  • libs/libmythtv/eitcache.h

    === libs/libmythtv/eitcache.h
    ==================================================================
     
    1 /*
     1/* -*- Mode: c++ -*-
    22 * Copyright 2006 (C) Stuart Auchterlonie <stuarta at squashedfrog.net>
    33 * License: GPL v2
    44 */
     
    3737
    3838    QMutex      eventMapLock;
    3939
     40    uint        lastPruneTime;
     41
    4042    // statistics
    4143    uint        accessCnt;
    4244    uint        hitCnt;
    4345    uint        tblChgCnt;
    4446    uint        verChgCnt;
     47    uint        pruneCnt;
     48    uint        prunedHitCnt;
    4549
    4650    static const uint kVersionMax;
    4751};
  • libs/libmythtv/eithelper.cpp

    === libs/libmythtv/eithelper.cpp
    ==================================================================
     
    209209
    210210    for (uint i = 0; i < eit->EventCount(); i++)
    211211    {
     212        QDateTime starttime = MythUTCToLocal(eit->StartTimeUTC(i));
    212213        // Skip event if we have already processed it before...
    213214        if (!eitcache->IsNewEIT(eit->OriginalNetworkID(), eit->TSID(),
    214215                                eit->ServiceID(), eit->EventID(i),
    215216                                eit->TableID(), eit->Version(),
    216                                 eit->StartTimeKey(i)+eit->DurationInSeconds(i)))
     217                                starttime.toTime_t()+eit->DurationInSeconds(i)))
    217218        {
    218219            continue;
    219220        }
     
    319320        if (!chanid)
    320321            continue;
    321322
    322         QDateTime starttime = MythUTCToLocal(eit->StartTimeUTC(i));
    323323        EITFixUp::TimeFix(starttime);
    324324        QDateTime endtime   = starttime.addSecs(eit->DurationInSeconds(i));
    325325
  • libs/libmythtv/eitcache.cpp

    === libs/libmythtv/eitcache.cpp
    ==================================================================
     
    11// -*- Mode: c++ -*-
    22/*
    33 * Copyright 2006 (C) Stuart Auchterlonie <stuarta at squashedfrog.net>
     4 * Copyright 2006 (C) Janne Grunau <janne-mythtv at grunau.be>
    45 * License: GPL v2
    56 */
    67
     8
     9#include <iostream>
     10using namespace std;
     11
     12#include <qdatetime.h>
     13
    714#include "eitcache.h"
    8 #include <stdio.h>
     15#include "mythcontext.h"
    916
     17#define LOC "EITCache: "
     18
    1019// Highest version number. version is 5bits
    1120const uint EITCache::kVersionMax = 31;
    1221
    1322EITCache::EITCache()
    14     : accessCnt(0), hitCnt(0), tblChgCnt(0), verChgCnt(0)
     23    : accessCnt(0), hitCnt(0), tblChgCnt(0), verChgCnt(0),
     24      pruneCnt(0), prunedHitCnt(0)
    1525{
     26    // six hours ago
     27    lastPruneTime = QDateTime::currentDateTime().addSecs(-21600).toTime_t();
    1628}
    1729
    1830void EITCache::ResetStatistics(void)
     
    2133    hitCnt    = 0;
    2234    tblChgCnt = 0;
    2335    verChgCnt = 0;
     36    pruneCnt  = 0;
     37    prunedHitCnt = 0;
    2438}
    2539
    2640QString EITCache::GetStatistics(void)
     
    2842    QMutexLocker locker(&eventMapLock);
    2943    return QString(
    3044        "EITCache::statistics: Accesses: %1, Hits: %2, "
    31         "Table Upgrades %3, New Versions: %4, Entries: %5")
    32         .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt).arg(eventMap.size());
     45        "Table Upgrades %3, New Versions: %4, Entries: %5 "
     46        "Pruned entries: %6, pruned Hits: %7.")
     47        .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt)
     48        .arg(eventMap.size()).arg(pruneCnt).arg(prunedHitCnt);
    3349}
    3450
    3551static uint64_t construct_key(uint onid, uint tsid, uint serviceid, uint eventid)
     
    5672
    5773static uint extract_endtime(uint64_t sig)
    5874{
    59     return sig & 0xffff;
     75    return sig & 0xffffffff;
    6076}
    6177
    6278bool EITCache::IsNewEIT(const uint onid, const uint tsid,
     
    6682{
    6783    accessCnt++;
    6884
     85    // don't readd pruned entries
     86    if (endtime < lastPruneTime)
     87    {
     88        prunedHitCnt++;
     89        return false;
     90    }
     91
    6992    uint64_t key = construct_key(onid, tsid, serviceid, eventid);
    7093
    7194    QMutexLocker locker(&eventMapLock);
     
    101124
    102125uint EITCache::PruneOldEntries(uint timestamp)
    103126{
     127    QDateTime extime = QDateTime();
     128    extime.setTime_t(timestamp);
     129    VERBOSE(VB_EIT, LOC + QString("Pruning all entries that ended before %1,")
     130            .arg(extime.toString()));
     131
    104132    QMutexLocker locker(&eventMapLock);
    105133    uint size = eventMap.size();
     134
    106135    key_map_t::iterator it = eventMap.begin();
    107136    while (it != eventMap.end())
    108137    {
     
    116145        else
    117146            ++it;
    118147    }
    119     return size -  eventMap.size();
     148
     149    lastPruneTime = timestamp;
     150    size -= eventMap.size();
     151    prunedHitCnt += size;
     152    return size;
    120153}
    121154
    122155/* vim: set expandtab tabstop=4 shiftwidth=4: */