LRESULT SpyFrame::onTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) { m_needsUpdateTime = true;//[+]IRainman refactoring SpyFrame if (!MainFrame::isAppMinimized(m_hWnd) && !isClosedOrShutdown())// [+] IRainman opt { auto s = new Stats; for (size_t i = 0; i < AVG_TIME; ++i) s->m_perM += m_perSecond[i]; s->m_perS = s->m_perM / AVG_TIME; m_tasks.add(TICK_AVG, s); } { if (m_current++ >= AVG_TIME) m_current = 0; m_perSecond[m_current] = 0; } if (m_log) { m_tasks.add(SAVE_LOG, nullptr); } doTimerTask(); return 0; }
/* void StatsFrame::addTick(int64_t bdiff, uint64_t tdiff, StatList& lst, AvgList& avg, int scroll) { int64_t bspeed = calcSpeed(bdiff, tdiff); avg.push_front(bspeed); bspeed = 0; for (auto ai = avg.cbegin(); ai != avg.cend(); ++ai) { bspeed += *ai; } bspeed /= avg.size(); updateStatList(bspeed, lst, scroll); while (avg.size() > SPEED_APPROXIMATION_INTERVAL_S) { avg.pop_back(); } } */ LRESULT StatsFrame::onTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { const uint64_t tick = MainFrame::getLastUpdateTick(); const uint64_t tdiff = tick - lastTick; if (tdiff == 0) return 0; const uint64_t scrollms = (tdiff + scrollTick) * PIX_PER_SEC; const uint64_t scroll = scrollms / 1000; if (scroll == 0) return 0; scrollTick = scrollms - (scroll * 1000); CRect rc; GetClientRect(rc); rc.left = twidth; ScrollWindow(-((int)scroll), 0, rc, rc); const int64_t d = MainFrame::getLastDownloadSpeed(); //const int64_t ddiff = d - m_lastSocketsDown; const int64_t u = MainFrame::getLastUploadSpeed(); //const int64_t udiff = u - m_lastSocketsUp; const int64_t dt = DownloadManager::getRunningAverage(); const int64_t ut = UploadManager::getRunningAverage(); // [~]IRainman //addTick(ddiff, tdiff, m_DownSockets, m_DownSocketsAvg, (int)scroll); //addTick(udiff, tdiff, m_UpSockets, m_UpSocketsAvg, (int)scroll); addAproximatedSpeedTick(d, m_DownSockets, (int)scroll); addAproximatedSpeedTick(u, m_UpSockets, (int)scroll); addAproximatedSpeedTick(dt, m_Downloads, (int)scroll); addAproximatedSpeedTick(ut, m_Uploads, (int)scroll); StatIter i; int64_t mspeed = 0; findMax(m_DownSockets, i, mspeed); findMax(m_UpSockets, i, mspeed); // [+]IRainman findMax(m_Downloads, i, mspeed); findMax(m_Uploads, i, mspeed); // [~]IRainman if (mspeed > m_max || ((m_max * 3 / 4) > mspeed)) { m_max = mspeed + 1;// [!] IRainman fix: +1 Invalidate(); } lastTick = tick; //m_lastSocketsUp = u; //m_lastSocketsDown = d; doTimerTask(); return 0; }