diff --git a/mythtv/programs/mythbackend/scheduler.cpp b/mythtv/programs/mythbackend/scheduler.cpp
index 49b291290f..a04fa53809 100644
a
|
b
|
void Scheduler::run(void)
|
2084 | 2084 | bool statuschanged = false; |
2085 | 2085 | QDateTime nextStartTime = MythDate::current().addDays(14); |
2086 | 2086 | QDateTime nextWakeTime = nextStartTime; |
2087 | | |
| 2087 | int numItersBeforeSleep = 0; |
2088 | 2088 | while (doRun) |
2089 | 2089 | { |
| 2090 | ++numItersBeforeSleep; |
| 2091 | LOG(VB_GENERAL, LOG_INFO, |
| 2092 | QString("At top of loop with nwt %1 nst %2 current time %3").arg(nextWakeTime.toString()).arg(nextStartTime.toString()).arg(MythDate::current().toString())); |
| 2093 | |
2090 | 2094 | // If something changed, it might have short circuited a pass |
2091 | 2095 | // through the list or changed the next run times. Start a |
2092 | 2096 | // new pass immediately to take care of anything that still |
2093 | 2097 | // needs attention right now and reset the run times. |
2094 | 2098 | if (reclist_changed) |
2095 | 2099 | { |
| 2100 | LOG(VB_GENERAL, LOG_INFO, |
| 2101 | QString("reclist_changed so resetting nextStartTime from %1").arg(nextStartTime.toString())); |
| 2102 | |
2096 | 2103 | nextStartTime = MythDate::current(); |
2097 | 2104 | reclist_changed = false; |
2098 | 2105 | } |
2099 | 2106 | |
| 2107 | LOG(VB_GENERAL, LOG_INFO, |
| 2108 | QString("About to set nextWakeTime to min of %1 and %2").arg(nextWakeTime.toString()).arg(nextStartTime.toString())); |
2100 | 2109 | nextWakeTime = min(nextWakeTime, nextStartTime); |
2101 | 2110 | QDateTime curtime = MythDate::current(); |
2102 | 2111 | int secs_to_next = curtime.secsTo(nextStartTime); |
| 2112 | LOG(VB_GENERAL, LOG_INFO, |
| 2113 | QString("secs_to_next is now %1 since nextStartTime %2 nextWakeTime %3 and schedRunTime %4 and ms2nwt %5").arg(secs_to_next).arg(nextStartTime.toString()).arg(nextWakeTime.toString()).arg(schedRunTime).arg(curtime.msecsTo(nextWakeTime))); |
| 2114 | |
2103 | 2115 | int sched_sleep = max(curtime.msecsTo(nextWakeTime), qint64(0)); |
| 2116 | |
2104 | 2117 | if (idleTimeoutSecs > 0) |
2105 | 2118 | sched_sleep = min(sched_sleep, 15000); |
2106 | 2119 | bool haveRequests = HaveQueuedRequests(); |
… |
… |
void Scheduler::run(void)
|
2114 | 2127 | { |
2115 | 2128 | if (sched_sleep) |
2116 | 2129 | { |
2117 | | LOG(VB_SCHEDULE, LOG_INFO, |
| 2130 | LOG(VB_GENERAL, LOG_INFO, |
2118 | 2131 | QString("sleeping for %1 ms " |
2119 | | "(s2n: %2 sr: %3 qr: %4 cs: %5)") |
| 2132 | "(s2n: %2 sr: %3 qr: %4 cs: %5) numItersBeforeSleep: %6") |
2120 | 2133 | .arg(sched_sleep).arg(secs_to_next).arg(schedRunTime) |
2121 | | .arg(haveRequests).arg(checkSlaves)); |
| 2134 | .arg(haveRequests).arg(checkSlaves).arg(numItersBeforeSleep)); |
| 2135 | numItersBeforeSleep = 0; |
2122 | 2136 | if (reschedWait.wait(&schedLock, sched_sleep)) |
| 2137 | { |
| 2138 | LOG(VB_GENERAL, LOG_INFO, |
| 2139 | QString("After sleeping for %1 ms wakeup and continue").arg(sched_sleep)); |
2123 | 2140 | continue; |
| 2141 | } |
| 2142 | LOG(VB_GENERAL, LOG_INFO, |
| 2143 | QString("After sleeping for %1 ms wakeup").arg(sched_sleep)); |
| 2144 | } |
| 2145 | else |
| 2146 | { |
| 2147 | LOG(VB_GENERAL, LOG_INFO, |
| 2148 | QString("NOT sleeping for %1 ms " |
| 2149 | "(s2n: %2 sr: %3 qr: %4 cs: %5)") |
| 2150 | .arg(sched_sleep).arg(secs_to_next).arg(schedRunTime) |
| 2151 | .arg(haveRequests).arg(checkSlaves)); |
2124 | 2152 | } |
2125 | 2153 | } |
2126 | 2154 | else |
2127 | 2155 | { |
| 2156 | LOG(VB_GENERAL, LOG_INFO, |
| 2157 | QString("In process segment with sched_sleep %1 ms " |
| 2158 | "(s2n: %2 sr: %3 qr: %4 cs: %5) numItersBeforeSleep :%6") |
| 2159 | .arg(sched_sleep).arg(secs_to_next).arg(schedRunTime) |
| 2160 | .arg(haveRequests).arg(checkSlaves).arg(numItersBeforeSleep)); |
| 2161 | |
2128 | 2162 | if (haveRequests) |
2129 | 2163 | { |
2130 | 2164 | // The master backend is a long lived program, so |
… |
… |
void Scheduler::run(void)
|
2147 | 2181 | } |
2148 | 2182 | schedRunTime = max(int(((t.elapsed() + 999) / 1000) * 1.5 + 2), |
2149 | 2183 | schedRunTime); |
| 2184 | LOG(VB_GENERAL, LOG_INFO, |
| 2185 | QString("schedRunTime is now %1 with statuschanged %2").arg(schedRunTime).arg(statuschanged)); |
2150 | 2186 | } |
2151 | 2187 | |
2152 | 2188 | if (firstRun) |
… |
… |
void Scheduler::run(void)
|
2172 | 2208 | |
2173 | 2209 | nextStartTime = MythDate::current().addDays(14); |
2174 | 2210 | nextWakeTime = lastSleepCheck.addSecs(kSleepCheck); |
| 2211 | LOG(VB_GENERAL, LOG_INFO, |
| 2212 | QString("Before skipping history with nwt %1 nst %2 lastSleepCheck %3").arg(nextWakeTime.toString()).arg(nextStartTime.toString()).arg(lastSleepCheck.toString())); |
| 2213 | |
2175 | 2214 | |
2176 | 2215 | // Skip past recordings that are already history |
2177 | 2216 | // (i.e. AddHistory() has been called setting oldrecstatus) |
… |
… |
void Scheduler::run(void)
|
2194 | 2233 | **it, statuschanged, nextStartTime, nextWakeTime, |
2195 | 2234 | prerollseconds); |
2196 | 2235 | } |
| 2236 | LOG(VB_GENERAL, LOG_INFO, |
| 2237 | QString("After HandleRecording with nwt %1 nst %2 prerollseconds %3 statuschanged %4 done %5 reclist_changed %6").arg(nextWakeTime.toString()).arg(nextStartTime.toString()).arg(prerollseconds).arg(statuschanged).arg(done).arg(reclist_changed)); |
2197 | 2238 | |
2198 | 2239 | // HandleRecording() temporarily unlocks schedLock. If |
2199 | 2240 | // anything changed, reclist iterators could be invalidated so |
2200 | 2241 | // start over. |
2201 | 2242 | if (reclist_changed) |
| 2243 | { |
| 2244 | LOG(VB_GENERAL, LOG_INFO, |
| 2245 | QString("reclist_changed after HandleRecording")); |
2202 | 2246 | continue; |
| 2247 | } |
2203 | 2248 | |
2204 | 2249 | /// Wake any slave backends that need waking |
2205 | 2250 | curtime = MythDate::current(); |
… |
… |
void Scheduler::run(void)
|
2214 | 2259 | |
2215 | 2260 | if (statuschanged) |
2216 | 2261 | { |
| 2262 | LOG(VB_GENERAL, LOG_INFO, |
| 2263 | QString("statuschanged so SCHEDULE_CHANGE")); |
| 2264 | |
2217 | 2265 | MythEvent me("SCHEDULE_CHANGE"); |
2218 | 2266 | gCoreContext->dispatch(me); |
2219 | 2267 | // a scheduler run has nothing to do with the idle shutdown |
… |
… |
void Scheduler::run(void)
|
2228 | 2276 | statuschanged); |
2229 | 2277 | if (idleSince.isValid()) |
2230 | 2278 | { |
| 2279 | LOG(VB_GENERAL, LOG_INFO, |
| 2280 | QString("Updating nextWakeTime after idleSince.isValid with idleSince %1 and idleTimeoutSecs %2 and curtime %3").arg(idleSince.toString()).arg(idleTimeoutSecs).arg(curtime.toString())); |
| 2281 | |
2231 | 2282 | nextWakeTime = MythDate::current().addSecs( |
2232 | 2283 | (idleSince.addSecs(idleTimeoutSecs - 10) <= curtime) ? 1 : |
2233 | 2284 | (idleSince.addSecs(idleTimeoutSecs - 30) <= curtime) ? 5 : 10); |
… |
… |
bool Scheduler::HandleRecording(
|
2665 | 2716 | // nothing later can shorten nextWakeTime, so stop scanning. |
2666 | 2717 | if (nextWakeTime.secsTo(nextrectime) - prerollseconds > 300) |
2667 | 2718 | { |
| 2719 | LOG(VB_GENERAL, LOG_INFO, |
| 2720 | QString("HandleRecording !WillRecord !Pending set nextStartTime to min %1 and %2").arg(nextStartTime.toString()).arg(nextrectime.toString())); |
2668 | 2721 | nextStartTime = min(nextStartTime, nextrectime); |
2669 | 2722 | return true; |
2670 | 2723 | } |
… |
… |
bool Scheduler::HandleRecording(
|
2683 | 2736 | // needs to be shorter than the related one in SchedLiveTV(). |
2684 | 2737 | if (secsleft - prerollseconds > 60) |
2685 | 2738 | { |
| 2739 | LOG(VB_GENERAL, LOG_INFO, |
| 2740 | QString("HandleRecording secsleft-preroll>60: set nextStartTime to min %1 and %2").arg(nextStartTime.toString()).arg(nextrectime.addSecs(-30).toString())); |
| 2741 | |
2686 | 2742 | nextStartTime = min(nextStartTime, nextrectime.addSecs(-30)); |
2687 | 2743 | nextWakeTime = min(nextWakeTime, |
2688 | 2744 | nextrectime.addSecs(-prerollseconds - 60)); |
… |
… |
bool Scheduler::HandleRecording(
|
2702 | 2758 | |
2703 | 2759 | if (secsleft - prerollseconds > 35) |
2704 | 2760 | { |
| 2761 | LOG(VB_GENERAL, LOG_INFO, |
| 2762 | QString("HandleRecording secleft-prefroll>35: set nextStartTime to min %1 and %2").arg(nextStartTime.toString()).arg(nextrectime.addSecs(-30).toString())); |
| 2763 | |
2705 | 2764 | nextStartTime = min(nextStartTime, nextrectime.addSecs(-30)); |
2706 | 2765 | nextWakeTime = min(nextWakeTime, |
2707 | 2766 | nextrectime.addSecs(-prerollseconds - 35)); |
… |
… |
bool Scheduler::HandleRecording(
|
2765 | 2824 | |
2766 | 2825 | if (secsleft - prerollseconds > 30) |
2767 | 2826 | { |
| 2827 | LOG(VB_GENERAL, LOG_INFO, |
| 2828 | QString("HandleRecording secleft-preroll>30: set nextStartTime to min %1 and %2").arg(nextStartTime.toString()).arg(nextrectime.addSecs(-30).toString())); |
| 2829 | |
2768 | 2830 | nextStartTime = min(nextStartTime, nextrectime.addSecs(-30)); |
2769 | 2831 | nextWakeTime = min(nextWakeTime, |
2770 | 2832 | nextrectime.addSecs(-prerollseconds - 30)); |
… |
… |
bool Scheduler::HandleRecording(
|
2803 | 2865 | EnqueuePlace("SlaveNotAwake"); |
2804 | 2866 | } |
2805 | 2867 | |
| 2868 | LOG(VB_GENERAL, LOG_INFO, |
| 2869 | QString("HandleRecording isWaking: set nextStartTime to min %1 and %2").arg(nextStartTime.toString()).arg(nextrectime.toString())); |
| 2870 | |
2806 | 2871 | nextStartTime = min(nextStartTime, nextrectime); |
2807 | 2872 | nextWakeTime = min(nextWakeTime, curtime.addSecs(1)); |
2808 | 2873 | return false; |
… |
… |
bool Scheduler::HandleRecording(
|
2846 | 2911 | |
2847 | 2912 | if (secsleft - prerollseconds > 0) |
2848 | 2913 | { |
| 2914 | LOG(VB_GENERAL, LOG_INFO, |
| 2915 | QString("HandleRecording secsleft-preroll>0: set nextStartTime to min %1 and %2").arg(nextStartTime.toString()).arg(nextrectime.toString())); |
| 2916 | |
2849 | 2917 | nextStartTime = min(nextStartTime, nextrectime); |
2850 | 2918 | nextWakeTime = min(nextWakeTime, |
2851 | 2919 | nextrectime.addSecs(-prerollseconds)); |